I'm looking for a command to put an S-expression to the kill ring, without removing it.
The following scenario would do the thing, however the expression would be removed, when using M-x kill-sexp
:
(foo (bar bam))
^
point here
I'm looking for a command to put an S-expression to the kill ring, without removing it.
The following scenario would do the thing, however the expression would be removed, when using M-x kill-sexp
:
(foo (bar bam))
^
point here
There is no single chord, but you can do two:
mark-sexp
kill-ring-save
Alternatively, you can do
If your buffer is read-only, the first command will fail, but the
S-expression will still be copied into the kill-ring
.
There are many ways to do this (e.g. with the built-in thing-at-point
, or just calling kill-sexp
via call-interactively
and restoring the original buffer contents after).
It's pretty straightforward to implement as a slightly modified kill-sexp
though. This is what I use:
(defun copy-sexp-as-kill (&optional arg)
"Save the sexp following point to the kill ring.
ARG has the same meaning as for `kill-sexp'."
(interactive "p")
(save-excursion
(let ((orig-point (point)))
(forward-sexp (or arg 1))
(kill-ring-save orig-point (point)))))
(global-set-key (kbd "M-K") #'copy-sexp-as-kill)