]> Cypherpunks repositories - gostls13.git/commitdiff
misc/emacs: Do not modify kill ring when programmatically deleting text
authorDominik Honnef <dominik.honnef@gmail.com>
Thu, 23 May 2013 17:19:03 +0000 (10:19 -0700)
committerBrad Fitzpatrick <bradfitz@golang.org>
Thu, 23 May 2013 17:19:03 +0000 (10:19 -0700)
Operations like gofmt and go-remove-unused-imports delete entire
lines of text. Previously this put them on the kill-ring,
negatively affecting user experience.

R=adonovan
CC=gobot, golang-dev
https://golang.org/cl/9605043

misc/emacs/go-mode.el

index b44740fafc12923a531e7ff9ba5dee1a9a7de199..d3c425cdca482b2a71f689d9793a60e7844cc29e 100644 (file)
       'kill-whole-line
     'kill-entire-line))
 
+;; Delete the current line without putting it in the kill-ring.
+(defun go--delete-whole-line (&optional arg)
+  ;; Emacs uses both kill-region and kill-new, Xemacs only uses
+  ;; kill-region. In both cases we turn them into operations that do
+  ;; not modify the kill ring. This solution does depend on the
+  ;; implementation of kill-line, but it's the only viable solution
+  ;; that does not require to write kill-line from scratch.
+  (flet ((kill-region (beg end)
+                      (delete-region beg end))
+         (kill-new (s) ()))
+    (go--kill-whole-line arg)))
+
+
 ;; XEmacs unfortunately does not offer position-bytes. We can fall
 ;; back to just using (point), but it will be incorrect as soon as
 ;; multibyte characters are being used.
@@ -524,7 +537,7 @@ buffer."
                 (goto-char (point-min))
                 (forward-line (- from line-offset 1))
                 (incf line-offset len)
-                (go--kill-whole-line len)))
+                (go--delete-whole-line len)))
              (t
               (error "invalid rcs patch or internal error in go--apply-rcs-patch")))))))))
 
@@ -853,7 +866,7 @@ will be commented, otherwise they will be removed completely."
           (beginning-of-line)
           (if arg
               (comment-region (line-beginning-position) (line-end-position))
-            (go--kill-whole-line)))
+            (go--delete-whole-line)))
         (message "Removed %d imports" (length lines)))
       (if flymake-state (flymake-mode-on)))))