+ (call-interactively
+ (if (pelican-mode-page-p)
+ #'pelican-mode-insert-page-header
+ #'pelican-mode-insert-draft-article-header)))
+
+(defun pelican-mode-set-field-rst-mode (field value)
+ "Set reStructuredText metadata FIELD to VALUE."
+ (setq field (downcase field))
+ (if (equal field "title")
+ (let ((header (format "%s\n%s\n\n"
+ value (make-string (string-width value) ?#))))
+ (if (looking-at ".*\n#+\n+")
+ (replace-match header)
+ (insert header)))
+ (let ((text (when value (format ":%s: %s\n" field value))))
+ (when (looking-at "^.*\n#")
+ (forward-line 3))
+ (if (re-search-forward (format "^:%s:.*\n" (regexp-quote field)) nil t)
+ (replace-match (or text ""))
+ (when text
+ (if (re-search-forward "^$" nil t)
+ (replace-match text)
+ (insert text)))))))
+
+(defun pelican-mode-set-field-markdown-mode (field value)
+ "Set Markdown metadata FIELD to VALUE."
+ (setq field (capitalize field))
+ (let ((text (when value (format "%s: %s\n" field value))))
+ (if (re-search-forward (format "^%s:.*\n" (regexp-quote field)) nil t)
+ (replace-match text)
+ (when value
+ (if (re-search-forward "^$" nil t)
+ (replace-match text)
+ (insert text))))))
+
+(defun pelican-mode-set-field-adoc-mode (field value)
+ "Set AsciiDoc metadata FIELD to VALUE."
+ (setq field (downcase field))
+ (if (equal field "title")
+ (let ((header (format "= %s\n\n" value)))
+ (if (looking-at "= .*\n\n+")
+ (replace-match header)
+ (insert header)))
+ (let ((text (when value (format ":%s: %s\n" field value))))
+ (when (looking-at "^=")
+ (forward-line 2))
+ (if (re-search-forward (format "^:%s:.*\n" (regexp-quote field)) nil t)
+ (replace-match (or text ""))
+ (when text
+ (if (re-search-forward "^$" nil t)
+ (replace-match text)
+ (insert text)))))))
+
+(defun pelican-mode-set-field-org-mode (field value)
+ "Set Org global metadata FIELD to VALUE."
+ ;; None of org-mode's functions I can find for setting properties
+ ;; operate on the global list, only a single property drawer.
+ (setq field (upcase field))
+ (setq field
+ (format (if (member field '("TITLE" "DATE" "CATEGORY" "AUTHOR"))
+ "#+%s:"
+ "#+PROPERTY: %s")
+ field))
+ (let ((text (when value (format "%s %s\n" field value))))
+ (if (re-search-forward (format "^%s .*\n" (regexp-quote field)) nil t)
+ (replace-match (or text ""))
+ (when text
+ (if (re-search-forward "^$" nil t)
+ (replace-match text)
+ (insert text))))))
+
+(defun pelican-mode-set-field (field value)
+ "Set FIELD to VALUE.
+
+FIELD may be a string or a symbol; if it is a symbol, the
+symbol name is used (removing a leading ':' if present).
+
+When called from Lisp, VALUE may be any value; except for the
+following special values, the unquoted printed representation of
+it is used:
+
+- `now' means the current time; see `pelican-mode-timestamp'.