-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path012_more_elisp.el
140 lines (96 loc) · 2.61 KB
/
012_more_elisp.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
;; To run: M-x ielm RET
;; To run buffer: M-x eval-buffer
;; To run ONE line; M-x eval-region
;; **Position AFTER code; C-x C-e evaluates**
;; exampes: let, defun, eval, substring, concat
(+ 4 5)
emacs-version
buffer-file-name
;; use fill-column (width); it is a symbol and need to evaluate it
(concat "The " (number-to-string (+ 2 fill-column)) " red foxes")
;; shocking, it evaluates to itself, letter a
(eval "a")
;; remember 1st step is to evaluate arguments, even if trivial
(concat "a" "b")
;; elisp zero-based; FROM TO (TO means up to and NOT including)
;; "cd"
(substring "abcd" 2 4)
;; setq takes w aruguments, here second is list
;; x is symbol, but in this case setq requires it be literal (??)
;; does two things, prints (rose violet)
;; side effect: symbol x points to list
(setq x '(rose violet))
;; but this is error, b/c literal (????)
(eval x)
;; return itself
(eval 'x)
;; function
(defun add-nums (+ a b) )
(add-nums 2 3)
;; lambda
((lambda (number) (* number 7)) 3)
;; nreverse
(nreverse '(1 2 3 4))
(nreverse (1 2 3 4)) # error
(reverse abc) # error
(def rac (lambda (abc) (car(nreverse abc))) # OK
rac(abc) # error
(def rac (lambda (abc)) (car (reverse abc)))
;; load, import library
(require 'ert)
;; return logical
(equal 5 5)
;; if-then
(if (< 0 4) "yes" "no")
;; predicate; no space before p
(numberp 1.1)
(number p "a")
;; REGISTERS
;; set-register to open a file (C-x C-3 AFTER code)
(set-register ?i (cons 'file "~/code/elisp_project/second"))
(set-register ?r (cons 'file "~/code/docs/tech_notes/310_R_notes.qmd")
(set-register ?z (cons 'file "~/code/elisp_project/second"))
;; TODO set and use a variable using `let`
(let (z "A"))
(let z "A")
(t "B")
(message "item %s" z)
;; (message "Item %s and %s" z t)
)
)
;; LOCAL VARIABLE
;; Create local variable
(defvar jim_var nil "Your documentation here.")
(set (make-local-variable 'jim_var) <the-value>)
;; position AFTER ) C-x C-e
(buffer-file-name)
;; evaluates to itsef
'(5 6 "A")
;;
?A
;; 10
?\n
?C-c
;; ^c
(kbd "C-c")
;; list, self-evaluates to itself?
;; but a macro, would evaluate (??)
[1 2 (+ 1 2)]
[+ 2 (+ 1 2)]
(+ 2 (+ 1 2))
;; defun
;; then use C-u 5; M-x multiply-by-seven(
(defun multiply-by-seven (number) ; Interactive version.
"Multiply NUMBER by seven."
(interactive "p")
(message "The result is %d" (* 7 number)))
;; TODO:
(defun my_name ()
"Returns my name."
(interactive "p")
(message "your name is jim"))
;; assign variable (?) zebra value `stripes`
(let ((zebra "stripes")
(tiger "fierce"))
(message "One kind of animal has %s and another is %s."
zebra tiger))