An empty string field value also means no field.
[pelican-mode.git] / pelican-mode.el
index 6e1ff8a..14d3472 100644 (file)
@@ -51,10 +51,12 @@ the unquoted printed representation of it is used:
 - `slug' means the file's path relative to the document root sans
   extension; see `pelican-default-slug'.
 
-- nil means return an empty string, without any name or value."
+- nil or an empty strings means return an empty string, without
+  any name or value."
   (setq value (pcase value
                 ('now (pelican-timestamp))
                 ('slug (pelican-default-slug))
+                ('"" nil)
                 (_ value)))
   (when (symbolp name)
     (setq name (string-remove-prefix ":" (symbol-name name))))
@@ -116,7 +118,7 @@ the unquoted printed representation of it is used:
 (defun pelican-insert-auto-header ()
   "Insert a Pelican header for a page or post."
   (interactive)
-  (call-interactively (if (pelican-is-page)
+  (call-interactively (if (pelican-page-p)
                           'pelican-insert-page-header
                         'pelican-insert-draft-post-header)))
 
@@ -125,12 +127,18 @@ the unquoted printed representation of it is used:
   (interactive "sField: \nsValue: ")
   (save-excursion
     (goto-char 0)
+    (when (and (derived-mode-p 'rst-mode)
+               (re-search-forward "^#" nil t))
+      (forward-line 2))
     (if (re-search-forward (concat "^" (pelican-field field ".+*")) nil t)
         (replace-match (pelican-field field value))
-      (re-search-forward "#")
-      (forward-line 2)
-      (re-search-forward "^$")
-      (replace-match (pelican-field field value)))))
+      (when value
+        (re-search-forward "^$")
+        (replace-match (pelican-field field value))))))
+
+(defun pelican-remove-field (field)
+  "Remove FIELD."
+  (pelican-set-field field nil))
 
 (defun pelican-set-title (title)
   "Set the title to TITLE."
@@ -147,15 +155,15 @@ the unquoted printed representation of it is used:
 (defun pelican-update-date ()
   "Update a Pelican date header."
   (interactive)
-  (pelican-set-field "date" (pelican-timestamp)))
+  (pelican-set-field :date 'now))
 
 (defun pelican-publish-draft ()
   "Remove draft status from a Pelican post."
   (interactive)
-  (pelican-set-field "status" nil)
+  (pelican-remove-field :status)
   (pelican-update-date))
 
-(defun pelican-is-page ()
+(defun pelican-page-p ()
   "Guess the current buffer is a Pelican page (vs. a post or neither)."
   (when-let (pelican-base (pelican-find-root))
     (let* ((relative (file-relative-name buffer-file-name pelican-base))
@@ -191,7 +199,7 @@ the unquoted printed representation of it is used:
   (when-let (conf (pelican-find-in-parents "pelicanconf.py"))
     (file-name-directory conf)))
 
-(defun pelican-is-in-site ()
+(defun pelican-site-p ()
   "Check if this buffer is under a Pelican site."
   (not (null (pelican-find-root))))
 
@@ -230,7 +238,7 @@ for editing Pelican site files."
 ;;;###autoload
 (defun pelican-enable-if-site ()
   "Enable `pelican-mode' if this buffer is under a Pelican site."
-  (when (pelican-is-in-site)
+  (when (pelican-site-p)
     (pelican-mode 1)))
 
 ;;;###autoload