397 captures
03 Jun 2004 - 13 Jan 2026
Mar APR May
24
2012 2013 2014
success
fail

About this capture

COLLECTED BY

Organization: Internet Archive

The Internet Archive discovers and captures web pages through many different web crawls. At any given time several distinct crawls are running, some for months, and some every day or longer. View the web archive through the Wayback Machine.

Collection: Wide Crawl started April 2013

Web wide crawl with initial seedlist and crawler configuration from April 2013.
TIMESTAMPS

The Wayback Machine - http://web.archive.org/web/20130424040527/http://en.wikipedia.org/wiki/Emacs_Lisp
 



Emacs Lisp

 

From Wikipedia, the free encyclopedia
 

Jump to: navigation, search  

Emacs Lisp is a dialect of the Lisp programming language used by the GNU Emacs and XEmacs text editors (which this article will refer to collectively as "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). Emacs Lisp is also referred to as Elisp, although there is also an older, unrelated Lisp dialect with that name.

Users of Emacs commonly write Emacs Lisp code to customize and extend Emacs. Other options include the "Customize" feature that's in GNU Emacs since version 20. This provides a set of preference pages and when the user saves their preferences, Customize writes the necessary Emacs Lisp code.

Emacs Lisp can also function as a scripting language, much like the Unix Bourne shellorPython, by calling Emacs in "batch mode". In this way it may be called from the command line or via an executable file, and its editing functions, such as buffers and movement commands are available just as in the normal mode.

Contents

[edit] Compared to other Lisp dialects

In terms of features, it is closely related to the Maclisp dialect, with some later influence from Common Lisp.[1] It supports imperative and functional programming methods. Richard Stallman chose Lisp as the extension language for his rewrite of Emacs (the original used TECO as its extension language) because of its powerful features, including the ability to treat functions as data. Unlike Common Lisp, Scheme existed at the time Stallman was rewriting Gosling Emacs into GNU Emacs, but he chose not to use it because of its comparatively poor performance on workstations, and he wanted to develop a dialect which he thought would be more easily optimized.[2]

The Lisp dialect used in Emacs differs substantially from the more modern Common Lisp and Scheme dialects commonly used for applications programming. For example: Emacs Lisp uses dynamic rather than lexical scope by default (see below). That is, a function can reference local variables within the scope that it is called in, and not in the one that it was defined.

[edit] Example

To understand the logic behind Emacs Lisp, it's important to remember that there is an emphasis on providing data structures and features specific to making a versatile text edit.

Here follows a simple example of an Emacs extension written in Emacs Lisp. In Emacs, the editing area can be split into separate areas called windows, each displaying a different buffer. A buffer is a region of text loaded into Emacs' memory (possibly from a file) which can be saved into a text document.

Users issue the "C-x 2" command to open a new window. This runs the Emacs Lisp function split-window-vertically. Normally, when the new window appears, it displays the same buffer as the previous one. Suppose we wish to make it display the next available buffer. In order to do this, the user writes the following Emacs Lisp code, in either an existing Emacs Lisp source file or an empty Emacs buffer:

(defun my-split-window-func ()
    (interactive)
    (split-window-vertically)
    (set-window-buffer (next-window) (other-buffer)))
 
(global-set-key "\C-x2" 'my-split-window-func )

The first statement, (defun ...), defines a new function, my-split-window-func, which calls split-window-vertically (the old window-splitting function), then tells the new window to display another (new) buffer. The second statement, (global-set-key ...) re-binds the key sequence "C-x 2" to the new function.

This can also be written using the feature called advice, which allows the user to create wrappers around existing functions instead of defining their own. This has the advantage of being simpler to write but the disadvantage of making debugging more complicated. For this reason, advice is not allowed in the source code of GNU Emacs itself,[3] but if a user wishes, the advice feature can be used in their own code to reimplement the above code as follows:

(defadvice split-window-vertically
    (after my-window-splitting-advice first () activate)
    (set-window-buffer (next-window) (other-buffer)))

This instructs split-window-vertically to execute the user-supplied code whenever it is called, before executing the rest of the function.

These changes take effect at code evaluation time, using (for instance) the command "M-x eval-buffer" flag. It is not necessary to recompile or even restart Emacs. If the code is saved into the Emacs "init file" (usually a file named ".emacs" in the user's home directory), then Emacs will load the extension the next time it starts. Otherwise, the changes will be lost when the user exits Emacs.

[edit] Source code

In file-systems, Emacs Lisp code exists as plain text files with the filename suffix ".el" (a common exception, the user's init file, often appears or appeared as ".emacs".) When the files are loaded, an interpreter component of the Emacs program reads and parses the functions and variables, storing them in memory. They are then available to other editing functions, and to user commands. Functions and variables can be freely modified and re-loaded.

In order to save time and memory space, much of the functionality of Emacs loads only when required. Each set of optional features is implemented by a collection of Emacs code called a "library". For example, there is a library for highlighting keywords in program source code, and a library for playing the game of Tetris. Each library is implemented using one or more Emacs Lisp source files.

Emacs developers write certain functions in C. These are "primitives", also known as "built-in functions" or "subrs". Although primitives can be called from Lisp code, they can only be modified by editing the C source files and recompiling. In GNU Emacs, primitives are not available as external libraries; they are part of the Emacs executable. In XEmacs, runtime loading of such primitives is possible, using the operating system's support for dynamic linking. Functions may be written as primitives because they need access to external data and libraries not otherwise available from Emacs Lisp, or because they are called often enough that the comparative speed of C versus Emacs Lisp makes a worthwhile difference.

However, because errors in C code can easily lead to segmentation violations or to more subtle bugs, which crash the editor, and because writing C code that interacts correctly with the Emacs Lisp garbage collector is error-prone, relatively few functions are implemented as primitives.

[edit] Byte code

"Byte-compilation" can make Emacs Lisp code faster. Emacs contains a compiler which can translate Emacs Lisp source files into a special representation known as bytecode. Emacs Lisp bytecode files have the filename suffix ".elc". Compared to source files, bytecode files load faster, occupy less space on the disk, use less memory when loaded, and run faster.

Bytecode still runs more slowly than primitives, but functions loaded as bytecode can be easily modified and re-loaded. In addition, bytecode files are platform-independent. The standard Emacs Lisp code distributed with Emacs is loaded as bytecode, although the matching source files are usually provided for the user's reference as well. User-supplied extensions are typically not byte-compiled, as they are neither as large nor as computationally intensive.

[edit] Language features

Notably, the "cl" package implements a fairly large subset of Common Lisp.

Emacs Lisp (unlike some other Lisp implementations) does not do tail-call optimization.[4] Without this, tail recursions can eventually lead to stack overflow.

The apel library aids in writing portable Emacs Lisp code, with the help of the polysylabi platform bridge.

[edit] From dynamic to lexical scoping

Emacs Lisp uses dynamic scope, offering static (or lexical) as an option starting from version 24.[5] It can be activated by setting the file local variable lexical-binding.[6][7]

In dynamic scoping, if a programmer declares a variable within the scope of a function, it is available to subroutines called from within that function. Originally, this was intended as an optimization; lexical scoping was still uncommon and of uncertain performance.[8] Dynamic scoping was also meant to provide greater flexibility for user customizations. However, dynamic scoping has several disadvantages. Firstly, it can easily lead to bugs in large programs, due to unintended interactions between variables in different functions. Secondly, accessing variables under dynamic scoping is generally slower than under lexical scoping.

Also, the lexical-let macro in the "cl" package does provide effective lexical scope to Emacs Lisp programmers, but while `cl' is widely used, lexical-let is rarely used.

[edit] Discouraged features

After decades of evolution, some features have become deprecated or replaced, and other features are now supported for Emacs users but their use is not allowed in the Emacs source code itself. defadvice and letf are two examples of the latter, of which Richard Stallman says "it makes for confusion in debugging. (...) Users can use these features -- the only people they might confuse are themselves, (....) However, in our code, we should handle these situations in other ways."[9] Adding new hooks can sometimes provide what's necessary to replace advice.[10]

[edit] Footnotes

  1. ^ "GNU Emacs Lisp is largely inspired by Maclisp, and a little by Common Lisp. If you know Common Lisp, you will notice many similarities. However, many features of Common Lisp have been omitted or simplified in order to reduce the memory requirements of GNU Emacs. Sometimes the simplifications are so drastic that a Common Lisp user might be very confused. We will occasionally point out how GNU Emacs Lisp differs from Common Lisp." — from the "History" section of the "Introduction" to the Emacs Lisp Manual, as of Emacs 21
  • ^ "So the development of that operating system, the GNU operating system, is what led me to write the GNU Emacs. In doing this, I aimed to make the absolute minimal possible Lisp implementation. The size of the programs was a tremendous concern. There were people in those days, in 1985, who had one-megabyte machines without virtual memory. They wanted to be able to use GNU Emacs. This meant I had to keep the program as small as possible." — from "My Lisp Experiences and the Development of GNU Emacs"
  • ^ https://lists.gnu.org/archive/html/emacs-devel/2012-12/msg00146.html
  • ^ "Lisp programmers will want to note that the current Emacs Lisp compiler does not optimize tail recursion. "[1]
  • ^ "Emacs 24.1 released". 
  • ^ http://lists.gnu.org/archive/html/emacs-devel/2011-04/msg00043.html
  • ^ http://www.emacswiki.org/emacs/DynamicBindingVsLexicalBinding#toc8
  • ^ "Emacs Lisp uses dynamic scoping because simple implementations of lexical scoping are slow."[2][dead link]; "I asked RMS when he was implementing emacs lisp why it was dynamically scoped and his exact reply was that lexical scope was too inefficient."[3]
  • ^ https://lists.gnu.org/archive/html/emacs-devel/2012-12/msg00146.html
  • ^ https://lists.gnu.org/archive/html/emacs-devel/2012-12/msg00166.html
  • [edit] External links

    Portal icon Free software portal

    Retrieved from "http://en.wikipedia.org/w/index.php?title=Emacs_Lisp&oldid=547155523" 

    Categories: 
    Lisp programming language family
    Free compilers and interpreters
    Emacs
    Articles with example Lisp code
    Hidden categories: 
    All articles with dead external links
    Articles with dead external links from June 2012
     

    Navigation menu

     

    Personal tools



    Create account
    Log in
     



    Namespaces



    Article

    Talk
     


    Variants








    Views



    Read

    Edit

    View history
     


    Actions












    Navigation




    Main page

    Contents

    Featured content

    Current events

    Random article

    Donate to Wikipedia
     



    Interaction




    Help

    About Wikipedia

    Community portal

    Recent changes

    Contact Wikipedia
     



    Toolbox




    What links here

    Related changes

    Upload file

    Special pages

    Permanent link

    Page information

    Cite this page
     



    Print/export




    Create a book

    Download as PDF

    Printable version
     



    Languages




    Deutsch

    Español

    فارسی

    Français

    Nederlands



    Polski

    Português

    Русский

    Українська



    Edit links
     





    This page was last modified on 26 March 2013 at 23:49.

    Text is available under the Creative Commons Attribution-ShareAlike License; additional terms may apply. By using this site, you agree to the Terms of Use and Privacy Policy. 
    Wikipedia® is a registered trademark of the Wikimedia Foundation, Inc., a non-profit organization.
     


    Privacy policy

    About Wikipedia

    Disclaimers

    Contact Wikipedia

    Mobile view
     


    Wikimedia Foundation
    Powered by MediaWiki