emacs-elpa-diffs
[Top][All Lists]
Advanced

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

[nongnu] elpa/go-mode 6b5fe38 204/495: write our own implementation of g


From: ELPA Syncer
Subject: [nongnu] elpa/go-mode 6b5fe38 204/495: write our own implementation of go--delete-whole-line
Date: Sat, 7 Aug 2021 09:05:14 -0400 (EDT)

branch: elpa/go-mode
commit 6b5fe389cb5bdd75f52c349b6be8915fb9913d10
Author: Dominik Honnef <dominikh@fork-bomb.org>
Commit: Dominik Honnef <dominikh@fork-bomb.org>

    write our own implementation of go--delete-whole-line
    
    Using flet to replace kill-region with delete-region was a hack, flet is
    deprecated and at least two people (probably due to a bug in a third
    party package) have had their kill ring broken by our hack.
---
 go-mode.el | 52 +++++++++++++++++++++++++++++++++++-----------------
 1 file changed, 35 insertions(+), 17 deletions(-)

diff --git a/go-mode.el b/go-mode.el
index 55ac3f8..330a51b 100644
--- a/go-mode.el
+++ b/go-mode.el
@@ -42,29 +42,47 @@
 ;; - Use go--old-completion-list-style when using a plain list as the
 ;;   collection for completing-read
 ;;
-;; - Use go--kill-whole-line instead of kill-whole-line (called
-;;   kill-entire-line in XEmacs)
-;;
 ;; - Use go--position-bytes instead of position-bytes
 (defmacro go--xemacs-p ()
   `(featurep 'xemacs))
 
-(defalias 'go--kill-whole-line
-  (if (fboundp 'kill-whole-line)
-      #'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)))
+  (setq arg (or arg 1))
+  (if (and
+       (> arg 0)
+       (eobp)
+       (save-excursion (forward-visible-line 0) (eobp)))
+      (signal 'end-of-buffer nil))
+  (if (and
+       (< arg 0)
+       (bobp)
+       (save-excursion (end-of-visible-line) (bobp)))
+      (signal 'beginning-of-buffer nil))
+
+  (let (start-point
+        end-point)
+    (cond ((zerop arg)
+           (forward-visible-line 0)
+           (setq start-point (point))
+
+           (end-of-visible-line)
+           (setq end-point (point)))
+          ((< arg 0)
+           (end-of-visible-line)
+           (setq start-point (point))
+
+           (forward-visible-line (1+ arg))
+           (unless (bobp)
+             (backward-char))
+           (setq end-point (point)))
+          (t
+           (forward-visible-line 0)
+           (setq start-point (point))
+
+           (forward-visible-line arg)
+           (setq end-point (point))))
+    (delete-region start-point end-point)))
 
 ;; declare-function is an empty macro that only byte-compile cares
 ;; about. Wrap in always false if to satisfy Emacsen without that



reply via email to

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