3

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
Drew
  • 29,895
  • 7
  • 74
  • 104
Anton Harald
  • 5,772
  • 4
  • 27
  • 61

3 Answers3

5

There is no single chord, but you can do two:

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.

sds
  • 58,617
  • 29
  • 161
  • 278
1

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)
tak
  • 136
  • 3
0

I recommend installing smartparens then simply using sp-copy-sexp.

Razzi Abuissa
  • 3,337
  • 2
  • 28
  • 29