el/dot-emacs.el: Complicated `exchange-point-and-mark' hack.
[profile] / el / dot-emacs.el
index e08b6fc..e9390dd 100644 (file)
@@ -164,6 +164,25 @@ library."
       (other-window 1))
     (select-window win)))
 
+;; Transient mark mode hacks.
+
+(defadvice exchange-point-and-mark
+    (around mdw-highlight (&optional arg) activate compile)
+  "Maybe don't actually exchange point and mark.
+If `transient-mark-mode' is on and the mark is inactive, then
+just activate it.  A non-trivial prefix argument will force the
+usual behaviour.  A trivial prefix argument (i.e., just C-u) will
+activate the mark and temporarily enable `transient-mark-mode' if
+it's currently off."
+  (cond ((or mark-active
+            (and (not transient-mark-mode) (not arg))
+            (and arg (or (not (consp arg))
+                         (not (= (car arg) 4)))))
+        ad-do-it)
+       (t
+        (or transient-mark-mode (setq transient-mark-mode 'only))
+        (set-mark (mark t)))))
+
 ;; Functions for sexp diary entries.
 
 (defun mdw-weekday (l)