I want to override the function
man mode using its hook, but not anywhere else. Is there something similar to
make-local-variable for functions?
At first the general statement: There is no buffer-local setting for the function cell of a symbol.
One can call an overriding function assigned to a buffer-local variable in an
:around advice of
(defvar-local helm-swoop-pre-input-optimize-function nil "Function overriding `helm-swoop-pre-input-optimize'.") (define-advice helm-swoop-pre-input-optimize (:around (fun &rest args) override) "Override `helm-swoop-pre-input-optimize'. Use the function registered at `helm-swoop-pre-input-optimize-function' instead of `helm-swoop-pre-input-optimize' if the value of `helm-swoop-pre-input-optimize-function' is non-nil." (if helm-swoop-pre-input-optimize-function (apply helm-swoop-pre-input-optimize-function args) (apply fun args))) (defun my-setup-Man-mode () "My personal setup for `Man-mode'." (setq helm-swoop-pre-input-optimize-function #'MY-SPECIAL-helm-swoop-pre-input-optimize)) (add-hook 'Man-mode #'my-setup-Man-mode)
MY-SPECIAL-helm-swoop-pre-input-optimize with your special override for
This solution is similar to that one on stackoverflow.
Since I do not use
helm you have to do the testing yourself.
A slight variation:
Instead of a buffer local variable you can also use an abnormal hook variable.
Add your function special to
Man-mode as buffer-local hook to that variable.
(defvar helm-swoop-pre-input-optimize-functions nil "Functions overriding `helm-swoop-pre-input-optimize'. They are called with the same arguments as `helm-swoop-pre-input-optimize' until one of them succeeds.") (define-advice helm-swoop-pre-input-optimize (:around (fun &rest args) override) "Override `helm-swoop-pre-input-optimize'. Use the functions registered at `helm-swoop-pre-input-optimize-functions' instead of `helm-swoop-pre-input-optimize' if one of them succeeds. Use the original `helm-swoop-pre-input-optimize' otherwise." (or (run-hook-with-args-until-success 'helm-swoop-pre-input-optimize-functions) (apply fun args))) (defun my-setup-Man-mode () "My personal setup for `Man-mode'." (add-hook 'helm-swoop-pre-input-optimize-functions #'MY-SPECIAL-helm-swoop-pre-input-optimize nil 'local)) (add-hook 'Man-mode #'my-setup-Man-mode)