Function: git-commit--insert-trailer

git-commit--insert-trailer is a byte-compiled function defined in git-commit.el.

Signature

(git-commit--insert-trailer TRAILER VALUE)

Source Code

;; Defined in ~/.emacs.d/elpa/magit-20260411.1452/git-commit.el
(defun git-commit--insert-trailer (trailer value)
  (save-excursion
    (let ((string (format "%s: %s" trailer value))
          (leading-comment-end nil))
      ;; Make sure we skip forward past any leading comments.
      (goto-char (point-min))
      (while (looking-at comment-start)
        (forward-line))
      (setq leading-comment-end (point))
      (goto-char (point-max))
      (cond
        ;; Look backwards for existing trailers.
        ((re-search-backward (git-commit--trailer-regexp) nil t)
         (end-of-line)
         (insert ?\n string)
         (unless (= (char-after) ?\n)
           (insert ?\n)))
        ;; Or place the new trailer right before the first non-leading
        ;; comments.
        (t
         (while (re-search-backward (concat "^" comment-start)
                                    leading-comment-end t))
         (unless (looking-back "\n\n" nil)
           (insert ?\n))
         (insert string ?\n))))
    (unless (or (eobp) (= (char-after) ?\n))
      (insert ?\n))))