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)