help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: ~`symbol-function' to get code as list even when byte-compiled?


From: Emanuel Berg
Subject: Re: ~`symbol-function' to get code as list even when byte-compiled?
Date: Wed, 27 May 2015 01:02:20 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux)

Stefan Monnier <monnier@iro.umontreal.ca> writes:

>> Perhaps this is a better (safer) way to have it in
>> but still out of action.
>
> Why have it out of action? The Right Thing to do is to
> pass it along to fun:
>
>    (defun add-one-shot-hook (hook fun) (let ((name
> (cl-gensym))) (setf (symbol-function name) (lambda
> (&rest args) (remove-hook hook name) (apply fun
> args))) (add-hook hook name)))

When I did this by putting the "payload" functions
directly into the w3m hook that required them to all
have one parameter, as w3m executed all them hook
functions with the URL passed as (the
single) argument.

However now with this solution when there is a lambda
around the functions the lambda can deal with the
argument, so I removed the parameters from all the
payloads. E.g., number-one-jump now looks like this:

    (defun number-one-jump () ; Google, Youtube
      (when (re-search-forward "^ 1." (point-max) t)
        (recenter-top-bottom 0)
        (w3m-next-anchor) ))

So correct me if I'm wrong, but if I used `apply' with
the argument as you suggest, wouldn't that lead to an
error, namely wrong-number-of-arguments? On the other
hand, if I then were to add those parameters again to
the payloads, wouldn't I have the byte-compiler
complain even more (once for each function) that
*they* don't use the argument?

-- 
underground experts united
http://user.it.uu.se/~embe8573


reply via email to

[Prev in Thread] Current Thread [Next in Thread]