Chris Beggy <[EMAIL PROTECTED]> writes: > From: Alex Schroeder <[EMAIL PROTECTED]> >> >> Lots of packages define missing functions in order to run on Emacs and >> XEmacs. Other packages test wethere critical functions are bound or >> not, and then assume they are on Emacs or XEmacs. :( >> >> I've had a similar problem with one package or another because BBDB >> used to do that as well (don't know wether it still does). > > What's the best solution for library writers then? Do you know > of any code examples where this is handled well?
Unfortunately, I don't have a general solution for this. All I can offer is some rules to guide would-be elisp authors: Always use the most specific test. Here are some examples from unspecific (avoid) to specific: * Testing for Emacs/XEmacs using (featurep 'xemacs). * Testing for packages using featurep. * Testing for variables using boundp and functions using fboundp. Here's an example from color-theme.el where I had to test for Emacs/XEmacs directly because the function define-key exists in both versions: (if color-theme-xemacs-p (define-key map (kbd "<button2>") 'color-theme-install-at-mouse) (define-key map (kbd "<mouse-2>") 'color-theme-install-at-mouse)) If you determine that a specific function or variable is lacking, implementing it may be dangerous and break other things. It's better to use your own names, and use defalias. Here's from color-theme.el, for example: (cond ((fboundp 'custom-face-attributes-get) (defalias 'color-theme-face-attr-construct 'custom-face-attributes-get)) ((fboundp 'face-custom-attributes-get) (defalias 'color-theme-face-attr-construct 'face-custom-attributes-get)) (t (defun color-theme-face-attr-construct (&rest ignore) (error "Unable to construct face attributes")))) An example of how things can go wrong is in my bug report from 2001-10-05. BBDB defined the function set-specifier if it was missing. ispell tested for set-specifier to execute some XEmacs specific code. I think that ispell was was right, because it use the most specific test and was right in assuming that if set-specifier was defined, other XEmacs specifier-related machinery would be present (such as the variable has-modeline-p). bbdb-gui.el contains the following code: (or (fboundp 'set-specifier) (fset 'set-specifier 'ignore)) Therefore, on my Emacs 20.7, I have set-specifier defined. This causes a problem with ispell.el, however. In ispell-command-loop, there is the following code: (and (fboundp 'set-specifier) ; prevent XEmacs modeline hiding (set-specifier has-modeline-p (cons (current-buffer) nil))) This will result in: Signaling: (void-variable has-modeline-p) The problem with this code is that it defines a function which exists in the other emacsen, unlike the example from color-theme. As you can see, however, the choices are not always easy to make. :( Alex. -- http://www.emacswiki.org/ _______________________________________________ [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/bbdb-info BBDB Home Page: http://bbdb.sourceforge.net/