help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

alt to copy-region-as-kill for kill ring


From: Jeremie Juste
Subject: alt to copy-region-as-kill for kill ring
Date: Sun, 07 Mar 2021 09:57:08 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

Hello,

The following function to copies a word in the visible buffer and comes
back to point to yank it. It builds on avy package.


(defun boomrang (query-char)
  "kill word and come back to point"
  (interactive (list (read-char "Query Char:")))
  (save-excursion
    (progn
      (avy-goto-word-1 query-char)      
      (copy-region-as-kill (point) (progn (re-search-forward "[[:alnum:]_-]*") 
(point)))))
  (yank))


There are a few limitations to it:
-  if the word is in a different buffer it yank it but the cursor does
not come back
-  If we bind the function to a key (say C-'), it is rather difficult to 
control the copy-region-as-kill as when
used with this function it behaves like C-M-w (see function kill-ring-save).

for instance (cursor position is represented as a |)
|dfd ## M-d C-' (Query-char i) ==> dfdinstance

when only instance is wanted. A temporary solution might be to enter a
key between after M-d to deactivate appending. But this solution is
costly.

Do you have an better solution?

Best regards,
-- 
Jeremie Juste



reply via email to

[Prev in Thread] Current Thread [Next in Thread]