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.
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.
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).
princ. See The Echo Area.
signal). The function
errordoes not return. See Signaling Errors.
beep to report errors.
y-or-n-pshould start with a capital letter and end with ‘? ’.
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) (interactive (list (if specified specified-pos))) (unless pos (setq pos default-pos)) ...)
rather than this:
(defun foo (pos) (interactive (list (if specified specified-pos default-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 ‘d’, ‘m’ and ‘r’, because they make special arrangements to recompute the argument values on repetition of the command.