Use (when (boundp 'some-variable) β¦) or (when (fboundp 'some-function) β¦) around any piece of code that uses a specific function. (While you're on it, start with (require 'cl) for those older versions that don't have a built-in when .)
If all else fails, highlight emacs-major-version , emacs-minor-version and running-xemacs (defined as (string-match "XEmacs\\|Lucid" emacs-version) ).
Avoid syntax and library functions that are only supported in newer versions.
Rarely does something break when you stick to documented interfaces. Therefore, try to find a way to do what is mentioned in the manual, and only lean back on changing some random non-configurable variable if you do not see another way. In my experience, there is always a fairly simple way to get something to work in all versions (at least with GNU Emacs, XEmacs, sometimes the hardest to please) if you allow random conditions.
For example, "\e\t" always worked for M-TAB . With dired-omit-mode return to dired-omit-toggle if the first does not exist:
(set (if boundp 'dired-omit-mode 'dired-omit-mode 'dired-omit-toggle) t)
Yes, it's a little painful, but not as dramatic as you do. I support .emacs , which has been working with anything since 19.23 (IIRC, it's been a while since I tested with something older than 19.34) on all DOS, Windows and unix. Windows compatibility is actually more of a burden than changing GNU Emacs versions.
As for the cookbook, most of the differences between the versions are related to features that are not very widely used (otherwise developers would attach greater importance to a strict increase in compatibility). Since Emacs is large, there is undoubtedly a lot of it that you use, but the cookbook writer has not heard. You will have to play by ear. Fortunately, this is not too complicated.