Does anyone know if there's an inbuilt way to insert either the last kill or another buffer as an escaped string in the current buffer? Seems like one of those things that is probably there, but I can't find, because emacs names it differently compared to anything else 😄.
Escaped according to what? Clojure strings? URL encoding? Something else?
elisp strings I guess
In any case I mostly mean things like \n \t \"
Maybe something like this https://www.gnu.org/software/emacs/manual/html_node/elisp/Output-Functions.html#index-prin1_002dto_002dstring?
The trouble I had with everything I tried is that for example evaling (`M-:`) (insert ...) would again unescape the string.
Just as a starting point:
(defun my-insert-elisp-string ()
(interactive)
(insert
(prin1-to-string
(substring-no-properties
(or
(gui-get-selection)
(gui-get-primary-selection))))))
(substring-no-properties (current-kill 0)) yep just was trying that, and it works well enough from a scratch buffer with pp-eval-last-sexp
For posterity, I see that there is a pp-eval-expression that I could use in the original workflow I had in mind, as a stand-in replacement for M-: (eval-expression) when I have this occasional need.