Function: embark-insert

embark-insert is a byte-compiled function defined in embark.el.

Signature

(embark-insert STRINGS)

Documentation

Join STRINGS and insert the result at point.

With a prefix argument, prompt for the separator to join the STRINGS, which defaults to a newline.

Some whitespace is also inserted if necessary to avoid having the inserted string blend into the existing buffer text. More precisely:

1. If the inserted string does not contain newlines, a space may
be added before or after it as needed to avoid inserting a word constituent character next to an existing word constituent.

2. For a multiline inserted string, newlines may be added before
or after as needed to ensure the inserted string is on lines of its own.

As a convenience, if the buffer is read-only, attempt the insertion in the window returned by other-window-for-scrolling instead.

Source Code

;; Defined in ~/.emacs.d/elpa/embark-20260610.302/embark.el
(defun embark-insert (strings)
  "Join STRINGS and insert the result at point.
With a prefix argument, prompt for the separator to join the
STRINGS, which defaults to a newline.

Some whitespace is also inserted if necessary to avoid having the
inserted string blend into the existing buffer text.  More
precisely:

1. If the inserted string does not contain newlines, a space may
be added before or after it as needed to avoid inserting a word
constituent character next to an existing word constituent.

2. For a multiline inserted string, newlines may be added before
or after as needed to ensure the inserted string is on lines of
its own.

As a convenience, if the buffer is read-only, attempt the insertion in
the window returned by `other-window-for-scrolling' instead."
  (let* ((separator (embark--separator strings))
         (multiline
          (or (and (cdr strings) (string-match-p "\n" separator))
              (and (null (cdr strings))
                   (equal (buffer-substring (line-beginning-position)
                                            (line-end-position))
                          (car strings)))
              (seq-some (lambda (s) (string-match-p "\n" s)) strings))))
    (cl-labels ((maybe-space ()
                  (and (looking-at "\\w") (looking-back "\\w" 1)
                       (insert " ")))
                (maybe-newline ()
                  (or (looking-back "^[ \t]*" 40) (looking-at "\n")
                      (newline-and-indent)))
                (maybe-whitespace ()
                  (if multiline (maybe-newline) (maybe-space)))
                (ins-string ()
                  (let ((start (point)))
                    (insert
                     (mapconcat #'substring-no-properties strings separator))
                    (save-excursion (goto-char start) (maybe-whitespace))
                    (when (looking-back "\n" 1) (delete-char -1))
                    (save-excursion (maybe-whitespace)))))
      (if buffer-read-only
          (with-selected-window (other-window-for-scrolling)
            (ins-string))
        (ins-string)))))