Difference between revisions of "Emacs Lisp"

From WikEmacs
Jump to navigation Jump to search
(extended the overview a bit)
Line 1: Line 1:
 +
Emacs Lisp is a dialect of the Lisp programming language used by GNU Emacs. It is used for implementing most of the editing functionality built into Emacs, 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 prefix is used but with the <tt>.elc</tt> filename suffix.
''(a short overview should go here)''
 
 
 
Also known as "elisp" or "Elisp". Files containing Emacs Lisp code use the <tt>.el</tt> filename suffix; when [[byte-compile]]d, the same prefix is used but with the <tt>.elc</tt> filename suffix.
 
  
 
= Basic setup =
 
= Basic setup =
Line 51: Line 49:
 
== Scope ==
 
== Scope ==
 
By default elisp using [[dynamic scope]]. Since Emacs 24 [[lexical scope]] has been added. <br/>
 
By default elisp using [[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 `lexical-binding’ to t 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 `lexical-binding’ to t in the file header, e.g., by using a first line like: <br/>
  
 
     ;;; -*- lexical-binding: t -*-
 
     ;;; -*- lexical-binding: t -*-

Revision as of 12:26, 28 March 2012

Emacs Lisp is a dialect of the Lisp programming language used by GNU Emacs. It is used for implementing most of the editing functionality built into Emacs, 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 prefix is used but with the .elc filename suffix.

Basic setup

You can customize this and all other lisp languages with M-x customize-group RET lisp RET.

Helpful keybindings

<span title="Try `C-h k M-<tab>' for more information." style="border-bottom
1px dotted">[M-<tab>]
Complete at point
[C-M-q]
Indent the sexp following point
[C-M-x]
Evaluate the defun at point

Common customizations

Outlining

For Org-style outlining, add the following snippet to your init.el or .emacs 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

Add the following snippet to your init.el or .emacs 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)))

Scope

By default elisp using 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