comparison lisp/mh-e/mh-acros.el @ 67758:6b063593fdad

Follow Emacs coding conventions. Use default setting of emacs-lisp-docstring-fill-column which is 65.
author Bill Wohler <wohler@newt.com>
date Fri, 23 Dec 2005 07:40:40 +0000
parents 3a8785724cca
children 9c3504ae6060
comparison
equal deleted inserted replaced
67757:488b4dbc7482 67758:6b063593fdad
47 ;; routines in their macro expansions. Use mh-require-cl to provide the cl 47 ;; routines in their macro expansions. Use mh-require-cl to provide the cl
48 ;; routines in the best way possible. 48 ;; routines in the best way possible.
49 (defmacro mh-require-cl () 49 (defmacro mh-require-cl ()
50 "Macro to load `cl' if needed. 50 "Macro to load `cl' if needed.
51 Some versions of `cl' produce code for the expansion of 51 Some versions of `cl' produce code for the expansion of
52 \(setf (gethash ...) ...) that uses functions in `cl' at run time. This macro 52 \(setf (gethash ...) ...) that uses functions in `cl' at run
53 recognizes that and loads `cl' where appropriate." 53 time. This macro recognizes that and loads `cl' where
54 appropriate."
54 (if (eq (car (macroexpand '(setf (gethash foo bar) baz))) 'cl-puthash) 55 (if (eq (car (macroexpand '(setf (gethash foo bar) baz))) 'cl-puthash)
55 `(require 'cl) 56 `(require 'cl)
56 `(eval-when-compile (require 'cl)))) 57 `(eval-when-compile (require 'cl))))
57 58
58 ;; Macros to generate correct code for different emacs variants 59 ;; Macros to generate correct code for different emacs variants
73 `(when (fboundp ',function) 74 `(when (fboundp ',function)
74 (funcall ',function ,@args)))) 75 (funcall ',function ,@args))))
75 76
76 (defmacro mh-make-local-hook (hook) 77 (defmacro mh-make-local-hook (hook)
77 "Make HOOK local if needed. 78 "Make HOOK local if needed.
78 XEmacs and versions of GNU Emacs before 21.1 require `make-local-hook' to be 79 XEmacs and versions of GNU Emacs before 21.1 require
79 called." 80 `make-local-hook' to be called."
80 (when (and (fboundp 'make-local-hook) 81 (when (and (fboundp 'make-local-hook)
81 (not (get 'make-local-hook 'byte-obsolete-info))) 82 (not (get 'make-local-hook 'byte-obsolete-info)))
82 `(make-local-hook ,hook))) 83 `(make-local-hook ,hook)))
83 84
84 (defmacro mh-mark-active-p (check-transient-mark-mode-flag) 85 (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 "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 In GNU Emacs if CHECK-TRANSIENT-MARK-MODE-FLAG is non-nil then
87 variable `transient-mark-mode' is active." 88 check if variable `transient-mark-mode' is active."
88 (cond ((featurep 'xemacs) ;XEmacs 89 (cond ((featurep 'xemacs) ;XEmacs
89 `(and (boundp 'zmacs-regions) zmacs-regions (region-active-p))) 90 `(and (boundp 'zmacs-regions) zmacs-regions (region-active-p)))
90 ((not check-transient-mark-mode-flag) ;GNU Emacs 91 ((not check-transient-mark-mode-flag) ;GNU Emacs
91 `(and (boundp 'mark-active) mark-active)) 92 `(and (boundp 'mark-active) mark-active))
92 (t ;GNU Emacs 93 (t ;GNU Emacs
93 `(and (boundp 'transient-mark-mode) transient-mark-mode 94 `(and (boundp 'transient-mark-mode) transient-mark-mode
94 (boundp 'mark-active) mark-active)))) 95 (boundp 'mark-active) mark-active))))
95 96
96 (defmacro mh-defstruct (name-spec &rest fields) 97 (defmacro mh-defstruct (name-spec &rest fields)
97 "Replacement for `defstruct' from the `cl' package. 98 "Replacement for `defstruct' from the `cl' package.
98 The `defstruct' in the `cl' library produces compiler warnings, and generates 99 The `defstruct' in the `cl' library produces compiler warnings,
99 code that uses functions present in `cl' at run-time. This is a partial 100 and generates code that uses functions present in `cl' at
100 replacement, that avoids these issues. 101 run-time. This is a partial replacement, that avoids these
102 issues.
101 103
102 NAME-SPEC declares the name of the structure, while FIELDS describes the 104 NAME-SPEC declares the name of the structure, while FIELDS
103 various structure fields. Lookup `defstruct' for more details." 105 describes the various structure fields. Lookup `defstruct' for
106 more details."
104 (let* ((struct-name (if (atom name-spec) name-spec (car name-spec))) 107 (let* ((struct-name (if (atom name-spec) name-spec (car name-spec)))
105 (conc-name (or (and (consp name-spec) 108 (conc-name (or (and (consp name-spec)
106 (cadr (assoc :conc-name (cdr name-spec)))) 109 (cadr (assoc :conc-name (cdr name-spec))))
107 (format "%s-" struct-name))) 110 (format "%s-" struct-name)))
108 (predicate (intern (format "%s-p" struct-name))) 111 (predicate (intern (format "%s-p" struct-name)))
134 (load (format "%s.el" (ad-get-arg 0)) t t)) 137 (load (format "%s.el" (ad-get-arg 0)) t t))
135 ad-do-it)) 138 ad-do-it))
136 139
137 (defmacro mh-assoc-ignore-case (key alist) 140 (defmacro mh-assoc-ignore-case (key alist)
138 "Check if KEY is present in ALIST while ignoring case to do the comparison. 141 "Check if KEY is present in ALIST while ignoring case to do the comparison.
139 Compatibility macro for Emacs versions that lack `assoc-string', introduced in 142 Compatibility macro for Emacs versions that lack `assoc-string',
140 Emacs 22." 143 introduced in Emacs 22."
141 (if (fboundp 'assoc-string) 144 (if (fboundp 'assoc-string)
142 `(assoc-string ,key ,alist t) 145 `(assoc-string ,key ,alist t)
143 `(assoc-ignore-case ,key ,alist))) 146 `(assoc-ignore-case ,key ,alist)))
144 147
145 (provide 'mh-acros) 148 (provide 'mh-acros)