diff options
| author | Richard M. Stallman | 2003-10-20 23:41:18 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 2003-10-20 23:41:18 +0000 |
| commit | b7a1c90026e5d2582ab17ba6d62522f42e0b07c3 (patch) | |
| tree | 8a81a88cca6e6ca7fb1f91c8afb56586ec5df483 | |
| parent | c80be8236db760ecda3545e75fb4b87636b9ef9d (diff) | |
| download | emacs-b7a1c90026e5d2582ab17ba6d62522f42e0b07c3.tar.gz emacs-b7a1c90026e5d2582ab17ba6d62522f42e0b07c3.zip | |
(add-hook): Correctly detect when make-local-hook was used.
(remove-hook): Correctly handle strange cases about local hooks.
| -rw-r--r-- | lisp/subr.el | 47 |
1 files changed, 25 insertions, 22 deletions
diff --git a/lisp/subr.el b/lisp/subr.el index f7c026e9296..e29c48ae743 100644 --- a/lisp/subr.el +++ b/lisp/subr.el | |||
| @@ -856,7 +856,9 @@ function, it is changed to a list of functions." | |||
| 856 | (set (make-local-variable hook) (list t))) | 856 | (set (make-local-variable hook) (list t))) |
| 857 | ;; Detect the case where make-local-variable was used on a hook | 857 | ;; Detect the case where make-local-variable was used on a hook |
| 858 | ;; and do what we used to do. | 858 | ;; and do what we used to do. |
| 859 | (unless (and (consp (symbol-value hook)) (memq t (symbol-value hook))) | 859 | (when (and (local-variable-p hook) |
| 860 | (not (and (consp (symbol-value hook)) | ||
| 861 | (memq t (symbol-value hook))))) | ||
| 860 | (setq local t))) | 862 | (setq local t))) |
| 861 | (let ((hook-value (if local (symbol-value hook) (default-value hook)))) | 863 | (let ((hook-value (if local (symbol-value hook) (default-value hook)))) |
| 862 | ;; If the hook value is a single function, turn it into a list. | 864 | ;; If the hook value is a single function, turn it into a list. |
| @@ -878,31 +880,32 @@ FUNCTION isn't the value of HOOK, or, if FUNCTION doesn't appear in the | |||
| 878 | list of hooks to run in HOOK, then nothing is done. See `add-hook'. | 880 | list of hooks to run in HOOK, then nothing is done. See `add-hook'. |
| 879 | 881 | ||
| 880 | The optional third argument, LOCAL, if non-nil, says to modify | 882 | The optional third argument, LOCAL, if non-nil, says to modify |
| 881 | the hook's buffer-local value rather than its default value. | 883 | the hook's buffer-local value rather than its default value." |
| 882 | This makes the hook buffer-local if needed." | ||
| 883 | (or (boundp hook) (set hook nil)) | 884 | (or (boundp hook) (set hook nil)) |
| 884 | (or (default-boundp hook) (set-default hook nil)) | 885 | (or (default-boundp hook) (set-default hook nil)) |
| 885 | (if local (unless (local-variable-if-set-p hook) | 886 | ;; Do nothing if LOCAL is t but this hook has no local binding. |
| 886 | (set (make-local-variable hook) (list t))) | 887 | (unless (and local (not (local-variable-p hook))) |
| 887 | ;; Detect the case where make-local-variable was used on a hook | 888 | ;; Detect the case where make-local-variable was used on a hook |
| 888 | ;; and do what we used to do. | 889 | ;; and do what we used to do. |
| 889 | (unless (and (consp (symbol-value hook)) (memq t (symbol-value hook))) | 890 | (when (and (local-variable-p hook) |
| 890 | (setq local t))) | 891 | (not (and (consp (symbol-value hook)) |
| 891 | (let ((hook-value (if local (symbol-value hook) (default-value hook)))) | 892 | (memq t (symbol-value hook))))) |
| 892 | ;; Remove the function, for both the list and the non-list cases. | 893 | (setq local t)) |
| 893 | (if (or (not (listp hook-value)) (eq (car hook-value) 'lambda)) | 894 | (let ((hook-value (if local (symbol-value hook) (default-value hook)))) |
| 894 | (if (equal hook-value function) (setq hook-value nil)) | 895 | ;; Remove the function, for both the list and the non-list cases. |
| 895 | (setq hook-value (delete function (copy-sequence hook-value)))) | 896 | (if (or (not (listp hook-value)) (eq (car hook-value) 'lambda)) |
| 896 | ;; If the function is on the global hook, we need to shadow it locally | 897 | (if (equal hook-value function) (setq hook-value nil)) |
| 897 | ;;(when (and local (member function (default-value hook)) | 898 | (setq hook-value (delete function (copy-sequence hook-value)))) |
| 898 | ;; (not (member (cons 'not function) hook-value))) | 899 | ;; If the function is on the global hook, we need to shadow it locally |
| 899 | ;; (push (cons 'not function) hook-value)) | 900 | ;;(when (and local (member function (default-value hook)) |
| 900 | ;; Set the actual variable | 901 | ;; (not (member (cons 'not function) hook-value))) |
| 901 | (if (not local) | 902 | ;; (push (cons 'not function) hook-value)) |
| 902 | (set-default hook hook-value) | 903 | ;; Set the actual variable |
| 903 | (if (equal hook-value '(t)) | 904 | (if (not local) |
| 904 | (kill-local-variable hook) | 905 | (set-default hook hook-value) |
| 905 | (set hook hook-value))))) | 906 | (if (equal hook-value '(t)) |
| 907 | (kill-local-variable hook) | ||
| 908 | (set hook hook-value)))))) | ||
| 906 | 909 | ||
| 907 | (defun add-to-list (list-var element &optional append) | 910 | (defun add-to-list (list-var element &optional append) |
| 908 | "Add to the value of LIST-VAR the element ELEMENT if it isn't there yet. | 911 | "Add to the value of LIST-VAR the element ELEMENT if it isn't there yet. |