[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

kill-append and buffer-undo-list

From: Sam Steingold
Subject: kill-append and buffer-undo-list
Date: Mon, 09 Jun 2014 16:17:33 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4.50 (darwin)

When text it killed with repeated C-k, they are appended in the
kill-ring (as if it were done by a single C-w or C-u XXX C-k) but not in
buffer-undo-list (i.e., an undo will reinsert just one line).
It is not obvious to me that this is the "correct" behavior
(although I am sure many people, myself included, rely on it).

Any objections to making that optional?

--8<---------------cut here---------------start------------->8---
=== modified file 'lisp/simple.el'
--- lisp/simple.el      2014-06-02 00:18:22 +0000
+++ lisp/simple.el      2014-06-09 20:13:14 +0000
@@ -3737,14 +3737,32 @@ argument should still be a \"useful\" st
   (if interprogram-cut-function
       (funcall interprogram-cut-function string)))
+(defcustom kill-append-merge-undo nil
+  "Whether appending to kill ring also makes \\[undo] restore both pieces of 
text simultaneously."
+  :type 'boolean
+  :group 'killing
+  :version "24.5")
 (defun kill-append (string before-p)
   "Append STRING to the end of the latest kill in the kill ring.
 If BEFORE-P is non-nil, prepend STRING to the kill.
+Also removes the last undo boundary in the current buffer,
+ depending on `kill-append-merge-undo'.
 If `interprogram-cut-function' is set, pass the resulting kill to it."
   (let* ((cur (car kill-ring)))
     (kill-new (if before-p (concat string cur) (concat cur string))
              (or (= (length cur) 0)
-                 (equal nil (get-text-property 0 'yank-handler cur))))))
+                 (equal nil (get-text-property 0 'yank-handler cur))))
+    (when (and kill-append-merge-undo (not buffer-read-only))
+      (let ((prev buffer-undo-list)
+            (next (cdr buffer-undo-list)))
+        ;; find the next undo boundary
+        (while (car next)
+          (pop next)
+          (pop prev))
+        ;; remove this undo boundary
+        (when prev
+          (setcdr prev (cdr next)))))))
 (defcustom yank-pop-change-selection nil
   "Whether rotating the kill ring changes the window system selection.

--8<---------------cut here---------------end--------------->8---

PS. Please see here for the source of this question:

Sam Steingold (http://sds.podval.org/) on darwin Ns 10.3.1265
http://www.childpsy.net/ http://pmw.org.il http://mideasttruth.com
http://openvotingconsortium.org http://palestinefacts.org
History doesn't repeat itself, but historians do repeat each other.

reply via email to

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