[ < ] | [ > ] | [ << ] | [Plus haut] | [ >> ] | [Top] | [Table des matières] | [Index] | [ ? ] |
Here are conventions that you should follow when writing Emacs Lisp code intended for widespread use:
This convention is mandatory for any file that includes custom definitions. If fixing such a file to follow this convention requires an incompatible change, go ahead and make the incompatible change; don't postpone it.
Occasionally, for a command name intended for users to use, it is more convenient if some words come before the package's name prefix. And constructs that define functions, variables, etc., work better if they start with ‘defun’ or ‘defvar’, so put the name prefix later on in the name.
This recommendation applies even to names for traditional Lisp primitives
that are not primitives in Emacs Lisp—such as copy-list
. Believe
it or not, there is more than one plausible way to define copy-list
.
Play it safe; append your name prefix to produce a name like
foo-copy-list
or mylib-copy-list
instead.
If you write a function that you think ought to be added to Emacs under a
certain name, such as twiddle-files
, don't call it by that name in
your program. Call it mylib-twiddle-files
in your program, and send
mail to ‘bug-gnu-emacs@gnu.org’ suggesting we add it to Emacs. If and
when we do, we can change the name easily enough.
If one prefix is insufficient, your package can use two or three alternative common prefixes, so long as they make sense.
Separate the prefix from the rest of the symbol name with a hyphen, ‘-’. This will be consistent with Emacs itself and with most Emacs Lisp programs.
provide
at the end of each separate Lisp file.
require
to make sure they are loaded.
(eval-when-compile (require 'bar)) |
(And the library bar should contain (provide 'bar)
, to
make the require
work.) This will cause bar to be loaded when
you byte-compile foo. Otherwise, you risk compiling foo without
the necessary macro loaded, and that would produce compiled code that won't
work right. Voir la section Macros and Byte Compilation.
Using eval-when-compile
avoids loading bar when the compiled
version of foo is used.
cl
package of Common Lisp extensions at run
time. Use of this package is optional, and it is not part of the standard
Emacs namespace. If your package loads cl
at run time, that could
cause name clashes for users who don't use that package.
However, there is no problem with using the cl
package at compile
time, with (eval-when-compile (require 'cl))
. That's sufficient for
using the macros in the cl
package, because the compiler expands them
before generating the byte-code.
framep
and frame-live-p
.
feature-unload-hook
, where feature is the name of the
feature the package provides, and make it undo any such changes. Using
unload-feature
to unload the file will run this function.
Voir la section Unloading.
(defalias 'gnus-point-at-bol (if (fboundp 'point-at-bol) 'point-at-bol 'line-beginning-position)) |
We hope to remove all the places in Emacs that advise primitives. In the mean time, please don't add any more.
eval-after-load
(voir la section Hooks for Loading) in
libraries and packages. This feature is meant for personal customizations;
using it in a Lisp program is unclean, because it modifies the behavior of
another Lisp file in a way that's not visible in that file. This is an
obstacle for debugging, much like advising a function in the other package.
emacs-mule
, and specify that for coding
in
the ‘-*-’ line or the local variables list.
;; XXX.el -*- coding: emacs-mule; -*- |
coding
. (The ‘!’ turns off any possible character translation.)
;; XXX.el -*- coding: iso-latin-2!; -*- |
indent-sexp
) using the default
indentation parameters.
;; Copyright (C) year name ;; This program is free software; you can redistribute it and/or ;; modify it under the terms of the GNU General Public License as ;; published by the Free Software Foundation; either version 2 of ;; the License, or (at your option) any later version. ;; This program is distributed in the hope that it will be ;; useful, but WITHOUT ANY WARRANTY; without even the implied ;; warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR ;; PURPOSE. See the GNU General Public License for more details. ;; You should have received a copy of the GNU General Public ;; License along with this program; if not, write to the Free ;; Software Foundation, Inc., 51 Franklin Street, Fifth Floor, ;; Boston, MA 02110-1301 USA |
If you have signed papers to assign the copyright to the Foundation, then use ‘Free Software Foundation, Inc.’ as name. Otherwise, use your name. See also Voir la section Conventional Headers for Emacs Libraries.
[ < ] | [ > ] | [ << ] | [Plus haut] | [ >> ] | [Top] | [Table des matières] | [Index] | [ ? ] |
Ce document a été généré par Eric Reinbold le 13 Octobre 2007 en utilisant texi2html 1.78.