emacs-devel
[Top][All Lists]
Advanced

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

Re: [PATCH] (Updated) Run hook when variable is set


From: Stefan Monnier
Subject: Re: [PATCH] (Updated) Run hook when variable is set
Date: Sat, 07 Feb 2015 10:09:38 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (gnu/linux)

> Your goal is to avoid the «if» at the end. In order to do that, you'd need 
> two functions:
> (defun set-internal-1 (args)
>   (block nil
>     (if (constant-p)
>       (if hooked ; Mutually exclusive with actual constant
>           (progn
>             (set-internal-1-and-run-varhook args)
>             (return))
>         (if (forbidden-p)
>             (error "setting constant")
>           (return))))
>     (do-some-stuff)
>     (and-many-more-lines-of-stuff)
>     (set-some-variable)))

> (defun set-internal-1-and-run-varhook (args)
>   (do-some-stuff)
>   (and-many-more-lines-of-stuff)
>   (set-some-variable)
>   (run-varhook))

No, the idea was rather to do:

(defun set-internal-1 (args)
  (block nil ; Because Elisp isn't CL
    (if (constant-or-hooked-p)
        (if (constant-p)
            (if (forbidden-p)
                (error "setting constant")
              (return))
          (funcall symbol-watch-function ..args..))
      (do-some-stuff)
      (and-many-more-lines-of-stuff)
      (set-some-variable))))

> I'd like to bikeshed the function names a bit more. Handler functions for
> varhook are already capable of not only reading variables, but also writing
> them. And now, writing (or blocking of writing) is actually going to be one
> of the intended use cases. That means ‟watch” is a misleading way of
> describing it; watching (which implies only reading) is only one of the
> things that a handler might do.

I think watchpoints usually have the functionality of catching the
modifications, being able to see the "before-change value" and being
able to replace the assignment with something else.  So "watch" makes
a lot of sense to me.

> BTW, why is the order of the first two arguments to advice-add reversed from
> add-function? And the words in their names too.

Don't ask,


        Stefan



reply via email to

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