Re: Emacs Lisp's Library System (tutorial)

Discussion in 'C Programming' started by Rivka Miller, Jul 14, 2010.

  1. Rivka Miller

    Rivka Miller Guest

    The first thing to understand elisp is to have the code of the elisp
    interpreter in elisp. I dont think that probably is published. You
    still have the choice of reading the C code which I referred to in an
    earlier post in comp.lang.c.

    http://xahlee.org/elisp/Writing-Emacs-Primitives.html#Writing-Emacs-Primitives

    Maybe you can expand on this topic.

    DEFUN ("or", For, Sor, 0, UNEVALLED, 0,
    doc: /* Eval args until one of them yields non-nil, then return
    that
    value. The remaining args are not evalled at all.
    If all args return nil, return nil.
    usage: (or CONDITIONS ...) */)
    (args)
    Lisp_Object args;
    {
    register Lisp_Object val = Qnil;
    struct gcpro gcpro1;

    GCPRO1 (args);

    while (CONSP (args))
    {
    val = Feval (XCAR (args));
    if (!NILP (val))
    break;
    args = XCDR (args);
    }

    UNGCPRO;
    return val;
    }


    On Jul 13, 5:44 pm, Xah Lee <> wrote:
    > • Emacs Lisp's Library System
    >  http://xahlee.org/emacs/elisp_library_system.html
    >
    > plain text version follows
    > --------------------------------------------------
    > Emacs Lisp's Library System
    >
    > Xah Lee, 2010-07-13
    >
    > This page explains emacs library system. For example, what's the
    > difference between library, package, features? And what's the
    > difference between load-file, load, require, autoload?
    >
    > --------------------------------------------------
    > What's Library, Package, Feature?
    >
    > ==============================
    > No Namespace
    >
    > Emacs lisp the language does not have name spaces. Everything is
    > global, with dynamic scope, with some shadowing mechanism. So, don't
    > expect library or module to be language defined name space constructs
    > that somewhat enforce name space and file name relation, as in Perl,
    > Python, Java.
    >
    > ==============================
    > What's the difference between a Package and Library?
    >
    > The terms “package†and “libraryâ€, are used losely in emacs/elisp
    > manual to refer to any useful elisp file. They are not technical
    > definitions in elisp.
    >
    > A “library†usually refers to elisp file containing library of lisp
    > functions, to be called by other lisp source code. For example, the
    > command backward-word is defined in “simple.elâ€, which is a library of
    > functions.
    >
    > A “package†usually refers to something useful for emacs users, like a
    > major mode or minor mode. The term “module†is not used by emacs.
    >
    > ==============================
    > Emacs's Concept of “Featureâ€
    >
    > The term “feature†has some meaning in elisp, but is not mechanical. A
    > “feature†is a elisp symbol, that is intended to represent the
    > functionality provided by a emacs package. This elisp symbol, can be
    > placed on the predefined global variable named “featuresâ€, which is a
    > list of symbols. For example, here's part of the value of “featuresâ€
    > when i do “Ctrl+x describe-variable Enter featuresâ€:
    >
    > ibuffer etags ring cc-mode cc-fonts cc-menus cc-cmds cc-styles
    > cc-align cc-engine cc-vars cc-defs xlsl-mode encoded-kb speck
    > sgml-mode dired info newcomment desktop recentf tree-widget wid-edit
    > advice help-fns ...
    >
    > A elisp file can call “(provide ‹some symbol›)†near the end, which
    > adds that symbol to the “features†list. The purpose of features and
    > the “features†variable is to provide a way for emacs to know if
    > something is already loaded.
    >
    > --------------------------------------------------
    > Package/Library/Feature are not Managed
    >
    > There is no absolute relation between any concept of package/library/
    > feature/autoload facilities and the file name.
    >
    > By convention, if a elisp file name is “xyz-mode.elâ€, it OFTEN
    > provides a lisp symbol “xyz-mode†as its feature name (it may not),
    > and the function to invoke the mode is OFTEN named “xyz-modeâ€.
    > Sometimes the “mode†part is dropped in the file name, feature symbol,
    > or function name.
    >
    > This is only a lose convention. There are a lot exceptions in many
    > bundled emacs packages. For example, the file “lisp-mode.el†provides
    > the symbol “lisp-mode†as feature, and is invoked by “emacs-lisp-
    > modeâ€. The “cua-base.el†file provides symbols “cua-base†and “cua†as
    > features, and is invoked by cua-mode. The “text-mode.el†file does not
    > provide any symbol for feature, but is a quite useful mode invoked by
    > text-mode. The file “desktop.el†provides “desktop†as feature, and is
    > invoked by desktop-save-mode.
    >
    > --------------------------------------------------
    > File/Package Loading Mechanisms
    >
    > [table]
    > Emacs's library/module/package is a primitive system, centered on
    > loading file (load-file), with some slightly high level things such as
    > its “featuresâ€, “autoloadâ€, “requireâ€. However, nothing is strict or
    > enforced by elisp.
    > Function Name   Purpose Tech Detail     Comment
    > load-file       Load a file.    Load one specific file. Use this if you have
    > one very SPECIFIC file at one particular file path.
    > load    Load a file.    Load a file by searching thru var “load-pathâ€. Also,
    > tries to load a compiled version (.elc) if exists.      Use this if there
    > are several possible location for the file, and you are using a short
    > file name such as “undo.el†or “undoâ€, and you want to load the
    > compiled version if it exists (“undo.elcâ€).
    > require Load a package if it has not already been loaded.       Checks the
    > var “featuresâ€, if symbol is not there, then call “load†to load it.
    > Best used in elisp source code, similar to other lang's “require†or
    > “importâ€.
    > autoload        Load a file only when a function is called.     Associate a
    > function name with a file path. When the function is called, load the
    > file, and execute the function. It is good to use this when you
    > install a package. It save startup time and makes emacs use less
    > system resource.
    >
    > All the above means, you could have a file named “xyz.elâ€, which
    > provides a feature named “abcâ€, while it really just provide a mode to
    > user with the command name “opq-mode†or sometimes just “opqâ€, and it
    > might be displayed in mode line as “OPQâ€, “OPQ helperâ€, or anything
    > else. And, this file can be considered as a package as well as
    > library.
    >
    > See also: How To Name Your Emacs Major Mode.
    >
    > --------------------------------------------------
    > Isn't this all very bad?
    >
    > Yes it is.
    >
    > Though, it's just the state of software. Many most popular langs, such
    > as C, C++, PHP, do worse. They don't have a module system neither, but
    > worse, they load a file by “includeâ€. Note that even Scheme didn't
    > have module system, until R6RS, released in 2007, and the new module
    > system defined in it widely criticized, and R6RS caused Scheme
    > community to split.
    >
    >   Xah
    > ∑http://xahlee.org/
    >
    > ☄
    Rivka Miller, Jul 14, 2010
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. ekzept
    Replies:
    0
    Views:
    356
    ekzept
    Aug 10, 2007
  2. nanothermite911fbibustards
    Replies:
    0
    Views:
    365
    nanothermite911fbibustards
    Jun 16, 2010
  3. nanothermite911fbibustards
    Replies:
    0
    Views:
    310
    nanothermite911fbibustards
    Jun 16, 2010
  4. small Pox
    Replies:
    4
    Views:
    364
    Steve Holden
    Dec 10, 2010
  5. Petter Gustad
    Replies:
    13
    Views:
    790
    Xah Lee
    Feb 11, 2011
Loading...

Share This Page