Difference between revisions of "Emacs Lisp"

From WikEmacs
Jump to: navigation, search
m
(formatting and add 2 links)
 
(5 intermediate revisions by 3 users not shown)
Line 1: Line 1:
Emacs Lisp is a dialect of the [[Lisp]] programming language used by GNU Emacs. Most of the editing functionality built into Emacs is written in Emacs Lisp, with the remainder being written in C (as is the Lisp interpreter itself). Users of Emacs commonly write Emacs Lisp code to customize and extend Emacs.
+
{{Infobox major-mode
 +
|title = Emacs Lisp
 +
|library = lisp-mode
 +
|command = emacs-lisp-mode
 +
|builtin = yes
 +
|auto activates = *.el, .emacs, _emacs
 +
}}
 +
'''Emacs Lisp''' is a dialect of the [[Lisp]] programming language used by GNU Emacs. Most of the editing functionality built into Emacs is written in Emacs Lisp, with the remainder being written in C (as is the Lisp interpreter itself). Users of Emacs commonly write Emacs Lisp code to customize and extend Emacs.
  
 
Emacs Lisp is also commonly referred to as "elisp" or "Elisp". Files containing Emacs Lisp code use the <tt>.el</tt> filename suffix; when [[byte-compile]]d, the same filename prefix is used but with the <tt>.elc</tt> filename suffix.
 
Emacs Lisp is also commonly referred to as "elisp" or "Elisp". Files containing Emacs Lisp code use the <tt>.el</tt> filename suffix; when [[byte-compile]]d, the same filename prefix is used but with the <tt>.elc</tt> filename suffix.
Line 5: Line 12:
 
