Annotated edit history of
Elisp version 9, including all changes.
View license author blame.
Rev |
Author |
# |
Line |
8 |
AristotlePagaltzis |
1 |
The [LISP]-based scripting language used to customise the [Emacs] programmers' editor. |
6 |
GlynWebster |
2 |
|
|
|
3 |
Emacs is completely scriptable in Elisp - look in /usr/share/emacs/site-lisp/*.el for the start-up and config files. |
|
|
4 |
|
|
|
5 |
''[Programming in Emacs Lisp | http://www.delorie.com/gnu/docs/emacs-lisp-intro/emacs-lisp-intro.html]'' is an online book about Emacs scripting by Robert J. Chassell. It does not assume you already know Lisp. |
|
|
6 |
|
|
|
7 |
!!! Note for Lisp programmers |
|
|
8 |
ELisp is __dynamically scoped__. This affects how global variables in function definitions are looked up. With dynamic scoping the interpreter looks up these variables in the environment where the function is ''called''. What other [LISP] do is to use the variable definitions that were present when the function was ''defined'' (i.e. ''lexical scoping''). This difference will only effect you if you are trying to do lots of [higher-order functional programming | HigherOrderFunctions] in ELisp, but if you do, it will trip you up. |
|
|
9 |
|
|
|
10 |
!!!Example |
|
|
11 |
|
|
|
12 |
This sets up the F12 key to instantly save and close a file that Emacs is editing: |
|
|
13 |
|
|
|
14 |
(defun begins-with-p (str sub) |
|
|
15 |
"True if string `str' begins with substring `sub'." |
|
|
16 |
(and (>= (length str) (length sub)) |
|
|
17 |
(string= (substring str 0 (length sub)) sub))) |
|
|
18 |
|
|
|
19 |
(defun put-away-buffer (&optional buffer) |
|
|
20 |
"This kills a buffer, saving its contents first, if necessary. |
|
|
21 |
Internal and *scratch* buffers are ignored." |
|
|
22 |
(interactive) |
|
|
23 |
(unless buffer |
|
|
24 |
(setq buffer (current-buffer))) |
|
|
25 |
(unless (or (begins-with-p (buffer-name buffer) " ") ;ignore internal buffers |
|
|
26 |
(string= "*scratch*" (buffer-name buffer))) ;ignore scratch buffer |
|
|
27 |
(when (and (buffer-file-name buffer) ;is visiting a file |
|
|
28 |
(buffer-modified-p buffer)) |
|
|
29 |
(save-buffer)) |
|
|
30 |
(kill-this-buffer))) |
|
|
31 |
|
7 |
GlynWebster |
32 |
(global-set-key [[f12] #'put-away-buffer) |
6 |
GlynWebster |
33 |
|
|
|
34 |
---- |
9 |
AristotlePagaltzis |
35 |
CategoryProgrammingLanguages, CategoryFunctionalProgrammingLanguages |