emacs - 在emacs中,删除( 不终止) 行 外部剪贴板不附加到终止环

  显示原文与译文双语对照的内容
98 3

很多时候我发现自己需要粘贴路径到emacs的minibuffer 。清除minibuffer快速定位到开始并执行c ( 终止行) 。

这有效地覆盖了我在系统剪贴板中的任何路径,用我在minibuffer中杀死的临时路径。使用m y 导航死环不会带来系统剪贴板中的路径。

是否可以删除当前行而不杀死它( 换句话说,删除它并将它的添加到kill环)?

到目前为止,我正在标记线并按下delete-selection-mote的。我想要一个类似于c k的关键解决方案。

时间:原作者:0个回答

68 1

在 Emacs 23.2中,你可以设置save-interprogram-paste-before-kill对于非零值( 帽子提示 ),将剪贴板选择复制到杀死环上,使它的可以以通过c y y:

(setq save-interprogram-paste-before-kill t)

如果你使用的是旧的Emacs,则以下建议具有相同的功能:

(defadvice kill-new (before kill-new-push-xselection-on-kill-ring activate)
"Before putting new kill onto the kill-ring, add the clipboard/external selection to the kill ring"
 (let ((have-paste (and interprogram-paste-function
 (funcall interprogram-paste-function))))
 (when have-paste (push have-paste kill-ring))))

然后,你可以以像这样做,从前面删除该行:

(define-key minibuffer-local-map (kbd"C-S-d") 'delete-line)
(defun delete-line (&optional arg)
 (interactive"P")
 ;; taken from kill-line
 (delete-region (point)
 ;; It is better to move point to the other end of the kill
 ;; before killing. That way, in a read-only buffer, point
 ;; moves across the text that is copied to the kill ring.
 ;; The choice has no effect on undo now that undo records
 ;; the value of point from before the command was run.
 (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))))
原作者:
54 0

在 Emacs 23.2中,这个问题可以用save-interprogram-paste-before-kill如果将这里变量设置为 t,则剪贴板中的内容将被添加到杀死环中,并且不会丢弃。

文档:

在替换剪贴板字符串之前将它的保存到kill环上。如果在它的他程序中选择了它,但在实际粘贴之前将它的杀死,除非这个变量为 `kill-ring 。

原作者:
77 4

在 xahlee的页面中,它显示了一些烦人的命令。

(defun my-delete-word (arg)
"Delete characters forward until encountering the end of a word.
With argument, do this that many times.
This command does not push erased text to kill-ring."
 (interactive"p")
 (delete-region (point) (progn (forward-word arg) (point))))
(defun my-backward-delete-word (arg)
"Delete characters backward until encountering the beginning of a word.
With argument, do this that many times.
This command does not push erased text to kill-ring."
 (interactive"p")
 (my-delete-word (- arg)))
(defun my-delete-line ()
"Delete text from current position to end of line char."
 (interactive)
 (delete-region
 (point)
 (save-excursion (move-end-of-line 1) (point)))
 (delete-char 1)
)
(defun my-delete-line-backward ()
"Delete text between the beginning of the line to the cursor position."
 (interactive)
 (let (x1 x2)
 (setq x1 (point))
 (move-beginning-of-line 1)
 (setq x2 (point))
 (delete-region x1 x2)))
; Here's the code to bind them with emacs's default shortcut keys:
(global-set-key (kbd"M-d") 'my-delete-word)
(global-set-key (kbd"<M-backspace>") 'my-backward-delete-word)
(global-set-key (kbd"C-k") 'my-delete-line)
(global-set-key (kbd"C-S-k") 'my-delete-line-backward)
原作者:
73 5

并没有。

GNU Emacs手册:

我们已经描述了( 删除字符) 和( delete-backward-char )的基本删除命令。请参见擦除。

其他删除命令为只删除空白字符的空格,制表符和换行符 M- ( delete-horizontal-space ) 删除点前面和后面的所有空格和制表符。使用前缀参数,这只在点之前删除空格和制表符。m ( just-one-space ) 同样可以以在点之后留下一个空格,不管前面的( 即使以前没有) 有多少空间。用数值参数n,它在点后留下n 个空格。

原作者:
59 2

那就像这样:

(defun del-line (p1)
 (interactive"d")
 (move-end-of-line 1)
 (when (eq p1 (point)) ; special case when p1 is already at the end of the line
 (forward-line))
 (delete-region p1 (point)))

行为应该类似于 C-k,但不会影响系统剪贴板或者终止环。

我更仔细地阅读了崔特的解决方案,看起来这只是他解决方案的简单案例。它在我的( 非常) 有限的测试中工作,但是有些特殊的例子可以能会失败。

原作者:
88 1

找到了一个答案。

首先在这里发布:https://unix.stackexchange.com/questions/26360/emacs-deleting-a-line-without-sending-it-to-the-kill-ring/136581#136581

;; 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)
原作者:
...