Emacs Lisp is a [https://hornbeck.wordpress.com/2009/07/05/lisp-1-vs-lisp-2/ Lisp-2], which means that a single identifier (in Lisp terminology, "symbol") can simultaneously exist as ("be bound to") both a function and a variable.
 
Emacs Lisp is a [https://hornbeck.wordpress.com/2009/07/05/lisp-1-vs-lisp-2/ Lisp-2], which means that a single identifier (in Lisp terminology, "symbol") can simultaneously exist as ("be bound to") both a function and a variable.
  
= Basic setup =
+
== Basic setup ==
  
 
You can customize the way Emacs edits and displays this and all other [[:Category:Lisp|lisp languages]] with  {{CustomizeGroup|lisp}}.
 
You can customize the way Emacs edits and displays this and all other [[:Category:Lisp|lisp languages]] with  {{CustomizeGroup|lisp}}.
  
= Helpful keybindings =
+
== Helpful keybindings ==
  
; {{Keys|M-<tab>}}
+
; {{Keys|M-TAB}}
 
: Complete at point
 
: Complete at point
  
Line 17: Line 24:
 
: Indent the [[S-expression]] following [[point and mark|point]]
 
: Indent the [[S-expression]] following [[point and mark|point]]
  
;{{Keys|C-M-x}}
+
; {{Keys|C-M-x}}
 
: Evaluate the <code>defun</code> at [[point and mark|point]]
 
: Evaluate the <code>defun</code> at [[point and mark|point]]
  
= Common customizations =
+
== Common customizations ==
  
== Outlining ==
+
=== Outlining ===
  
 
For [[Org]]-style outlining, add the following snippet to your {{EmacsConfigFile}}.
 
For [[Org]]-style outlining, add the following snippet to your {{EmacsConfigFile}}.
Line 39: Line 46:
 
Now visit any elisp file (say {{Command|find-library RET outline}}) and keep pressing {{Keys|S-TAB}} and see what happens.  Experiment similarly with {{Keys|C-TAB}}.
 
Now visit any elisp file (say {{Command|find-library RET outline}}) and keep pressing {{Keys|S-TAB}} and see what happens.  Experiment similarly with {{Keys|C-TAB}}.
  
== Indentation ==
+
=== Indentation ===
  
 
Add the following snippet to your {{EmacsConfigFile}}, so that you don't have to indent deliberately. See {{Command|reindent-then-newline-and-indent}}.
 
Add the following snippet to your {{EmacsConfigFile}}, so that you don't have to indent deliberately. See {{Command|reindent-then-newline-and-indent}}.
Line 49: Line 56:
 
</source>
 
</source>
  
== Always keep parentheses balanced ==
+
=== Always keep parentheses balanced ===
  
 
See [[Skeleton#Keep some chars always balanced]]
 
See [[Skeleton#Keep some chars always balanced]]
  
== Scope ==
+
=== Scope ===
 
By default elisp uses [[dynamic scope]]. Since Emacs 24 [[lexical scope]] has been added. <br/>
 
By default elisp uses [[dynamic scope]]. Since Emacs 24 [[lexical scope]] has been added. <br/>
 
To use lexical binding, an Emacs-lisp source file must set a file-variable {{Variable|lexical-binding}} to <tt>t</tt> in the file header, e.g., by using a first line like: <br/>
 
To use lexical binding, an Emacs-lisp source file must set a file-variable {{Variable|lexical-binding}} to <tt>t</tt> in the file header, e.g., by using a first line like: <br/>
Line 59: Line 66:
 
     ;;; -*- lexical-binding: t -*-
 
     ;;; -*- lexical-binding: t -*-
  
= External links =
+
== External links ==
  
 
* [http://www.gnu.org/software/emacs/manual/html_node/elisp/index.html Emacs Lisp manual]
 
* [http://www.gnu.org/software/emacs/manual/html_node/elisp/index.html Emacs Lisp manual]
 +
* [http://libreplanet.org/wiki/Programming_in_elisp Programming in elisp], libreplanet.org wiki
 +
* [http://www.emacswiki.org/emacs/EmacsLisp EmacsLips], from emacswiki.org
  
[[Category:Emacs User]][[Category:Emacs Contributor]][[Category:Intermediate]][[Category:Lisp]]
+
 
 +
[[Category:Lisp]]
 +
[[Category:Emacs Lisp]]
 +
[[Category:Programming]]
 +
[[Category:Programming languages]]

Latest revision as of 13:35, 29 April 2013

Emacs Lisp
Library lisp-mode
Command emacs-lisp-mode
Builtin yes
Auto-activates for *.el, .emacs, _emacs


Emacs Lisp is a dialect of the Lisp programming language used by GNU Emacs. Most of the editing functionality built into Emacs is written in Emacs Lisp, with the remainder being written in C (as is the Lisp interpreter itself). Users of Emacs commonly write Emacs Lisp code to customize and extend Emacs.

Emacs Lisp is also commonly referred to as "elisp" or "Elisp". Files containing Emacs Lisp code use the .el filename suffix; when byte-compiled, the same filename prefix is used but with the .elc filename suffix.

Emacs Lisp is a Lisp-2, which means that a single identifier (in Lisp terminology, "symbol") can simultaneously exist as ("be bound to") both a function and a variable.

Basic setup[edit]

You can customize the way Emacs edits and displays this and all other lisp languages with M-x customize-group RET lisp RET.

Helpful keybindings[edit]

[M-TAB]
Complete at point
[C-M-q]
Indent the S-expression following point
[C-M-x]
Evaluate the defun at point

Common customizations[edit]

Outlining[edit]

For Org-style outlining, add the following snippet to your Emacs configuration file.

;; Turn on outline minor mode
(add-hook 'emacs-lisp-mode-hook  'outline-minor-mode)
 
;; Add key bindings for Org-style outline cycling
(add-hook 'outline-minor-mode-hook
  (lambda ()
    (define-key outline-minor-mode-map [(control tab)] 'org-cycle)
    (define-key outline-minor-mode-map [(shift tab)] 'org-global-cycle)))

Now visit any elisp file (say M-x find-library RET outline) and keep pressing [S-TAB] and see what happens. Experiment similarly with [C-TAB].

Indentation[edit]

Add the following snippet to your Emacs configuration file, so that you don't have to indent deliberately. See M-x reindent-then-newline-and-indent.

(add-hook 'emacs-lisp-mode-hook
	  (lambda nil
	    (local-set-key [(return)] 'reindent-then-newline-and-indent)))

Always keep parentheses balanced[edit]

See Skeleton#Keep some chars always balanced

Scope[edit]

By default elisp uses dynamic scope. Since Emacs 24 lexical scope has been added.
To use lexical binding, an Emacs-lisp source file must set a file-variable lexical-binding to t in the file header, e.g., by using a first line like:

   ;;; -*- lexical-binding: t -*-

External links[edit]