emacs-devel
[Top][All Lists]
Advanced

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

Re: [PATCH] Run hook when variable is set


From: Stefan Monnier
Subject: Re: [PATCH] Run hook when variable is set
Date: Sat, 31 Jan 2015 15:48:08 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (gnu/linux)

>> you can drop the let-with-hook

> Without it, code which would be simply:
> (let-with-hook ((hooked-var foo))
>              (body))

> would have to become:
> (setq tmp hooked-var)
> (setq-with-hook hooked-var foo)
> (body)
> (setq-with-hook hooked-var tmp)

> That's cumbersome.

No, if you really need it, it's a simple (cl-letf (((get-var) foo)) ...).

>> since it would be a misfeature anyway,
> If it's missing (and you don't manually do it as above), then the hooked
> variable and the dependent variable become unsynchronized when the former is
> let-bound.  That's bound to introduce bugs.

Right, and I think the bug is in let-binding such vars.

> How do you combine setq-with-hook, set-with-hook,
> setq-default-with-hook, set-default-with-hook, and
> setq-local-with-hook into a single function?

The obvious way: (set-with-hook VAR VALUE LOCAL)

> Anyway, since you said varhook, or something like it, would be useful
> for debugging even though you don't want to use it to implement
> regular features, is my implementation reasonably close to what you
> had in mind?

I think I'd rather have something yet a bit simpler:
- extend the `constant' bit to allow a "hooked" value, for efficiency.
  Provide a function to set/unset this "hooked" annotation.
- when setting a hooked var, call a global Elisp function with args VAR and VAL.
Then you can provide debugging functions to "watch/unwatch" variables.

> That would fail in this case:
> (setq-default cursor-type 'bar)
> Later in the same Emacs session...
> (dynamic-cursor-mode)

As I already said, enabling dynamic-cursor-mode should set cursor-type to t.

> The user would reasonably think that DCM's failure to work in that case is a 
> bug.

> In that case, how do you turn it on buffer-locally?

I don't see a need for it.

> then it won't work. If you instead do:
> (make-local-variable 'dynamic-cursor-mode)
> (dynamic-cursor-mode)
> then DCM is enabled only locally,

Not really.  Such usage is unsupported.  Users who do that get what they
deserve.

> This has the edge case that if the mark happens to be active when you set
> cursor-type to 'bar, then the setting doesn't stick;

That's right.  I'm not worried about that either.


        Stefan



reply via email to

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