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)