diff options
| author | Chong Yidong | 2011-10-26 08:44:06 +0800 |
|---|---|---|
| committer | Chong Yidong | 2011-10-26 08:44:06 +0800 |
| commit | b1f6fa2666442e27ae8ac3439fd1891c94fe36bc (patch) | |
| tree | bb17cd1f4a09f00db5cf2ee1b752a94e86f05d02 /lisp | |
| parent | 507ea2587e3b868468e83ff6bc8b3303c4097984 (diff) | |
| download | emacs-b1f6fa2666442e27ae8ac3439fd1891c94fe36bc.tar.gz emacs-b1f6fa2666442e27ae8ac3439fd1891c94fe36bc.zip | |
Document with-wrapper-hook.
* doc/emacs/modes.texi (Running Hooks): Document with-wrapper-hook.
* lisp/subr.el (with-wrapper-hook): Rewrite doc.
Diffstat (limited to 'lisp')
| -rw-r--r-- | lisp/ChangeLog | 4 | ||||
| -rw-r--r-- | lisp/subr.el | 40 |
2 files changed, 28 insertions, 16 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 95113007f27..b75d262a9b6 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,7 @@ | |||
| 1 | 2011-10-26 Chong Yidong <cyd@gnu.org> | ||
| 2 | |||
| 3 | * subr.el (with-wrapper-hook): Rewrite doc. | ||
| 4 | |||
| 1 | 2011-10-25 Michael Albinus <michael.albinus@gmx.de> | 5 | 2011-10-25 Michael Albinus <michael.albinus@gmx.de> |
| 2 | 6 | ||
| 3 | * net/tramp-sh.el (tramp-sh-handle-file-directory-p): Return t for | 7 | * net/tramp-sh.el (tramp-sh-handle-file-directory-p): Return t for |
diff --git a/lisp/subr.el b/lisp/subr.el index c88cef0ba0f..7ac287d2473 100644 --- a/lisp/subr.el +++ b/lisp/subr.el | |||
| @@ -1364,18 +1364,26 @@ All symbols are bound before the VALUEFORMs are evalled." | |||
| 1364 | ,@(mapcar (lambda (binder) `(setq ,@binder)) binders) | 1364 | ,@(mapcar (lambda (binder) `(setq ,@binder)) binders) |
| 1365 | ,@body)) | 1365 | ,@body)) |
| 1366 | 1366 | ||
| 1367 | (defmacro with-wrapper-hook (var args &rest body) | 1367 | (defmacro with-wrapper-hook (hook args &rest body) |
| 1368 | "Run BODY wrapped with the VAR hook. | 1368 | "Run BODY, using wrapper functions from HOOK with additional ARGS. |
| 1369 | VAR is a special hook: its functions are called with a first argument | 1369 | HOOK is an abnormal hook. Each hook function in HOOK \"wraps\" |
| 1370 | which is the \"original\" code (the BODY), so the hook function can wrap | 1370 | around the preceding ones, like a set of nested `around' advices. |
| 1371 | the original function, or call it any number of times (including not calling | 1371 | |
| 1372 | it at all). This is similar to an `around' advice. | 1372 | Each hook function should accept an argument list consisting of a |
| 1373 | VAR is normally a symbol (a variable) in which case it is treated like | 1373 | function FUN, followed by the additional arguments in ARGS. |
| 1374 | a hook, with a buffer-local and a global part. But it can also be an | 1374 | |
| 1375 | arbitrary expression. | 1375 | The FUN passed to the first hook function in HOOK performs BODY, |
| 1376 | ARGS is a list of variables which will be passed as additional arguments | 1376 | if it is called with arguments ARGS. The FUN passed to each |
| 1377 | to each function, after the initial argument, and which the first argument | 1377 | successive hook function is defined based on the preceding hook |
| 1378 | expects to receive when called." | 1378 | functions; if called with arguments ARGS, it does what the |
| 1379 | `with-wrapper-hook' call would do if the preceding hook functions | ||
| 1380 | were the only ones present in HOOK. | ||
| 1381 | |||
| 1382 | In the function definition of each hook function, FUN can be | ||
| 1383 | called any number of times (including not calling it at all). | ||
| 1384 | That function definition is then used to construct the FUN passed | ||
| 1385 | to the next hook function, if any. The last (or \"outermost\") | ||
| 1386 | FUN is then called once." | ||
| 1379 | (declare (indent 2) (debug (form sexp body))) | 1387 | (declare (indent 2) (debug (form sexp body))) |
| 1380 | ;; We need those two gensyms because CL's lexical scoping is not available | 1388 | ;; We need those two gensyms because CL's lexical scoping is not available |
| 1381 | ;; for function arguments :-( | 1389 | ;; for function arguments :-( |
| @@ -1404,11 +1412,11 @@ expects to receive when called." | |||
| 1404 | ;; Once there are no more functions on the hook, run | 1412 | ;; Once there are no more functions on the hook, run |
| 1405 | ;; the original body. | 1413 | ;; the original body. |
| 1406 | (apply (lambda ,args ,@body) ,argssym))))) | 1414 | (apply (lambda ,args ,@body) ,argssym))))) |
| 1407 | (funcall ,runrestofhook ,var | 1415 | (funcall ,runrestofhook ,hook |
| 1408 | ;; The global part of the hook, if any. | 1416 | ;; The global part of the hook, if any. |
| 1409 | ,(if (symbolp var) | 1417 | ,(if (symbolp hook) |
| 1410 | `(if (local-variable-p ',var) | 1418 | `(if (local-variable-p ',hook) |
| 1411 | (default-value ',var))) | 1419 | (default-value ',hook))) |
| 1412 | (list ,@args))))) | 1420 | (list ,@args))))) |
| 1413 | 1421 | ||
| 1414 | (defun add-to-list (list-var element &optional append compare-fn) | 1422 | (defun add-to-list (list-var element &optional append compare-fn) |