]> git.earman.xyz Git - emacsinit.git/commitdiff
Switch to temporary transient-mark-mode setup
authorrearman <rearman@r717.net>
Fri, 19 Sep 2025 16:03:52 +0000 (12:03 -0400)
committerrearman <rearman@r717.net>
Fri, 19 Sep 2025 16:03:52 +0000 (12:03 -0400)
Taken from 'https://spwhitton.name/blog/entry/transient-mark-mode/'.
Enable transient-mark-mode for various commands, leave it disabled
otherwise.

init.el

diff --git a/init.el b/init.el
index 7b73115262a0e61dbb8968054f84bbc47dbf9fc6..edc46b9d8ea76129f47af492c292b6861577ed28 100644 (file)
--- a/init.el
+++ b/init.el
@@ -29,8 +29,7 @@
 
 (setq-default indicate-empty-lines t
              mouse-prefer-closest-glyph t
-             line-move-visual nil
-             transient-mark-mode nil)
+             line-move-visual nil)
 
 (blink-cursor-mode -1)
 (column-number-mode t)
                    :underline
                    t)
 
+;; Transient mark mode temp enabling
+(setq transient-mark-mode nil)
+
+(defun re/remap-mark-command (command &optional map)
+  "Remap a mark-* command to temporarily activate Transient Mark mode.
+Taken from https://spwhitton.name/blog/entry/transient-mark-mode/"
+  (let* ((cmd (symbol-name command))
+        (fun (intern (concat "re/" cmd)))
+        (doc (concat "Call `"
+                     cmd
+                     "' and temporarily activate Transient Mark mode.")))
+    (fset fun `(lambda ()
+                ,doc
+                (interactive)
+                (call-interactively #',command)
+                (activate-mark)))
+    (if map
+       (define-key map (vector 'remap command) fun)
+      (global-set-key (vector 'remap command) fun))))
+
+(dolist (command '(mark-beginning-of-buffer
+                  mark-end-of-buffer
+                  mark-end-of-sentence
+                  mark-page
+                  mark-paragraph
+                  mark-sexp
+                  mark-defun
+                  mark-whole-buffer
+                  mark-word
+                  rectangle-mark-mode))
+  (re/remap-mark-command command))
+
 ;; Help
 (setq apropos-do-all t)