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: Wed, 28 Jan 2015 09:23:19 +0000

Stefan Monnier wrote:
> Of course.  But to me the whole point of this exercise is to change
> the default.

Ok. The attached patch relies on the varhook feature, which I implemented so 
that it's possible to enable dynamic-cursor-mode by default without causing any 
conflict with other uses of cursor-type.

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,34 @@
 (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 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)
+
 (defun deactivate-mark (&optional force)
   "Deactivate the mark.
 If Transient Mark mode is disabled, this function normally does
@@ -4430,6 +4458,8 @@
      ((eq transient-mark-mode 'lambda)
       (setq transient-mark-mode nil)))
     (setq mark-active nil)
+    (let ((cursor-type-varhook nil))
+      (if dynamic-cursor-mode (setq cursor-type t)))
     (run-hooks 'deactivate-mark-hook)
     (redisplay--update-region-highlight (selected-window))))
 
@@ -4445,3 +4475,5 @@
+      (let ((cursor-type-varhook nil))
+       (if dynamic-cursor-mode (setq cursor-type 'bar)))
       (run-hooks 'activate-mark-hook))))
 
 (defun set-mark (pos)

reply via email to

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