emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] New convenience macros


From: Steve Youngs
Subject: [PATCH] New convenience macros
Date: Sun, 19 Aug 2007 00:30:44 +1000
User-agent: Gnus/5.110007 (No Gnus v0.7) SXEmacs/22.1.7 (De Lorean, linux)

I added these to SXEmacs a little while ago.  They are a couple of
macros that can be used when you need to conditionalise on emacs
flavour.  And at the same time not generate byte-compiler warnings,
regardless of the flavour of emacs you are using to compile the .el.

It is my hope that both XEmacs and GNU/Emacs will include these macros
so that elisp programmers can benefit from them no matter what their
preferred emacsen is.

ChangeLog entry for XEmacs (sorry, I have no clue where these macros
should go in GNU/Emacs)...

2007-08-19  Steve Youngs  <address@hidden>

        * subr.el (do-in-sxemacs, do-in-xemacs, do-in-gnu-emacs)
        (with-emacs-type): Convenience macros to use when you need to
        conditionalise on emacs flavour.  They have the added advantage of
        suppressing byte-compiler warnings.

diff -r ad09012c3de7 lisp/subr.el
--- a/lisp/subr.el      Wed Aug 15 23:23:30 2007 +0000
+++ b/lisp/subr.el      Sun Aug 19 00:29:24 2007 +1000
@@ -188,6 +188,69 @@ ELT must be a string.  Upper-case and lo
   (while (and list (not (eq t (compare-strings elt 0 nil (car list) 0 nil t))))
     (setq list (cdr list)))
   list)
+
+;; Convenience macros to let you conditionalise code for different
+;; emacs variants without generating any byte-compiler warnings
+
+(eval-when-compile
+  (if (featurep 'xemacs)
+      (or (featurep 'sxemacs)
+         (defvar running-sxemacs))
+    (defvar running-sxemacs)
+    (defvar running-xemacs)))
+
+(defmacro do-in-sxemacs (&rest body)
+  "Execute BODY if in SXEmacs."
+  (and running-sxemacs
+       (cons 'progn body)))
+
+(put 'do-in-sxemacs 'lisp-indent-hook 'defun)
+
+(defmacro do-in-xemacs (&rest body)
+  "Execute BODY if in XEmacs."
+  (and running-xemacs
+       (cons 'progn body)))
+
+(put 'do-in-xemacs 'lisp-indent-hook 'defun)
+
+(defmacro do-in-gnu-emacs (&rest body)
+  "Execute BODY if in GNU/Emacs."
+  (unless (or running-sxemacs
+             running-xemacs)
+    (cons 'progn body)))
+
+(put 'do-in-gnu-emacs 'lisp-indent-hook 'defun)
+
+(defmacro with-emacs-type (type &rest body)
+  "Execute BODY depending on emacs TYPE.
+
+Argument TYPE is a quoted symbol, being one of `sxemacs', `xemacs', or
+`gnu'.  For example...
+
+  \(with-emacs-type 'sxemacs
+    ;; SXEmacs only code goes here.
+    ;; XEmacs and GNU/Emacs won't see it and won't complain about unbound
+    ;; funcs/vars.
+    \)
+  \(with-emacs-type 'xemacs
+    ;; XEmacs code goes here.
+    ;; GNU/Emacs won't see it and won't complain about unbound funcs/vars.
+    \)
+  \(with-emacs-type 'gnu
+    ;; GNU/Emacs code goes here.
+    ;; SXEmacs and XEmacs won't see it and won't complain about unbound
+    ;; funcs/vars.
+    \)"
+  (cond
+   ((equal type '(quote sxemacs))
+    (do-in-sxemacs (cons 'progn body)))
+   ((equal type '(quote xemacs))
+    (do-in-xemacs (cons 'progn body)))
+   ((equal type '(quote gnu))
+    (do-in-gnu-emacs (cons 'progn body)))
+   (t (error 'invalid-argument type))))
+
+(put 'with-emacs-type 'lisp-indent-hook 'defun)
 

 ;;;; Keymap support.


-- 
|---<Steve Youngs>---------------<GnuPG KeyID: A94B3003>---|
|       SXEmacs - The only _______ you'll ever need.       |
|         Fill in the blank, yes, it's THAT good!          |
|------------------------------------<address@hidden>---|

Attachment: pgp318OA6oD_K.pgp
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]