31

You need to customize save-interprogram-paste-before-kill to t. This will push your clipboard onto the killring in case you kill something in emacs before pasting the clipboard. A related customization is yank-pop-change-selection which pushes your current yank in emacs onto the clipboard. For both of these to work, you need x-select-enable-clipboard (...


29

There is no bug here. Since I was also annoyed with this behavior, I just read Evil code to find out why this is happening. So, here is a straight copy/paste of the well-commented one-liner from my Emacs configuration that fixes this issue: ;; Imagine the following scenario. One wants to paste some previously copied ;; (from application other than Emacs) ...


22

Emacs ≤24.3 Pressing RET doesn't indent by default (except in some programming modes, for which you need to check mode-specific configuration, e.g. “electric” settings). Unix terminals normally paste a carriage return character when the clipboard contents contains a newline (represented by the line feed character). In Emacs, a carriage return looks like ...


6

You can use the external utilities xsel or xclip (they have mostly the same features, I'll use xsel in this answer) to copy data from or to the X clipboard. To copy to the clipboard, pass the desired content on standard input. When pasting from the clipboard, the content is written to standard output. To copy the selection to the X clipboard, use M-| xsel -...


6

Use kill-new instead of clipboard-kill-region for this. clipboard-kill-region uses kill-region which will append the text to the last kill if the last call was kill-region. (defun sk-copy-file-name () "Put the current file name on the clipboard" (interactive) (kill-new (or (buffer-file-name) default-directory)))


5

Here is a one-off command you can use to yank the each line of the current kill on the end of each subsequent line, starting on the current line. (defun yank-append-lines (&optional without-space) "Yank each line of the current kill at the end of each subsequent line. A space will be added between each line unless WITHOUT-SPACE which can be passed in ...


5

TL;DR: you can use clipmon available on MELPA, and turn on clipmon-mode. Note: the details below apply to X servers, but the package should work on any platform. How does the clipboard work ? Clipboard is implemented as an asynchronous process. When you copy from an application, it becomes the "clipboard owner" but doesn't actually put the copied data ...


4

The function x-select-text can be used to do this: Select TEXT, a string, according to the window system. On X, if `x-select-enable-clipboard' is non-nil, copy TEXT to the clipboard. If `x-select-enable-primary' is non-nil, put TEXT in the primary selection. So we need to setx-select-enable-clipboard to a non-nil value (e.g., t). On Linux machines, it's ...


3

Emacs Command Instead of select-and-copy manually, you can also write a command and let it do the work for you: ;; Adapted from `comint-delete-output' (defun comint-copy-output () "Copy all output from interpreter since last input." (interactive) (let ((proc (get-buffer-process (current-buffer)))) (save-excursion (let ((pmark (progn (goto-...


3

I suggest you try out the xclip package, availble in GNU ELPA.


3

another solution is just use cli tool if possible, pbcopy/pbpaste on Mac getclip/putclip on Cygwin xsel on Linux x-clipboard in GUI Emacs (as others mentioned, you need turn on the flag x-select-enable-clipboard). The advantage of this solution is that the clipboard is always usable (for example, when you remote ssh). My answer has two parts. part one ...


3

I'm not sure that it is possible to have copied text appear in your kill-ring immediately after copying, unless there is some way to run a hook on copy. This would obviously depend on your operating system/environment, but I did want to mention that you might want to try setting (setq save-interprogram-paste-before-kill t) Which will at least preserve ...


3

The linebreaks are missing because there is a conflict between your coding system on the desktop and your emacs setup. Emacs can be configured to have different coding systems for the terminal, keyboard and clipboard. Try to set your clipboard coding system and selection coding system to utf-16-le, i.e.,: (if (eq system-type 'windows-nt) (progn (...


3

The following code augments the key sequence M-w such that it copies the date below point with the format "%d.%m.%Y when region is not active ( %d: zero padded day, %m: zero-padded month, %Y: year). You can change the format with the customization option calendar-copy-as-kill-format. (defcustom calendar-copy-as-kill-format "%d.%m.%Y" "Format string for ...


3

According to documentation of the kill-ring variable, interact with the kill ring directly is not recommended: Since the kill ring is supposed to interact nicely with cut-and-paste facilities offered by window systems, use of this variable should interact nicely with interprogram-cut-function and interprogram-paste-function. The functions kill-new, ...


2

The NEWS for 25.1 says: *** Killing text now also sets the CLIPBOARD/PRIMARY selection in the surrounding GUI (using the OSC-52 escape sequence). This only works if your xterm supports it and enables the 'allowWindowOps' options (disabled by default at least in Debian, for security reasons). Similarly, you can yank the CLIPBOARD/PRIMARY selection (using ...


2

Try the following: (setq interprogram-paste-function nil)


2

Finally I figured out a clumsy solution, which referred to the concept of clipmon. But very simple with one line's code: (run-at-time 0 3 (lambda () (interactive) (current-kill 0))) The kill ring will be synchronized every 3 seconds with system clipboard. Of course you can alter the interval to a even smaller value. PS: The reason why I need this ...


2

This should do the trick :- (setq select-active-regions 'only) This will make sure that emacs will only save the temporarily active regions to the primary selection, i.e those made with the mouse or shift keys.


2

By default (at least in Emacs 25), <S-Insert> is bound to the same command as C-y: they both invoke the yank command. You could try rebinding one of the them to clipboard-yank instead. (global-set-key (kbd "<S-Insert>") #'clipboard-yank)


2

(defun copy-rectangle-to-system-clipboard (start end) "Like `copy-rectangle-as-kill', but also copy to system clipboard." (interactive "r") (call-interactively #'copy-rectangle-as-kill) (with-temp-buffer (yank-rectangle) (delete-trailing-whitespace) (funcall interprogram-cut-function (buffer-string)))) I have tested it using graphical ...


2

Step 1: Select text and M-x diff-region-tag-selected-as-a Step 2, Select or not select text, M-x diff-region-tag-selected-as-b You need install cli tool diff on windows (its bundled with Cygwin or MSYS2). To read clipboard, you need install Emacs plugin simpleclip. Here is the code: ;; {{ diff region SDK (defun diff-region-exit-from-certain-buffer (...


2

After reading Primary Selection I got a clue for the solution. A simple deactivate-mark did the trick for me: (defun copy-no-white-space () (interactive) (deactivate-mark) (gui-set-selection 'PRIMARY (replace-regexp-in-string "[\s\n]" "" (buffer-substring (region-beginning) (region-end)))) My interpretation is the following: After leaving the ...


1

Is it possible to Meta-: Eval: and tell emacs to send whatever is in the emacs clipboard to the OS (MacOS) clipboard? Yes M-: (call-process-region (car kill-ring) nil "pbcopy")


1

You can call copy-to-x-clipboard from Meta-X or Eval:. No Emacs packages necessary. It relies on the pbcopy shell command, which is available in all macOS installations. (defun copy-to-x-clipboard () (interactive) (switch-to-buffer (make-temp-name "scratch")) (insert (current-kill 1)) (shell-command-on-region (point-min) (point-max) "pbcopy") (...


1

Evil provides C-p and C-n to exchange the currently pasted item with the previous or next kill ring item. When combined with (setq save-interprogram-paste-before-kill t) whatever has been in the X clipboard will be saved to the kill ring before a kill operation, thereby becoming retrievable with C-p.


1

Try simpleclip. I believe it does exactly what you want, keeping a distinct clipboard to interact with the system, separate from emacs's kill ring.


1

https://github.com/rolandwalker/simpleclip It uses either Emacs internal API or third party CLI tool to insert the text. So syntax highlighting thing is skipped. You can use simpleclip's default setup. But I recommend re-assign a more convenient key for pasting. simpleclip doesn't work in certain scenario. See https://github.com/rolandwalker/simpleclip/...


1

I use simpleclip, there is a short explanation on the github page for what may be going on: https://github.com/rolandwalker/simpleclip I bind simpleclip-paste to f9 f9


1

I think the docstring from interprogram-paste-function describes the problem and a possible solution: Note that the function should return a string only if a program other than Emacs has provided a string for pasting; if Emacs provided the most recent string, the function should return nil. If it is difficult to tell whether Emacs or some other ...


Only top voted, non community-wiki answers of a minimum length are eligible