emacs-devel
[Top][All Lists]
Advanced

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

Re: [PATCH] Proposal to change cursor appearance to indicate region acti


From: Kelly Dean
Subject: Re: [PATCH] Proposal to change cursor appearance to indicate region activation
Date: Fri, 23 Jan 2015 11:07:38 +0000

Stefan Monnier wrote:
>> +(defun maybe-disable--dynamic-cursor ()
>> +  (unless (eq (default-value 'cursor-type)
>> +          (eval (car (get 'cursor-type 'standard-value))))
>> +    (global-dynamic-cursor-mode 0)))
>
> Hmm... that's rather ugly.

I agree.

> I was thinking of rather doing something like:
>
> (defvar-local dynamic-cursor-mode--set nil
>   "If non-nil, we've temporarily modified the cursor.")
>
>> +    (if dynamic-cursor-mode (setq cursor-type t))
>        (when dynamic-cursor-mode
>          (if (and dynamic-cursor-mode--set (eq cursor-type 'bar))
>              (setq cursor-type t))
>          (setq dynamic-cursor-mode--set nil))
>
> and
>
>> +      (if dynamic-cursor-mode (setq cursor-type 'bar))
>          (if (and dynamic-cursor-mode (eq cursor-type t))
>            (setq cursor-type 'bar dynamic-cursor-mode--set t))

That's even uglier! ;-) You still have a global minor mode (and its variable), 
and a separately-named buffer-local variable, so it's no simpler. And the logic 
is more complex.

And it appears it would fail in the example case I gave in my previous message:
(setq-default cursor-type 'bar)
A few days later in the same Emacs session...
(dynamic-cursor-mode)

The user would reasonably think the failure is a bug in dynamic-cursor-mode; 
after all, the point of the mode is to control the cursor.

I guess you could fix that failure, but make sure it doesn't then fail if the 
user set some other cursor type (e.g. 'hbar) instead of 'bar.

I agree that there shouldn't be a buffer-local minor mode for dynamic-cursor; 
it's overkill, since all it's used for is the variable. But the global minor 
mode that you want is also overkill for the same reason. I suggest using a 
defcustom and just dropping the potentially-misleading ⌜-mode⌝ suffix, and 
maybe adding a ⌜use-⌝ or ⌜enable-⌝ prefix, analogous to the other variables I 
cited.

> So you don't need a buffer-local activation of dynamic-cursor-mode.

I still would need it. If (global) dynamic-cursor-mode is enabled, your code 
provides no way to prevent it from operating in a buffer in which cursor-type 
happens to be t.

I agree that having a pair of minor modes is gross. The cleanest way to do it 
is with a defcustom (for which I can do (setq-local dynamic-cursor nil) when 
necessary) with no ⌜-mode⌝ suffix, and since Emacs lacks triggers on variable 
writes, simply have the default be nil in order to avoid the ugliness that 
would be needed to avoid conflict with other uses of cursor-type. Then 
dynamic-cursor's control of cursor-type won't surprise or annoy users, because 
they only get it if they choose to enable it.

Modifying the «set» family of functions to provide triggers would be the ideal 
solution, as I described in my previous message. E.g. have a 'triggers property 
for each symbol, storing a list of functions to run when the symbol (i.e. 
dynamic variable) is set, analogous to a hook. Then dynamic-cursor could 
default to t, with no ugliness needed to avoid conflict.



reply via email to

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