From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: David Kastrup Newsgroups: gmane.emacs.devel Subject: Re: [PATCH] Proposal to change cursor appearance to indicate region activation Date: Wed, 28 Jan 2015 13:13:44 +0100 Message-ID: <87zj93ayrr.fsf@fencepost.gnu.org> References: <0cKOQ95j7CUiQLCExsRqM9mvV5ADaC7ZcKGBLr3Ut5G@local> <874mrbcflj.fsf@fencepost.gnu.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1422447249 29334 80.91.229.3 (28 Jan 2015 12:14:09 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 28 Jan 2015 12:14:09 +0000 (UTC) Cc: Stefan Monnier , emacs-devel@gnu.org To: Kelly Dean Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Jan 28 13:14:04 2015 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1YGRVS-0003Ch-R3 for ged-emacs-devel@m.gmane.org; Wed, 28 Jan 2015 13:14:02 +0100 Original-Received: from localhost ([::1]:52796 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YGRVS-0001gc-9M for ged-emacs-devel@m.gmane.org; Wed, 28 Jan 2015 07:14:02 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:41310) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YGRVE-0001ft-F2 for emacs-devel@gnu.org; Wed, 28 Jan 2015 07:13:49 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YGRVD-0000NS-9H for emacs-devel@gnu.org; Wed, 28 Jan 2015 07:13:48 -0500 Original-Received: from fencepost.gnu.org ([2001:4830:134:3::e]:51954) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YGRVD-0000NO-6J for emacs-devel@gnu.org; Wed, 28 Jan 2015 07:13:47 -0500 Original-Received: from localhost ([127.0.0.1]:59129 helo=lola) by fencepost.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YGRVB-0002HR-9T; Wed, 28 Jan 2015 07:13:45 -0500 Original-Received: by lola (Postfix, from userid 1000) id AC7A7E07AB; Wed, 28 Jan 2015 13:13:44 +0100 (CET) In-Reply-To: <874mrbcflj.fsf@fencepost.gnu.org> (David Kastrup's message of "Wed, 28 Jan 2015 12:24:56 +0100") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2001:4830:134:3::e X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:181900 Archived-At: David Kastrup writes: > Kelly Dean 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