删除(不杀死)emacs中的一行.外部剪贴板未附加到kill ring

oct*_*cti 6 emacs

很多时候,我发现自己需要从任何地方粘贴一条路径到emacs的迷你缓冲区.要快速清除迷你缓冲区,我导航到开头并执行Ck(kill line).

这有效地覆盖了我在系统剪贴板中使用我在迷你缓冲区中杀死的临时路径的任何路径.用My导航杀戮戒指不会带来我在系统剪贴板中的路径.

有没有办法删除当前行而不杀死它(即删除它并将其添加到杀死环)?

到目前为止,我正在标记该行并按下删除,其中delete-selection-mote处于活动状态.我想要一个类似于Ck的一键解决方案.

Tre*_*son 8

从Emacs 23.2开始,你可以设置save-interprogram-paste-before-kill一个非零值(帽子提示Tyler)将剪贴板选择复制到kill ring上,以便通过C-y M-y以下方式获得:

(setq save-interprogram-paste-before-kill t)
Run Code Online (Sandbox Code Playgroud)

如果您使用的是较旧的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))))
Run Code Online (Sandbox Code Playgroud)

并且,你可以做这样的事情(可怕的键绑定,自定义以适应)从前面的点删除线:

(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))))
Run Code Online (Sandbox Code Playgroud)