我想使用C-k删除一行,而不将其发送到kill-ring。
我的.emacs文件中有以下内容
(delete-selection-mode 1)但这似乎只适用于C-d (delete-char)
我还读过这个线程中描述的解决方案:如何删除文本而不杀环?,但是我没有看到任何解决这个精确问题的方法。
发布于 2011-12-09 01:29:42
(defun delete-line (&optional arg)
(interactive "P")
(flet ((kill-region (begin end)
(delete-region begin end)))
(kill-line arg)))也许这不是最好的解决方案,但它似乎有效。您可能需要将“删除行”绑定到某个全局键,例如
(global-set-key [(control shift ?k)] 'delete-line)发布于 2014-06-11 12:13:29
辛斯克的回答对我来说并不适用于emacs 24。
但这确实做到了:
;; Ctrl-K with no kill
(defun delete-line-no-kill ()
(interactive)
(delete-region
(point)
(save-excursion (move-end-of-line 1) (point)))
(delete-char 1)
)
(global-set-key (kbd "C-k") 'delete-line-no-kill)发布于 2018-06-08 15:02:54
我遵循的方法是重写kill-line以使用delete-region而不是kill-region。kill-region和delete-region的功能几乎相同。最大的不同是前者保存了在杀死环中删除的内容。后者没有。用这个替换来重写函数保留了kill-line的确切行为,没有任何副作用。
(defun my/kill-line (&optional arg)
"Delete the rest of the current line; if no nonblanks there, delete thru newline.
With prefix argument ARG, delete that many lines from point.
Negative arguments delete lines backward.
With zero argument, delete the text before point on the current line.
When calling from a program, nil means \"no arg\",
a number counts as a prefix arg.
If `show-trailing-whitespace' is non-nil, this command will just
delete the rest of the current line, even if there are no nonblanks
there.
If option `kill-whole-line' is non-nil, then this command deletes the whole line
including its terminating newline, when used at the beginning of a line
with no argument.
If the buffer is read-only, Emacs will beep and refrain from deleting
the line."
(interactive "P")
(delete-region
(point)
(progn
(if arg
(forward-visible-line (prefix-numeric-value arg))
(if (eobp)
(signal 'end-of-buffer nil))
(let ((end
(save-excursion
(end-of-visible-line) (point))))
(if (or (save-excursion
;; If trailing whitespace is visible,
;; don't treat it as nothing.
(unless show-trailing-whitespace
(skip-chars-forward " \t" end))
(= (point) end))
(and kill-whole-line (bolp)))
(forward-visible-line 1)
(goto-char end))))
(point))))
(global-set-key (kbd "C-k") 'my/kill-line)https://unix.stackexchange.com/questions/26360
复制相似问题