aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChong Yidong2011-10-26 08:44:06 +0800
committerChong Yidong2011-10-26 08:44:06 +0800
commitb1f6fa2666442e27ae8ac3439fd1891c94fe36bc (patch)
treebb17cd1f4a09f00db5cf2ee1b752a94e86f05d02
parent507ea2587e3b868468e83ff6bc8b3303c4097984 (diff)
downloademacs-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.
-rw-r--r--etc/NEWS8
-rw-r--r--lisp/ChangeLog4
-rw-r--r--lisp/subr.el40
3 files changed, 35 insertions, 17 deletions
diff --git a/etc/NEWS b/etc/NEWS
index d6b0bdb484c..58f3fa492e2 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1169,7 +1169,13 @@ must also be supplied.
1169** pre/post-command-hook are not reset to nil upon error. 1169** pre/post-command-hook are not reset to nil upon error.
1170Instead, the offending function is removed. 1170Instead, the offending function is removed.
1171 1171
1172** New low-level function run-hook-wrapped. 1172** New hook types
1173
1174*** New function `run-hook-wrapped' for running an abnormal hook by
1175passing the hook functions as arguments to a "wrapping" function.
1176+++
1177*** New macro `with-wrapper-hook' for running an abnormal hook as a
1178set of "wrapping" filters, similar to around advice.
1173 1179
1174** `server-eval-at' is provided to allow evaluating forms on different 1180** `server-eval-at' is provided to allow evaluating forms on different
1175Emacs server instances. 1181Emacs server instances.
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 95113007f27..b75d262a9b6 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,7 @@
12011-10-26 Chong Yidong <cyd@gnu.org>
2
3 * subr.el (with-wrapper-hook): Rewrite doc.
4
12011-10-25 Michael Albinus <michael.albinus@gmx.de> 52011-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.
1369VAR is a special hook: its functions are called with a first argument 1369HOOK is an abnormal hook. Each hook function in HOOK \"wraps\"
1370which is the \"original\" code (the BODY), so the hook function can wrap 1370around the preceding ones, like a set of nested `around' advices.
1371the original function, or call it any number of times (including not calling 1371
1372it at all). This is similar to an `around' advice. 1372Each hook function should accept an argument list consisting of a
1373VAR is normally a symbol (a variable) in which case it is treated like 1373function FUN, followed by the additional arguments in ARGS.
1374a hook, with a buffer-local and a global part. But it can also be an 1374
1375arbitrary expression. 1375The FUN passed to the first hook function in HOOK performs BODY,
1376ARGS is a list of variables which will be passed as additional arguments 1376if it is called with arguments ARGS. The FUN passed to each
1377to each function, after the initial argument, and which the first argument 1377successive hook function is defined based on the preceding hook
1378expects to receive when called." 1378functions; if called with arguments ARGS, it does what the
1379`with-wrapper-hook' call would do if the preceding hook functions
1380were the only ones present in HOOK.
1381
1382In the function definition of each hook function, FUN can be
1383called any number of times (including not calling it at all).
1384That function definition is then used to construct the FUN passed
1385to the next hook function, if any. The last (or \"outermost\")
1386FUN 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)