Hej Hej,
Or you could just write the defun inside the add-hook
(add-hook 'org-mode-hook (defun silly-hook-defun () (message "it works)))
This should allow to remove later the hook if you want.
Cheers!
A community for the timeless and infinitely powerful editor. Want to see what Emacs is capable of?!
Hej Hej,
Or you could just write the defun inside the add-hook
(add-hook 'org-mode-hook (defun silly-hook-defun () (message "it works)))
This should allow to remove later the hook if you want.
Cheers!
When it comes to personal configuration, I see no good reason not to use lambdas in this case. I also use them a lot when binding keys to simple commands which I don't want to name.
Also: option 1.
M-x remove-hook
has alleviated that to an extent.Use named functions. It's just better.
You can also use this approach:
(add-hook 'text-mode-hook
(defalias 'my/fancy-mode-setup
(let (some-closure-var)
(lambda () ...))))
Advantage is that there can be only one alias, and it's added by name to the hook. So you can alter and re-run add-hook
without duplication, and you can easily remove it by name. Best of all, you can create a closure (the let
there) if you need that gives you "local storage in the function" that persists between runs (without cluttering the namespace with global variables).
but the documentation recommends against using lambdas in add-hook calls (which makes sense).
Why? I use lambdas in add-hook calls all the time, because it seems un-Lisp-ish to create a function to be called only once.
Can't modify a lamdba hook once it's been created, however if you named it via defun
you can redeclare it with new behaviour or remove it from the advice list.