Delete (DO NOT kill) a line in emacs. External clipboard not added to destruction ring

Many times I find myself needing to insert a path from anywhere in the emacs minibuffer. To quickly clear the minibuffer, I go to the beginning and do Ck (kill line).

This effectively undoes any path I had in the system clipboard, with the temporary path I just killed in the minibuffer. Navigating the death ring with My will not lead to the path that I had in the system clipboard.

Is there a way to delete the current line without killing it (i.e. deleting it and adding it to the kill ring)?

So far I mark the line and press the delete button with the delete-selection-mote activity. I would like to get one key solution like Ck.

+6
source share
6 answers

As in Emacs 23.2, you can set save-interprogram-paste-before-kill to non-nil (tip tip Tyler ) to copy the clipboard selection to the kill ring, so that it is accessible via Cy My :

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

If you are in older Emacs, the following tip has the same functionality:

 (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)))) 

And you can do something like this (terrible key binding, adjust according) to remove the line from the point forward:

 (define-key minibuffer-local-map (kbd "CSd") '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)))) 
+8
source

Starting with Emacs 23.2, this problem can be solved with save-interprogram-paste-before-kill . If you set this variable to t , then the material in the clipboard is added to the kill-ring and is not discarded by your next kill.

Documentation:

Save the clipboard lines to the kill ring before replacing them. When you select something in another program to paste it in Emacs, but kills something in Emacs before you paste it, this choice is absent if this variable is non-zero, in which case the other program selection is saved in `kill -ring 'before Emacs kills, and you can still paste it with Cy My.

+4
source

From the Xahlee page , he shows several teams that are annoying.

 (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 the code to bind them with emacs default shortcut keys: (global-set-key (kbd "Md") 'my-delete-word) (global-set-key (kbd "<M-backspace>") 'my-backward-delete-word) (global-set-key (kbd "Ck") 'my-delete-line) (global-set-key (kbd "CSk") 'my-delete-line-backward) 
+1
source

Not.

from GNU Emacs Manual :

We have already described the basic delete commands Cd (delete-char) and (delete-backward-char). See Erase.

Other delete commands are those that remove only whitespace characters : spaces, tabs, and newlines. M - \ (delete-horizontal space) removes all spaces and tabs before and after the period. With a prefix argument, this only removes spaces and tabs before the period. M- (single-space only) does the same, but leaves one space after the point, regardless of the number of existing spaces previously (even if they were not there before). With the numeric argument n, it leaves n spaces after the period.

0
source

Sort of:

 (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))) 

The behavior should be similar to Ck , but does not affect the system clipboard or the killer ring.

ETA: I read Trey's decision more carefully, and it looks like this is just a simple case of solving it. It worked in my (very!) Limited tests, but probably is not suitable for some special cases when the more complex kill line code works correctly.

0
source

Found the answer to this question.

First posted here: 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 "Ck") 'delete-line-no-kill) 
0
source

Source: https://habr.com/ru/post/903332/


All Articles