Function: yank-in-context

yank-in-context is an interactive and byte-compiled function defined in simple.el.gz.

Signature

(yank-in-context &optional ARG)

Documentation

Insert the last stretch of killed text while preserving syntax.

In particular, if point is inside a string, any quote characters in the killed text will be quoted, so that the string remains a valid string.

If point is inside a comment, ensure that the inserted text is also marked as a comment.

This command otherwise behaves as yank. See that command for explanation of ARG.

This function uses the escaped-string-quote buffer-local variable to determine how strings should be escaped.

Probably introduced at or before Emacs version 29.1.

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/simple.el.gz
(defun yank-in-context (&optional arg)
  "Insert the last stretch of killed text while preserving syntax.
In particular, if point is inside a string, any quote characters
in the killed text will be quoted, so that the string remains a
valid string.

If point is inside a comment, ensure that the inserted text is
also marked as a comment.

This command otherwise behaves as `yank'.  See that command for
explanation of ARG.

This function uses the `escaped-string-quote' buffer-local
variable to determine how strings should be escaped."
  (interactive "*P")
  (let ((yank-transform-functions (cons #'yank-in-context--transform
                                        yank-transform-functions)))
    (yank arg)))