all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* kill-append and buffer-undo-list
@ 2014-06-09 20:17 Sam Steingold
  2014-06-09 22:48 ` Juri Linkov
  0 siblings, 1 reply; 2+ messages in thread
From: Sam Steingold @ 2014-06-09 20:17 UTC (permalink / raw)
  To: emacs-devel

Hi,
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:
http://stackoverflow.com/questions/24123101/how-do-i-collapse-multiple-kill-lines-as-one-undo-history-in-emacs/

-- 
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.




^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: kill-append and buffer-undo-list
  2014-06-09 20:17 kill-append and buffer-undo-list Sam Steingold
@ 2014-06-09 22:48 ` Juri Linkov
  0 siblings, 0 replies; 2+ messages in thread
From: Juri Linkov @ 2014-06-09 22:48 UTC (permalink / raw)
  To: Sam Steingold; +Cc: emacs-devel

> 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?

I think better would be to make this an option of the undo feature itself.
Currently only `self-insert-command' commands are grouped into undo as a unit
of 20 consecutive self-inserting commands.  A new option would allow specifying
a command name to group, and also a number of consecutive commands to accept
as a group before adding a boundary between them.  A possible value for such
an option: (defcustom undo-group '((self-insert-command . 20) (kill-line . 20) ...))

Or maybe better to specify the same using symbol properties:

(put 'self-insert-command 'undo-group 20)
(put 'kill-line 'undo-group 20)



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2014-06-09 22:48 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-06-09 20:17 kill-append and buffer-undo-list Sam Steingold
2014-06-09 22:48 ` Juri Linkov

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.