Function: message-position-on-field

message-position-on-field is a byte-compiled function defined in message.el.gz.

Signature

(message-position-on-field HEADER &rest AFTERS)

Documentation

Move point to header HEADER or insert it if not found.

If HEADER is not present, insert it with an empty value, after any headers specified in AFTERS.

Source Code

;; Defined in /usr/src/emacs/lisp/gnus/message.el.gz
(defun message-position-on-field (header &rest afters)
  "Move point to header HEADER or insert it if not found.

If HEADER is not present, insert it with an empty value, after any
headers specified in AFTERS."
  (let ((case-fold-search t))
    (save-restriction
      (narrow-to-region
       (goto-char (point-min))
       (progn
	 (re-search-forward
	  (concat "^" (regexp-quote mail-header-separator) "$"))
	 (match-beginning 0)))
      (goto-char (point-min))
      (if (re-search-forward (concat "^" (regexp-quote header) ":") nil t)
	  (progn
	    (re-search-forward "^[^ \t]" nil 'move)
	    (beginning-of-line)
	    (skip-chars-backward "\n")
	    t)
	(while (and afters
		    (not (re-search-forward
			  (concat "^" (regexp-quote (car afters)) ":")
			  nil t)))
	  (pop afters))
	(when afters
	  (re-search-forward "^[^ \t]" nil 'move)
	  (beginning-of-line))
	(insert header ": \n")
	(forward-char -1)
	nil))))