Function: markdown-wrap-or-insert

markdown-wrap-or-insert is a byte-compiled function defined in markdown-mode.el.

Signature

(markdown-wrap-or-insert S1 S2 &optional THING BEG END)

Documentation

Insert the strings S1 and S2, wrapping around region or THING.

If a region is specified by the optional BEG and END arguments, wrap the strings S1 and S2 around that region. If there is an active region, wrap the strings S1 and S2 around the region. If there is not an active region but the point is at THING, wrap that thing (which defaults to word). Otherwise, just insert S1 and S2 and place the point in between. Return the bounds of the entire wrapped string, or nil if nothing was wrapped and S1 and S2 were only inserted.

Source Code

;; Defined in ~/.emacs.d/elpa/markdown-mode-20260321.143/markdown-mode.el
(defun markdown-wrap-or-insert (s1 s2 &optional thing beg end)
  "Insert the strings S1 and S2, wrapping around region or THING.
If a region is specified by the optional BEG and END arguments,
wrap the strings S1 and S2 around that region.
If there is an active region, wrap the strings S1 and S2 around
the region.  If there is not an active region but the point is at
THING, wrap that thing (which defaults to word).  Otherwise, just
insert S1 and S2 and place the point in between.  Return the
bounds of the entire wrapped string, or nil if nothing was wrapped
and S1 and S2 were only inserted."
  (let (a b bounds new-point)
    (cond
     ;; Given region
     ((and beg end)
      (setq a beg
            b end
            new-point (+ (point) (length s1))))
     ;; Active region
     ((use-region-p)
      (setq a (region-beginning)
            b (region-end)
            new-point (+ (point) (length s1))))
     ;; Thing (word) at point
     ((setq bounds (markdown-bounds-of-thing-at-point (or thing 'word)))
      (setq a (car bounds)
            b (cdr bounds)
            new-point (+ (point) (length s1))))
     ;; No active region and no word
     (t
      (setq a (point)
            b (point))))
    (goto-char b)
    (insert s2)
    (goto-char a)
    (insert s1)
    (when new-point (goto-char new-point))
    (if (= a b)
        nil
      (setq b (+ b (length s1) (length s2)))
      (cons a b))))