Here are some tips for avoiding common errors in writing Lisp code intended for widespread use:
cadr.
Believe it or not, there is more than one plausible way to define
cadr. Play it safe; append your name prefix to produce a name
like foo-cadr or mylib-cadr 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@prep.ai.mit.edu' 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 may 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 in each separate
library program, at least if there is more than one entry point to the
program.
require to make sure they are loaded.
(eval-when-compile (require 'bar))(And 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. See section Macros and Byte Compilation.
Using eval-when-compile avoids loading bar when
the compiled version of foo is used.
run-hooks, just as the existing major modes do. See section Hooks.
framep and frame-live-p.
whatever-mode which turns the feature on or
off, and make it autoload (see section Autoload). Design the package so
that simply loading it has no visible effect--that should not enable
the feature. Users will request the feature by invoking the command.
next-line or previous-line in programs; nearly
always, forward-line is more convenient as well as more
predictable and robust. See section Motion by Text Lines.
beginning-of-buffer, end-of-buffer
replace-string, replace-regexp
message function, not princ. See section The Echo Area.
error
(or signal). The function error does not return.
See section How to Signal an Error.
Do not use message, throw, sleep-for,
or beep to report errors.
edit-options command does: switch to another buffer and let the
user switch back at will. See section Recursive Editing.
defvar definitions for these variables.
If you bind a variable in one function, and use it or set it in another
function, the compiler warns about the latter function unless the
variable has a definition. But often these variables have short names,
and it is not clean for Lisp packages to define such variables names.
Therefore, you should rename the variable to start with the name prefix
used for the other functions and variables in your package.
indent-sexp) using the
default indentation parameters.
Go to the first, previous, next, last section, table of contents.