Function: log-edit-extract-headers

log-edit-extract-headers is a byte-compiled function defined in log-edit.el.gz.

Signature

(log-edit-extract-headers HEADERS COMMENT)

Documentation

Extract headers from VC commit COMMENT to form command line arguments.

HEADERS should be an alist with elements (HEADER . CMDARG) or (HEADER . FUNCTION) associating headers to command line options and the result is then a list of the form (MSG ARGUMENTS...) where MSG is the remaining text from COMMENT. FUNCTION should be a function of one argument that takes the header value and returns the list of strings to be appended to ARGUMENTS. CMDARG will be added to ARGUMENTS followed by the header value. If "Summary" is not in HEADERS, then the
"Summary" header is extracted anyway and put back as the first
line of MSG.

Source Code

;; Defined in /usr/src/emacs/lisp/vc/log-edit.el.gz
(defun log-edit-extract-headers (headers comment)
  "Extract headers from VC commit COMMENT to form command line arguments.
HEADERS should be an alist with elements (HEADER . CMDARG)
or (HEADER . FUNCTION) associating headers to command line
options and the result is then a list of the form (MSG ARGUMENTS...)
where MSG is the remaining text from COMMENT.
FUNCTION should be a function of one argument that takes the
header value and returns the list of strings to be appended to
ARGUMENTS.  CMDARG will be added to ARGUMENTS followed by the
header value.  If \"Summary\" is not in HEADERS, then the
\"Summary\" header is extracted anyway and put back as the first
line of MSG."
  (with-temp-buffer
    (insert comment)
    (rfc822-goto-eoh)
    (narrow-to-region (point-min) (point))
    (let ((case-fold-search t)
          (summary ())
          (res ()))
      (dolist (header (if (assoc "Summary" headers) headers
                        (cons '("Summary" . t) headers)))
        (goto-char (point-min))
        (while (re-search-forward (concat "^" (car header)
                                          ":" log-edit-header-contents-regexp)
                                  nil t)
          (let ((txt (match-string 1)))
            (replace-match "" t t)
            (if (eq t (cdr header))
                (setq summary txt)
              (if (functionp (cdr header))
                  (setq res (nconc res (funcall (cdr header) txt)))
                (push txt res)
                (push (or (cdr header) (car header)) res))))))
      ;; Remove header separator if the header is empty.
      (widen)
      (goto-char (point-min))
      (when (looking-at "\\([ \t]*\n\\)+")
        (delete-region (match-beginning 0) (match-end 0)))
      (if summary (insert summary "\n\n"))
      (cons (buffer-string) res))))