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: David Kastrup
Subject: Re: [PATCH] Proposal to change cursor appearance to indicate region activation
Date: Wed, 28 Jan 2015 13:13:44 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (gnu/linux)

David Kastrup <address@hidden> writes:

> Kelly Dean <address@hidden> writes:
>
>> +(define-minor-mode dynamic-cursor-mode
>> +  "Toggle Dynamic Cursor mode.
>> +With a prefix argument ARG, enable Dynamic Cursor mode if ARG is
>> +positive, and disable it otherwise.  If called from Lisp, enable
>> +Dynamic Cursor mode if ARG is omitted or nil.
>> +
>> +Dynamic Cursor mode is a global minor mode.  When enabled,
>> +`cursor-type' is set dynamically to reflect `mark-active'.
>> +
>> +Dynamic Cursor mode can be enabled or disabled buffer-locally
>> +using (setq-local dynamic-cursor-mode t)
>> +or (setq-local dynamic-cursor-mode nil).
>> +This will override the global setting.
>> +
>> +Setting `cursor-type' globally or buffer-locally will automatically
>> +disable Dynamic Cursor mode in the same environment."
>> +  :global t
>> +  :init-value t)
>> +
>> +(defvar cursor-type-varhook nil)
>> +(add-hook 'cursor-type-varhook
>> +      (lambda (_sym env)
>> +        (if (eq env 'global)
>> +            (setq-default dynamic-cursor-mode nil)
>> +          (if (eq env 'buffer-local)
>> +              (setq-local dynamic-cursor-mode nil)))))
>> +(put 'cursor-type 'varhook 'cursor-type-varhook)
>
> Ugh.  That's implementing and using a sledgehammer (and one which slows
> down any variable access on a symbol with properties) on a comparatively
> straightforward problem, resulting in pretty inscrutable code.  I don't
> think that this approach is worth the complexity.
>
> As to the varhook feature itself: apart from the performance impact, it
> also has the problem that one cannot usefully manipulate such a varhook
> using add-hook or remove-hook.  That makes it a feature that does not
> scale to multiple applications (like variable profiling).

Aaaand another data point.  You put in a fast access path for the case
where the symbol has no properties.  However, if I do

(cl-loop for s being the symbols
         with x = 0 with p = 0
         finally return (/ (* p 100) x)
         do (when (boundp s) (setq x (1+ x))
                             (if (symbol-plist s)
                                 (setq p (1+ p)))))

which calculates the percentage of bound symbols (those are the ones
likely to be relevant for variable access, as opposed to symbols like f1
which are mostly used as interned strings and property list containers)
with a non-nil property list, I get 76 in my current Emacs session.

So 76% of all variable accesses will be slowed down searching for the
varhook property.  That seems expensive.

-- 
David Kastrup



reply via email to

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