Mercurial > emacs
annotate lisp/mh-e/mh-acros.el @ 67870:60b2bb5ad00f
(mouse-drag-region-1): When remapping mouse-1 to mouse-2, go back to
previously selected window, so it's selected when mouse-2 command runs.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Wed, 28 Dec 2005 03:19:29 +0000 |
parents | 9c3504ae6060 |
children | ec4727559827 |
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 ;; | |
67760
9c3504ae6060
Follow MH-E Developers Guide conventions. Use `' quotes for Help
Bill Wohler <wohler@newt.com>
parents:
67758
diff
changeset
|
35 ;; It is so named with a silent "m" so that it is compiled first. Otherwise, |
56676 | 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 () | |
67760
9c3504ae6060
Follow MH-E Developers Guide conventions. Use `' quotes for Help
Bill Wohler <wohler@newt.com>
parents:
67758
diff
changeset
|
50 "Macro to load \"cl\" if needed. |
9c3504ae6060
Follow MH-E Developers Guide conventions. Use `' quotes for Help
Bill Wohler <wohler@newt.com>
parents:
67758
diff
changeset
|
51 Some versions of \"cl\" produce code for the expansion of |
9c3504ae6060
Follow MH-E Developers Guide conventions. Use `' quotes for Help
Bill Wohler <wohler@newt.com>
parents:
67758
diff
changeset
|
52 \(setf (gethash ...) ...) that uses functions in \"cl\" at run |
9c3504ae6060
Follow MH-E Developers Guide conventions. Use `' quotes for Help
Bill Wohler <wohler@newt.com>
parents:
67758
diff
changeset
|
53 time. This macro recognizes that and loads \"cl\" where |
67758
6b063593fdad
Follow Emacs coding conventions. Use default setting of
Bill Wohler <wohler@newt.com>
parents:
67681
diff
changeset
|
54 appropriate." |
56676 | 55 (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
|
56 `(require 'cl) |
56676 | 57 `(eval-when-compile (require 'cl)))) |
58 | |
67681 | 59 ;; Macros to generate correct code for different emacs variants |
56676 | 60 |
61 (defmacro mh-do-in-gnu-emacs (&rest body) | |
62 "Execute BODY if in GNU Emacs." | |
63 (unless (featurep 'xemacs) `(progn ,@body))) | |
64 (put 'mh-do-in-gnu-emacs 'lisp-indent-hook 'defun) | |
65 | |
66 (defmacro mh-do-in-xemacs (&rest body) | |
67 "Execute BODY if in GNU Emacs." | |
68 (when (featurep 'xemacs) `(progn ,@body))) | |
69 (put 'mh-do-in-xemacs 'lisp-indent-hook 'defun) | |
70 | |
71 (defmacro mh-funcall-if-exists (function &rest args) | |
72 "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
|
73 (when (fboundp function) |
aa8c2e12ee24
Upgraded to MH-E version 7.84.
Bill Wohler <wohler@newt.com>
parents:
62465
diff
changeset
|
74 `(when (fboundp ',function) |
aa8c2e12ee24
Upgraded to MH-E version 7.84.
Bill Wohler <wohler@newt.com>
parents:
62465
diff
changeset
|
75 (funcall ',function ,@args)))) |
56676 | 76 |
77 (defmacro mh-make-local-hook (hook) | |
78 "Make HOOK local if needed. | |
67758
6b063593fdad
Follow Emacs coding conventions. Use default setting of
Bill Wohler <wohler@newt.com>
parents:
67681
diff
changeset
|
79 XEmacs and versions of GNU Emacs before 21.1 require |
6b063593fdad
Follow Emacs coding conventions. Use default setting of
Bill Wohler <wohler@newt.com>
parents:
67681
diff
changeset
|
80 `make-local-hook' to be called." |
56676 | 81 (when (and (fboundp 'make-local-hook) |
82 (not (get 'make-local-hook 'byte-obsolete-info))) | |
83 `(make-local-hook ,hook))) | |
84 | |
85 (defmacro mh-mark-active-p (check-transient-mark-mode-flag) | |
86 "A macro that expands into appropriate code in XEmacs and nil in GNU Emacs. | |
67758
6b063593fdad
Follow Emacs coding conventions. Use default setting of
Bill Wohler <wohler@newt.com>
parents:
67681
diff
changeset
|
87 In GNU Emacs if CHECK-TRANSIENT-MARK-MODE-FLAG is non-nil then |
6b063593fdad
Follow Emacs coding conventions. Use default setting of
Bill Wohler <wohler@newt.com>
parents:
67681
diff
changeset
|
88 check if variable `transient-mark-mode' is active." |
56676 | 89 (cond ((featurep 'xemacs) ;XEmacs |
90 `(and (boundp 'zmacs-regions) zmacs-regions (region-active-p))) | |
91 ((not check-transient-mark-mode-flag) ;GNU Emacs | |
92 `(and (boundp 'mark-active) mark-active)) | |
93 (t ;GNU Emacs | |
94 `(and (boundp 'transient-mark-mode) transient-mark-mode | |
95 (boundp 'mark-active) mark-active)))) | |
96 | |
97 (defmacro mh-defstruct (name-spec &rest fields) | |
67760
9c3504ae6060
Follow MH-E Developers Guide conventions. Use `' quotes for Help
Bill Wohler <wohler@newt.com>
parents:
67758
diff
changeset
|
98 "Replacement for `defstruct' from the \"cl\" package. |
9c3504ae6060
Follow MH-E Developers Guide conventions. Use `' quotes for Help
Bill Wohler <wohler@newt.com>
parents:
67758
diff
changeset
|
99 The `defstruct' in the \"cl\" library produces compiler warnings, |
9c3504ae6060
Follow MH-E Developers Guide conventions. Use `' quotes for Help
Bill Wohler <wohler@newt.com>
parents:
67758
diff
changeset
|
100 and generates code that uses functions present in \"cl\" at |
67758
6b063593fdad
Follow Emacs coding conventions. Use default setting of
Bill Wohler <wohler@newt.com>
parents:
67681
diff
changeset
|
101 run-time. This is a partial replacement, that avoids these |
6b063593fdad
Follow Emacs coding conventions. Use default setting of
Bill Wohler <wohler@newt.com>
parents:
67681
diff
changeset
|
102 issues. |
56676 | 103 |
67758
6b063593fdad
Follow Emacs coding conventions. Use default setting of
Bill Wohler <wohler@newt.com>
parents:
67681
diff
changeset
|
104 NAME-SPEC declares the name of the structure, while FIELDS |
6b063593fdad
Follow Emacs coding conventions. Use default setting of
Bill Wohler <wohler@newt.com>
parents:
67681
diff
changeset
|
105 describes the various structure fields. Lookup `defstruct' for |
6b063593fdad
Follow Emacs coding conventions. Use default setting of
Bill Wohler <wohler@newt.com>
parents:
67681
diff
changeset
|
106 more details." |
56676 | 107 (let* ((struct-name (if (atom name-spec) name-spec (car name-spec))) |
108 (conc-name (or (and (consp name-spec) | |
109 (cadr (assoc :conc-name (cdr name-spec)))) | |
110 (format "%s-" struct-name))) | |
111 (predicate (intern (format "%s-p" struct-name))) | |
112 (constructor (or (and (consp name-spec) | |
113 (cadr (assoc :constructor (cdr name-spec)))) | |
114 (intern (format "make-%s" struct-name)))) | |
115 (field-names (mapcar #'(lambda (x) (if (atom x) x (car x))) fields)) | |
116 (field-init-forms (mapcar #'(lambda (x) (and (consp x) (cadr x))) | |
117 fields)) | |
118 (struct (gensym "S")) | |
119 (x (gensym "X")) | |
120 (y (gensym "Y"))) | |
121 `(progn | |
122 (defun* ,constructor (&key ,@(mapcar* #'(lambda (x y) (list x y)) | |
123 field-names field-init-forms)) | |
56751
72a02133177e
Upgraded to MH-E version 7.81.
Bill Wohler <wohler@newt.com>
parents:
56677
diff
changeset
|
124 (list (quote ,struct-name) ,@field-names)) |
56676 | 125 (defun ,predicate (arg) |
56751
72a02133177e
Upgraded to MH-E version 7.81.
Bill Wohler <wohler@newt.com>
parents:
56677
diff
changeset
|
126 (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
|
127 ,@(loop for x from 1 |
56676 | 128 for y in field-names |
129 collect `(defmacro ,(intern (format "%s%s" conc-name y)) (z) | |
130 (list 'nth ,x z))) | |
131 (quote ,struct-name)))) | |
132 | |
56787
25da1d331c99
Upgraded to MH-E version 7.82.
Bill Wohler <wohler@newt.com>
parents:
56751
diff
changeset
|
133 (defadvice require (around mh-prefer-el activate) |
25da1d331c99
Upgraded to MH-E version 7.82.
Bill Wohler <wohler@newt.com>
parents:
56751
diff
changeset
|
134 "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
|
135 (or (featurep (ad-get-arg 0)) |
25da1d331c99
Upgraded to MH-E version 7.82.
Bill Wohler <wohler@newt.com>
parents:
56751
diff
changeset
|
136 (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
|
137 (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
|
138 ad-do-it)) |
56676 | 139 |
66357
f5ade15d46f2
* mh-identity.el (mh-assoc-ignore-case): Merge with version in
Bill Wohler <wohler@newt.com>
parents:
64085
diff
changeset
|
140 (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
|
141 "Check if KEY is present in ALIST while ignoring case to do the comparison. |
67758
6b063593fdad
Follow Emacs coding conventions. Use default setting of
Bill Wohler <wohler@newt.com>
parents:
67681
diff
changeset
|
142 Compatibility macro for Emacs versions that lack `assoc-string', |
6b063593fdad
Follow Emacs coding conventions. Use default setting of
Bill Wohler <wohler@newt.com>
parents:
67681
diff
changeset
|
143 introduced in Emacs 22." |
66357
f5ade15d46f2
* mh-identity.el (mh-assoc-ignore-case): Merge with version in
Bill Wohler <wohler@newt.com>
parents:
64085
diff
changeset
|
144 (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
|
145 `(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
|
146 `(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
|
147 |
56676 | 148 (provide 'mh-acros) |
149 | |
67681 | 150 ;; Local Variables: |
151 ;; no-byte-compile: t | |
152 ;; indent-tabs-mode: nil | |
153 ;; sentence-end-double-space: nil | |
154 ;; End: | |
56676 | 155 |
56677 | 156 ;; arch-tag: b383b49a-494f-4ed0-a30a-cb6d5d2da4ff |
56676 | 157 ;;; mh-acros.el ends here |