diff options
| author | Richard M. Stallman | 1993-11-10 20:30:32 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1993-11-10 20:30:32 +0000 |
| commit | 24980d168f372bcfcca2526970af6c2f5987e99c (patch) | |
| tree | 1bc6f8155c0317a951165bee0f5057460374b565 | |
| parent | 240d5222116448aea048b1115063118245f96428 (diff) | |
| download | emacs-24980d168f372bcfcca2526970af6c2f5987e99c.tar.gz emacs-24980d168f372bcfcca2526970af6c2f5987e99c.zip | |
(remove-hook): New function, analogous to add-hook. This
is now the recommended way to remove a hook that you have added.
| -rw-r--r-- | lisp/subr.el | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/lisp/subr.el b/lisp/subr.el index aa158175998..02ada23bb67 100644 --- a/lisp/subr.el +++ b/lisp/subr.el | |||
| @@ -493,6 +493,21 @@ function, it is changed to a list of functions." | |||
| 493 | (nconc (symbol-value hook) (list function)) | 493 | (nconc (symbol-value hook) (list function)) |
| 494 | (cons function (symbol-value hook)))))) | 494 | (cons function (symbol-value hook)))))) |
| 495 | 495 | ||
| 496 | (defun remove-hook (hook function) | ||
| 497 | "Remove from the value of HOOK the function FUNCTION. | ||
| 498 | HOOK should be a symbol, and FUNCTION may be any valid function. If | ||
| 499 | FUNCTION isn't the value of HOOK, or, if FUNCTION doesn't appear in the | ||
| 500 | list of hooks to run in HOOK, then nothing is done. See add-hook." | ||
| 501 | (if (or (not (boundp hook)) ;unbound symbol, or | ||
| 502 | (null (symbol-value hook)) ;value is nil, or | ||
| 503 | (null function)) ;function is nil, then | ||
| 504 | nil ;Do nothing. | ||
| 505 | (let ((hook-value (symbol-value hook))) | ||
| 506 | (if (consp hook-value) | ||
| 507 | (setq hook-value (delete function hook-value)) | ||
| 508 | (if (eq hook-value function) | ||
| 509 | (setq hook-value nil))) | ||
| 510 | (set hook hook-value)))) | ||
| 496 | 511 | ||
| 497 | ;;;; Specifying things to do after certain files are loaded. | 512 | ;;;; Specifying things to do after certain files are loaded. |
| 498 | 513 | ||