-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEmacs-Lisp-Tutorial.el
173 lines (125 loc) · 3.3 KB
/
Emacs-Lisp-Tutorial.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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
(+ 2 2)
4
(+ 2 (+ 1 1))
4
(+ 3 (+ 1 2))
(setq my-name "Bastien")
"Bastien"
(insert "Hello!")Hello!
Hello!nil
(insert "Hello" " world!" )
Hello world!nil
(defun hello ()(insert "Hello, I am " my-name))
hello
(hello)
Hello, I am Bastiennil
(defun hello ()(insert "Hello, I am " my-name))
hello
(defun hello (name)
(insert "Hello " name)
)
hello
(hello "you")
Hello younil
(switch-to-buffer-other-window "*test*")
#<buffer *test*>
(progn
(switch-to-buffer-other-window "*test*")
(hello "you"))
nil
(progn (switch-to-buffer-other-window "*test*")
(erase-buffer)
(hello "there"))
(progn (switch-to-buffer-other-window "*test*")
(erase-buffer)
(hello "you")
(other-window 1))
nil
(let* ((local-name "you"))
(switch-to-buffer-other-window "*test*")
(erase-buffer)
(hello local-name)
(other-window 1)
)
nil
(format "Hello %s!\n" "visitor")
"Hello visitor!
"
(defun hello (name)
(insert (format "Hello %s!\n" name))
)
hello
(hello "you")
Hello you!
nil
(defun greeting (name)
(let ((your-name "Bastien"))
)
(insert (format "Hello %s!\n\nI am %s." name your-name))
)
(greeting "you")Hello you!
I am nil.
(defun greeting (name)
(let ((your-name "Bastien"))
(insert (format "Hello %s!\n\nI am %s."
name ; the argument of the function
your-name ; the let-bound variable "Bastien"
))))
(greeting "you")Hello you!
I am Bastien.
(read-from-minibuffer "Enter your name: ")
(defun greeting (from-name)
(let ((your-name (read-from-minibuffer "Enter your name: ")))
(switch-to-buffer-other-window "*test*")
(erase-buffer)
(insert (format "Hello %s!\n\nI am %s." your-name from-name))
(other-window 1)))
(greeting "Bastien")
(defun greeting (from-name)
(let ((your-name (read-from-minibuffer "Enter your name: ")))
(switch-to-buffer-other-window "*test*")
(erase-buffer)
(insert (format "Hello %s!\n\nI am %s." your-name from-name))
(other-window 1)))
(greeting "Bastien")
(setq list-of-names '("Sarah" "Chloe" "Mathilde"))
(setq list-of-names '("Sarah" "Chloe" "Mathilde"))
(car list-of-names)
(cdr list-of-names)
(push "Stephanie" list-of-names)
(mapcar 'hello list-of-names)Hello StephanieHello StephanieHello SarahHello ChloeHello Mathilde
(defun greeting ()
(switch-to-buffer-other-window "*test*")
(erase-buffer)
(mapcar 'hello list-of-names)
(other-window 1))
(greeting)
(defun greeting ()
(switch-to-buffer-other-window "*test*")
(erase-buffer)
(mapcar 'hello list-of-names)
(other-window 1)
)
(greeting)
(defun replace-hello-by-bonjour ()
(switch-to-buffer-other-window "*test*")
(goto-char (point-min))
(while (search-forward "Hello")
(replace-match "Bonjour"))
(other-window 1))
(defun replace-hello-by-bonjour ()
(switch-to-buffer-other-window "*test*")
(goto-char (point-min))
(while (search-forward "Hello" nil 't)
(replace-match "Bonjour"))
(other-window 1))
(replace-hello-by-bonjour)
(defun boldify-names ()
(switch-to-buffer-other-window "*test*")
(goto-char (point-min))
(while (re-search-forward "Bonjour \\(.+\\)!" nil 't)
(add-text-properties (match-beginning 1)
(match-end 1)
(list 'face 'bold)))
(other-window 1))
(boldify-names)