mirror of
https://github.com/golang/go.git
synced 2025-05-23 08:21:24 +00:00
misc/emacs: replace hacky go--delete-whole-line with own implementation
Using flet to replace kill-region with delete-region was a hack, flet is now (GNU Emacs 24.3) deprecated and at least two people have reported an issue where using go--delete-whole-line would permanently break their kill ring. While that issue is probably caused by faulty third party code (possibly prelude), it's easier to write a clean implementation than to tweak the hack. LGTM=ruiu, adonovan R=adonovan, ruiu CC=adg, golang-codereviews https://golang.org/cl/106010043
This commit is contained in:
parent
3d853585b6
commit
2005bea7fd
@ -33,29 +33,35 @@
|
|||||||
;; - Use go--old-completion-list-style when using a plain list as the
|
;; - Use go--old-completion-list-style when using a plain list as the
|
||||||
;; collection for completing-read
|
;; 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
|
;; - Use go--position-bytes instead of position-bytes
|
||||||
(defmacro go--xemacs-p ()
|
(defmacro go--xemacs-p ()
|
||||||
`(featurep 'xemacs))
|
`(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.
|
;; Delete the current line without putting it in the kill-ring.
|
||||||
(defun go--delete-whole-line (&optional arg)
|
(defun go--delete-whole-line (&optional arg)
|
||||||
;; Emacs uses both kill-region and kill-new, Xemacs only uses
|
;; Derived from `kill-whole-line'.
|
||||||
;; kill-region. In both cases we turn them into operations that do
|
;; ARG is defined as for that function.
|
||||||
;; not modify the kill ring. This solution does depend on the
|
(setq arg (or arg 1))
|
||||||
;; implementation of kill-line, but it's the only viable solution
|
(if (and (> arg 0)
|
||||||
;; that does not require to write kill-line from scratch.
|
(eobp)
|
||||||
(flet ((kill-region (beg end)
|
(save-excursion (forward-visible-line 0) (eobp)))
|
||||||
(delete-region beg end))
|
(signal 'end-of-buffer nil))
|
||||||
(kill-new (s) ()))
|
(if (and (< arg 0)
|
||||||
(go--kill-whole-line arg)))
|
(bobp)
|
||||||
|
(save-excursion (end-of-visible-line) (bobp)))
|
||||||
|
(signal 'beginning-of-buffer nil))
|
||||||
|
(cond ((zerop arg)
|
||||||
|
(delete-region (progn (forward-visible-line 0) (point))
|
||||||
|
(progn (end-of-visible-line) (point))))
|
||||||
|
((< arg 0)
|
||||||
|
(delete-region (progn (end-of-visible-line) (point))
|
||||||
|
(progn (forward-visible-line (1+ arg))
|
||||||
|
(unless (bobp)
|
||||||
|
(backward-char))
|
||||||
|
(point))))
|
||||||
|
(t
|
||||||
|
(delete-region (progn (forward-visible-line 0) (point))
|
||||||
|
(progn (forward-visible-line arg) (point))))))
|
||||||
|
|
||||||
;; declare-function is an empty macro that only byte-compile cares
|
;; declare-function is an empty macro that only byte-compile cares
|
||||||
;; about. Wrap in always false if to satisfy Emacsen without that
|
;; about. Wrap in always false if to satisfy Emacsen without that
|
||||||
|
Loading…
x
Reference in New Issue
Block a user