Assuming that your current work flow is doing
kill-ring-save) and then yanking it with
C-y, you can accomplish what you want with a function modeled after
kill-ring-save, which saves a substring of the buffer to the kill ring but without any properties. The modified function works by temporarily setting the variable
filter-buffer-substring-function to a function that filters the buffer substring and gets rid of properties:
(defun ndk/buffer-substring-no-properties-filter (beg end delete)
(buffer-substring-no-properties beg end))
(defun ndk/kill-ring-save-no-properties (beg end &optional region)
(interactive (list (mark) (point)
(let ((filter-buffer-substring-function #'ndk/buffer-substring-no-properties-filter))
(kill-ring-save beg end region)
(kill-ring-sage beg end))))
You can bind the function to a key like this:
(global-set-key (kbd "C-c w") #'ndk/kill-ring-save-no-properties)
I am assuming that
C-c w is not used either in the global map or in any of the local maps that might be active in the buffer where the strings you wish to copy are (the Java properties file in your example). If it is, you might have to hunt around for a suitable alternative, but
C-c w should be free: the sequence
C-c <letter> where
<letter> is an upper or lower case letter is reserved for users.
You can add the definitions of the two function and the key binding to your emacs initialization file.
With these settings, the work flow is:
- select a region in the original buffer
C-c w (instead of
- switch to the other buffer
- yank with
See the doc string for the variable
filter-buffer-substring-function for some of the gory details.
EDIT: I tried doing something similar on the
yank side, rather than the
kill-ring-save side, as @Drew indicated in his answer, but it did not work for me and I'm not sure why it did not work.
Here's the function I tried:
(defun ndk/yank-no-properties ()
(let ((yank-excluded-properties t))
From a very cursory reading of the
yank code (i.e. this may be completely wrong), it looks as if the
yank-handler property is an essential ingredient but I don't know how to deal with it.