3
  1. I select an absolute file name with the mouse in a terminal
  2. I want to open this file in a running emacs: ctrl+x ctrl+f
  3. Emacs mini buffer: contains "~/...."
  4. I enter ctrl-a ctrl-k to delete "~/...."
  5. I want to paste with middle button
  6. "~/...." gets inserted, not the file name of step one.

How can I stop emacs from overwriting my text I selected with the mouse?

2

If I understand your requirements correctly, probably the easiest solution is to yank (paste) the copied filename at the start of the mini buffer before performing the kill-to-end-of-line i.e. instead of Ctrl+a Ctrl+k, do Ctrl+a Ctrl+yCtrl+k. You could replace the Ctrl+y by a middle-click paste at the same point if you prefer to use the mouse.

Alternatively, according to this stackoverflow answer delete (NOT kill) a line in emacs it should be possible to automatically add the externally-copied text to the emacs kill-ring by adding

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

to your emacs configuration - this should make the filename available for yanking by scrolling back through the kill ring using Meta+y

| improve this answer | |
0

This have bothered me in the past as well.

The solution I found was to make Ctrl+K a delete only command. This worked for me, as I never used Ctrl+K to copy and paste.

Originally posted here

;; 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)
| improve this answer | |
0

EMACS will convert multiple slashes to a root path, e.g. // becomes /
If you were to

  1. leave whatever text is in the minibuffer
  2. append a /
  3. paste the absolute path in the minibuffer, appending it to existing text

The minibuffer will have a path such as ~//path2file/file
EMACS will open /path2file/file

There's no need to reassign Ctrl+K, just learn how EMACS handles filenames in the minibuffer.
Read the GNU EMACS manual topic "Minibuffers for File Names" here; begin reading at the text "But you don't need to kill the default;"

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.