| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 |
|
|---|
| 29 |
|
|---|
| 30 |
|
|---|
| 31 |
|
|---|
| 32 |
|
|---|
| 33 |
|
|---|
| 34 |
|
|---|
| 35 |
|
|---|
| 36 |
|
|---|
| 37 |
|
|---|
| 38 |
|
|---|
| 39 |
(defun macro-declaration-function (macro decl) |
|---|
| 40 |
"Process a declaration found in a macro definition. |
|---|
| 41 |
This is set as the value of the variable `macro-declaration-function'. |
|---|
| 42 |
MACRO is the name of the macro being defined. |
|---|
| 43 |
DECL is a list `(declare ...)' containing the declarations. |
|---|
| 44 |
The return value of this function is not used." |
|---|
| 45 |
|
|---|
| 46 |
(let (d) |
|---|
| 47 |
|
|---|
| 48 |
(while (setq decl (cdr decl)) |
|---|
| 49 |
(setq d (car decl)) |
|---|
| 50 |
(cond ((and (consp d) (eq (car d) 'indent)) |
|---|
| 51 |
(put macro 'lisp-indent-function (car (cdr d)))) |
|---|
| 52 |
((and (consp d) (eq (car d) 'debug)) |
|---|
| 53 |
(put macro 'edebug-form-spec (car (cdr d)))) |
|---|
| 54 |
((and (consp d) (eq (car d) 'doc-string)) |
|---|
| 55 |
(put macro 'doc-string-elt (car (cdr d)))) |
|---|
| 56 |
(t |
|---|
| 57 |
(message "Unknown declaration %s" d)))))) |
|---|
| 58 |
|
|---|
| 59 |
(setq macro-declaration-function 'macro-declaration-function) |
|---|
| 60 |
|
|---|
| 61 |
|
|---|
| 62 |
|
|---|
| 63 |
|
|---|
| 64 |
(fset 'inline 'progn) |
|---|
| 65 |
(put 'inline 'lisp-indent-function 0) |
|---|
| 66 |
|
|---|
| 67 |
|
|---|
| 68 |
|
|---|
| 69 |
|
|---|
| 70 |
|
|---|
| 71 |
|
|---|
| 72 |
|
|---|
| 73 |
|
|---|
| 74 |
|
|---|
| 75 |
|
|---|
| 76 |
|
|---|
| 77 |
|
|---|
| 78 |
|
|---|
| 79 |
|
|---|
| 80 |
|
|---|
| 81 |
|
|---|
| 82 |
|
|---|
| 83 |
|
|---|
| 84 |
|
|---|
| 85 |
|
|---|
| 86 |
|
|---|
| 87 |
|
|---|
| 88 |
|
|---|
| 89 |
|
|---|
| 90 |
|
|---|
| 91 |
|
|---|
| 92 |
|
|---|
| 93 |
|
|---|
| 94 |
|
|---|
| 95 |
(defmacro defsubst (name arglist &rest body) |
|---|
| 96 |
"Define an inline function. The syntax is just like that of `defun'." |
|---|
| 97 |
(declare (debug defun)) |
|---|
| 98 |
(or (memq (get name 'byte-optimizer) |
|---|
| 99 |
'(nil byte-compile-inline-expand)) |
|---|
| 100 |
(error "`%s' is a primitive" name)) |
|---|
| 101 |
`(prog1 |
|---|
| 102 |
(defun ,name ,arglist ,@body) |
|---|
| 103 |
(eval-and-compile |
|---|
| 104 |
(put ',name 'byte-optimizer 'byte-compile-inline-expand)))) |
|---|
| 105 |
|
|---|
| 106 |
(defmacro declare-function (&rest args) |
|---|
| 107 |
"In Emacs 22, does nothing. In 23, it will suppress byte-compiler warnings. |
|---|
| 108 |
This definition is so that packages may take advantage of the |
|---|
| 109 |
Emacs 23 feature and still remain compatible with Emacs 22." |
|---|
| 110 |
nil) |
|---|
| 111 |
|
|---|
| 112 |
(defun make-obsolete (obsolete-name current-name &optional when) |
|---|
| 113 |
"Make the byte-compiler warn that OBSOLETE-NAME is obsolete. |
|---|
| 114 |
The warning will say that CURRENT-NAME should be used instead. |
|---|
| 115 |
If CURRENT-NAME is a string, that is the `use instead' message. |
|---|
| 116 |
If provided, WHEN should be a string indicating when the function |
|---|
| 117 |
was first made obsolete, for example a date or a release number." |
|---|
| 118 |
(interactive "aMake function obsolete: \nxObsoletion replacement: ") |
|---|
| 119 |
(let ((handler (get obsolete-name 'byte-compile))) |
|---|
| 120 |
(if (eq 'byte-compile-obsolete handler) |
|---|
| 121 |
(setq handler (nth 1 (get obsolete-name 'byte-obsolete-info))) |
|---|
| 122 |
(put obsolete-name 'byte-compile 'byte-compile-obsolete)) |
|---|
| 123 |
(put obsolete-name 'byte-obsolete-info (list current-name handler when))) |
|---|
| 124 |
obsolete-name) |
|---|
| 125 |
|
|---|
| 126 |
(defmacro define-obsolete-function-alias (obsolete-name current-name |
|---|
| 127 |
&optional when docstring) |
|---|
| 128 |
"Set OBSOLETE-NAME's function definition to CURRENT-NAME and mark it obsolete. |
|---|
| 129 |
|
|---|
| 130 |
\(define-obsolete-function-alias 'old-fun 'new-fun \"22.1\" \"old-fun's doc.\") |
|---|
| 131 |
|
|---|
| 132 |
is equivalent to the following two lines of code: |
|---|
| 133 |
|
|---|
| 134 |
\(defalias 'old-fun 'new-fun \"old-fun's doc.\") |
|---|
| 135 |
\(make-obsolete 'old-fun 'new-fun \"22.1\") |
|---|
| 136 |
|
|---|
| 137 |
See the docstrings of `defalias' and `make-obsolete' for more details." |
|---|
| 138 |
(declare (doc-string 4)) |
|---|
| 139 |
`(progn |
|---|
| 140 |
(defalias ,obsolete-name ,current-name ,docstring) |
|---|
| 141 |
(make-obsolete ,obsolete-name ,current-name ,when))) |
|---|
| 142 |
|
|---|
| 143 |
(defun make-obsolete-variable (obsolete-name current-name &optional when) |
|---|
| 144 |
"Make the byte-compiler warn that OBSOLETE-NAME is obsolete. |
|---|
| 145 |
The warning will say that CURRENT-NAME should be used instead. |
|---|
| 146 |
If CURRENT-NAME is a string, that is the `use instead' message. |
|---|
| 147 |
If provided, WHEN should be a string indicating when the variable |
|---|
| 148 |
was first made obsolete, for example a date or a release number." |
|---|
| 149 |
(interactive |
|---|
| 150 |
(list |
|---|
| 151 |
(let ((str (completing-read "Make variable obsolete: " obarray 'boundp t))) |
|---|
| 152 |
(if (equal str "") (error "")) |
|---|
| 153 |
(intern str)) |
|---|
| 154 |
(car (read-from-string (read-string "Obsoletion replacement: "))))) |
|---|
| 155 |
(put obsolete-name 'byte-obsolete-variable (cons current-name when)) |
|---|
| 156 |
obsolete-name) |
|---|
| 157 |
|
|---|
| 158 |
(defmacro define-obsolete-variable-alias (obsolete-name current-name |
|---|
| 159 |
&optional when docstring) |
|---|
| 160 |
"Make OBSOLETE-NAME a variable alias for CURRENT-NAME and mark it obsolete. |
|---|
| 161 |
|
|---|
| 162 |
\(define-obsolete-variable-alias 'old-var 'new-var \"22.1\" \"old-var's doc.\") |
|---|
| 163 |
|
|---|
| 164 |
is equivalent to the following two lines of code: |
|---|
| 165 |
|
|---|
| 166 |
\(defvaralias 'old-var 'new-var \"old-var's doc.\") |
|---|
| 167 |
\(make-obsolete-variable 'old-var 'new-var \"22.1\") |
|---|
| 168 |
|
|---|
| 169 |
See the docstrings of `defvaralias' and `make-obsolete-variable' or |
|---|
| 170 |
Info node `(elisp)Variable Aliases' for more details." |
|---|
| 171 |
(declare (doc-string 4)) |
|---|
| 172 |
`(progn |
|---|
| 173 |
(defvaralias ,obsolete-name ,current-name ,docstring) |
|---|
| 174 |
(make-obsolete-variable ,obsolete-name ,current-name ,when))) |
|---|
| 175 |
|
|---|
| 176 |
(defmacro dont-compile (&rest body) |
|---|
| 177 |
"Like `progn', but the body always runs interpreted (not compiled). |
|---|
| 178 |
If you think you need this, you're probably making a mistake somewhere." |
|---|
| 179 |
(declare (debug t) (indent 0)) |
|---|
| 180 |
(list 'eval (list 'quote (if (cdr body) (cons 'progn body) (car body))))) |
|---|
| 181 |
|
|---|
| 182 |
|
|---|
| 183 |
|
|---|
| 184 |
|
|---|
| 185 |
|
|---|
| 186 |
|
|---|
| 187 |
|
|---|
| 188 |
(defmacro eval-when-compile (&rest body) |
|---|
| 189 |
"Like `progn', but evaluates the body at compile time if you're compiling. |
|---|
| 190 |
Thus, the result of the body appears to the compiler as a quoted constant. |
|---|
| 191 |
In interpreted code, this is entirely equivalent to `progn'." |
|---|
| 192 |
(declare (debug t) (indent 0)) |
|---|
| 193 |
|
|---|
| 194 |
|
|---|
| 195 |
(cons 'progn body)) |
|---|
| 196 |
|
|---|
| 197 |
(defmacro eval-and-compile (&rest body) |
|---|
| 198 |
"Like `progn', but evaluates the body at compile time and at load time." |
|---|
| 199 |
(declare (debug t) (indent 0)) |
|---|
| 200 |
|
|---|
| 201 |
(cons 'progn body)) |
|---|
| 202 |
|
|---|
| 203 |
(put 'with-no-warnings 'lisp-indent-function 0) |
|---|
| 204 |
(defun with-no-warnings (&rest body) |
|---|
| 205 |
"Like `progn', but prevents compiler warnings in the body." |
|---|
| 206 |
|
|---|
| 207 |
(car (last body))) |
|---|
| 208 |
|
|---|
| 209 |
|
|---|
| 210 |
|
|---|
| 211 |
|
|---|
| 212 |
|
|---|
| 213 |
|
|---|
| 214 |
|
|---|
| 215 |
|
|---|
| 216 |
|
|---|
| 217 |
|
|---|
| 218 |
|
|---|
| 219 |
|
|---|
| 220 |
|
|---|
| 221 |
|
|---|
| 222 |
|
|---|
| 223 |
|
|---|
| 224 |
|
|---|
| 225 |
|
|---|
| 226 |
|
|---|
| 227 |
|
|---|
| 228 |
|
|---|
| 229 |
|
|---|
| 230 |
|
|---|
| 231 |
|
|---|
| 232 |
|
|---|
| 233 |
|
|---|
| 234 |
|
|---|
| 235 |
|
|---|
| 236 |
|
|---|
| 237 |
|
|---|
| 238 |
|
|---|
| 239 |
|
|---|
| 240 |
|
|---|
| 241 |
|
|---|
| 242 |
|
|---|
| 243 |
|
|---|