In general, there's nothing wrong with using commands as part of elisp
code. Those functions which are only meant for interactive use will
(or should) warn you about that. See
In order to delete, instead of killing, just make sure the kill-ring isn't changed:
(comment-kill (count-lines (...
The best solution is using C-x C-x to reactivate the mark.
But if you want to really keep the selection you can use:
(defun copy-keep-highlight (beg end)
(prog1 (kill-ring-save beg end)
(setq deactivate-mark nil)))
If yanking the path into the current buffer is not acceptable, use C-u C-c C-k, which invokes helm-kill-selection-and-quit.
From the documentation of helm-kill-selection-and-quit:
Store display value of current selection to kill ring.
With a prefix arg set to real value of current selection.
Display value is what you see in `helm-buffer' and real ...
This is from 12.2.2 Yanking Earlier Kills:
‘M-y’ can take a numeric argument, which tells it how many entries to
advance the “last yank” pointer by. A negative argument moves the
pointer toward the front of the ring; from the front of the ring, it
moves “around” to the last entry and continues forward from there.
Your code is alright except that it is missing the mandatory arguments to the other-window command.
From the function documentation (C-h f other-window RET),
(other-window COUNT &optional ALL-FRAMES)
Select another window in cyclic ordering of windows.
COUNT specifies the number of windows to skip, starting with the
selected window, before ...
Try C-c TAB when you have the file highlighted. This will yank the path into the current buffer, which might be an undesired side effect, but as long as you do helm-find-files from the buffer you want to use it in, you should be fine.
@Malabarba's answer looks like the simplest and most elegant
solution. However, if you do this enough that it warrants its
own function, you can also adapt comment-kill to delete without
modifying the kill ring. Here's the source code of
comment-kill with the single-line change to define comment-delete:
(defun comment-delete (arg)
"Delete the first ...
According to the documentation:
<C-delete> runs the command kill-word (found in global-map), which is
an interactive compiled Lisp function in ‘simple.el’.
It is bound to <C-delete>, M-d.
Kill characters forward until encountering the end of a word. With
argument ARG, do this that many times.
Now, let's ...
As the comments suggest, eval-buffer manipulates the position of point, so that by the time you call kill-region, region-beginning and region-end are no longer what they were when you started. The position of point is 'preserved', as @ColinBell points out, but in this case that means that point is moved during eval-buffer, and then restored to it's original ...
The package https://github.com/Lindydancer/highlight2clipboard does exactly what you asked for. It use htmlize to create a HTML version of the text which it adds as an alternative paste text. (Note: This is a non-trivial operation which requires interfacing with the clipboard. This is operating system specific, currently OS X and MS-Windows are supported.)
If I understood your question, your are looking to something like this:
(defun youngfrog/copy-rectangle-to-kill-ring (start end)
"Saves a rectangle to the normal kill ring. Not suitable for yank-rectangle."
(let ((lines (extract-rectangle start end)))
(while lines ;; insert-rectangle, but without the ...
I want to simplify the kill-ring so that it behaves like a simple clipboard. I find it complex that the kill-ring contains multiple items.
You can completely ignore the fact that the kill ring contains multiple items if you want. If you only ever use yank (C-y) to paste, then you will only ever paste the most recently-killed text.
Unless you actively tell ...
Simply use the kill ring. In evil, your simplest option is to use evil-paste-pop, bound by default to C-p. Here's the docstring:
Replace the just-yanked stretch of killed text with a different stretch.
This command is allowed only immediatly after a yank,
evil-paste-before, evil-paste-after or evil-paste-pop.
This command uses the same paste ...
The htmlize package can do this. Install it with M-x package-install htmlize and you get access to the commands htmlize-region
(htmlize-region BEG END)
Convert the region to HTML, preserving colors and decorations.
(htmlize-region-for-paste BEG END)
Htmlize the region and return just the HTML as a string.
If you look at what M-backspace calls using C-h <M-backspace> you see that it calls backward-kill-word that function simply calls kill-word with a negative argument. The kill-word function is coded as:
(defun kill-word (arg)
"Kill characters forward until encountering the end of a word.
With argument ARG, do this that many times."
Since Emacs 24, without any configuration, you can delete any text without adding it to the kill ring by selecting it and then pressing Backspace or Delete. When the mark is active, these keys delete the region instead of just deleting the character before/after the cursor.
That is, move to one end of the text you want to delete, press Ctrl+Space, move to ...
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 ...
expand-region or easy-kill or hydra might provide better idea on how to do one thing continuously, but here is a silly command which tries to do exactly what you want.
(defun my-kill-ring-save ()
(if (eq last-command this-command)
kill-whole-line is an interactive compiled Lisp function.
It is bound to <C-S-backspace>.
(kill-whole-line &optional ARG)
Kill current line. With prefix ARG, kill that many lines starting from
the current line. If ARG is negative, kill backward. Also kill the
preceding newline. (This is meant to make C-x z ...
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 ...
You have a few options for this :-
You can use counsel which provides with the command counsel-yank-pop which will show the list of all the yanked text and you can select anyone of them using ivy (this is what I use). In your case, you can press M-> to go the first entry in the kill-ring.
if you use helm, there is the command helm-show-kill-ring which ...
From the various comments so far, it sounds like you are in the process of learning about Emacs (welcome!). There are many things in Emacs that are unlike other editors, and as you go through the tutorials and read about things you might come across concepts like the kill ring that seem confusing and/or unnecessary.
Emacs is endlessly configurable so you ...
A fourth option is optimized for ease of yanking, at the cost of a little forethought during the killing phase. We use append-next-kill (C-M-w) before the second and each subsequent kill operation. This means that all the killed text is amalgamated into the same entry in the kill ring. So a single C-y is all that is needed to yank it all back at the new ...
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 ...
Here's one approach for dealing with blank (i.e. only whitespace) kills. Rather than filtering them out altogether, this will allow at most one blank entry in the kill ring. Each new kill will check the head of the kill-ring and replace it if it is blank.
(defun my/replace-blank-kill (args)
(let ((string (car args))
(replace (cdr args))
Not sure what is special about having the rectangle in the kill-ring, but if you upgrade to Emacs-24.4, then you can do: C-x SPC .... M-w to select a rectangle and place it on the kill-ring. After that C-y will yank that rectangle (in the same was that C-x r y does, tho).
It seems you could use -1 as a prefix argument to M-y as hinted by the manual:
M-y can take a numeric argument, which tells it how many entries to advance the last-yank pointer by. A negative argument moves the pointer toward the front of the ring; from the front of the ring, it moves around to the last entry and continues forward from there.
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."
(let ((proc (get-buffer-process (current-buffer))))
(let ((pmark (progn (goto-...