[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: hooks, again
From: |
Emanuel Berg |
Subject: |
Re: hooks, again |
Date: |
Wed, 06 May 2015 21:17:29 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux) |
Stefan Monnier <monnier@iro.umontreal.ca> writes:
> But as seen earlier, you have to look at the value
> of `foo-hook' before this setq takes place to be
> sure it's safe. So you still need "the help or
> evaluation of the variable name or anything".
Yes, but only once.
> And next time you upgrade Emacs, you'll have to look
> again at the value of `foo-hook' before this setq,
> to make sure your `setq' is still OK.
This never presented a problem and I think it won't
since in my case all this relates to programming mode
hooks and not the more complicated ones that
supposedly would glue together a software package, for
example Gnus. But it is a valid point.
> And nothing explains why you want to remove
> previously present elements from that hook.
And this is nothing I have done either. Usually those
programming mode hooks are empty.
> And of course the above setq doesn't prevent later
> modification of the hook (luckily), so you may still
> need to look at the var's value if you want to know
> what's on the hook.
Indeed, here is some unorthodox use (?) of `add-hook'
and `remove-hook' where I don't want to use `setq',
because that would require first extracting the
original value and then resetting it.
(defun enable-jump ()
(add-hook 'w3m-display-hook 'goto-first-hit) )
(defun goto-first-hit (&optional url)
(if (search-forward "Top Definition" (point-max) t) ; Urban Dictionary
(progn
(forward-line 2)
(beginning-of-line)
(recenter-top-bottom 0) )
(search-forward " 1." (point-max) t)) ; YouTube
(remove-hook 'w3m-display-hook 'goto-first-hit) )
(defun web-search ()
(interactive)
(let ((search (get-search-string "Google")))
(unless (empty-string-p search)
(w3m-new-tab (format "Google: %s" search))
(w3m-search "google" search) ))
(enable-jump) ) ; all code [1]
> Normally, you shouldn't need to care what other
> functions are there.
Che Guevara said revolutionaries aren't normal people.
I don't think programmers are either.
> As mentioned before, if you like to use `setq' for
> your hooks, go right ahead. After all, that's how
> add-hook works under the hood. I just strongly
> discourage it and consider it a bug to do that in an
> Elisp package, except for very
> particular circumstances.
The anomaly mentioned was only indirectly the
consequence of `setq'. The hook worked for a single
function when that function was included in a list,
but not if the hook was set to only that function
(quoted). In addition, it was only reported in some
cases (which is why I supplied the code). Just setting
the mode did not result in an error for "non-list"
use. But it all other hooks that I had, for a single,
quoted function (i.e. no list) it worked.
... wait, you mean YOU consider it a bug? Yes, I would
consider it a bug as well in packages because that
could ruin the user's configurations. The idea with
packages are they should float in the air and not ruin
what is below. Agreed.
[1] http://user.it.uu.se/~embe8573/conf/emacs-init/w3m/w3m-unisearch.el
--
underground experts united
http://user.it.uu.se/~embe8573
- --batch on many files without reloading config (was: Re: hook syntax), Emanuel Berg, 2015/05/04
- Re: --batch on many files without reloading config, Stefan Monnier, 2015/05/05
- hooks, again (was: Re: --batch on many files without reloading config), Emanuel Berg, 2015/05/05
- Re: hooks, again, Stefan Monnier, 2015/05/05
- Message not available
- Re: hooks, again, Emanuel Berg, 2015/05/05
- Re: hooks, again, Stefan Monnier, 2015/05/05
- Message not available
- Re: hooks, again, Emanuel Berg, 2015/05/05
- Re: hooks, again, Stefan Monnier, 2015/05/06
- Re: hooks, again,
Emanuel Berg <=
- Re: hooks, again, Stefan Monnier, 2015/05/06
- Message not available
- Re: hooks, again, Emanuel Berg, 2015/05/06
- Re: hooks, again, Stefan Monnier, 2015/05/06
- Message not available
- Re: hooks, again, Emanuel Berg, 2015/05/10