* autoloading entire function
@ 2016-06-13 15:43 Phillip Lord
2016-06-13 17:36 ` Glenn Morris
0 siblings, 1 reply; 3+ messages in thread
From: Phillip Lord @ 2016-06-13 15:43 UTC (permalink / raw)
To: help-gnu-emacs
I have written a function in my package which looks like this...
(defun lentic-script-hook (mode-hook init)
(add-to-list 'lentic-init-functions
init)
(add-hook mode-hook
(lambda ()
(unless lentic-init
(setq lentic-init init)))))
It then gets used like this:
(lentic-script-hook 'python-mode-hook
'lentic-python-script-init)
Essentially, it makes writing a set of stereotyped "add-hook" calls a
bit easier.
But I now have an autoload problem. If I want to do this:
;;;###autoload
(lentic-script-hook 'python-mode-hook
'lentic-python-script-init)
My code will now break since `lentic-script-hook' is not defined.
I could, of course, add an autoload cookie to `lentic-script-hook'. But
now, when the autoload file is loaded, lentic-script-hook is called, so
loading will be forced which defeats the point of autoloading.
So, I need to put the entirely of `lentic-script-hook' into the autoload
files. Of course, it will itself not be autoloaded, but that's not a
huge problem.
How to achieve this?
The only solutions I have so far are this:
;;;###autoload (defun lentic-script-hook (mode-hook init) (add-to-list 'lentic-init-functions init) (add-hook mode-hook (lambda nil (unless lentic-init (setq lentic-init init))))))
putting everything on oneline does the trick. But it's ugly to read,
and, if I evaluate the source file manually (i.e. I don't use
autoloads), the form is commented so does not get evaluated.
Another options is not use defun but it's expansion and autoload this:
;;;###autoload
(defalias 'lentic-script-hook
#'(lambda
(mode-hook init)
(add-to-list 'lentic-init-functions init)
(add-hook mode-hook
(lambda nil
(unless lentic-init
(setq lentic-init init))))))
which works but, also, is not ideal. The defun macro is there for a
reason, and it would be nice to use it.
Any other options I have missed?
Phil
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2016-06-13 20:07 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-06-13 15:43 autoloading entire function Phillip Lord
2016-06-13 17:36 ` Glenn Morris
2016-06-13 20:07 ` Phillip Lord
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.