unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* [PATCH] New convenience macros
@ 2007-08-18 14:30 Steve Youngs
  2007-08-19 15:52 ` Richard Stallman
  2007-08-20  4:09 ` Stefan Monnier
  0 siblings, 2 replies; 17+ messages in thread
From: Steve Youngs @ 2007-08-18 14:30 UTC (permalink / raw)
  To: XEmacs patches; +Cc: Emacs devel


[-- Attachment #1.1: Type: text/plain, Size: 3345 bytes --]

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  <steve@sxemacs.org>

	* 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)
 
 \f
 ;;;; Keymap support.


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

[-- Attachment #1.2: Type: application/pgp-signature, Size: 312 bytes --]

[-- Attachment #2: Type: text/plain, Size: 165 bytes --]

_______________________________________________
XEmacs-Patches mailing list
XEmacs-Patches@xemacs.org
http://calypso.tux.org/cgi-bin/mailman/listinfo/xemacs-patches

^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2007-08-27  3:20 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-08-18 14:30 [PATCH] New convenience macros Steve Youngs
2007-08-19 15:52 ` Richard Stallman
2007-08-20  2:06   ` Steve Youngs
2007-08-20 10:58     ` Kim F. Storm
2007-08-20 18:30     ` Richard Stallman
2007-08-23 10:54       ` Steve Youngs
2007-08-23 14:12         ` Johan Bockgård
2007-08-23 14:47         ` Stefan Monnier
2007-08-23 18:24           ` Steve Youngs
2007-08-23 19:12             ` Stefan Monnier
2007-08-26 14:52               ` Steve Youngs
2007-08-26 22:47                 ` Richard Stallman
2007-08-27  3:20                   ` Steve Youngs
2007-08-20  4:09 ` Stefan Monnier
2007-08-23 11:13   ` Steve Youngs
2007-08-23 15:11     ` Stefan Monnier
2007-08-23 18:24       ` Steve Youngs

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).