X-Git-Url: https://git.korewanetadesu.com/?p=pelican-mode.git;a=blobdiff_plain;f=pelican-mode.el;h=dce4bb8ddfe0f06e7a559d73581fddf22f77b011;hp=f82be8a09194fafdf26ff9620673a965d0da00c2;hb=f292b498bf735f01375e68add5539e3bf3cd729d;hpb=3315a18243301484682db5648146579430001772 diff --git a/pelican-mode.el b/pelican-mode.el index f82be8a..dce4bb8 100644 --- a/pelican-mode.el +++ b/pelican-mode.el @@ -49,12 +49,16 @@ (t (error "Unsupported major mode %S" major-mode))) "")) +(defun pelican-rst-title (title) + "Create a ReSt version of TITLE." + (concat title "\n" (make-string (string-width title) ?#) "\n\n")) + (defun pelican-title (title) "Format a TITLE for the current document, according to major mode." (cond ((derived-mode-p 'markdown-mode) (pelican-field "title" title)) ((derived-mode-p 'rst-mode) - (concat title "\n" (make-string (string-width title) ?#) "\n")) + (pelican-rst-title title)) (t (error "Unsupported major mode %S" major-mode)))) (defun pelican-header (title date status category tags slug) @@ -99,13 +103,28 @@ (defun pelican-set-field (field value) "Set FIELD to VALUE." + (interactive "sField: \nsValue: ") (save-excursion (goto-char 0) (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))))) +(defun pelican-set-title (title) + "Set the title to TITLE." + (interactive "sTitle: ") + (if (pelican-is-markdown) + (pelican-set-field "title" title) + (save-excursion + (goto-char 0) + (let ((header (pelican-rst-title title))) + (if (looking-at ".*\n#+\n+") + (replace-match header) + (insert header)))))) + (defun pelican-update-date () "Update a Pelican date header." (interactive) @@ -157,11 +176,6 @@ "Check if this buffer is under a Pelican site." (not (null (pelican-find-root)))) -(defun pelican-enable-if-site () - "Enable `pelican-mode' if this buffer is under a Pelican site." - (when (pelican-is-in-site) - (pelican-mode 1))) - (defun pelican-make (target) "Execute TARGET in a Makefile at the root of the site." (interactive "sMake Pelican target: ") @@ -202,12 +216,17 @@ "Toggle Pelican mode. Interactively with no argument, this command toggles the mode. -to show buffer size and position in mode-line." +for editing Pelican site files." :init-value nil :lighter " Pelican" :keymap pelican-keymap :group 'pelican) +;;;###autoload +(defun pelican-enable-if-site () + "Enable `pelican-mode' if this buffer is under a Pelican site." + (when (pelican-is-in-site) + (pelican-mode 1))) ;;;###autoload (add-hook 'markdown-mode-hook 'pelican-enable-if-site)