Following these conventions will make your program fit better into Emacs when it runs.
previous-linein programs; nearly always,
forward-lineis more convenient as well as more predictable and robust. See Text Lines.
Don’t call functions that set the mark, unless setting the mark is one of the intended features of your program. The mark is a user-level feature, so it is incorrect to change the mark except to supply a value for the user’s benefit. See The Mark.
In particular, don’t use any of these functions:
If you just want to move point, or replace a certain string, or insert a file or buffer’s contents, without any of the other features intended for interactive users, you can replace these functions with one or two lines of simple Lisp code.
Use lists rather than vectors, except when there is a particular reason to use a vector. Lisp has more facilities for manipulating lists than for vectors, and working with lists is usually more convenient.
Vectors are advantageous for tables that are substantial in size and are accessed in random order (not searched front to back), provided there is no need to insert or delete elements (only lists allow that).
The recommended way to show a message in the echo area is with the
princ. See The Echo Area.
When you encounter an error condition, call the function
signal). The function
errordoes not return. See Signaling Errors.
beepto report errors.
An error message should start with a capital letter but should not end with a period.
A question asked in the minibuffer with
y-or-n-pshould start with a capital letter and end with ‘
When you mention a default value in a minibuffer prompt, put it and the word ‘
default’ inside parentheses. It should look like this:
Enter the answer (default 42):
interactive, if you use a Lisp expression to produce a list of arguments, don’t try to provide the correct default values for region or position arguments. Instead, provide
nilfor those arguments if they were not specified, and have the function body compute the default value when the argument is
nil. For instance, write this:
(defun foo (pos)
(list (if specified specified-pos)))
(unless pos (setq pos default-pos))
rather than this:
(defun foo (pos)
(list (if specified specified-pos
This is so that repetition of the command will recompute these defaults based on the current circumstances.
You do not need to take such precautions when you use interactive specs ‘
m’ and ‘
r’, because they make special arrangements to recompute the argument values on repetition of the command.
Many commands that take a long time to execute display a message that says something like ‘
Operating...’ when they start, and change it to ‘
Operating...done’ when they finish. Please keep the style of these messages uniform: no space around the ellipsis, and no period after ‘
done’. See Progress, for an easy way to generate such messages.
Try to avoid using recursive edits. Instead, do what the Rmail
ecommand does: use a new local keymap that contains a command defined to switch back to the old local keymap. Or simply switch to another buffer and let the user switch back at will. See Recursive Editing.