From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Kelly Dean Newsgroups: gmane.emacs.devel Subject: Re: [PATCH] Proposal to change cursor appearance to indicate region activation Date: Fri, 23 Jan 2015 03:08:33 +0000 Message-ID: References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: ger.gmane.org 1421982648 12944 80.91.229.3 (23 Jan 2015 03:10:48 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 23 Jan 2015 03:10:48 +0000 (UTC) Cc: emacs-devel@gnu.org To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Fri Jan 23 04:10:47 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 1YEUdz-0004se-5j for ged-emacs-devel@m.gmane.org; Fri, 23 Jan 2015 04:10:47 +0100 Original-Received: from localhost ([::1]:56884 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YEUdy-0002Dx-Eo for ged-emacs-devel@m.gmane.org; Thu, 22 Jan 2015 22:10:46 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:32898) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YEUdt-0002Dh-Kx for emacs-devel@gnu.org; Thu, 22 Jan 2015 22:10:42 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YEUdq-0001R4-46 for emacs-devel@gnu.org; Thu, 22 Jan 2015 22:10:41 -0500 Original-Received: from relay3-d.mail.gandi.net ([2001:4b98:c:538::195]:56055) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YEUdp-0001Qw-Ke for emacs-devel@gnu.org; Thu, 22 Jan 2015 22:10:37 -0500 Original-Received: from mfilter37-d.gandi.net (mfilter37-d.gandi.net [217.70.178.168]) by relay3-d.mail.gandi.net (Postfix) with ESMTP id 428C8A80AD; Fri, 23 Jan 2015 04:10:37 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at mfilter37-d.gandi.net Original-Received: from relay3-d.mail.gandi.net ([217.70.183.195]) by mfilter37-d.gandi.net (mfilter37-d.gandi.net [10.0.15.180]) (amavisd-new, port 10024) with ESMTP id pjR7cl6wPdQZ; Fri, 23 Jan 2015 04:10:35 +0100 (CET) X-Originating-IP: 66.220.3.179 Original-Received: from localhost (gm179.geneticmail.com [66.220.3.179]) (Authenticated sender: kelly@prtime.org) by relay3-d.mail.gandi.net (Postfix) with ESMTPSA id E8490A80AC; Fri, 23 Jan 2015 04:10:32 +0100 (CET) In-Reply-To: X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2001:4b98:c:538::195 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:181647 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Stefan Monnier wrote: > I'd rather see a `define-minor-mode' here, especially since you already > chose a "...-mode" name. Ok, the attached dynamic-cursor-mode-gross.patch does that. Can't just add =E2=8C=9C:global t=E2=8C=9D to dynamic-cursor-mode, since = the mode needs to be en/dis-ableable buffer-locally. That's why a pair of= minor modes is necessary. But I recommend against implementing the feature that way, since it's gro= ss. shift-select-mode is a defcustom, not an actual minor mode, so that's pre= cedence. I guess it's bad precedence. But assuming things with a =E2=8C=9C-mode=E2=8C=9D suffix in their names = are supposed to be actual modes, would it be ok to just drop the suffix? The attached dynamic-cursor-mode-1.patch does that. Maybe add a =E2=8C=9Cuse-=E2=8C=9D prefix, like for use-empty-active-regi= on (which is a defcustom)? Or =E2=8C=9Cenable-=E2=8C=9D prefix, like for enable-dir-local-variables,= enable-recursive-minibuffers, and enable-multibyte-characters (which are= all variables)? > But if the user has set cursor-type in his .emacs, we'll now overwrite > his choice. So we can't enable this code by default. Two options: > - keep the default as nil. > - change the code to only modify the cursor-type if it hasn't been chan= ged. Oops. Fixed in both of the attached patches. Or did you mean _ever_ changed, rather than just at startup? In that case= , what happens if the user first tries =E2=8C=9C(setq-default cursor-type= 'bar)=E2=8C=9D while looking for nice features in Emacs, then later deci= des to try the dynamic cursor? It won't work, and that failure might seem= like a bug, because by manually turning on the feature, he surely expect= s it to control the cursor, even though he set it to something nonstandar= d before. It seems the right way would be for set-default and setq-default on curso= r-type to automatically trigger a call of (setq-default dynamic-cursor ni= l), but I'm not aware of any feature in Emacs to trigger functions when v= ariables are set. This is the same problem as for bug #19068, where there= 's no way for writes to the message-directory variable to automatically t= rigger updates to its dependent variables. So I guess just keep the default as nil. :-( --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=dynamic-cursor-mode-gross.patch Third hunk adjusted to avoid conflict with current Emacs trunk. --- emacs-24.4/lisp/simple.el +++ emacs-24.4/lisp/simple.el @@ -4391,6 +4391,31 @@ (declare-function x-selection-exists-p "xselect.c" (&optional selection terminal)) +(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 buffer-local minor mode. When enabled, +`cursor-type' is set dynamically to reflect `mark-active'.") + +(define-globalized-minor-mode global-dynamic-cursor-mode + dynamic-cursor-mode dynamic-cursor-mode) + +;; Enabling before init lets user disable in init file +(global-dynamic-cursor-mode) + +;; Auto-disable to avoid conflict if cursor-type set in init file. +;; Use emacs-startup-hook instead of after-init-hook in case +;; cursor-type set in some file loaded as command line option. +(defun maybe-disable--dynamic-cursor () + (unless (eq (default-value 'cursor-type) + (eval (car (get 'cursor-type 'standard-value)))) + (global-dynamic-cursor-mode 0))) + +(add-hook 'emacs-startup-hook #'maybe-disable--dynamic-cursor) + (defun deactivate-mark (&optional force) "Deactivate the mark. If Transient Mark mode is disabled, this function normally does @@ -4430,6 +4455,7 @@ ((eq transient-mark-mode 'lambda) (setq transient-mark-mode nil))) (setq mark-active nil) + (if dynamic-cursor-mode (setq cursor-type t)) (run-hooks 'deactivate-mark-hook) (redisplay--update-region-highlight (selected-window)))) @@ -4445,3 +4471,4 @@ + (if dynamic-cursor-mode (setq cursor-type 'bar)) (run-hooks 'activate-mark-hook)))) (defun set-mark (pos) --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=dynamic-cursor-mode-1.patch Third hunk adjusted to avoid conflict with current Emacs trunk. --- emacs-24.4/lisp/simple.el +++ emacs-24.4/lisp/simple.el @@ -4391,6 +4391,22 @@ (declare-function x-selection-exists-p "xselect.c" (&optional selection terminal)) +(defcustom dynamic-cursor t + "If non-nil, `cursor-type' is set dynamically to reflect `mark-active'." + :type 'boolean + :version "25.1" + :group 'editing-basics) + +;; Auto-disable to avoid conflict if cursor-type set in init file. +;; Use emacs-startup-hook instead of after-init-hook in case +;; cursor-type set in some file loaded as command line option. +(defun maybe-disable--dynamic-cursor () + (unless (eq (default-value 'cursor-type) + (eval (car (get 'cursor-type 'standard-value)))) + (setq dynamic-cursor nil))) + +(add-hook 'emacs-startup-hook #'maybe-disable--dynamic-cursor) + (defun deactivate-mark (&optional force) "Deactivate the mark. If Transient Mark mode is disabled, this function normally does @@ -4430,6 +4446,7 @@ ((eq transient-mark-mode 'lambda) (setq transient-mark-mode nil))) (setq mark-active nil) + (if dynamic-cursor (setq cursor-type t)) (run-hooks 'deactivate-mark-hook) (redisplay--update-region-highlight (selected-window)))) @@ -4445,3 +4462,4 @@ + (if dynamic-cursor (setq cursor-type 'bar)) (run-hooks 'activate-mark-hook)))) (defun set-mark (pos) --=-=-=--