Mercurial > emacs
annotate lisp/mh-e/mh-acros.el @ 66986:24b9342c0182
*** empty log message ***
author | Francesco Potortì <pot@gnu.org> |
---|---|
date | Fri, 18 Nov 2005 13:57:25 +0000 |
parents | f5ade15d46f2 |
children | 3a8785724cca |
rev | line source |
---|---|
56676 | 1 ;;; mh-acros.el --- Macros used in MH-E |
2 | |
62847
aa8c2e12ee24
Upgraded to MH-E version 7.84.
Bill Wohler <wohler@newt.com>
parents:
62465
diff
changeset
|
3 ;; Copyright (C) 2004 Free Software Foundation, Inc. |
56676 | 4 |
5 ;; Author: Satyaki Das <satyaki@theforce.stanford.edu> | |
6 ;; Maintainer: Bill Wohler <wohler@newt.com> | |
7 ;; Keywords: mail | |
8 ;; See: mh-e.el | |
9 | |
10 ;; This file is part of GNU Emacs. | |
11 | |
12 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
13 ;; it under the terms of the GNU General Public License as published by | |
14 ;; the Free Software Foundation; either version 2, or (at your option) | |
15 ;; any later version. | |
16 | |
17 ;; GNU Emacs is distributed in the hope that it will be useful, | |
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
20 ;; GNU General Public License for more details. | |
21 | |
22 ;; You should have received a copy of the GNU General Public License | |
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
64085 | 24 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
25 ;; Boston, MA 02110-1301, USA. | |
56676 | 26 |
27 ;;; Commentary: | |
28 | |
29 ;; This file contains macros that would normally be in mh-utils.el except that | |
30 ;; their presence there would cause a dependency loop with mh-customize.el. | |
31 ;; This file must always be included like this: | |
32 ;; | |
33 ;; (eval-when-compile (require 'mh-acros)) | |
34 ;; | |
35 ;; It is so named with a silent `m' so that it is compiled first. Otherwise, | |
36 ;; "make recompile" in Emacs 21.4 fails. | |
37 | |
38 ;;; Change Log: | |
39 | |
40 ;;; Code: | |
41 | |
42 (require 'cl) | |
62847
aa8c2e12ee24
Upgraded to MH-E version 7.84.
Bill Wohler <wohler@newt.com>
parents:
62465
diff
changeset
|
43 (require 'advice) |
56676 | 44 |
45 ;; The Emacs coding conventions require that the cl package not be required at | |
46 ;; runtime. However, the cl package in versions of Emacs prior to 21.4 left cl | |
47 ;; routines in their macro expansions. Use mh-require-cl to provide the cl | |
48 ;; routines in the best way possible. | |
49 (defmacro mh-require-cl () | |
50 "Macro to load `cl' if needed. | |
51 Some versions of `cl' produce code for the expansion of | |
52 \(setf (gethash ...) ...) that uses functions in `cl' at run time. This macro | |
53 recognizes that and loads `cl' where appropriate." | |
54 (if (eq (car (macroexpand '(setf (gethash foo bar) baz))) 'cl-puthash) | |
56787
25da1d331c99
Upgraded to MH-E version 7.82.
Bill Wohler <wohler@newt.com>
parents:
56751
diff
changeset
|
55 `(require 'cl) |
56676 | 56 `(eval-when-compile (require 'cl)))) |
57 | |
58 ;;; Macros to generate correct code for different emacs variants | |
59 | |
60 (defmacro mh-do-in-gnu-emacs (&rest body) | |
61 "Execute BODY if in GNU Emacs." | |
62 (unless (featurep 'xemacs) `(progn ,@body))) | |
63 (put 'mh-do-in-gnu-emacs 'lisp-indent-hook 'defun) | |
64 | |
65 (defmacro mh-do-in-xemacs (&rest body) | |
66 "Execute BODY if in GNU Emacs." | |
67 (when (featurep 'xemacs) `(progn ,@body))) | |
68 (put 'mh-do-in-xemacs 'lisp-indent-hook 'defun) | |
69 | |
70 (defmacro mh-funcall-if-exists (function &rest args) | |
71 "Call FUNCTION with ARGS as parameters if it exists." | |
62847
aa8c2e12ee24
Upgraded to MH-E version 7.84.
Bill Wohler <wohler@newt.com>
parents:
62465
diff
changeset
|
72 (when (fboundp function) |
aa8c2e12ee24
Upgraded to MH-E version 7.84.
Bill Wohler <wohler@newt.com>
parents:
62465
diff
changeset
|
73 `(when (fboundp ',function) |
aa8c2e12ee24
Upgraded to MH-E version 7.84.
Bill Wohler <wohler@newt.com>
parents:
62465
diff
changeset
|
74 (funcall ',function ,@args)))) |
56676 | 75 |
76 (defmacro mh-make-local-hook (hook) | |
77 "Make HOOK local if needed. | |
78 XEmacs and versions of GNU Emacs before 21.1 require `make-local-hook' to be | |
79 called." | |
80 (when (and (fboundp 'make-local-hook) | |
81 (not (get 'make-local-hook 'byte-obsolete-info))) | |
82 `(make-local-hook ,hook))) | |
83 | |
84 (defmacro mh-mark-active-p (check-transient-mark-mode-flag) | |
85 "A macro that expands into appropriate code in XEmacs and nil in GNU Emacs. | |
86 In GNU Emacs if CHECK-TRANSIENT-MARK-MODE-FLAG is non-nil then check if | |
87 variable `transient-mark-mode' is active." | |
88 (cond ((featurep 'xemacs) ;XEmacs | |
89 `(and (boundp 'zmacs-regions) zmacs-regions (region-active-p))) | |
90 ((not check-transient-mark-mode-flag) ;GNU Emacs | |
91 `(and (boundp 'mark-active) mark-active)) | |
92 (t ;GNU Emacs | |
93 `(and (boundp 'transient-mark-mode) transient-mark-mode | |
94 (boundp 'mark-active) mark-active)))) | |
95 | |
96 (defmacro mh-defstruct (name-spec &rest fields) | |
97 "Replacement for `defstruct' from the `cl' package. | |
98 The `defstruct' in the `cl' library produces compiler warnings, and generates | |
99 code that uses functions present in `cl' at run-time. This is a partial | |
100 replacement, that avoids these issues. | |
101 | |
102 NAME-SPEC declares the name of the structure, while FIELDS describes the | |
103 various structure fields. Lookup `defstruct' for more details." | |
104 (let* ((struct-name (if (atom name-spec) name-spec (car name-spec))) | |
105 (conc-name (or (and (consp name-spec) | |
106 (cadr (assoc :conc-name (cdr name-spec)))) | |
107 (format "%s-" struct-name))) | |
108 (predicate (intern (format "%s-p" struct-name))) | |
109 (constructor (or (and (consp name-spec) | |
110 (cadr (assoc :constructor (cdr name-spec)))) | |
111 (intern (format "make-%s" struct-name)))) | |
112 (field-names (mapcar #'(lambda (x) (if (atom x) x (car x))) fields)) | |
113 (field-init-forms (mapcar #'(lambda (x) (and (consp x) (cadr x))) | |
114 fields)) | |
115 (struct (gensym "S")) | |
116 (x (gensym "X")) | |
117 (y (gensym "Y"))) | |
118 `(progn | |
119 (defun* ,constructor (&key ,@(mapcar* #'(lambda (x y) (list x y)) | |
120 field-names field-init-forms)) | |
56751
72a02133177e
Upgraded to MH-E version 7.81.
Bill Wohler <wohler@newt.com>
parents:
56677
diff
changeset
|
121 (list (quote ,struct-name) ,@field-names)) |
56676 | 122 (defun ,predicate (arg) |
56751
72a02133177e
Upgraded to MH-E version 7.81.
Bill Wohler <wohler@newt.com>
parents:
56677
diff
changeset
|
123 (and (consp arg) (eq (car arg) (quote ,struct-name)))) |
72a02133177e
Upgraded to MH-E version 7.81.
Bill Wohler <wohler@newt.com>
parents:
56677
diff
changeset
|
124 ,@(loop for x from 1 |
56676 | 125 for y in field-names |
126 collect `(defmacro ,(intern (format "%s%s" conc-name y)) (z) | |
127 (list 'nth ,x z))) | |
128 (quote ,struct-name)))) | |
129 | |
56787
25da1d331c99
Upgraded to MH-E version 7.82.
Bill Wohler <wohler@newt.com>
parents:
56751
diff
changeset
|
130 (defadvice require (around mh-prefer-el activate) |
25da1d331c99
Upgraded to MH-E version 7.82.
Bill Wohler <wohler@newt.com>
parents:
56751
diff
changeset
|
131 "Modify `require' to load uncompiled MH-E files." |
25da1d331c99
Upgraded to MH-E version 7.82.
Bill Wohler <wohler@newt.com>
parents:
56751
diff
changeset
|
132 (or (featurep (ad-get-arg 0)) |
25da1d331c99
Upgraded to MH-E version 7.82.
Bill Wohler <wohler@newt.com>
parents:
56751
diff
changeset
|
133 (and (string-match "^mh-" (symbol-name (ad-get-arg 0))) |
25da1d331c99
Upgraded to MH-E version 7.82.
Bill Wohler <wohler@newt.com>
parents:
56751
diff
changeset
|
134 (load (format "%s.el" (ad-get-arg 0)) t t)) |
25da1d331c99
Upgraded to MH-E version 7.82.
Bill Wohler <wohler@newt.com>
parents:
56751
diff
changeset
|
135 ad-do-it)) |
56676 | 136 |
66357
f5ade15d46f2
* mh-identity.el (mh-assoc-ignore-case): Merge with version in
Bill Wohler <wohler@newt.com>
parents:
64085
diff
changeset
|
137 (defmacro mh-assoc-ignore-case (key alist) |
f5ade15d46f2
* mh-identity.el (mh-assoc-ignore-case): Merge with version in
Bill Wohler <wohler@newt.com>
parents:
64085
diff
changeset
|
138 "Check if KEY is present in ALIST while ignoring case to do the comparison. |
f5ade15d46f2
* mh-identity.el (mh-assoc-ignore-case): Merge with version in
Bill Wohler <wohler@newt.com>
parents:
64085
diff
changeset
|
139 Compatibility macro for Emacs versions that lack `assoc-string', introduced in |
f5ade15d46f2
* mh-identity.el (mh-assoc-ignore-case): Merge with version in
Bill Wohler <wohler@newt.com>
parents:
64085
diff
changeset
|
140 Emacs 22." |
f5ade15d46f2
* mh-identity.el (mh-assoc-ignore-case): Merge with version in
Bill Wohler <wohler@newt.com>
parents:
64085
diff
changeset
|
141 (if (fboundp 'assoc-string) |
f5ade15d46f2
* mh-identity.el (mh-assoc-ignore-case): Merge with version in
Bill Wohler <wohler@newt.com>
parents:
64085
diff
changeset
|
142 `(assoc-string ,key ,alist t) |
f5ade15d46f2
* mh-identity.el (mh-assoc-ignore-case): Merge with version in
Bill Wohler <wohler@newt.com>
parents:
64085
diff
changeset
|
143 `(assoc-ignore-case ,key ,alist))) |
f5ade15d46f2
* mh-identity.el (mh-assoc-ignore-case): Merge with version in
Bill Wohler <wohler@newt.com>
parents:
64085
diff
changeset
|
144 |
56676 | 145 (provide 'mh-acros) |
146 | |
147 ;;; Local Variables: | |
148 ;;; no-byte-compile: t | |
149 ;;; indent-tabs-mode: nil | |
150 ;;; sentence-end-double-space: nil | |
151 ;;; End: | |
152 | |
56677 | 153 ;; arch-tag: b383b49a-494f-4ed0-a30a-cb6d5d2da4ff |
56676 | 154 ;;; mh-acros.el ends here |