Minor mode to capture:
(define-minor-mode lmno-blog-capture-mode
"Mode for capturing blog entries like org-capture."
:lighter ">> BlogCapture"
:keymap (let ((map (make-sparse-keymap)))
(define-key map (kbd "C-c C-c") #'lmno-blog-capture-finalize)
(define-key map (kbd "C-c C-k") #'lmno-blog-capture-abort)
map))
The capture function:
(defun lmno-capture-post ()
"Start a blog post capture session in a temporary buffer."
(interactive)
(let* ((title (read-string "Post title: "))
(date (format-time-string "%Y-%m-%d"))
(heading (format "# [%s] %s\n\n" date title))
(buf (get-buffer-create "*LMNO Blog Capture*")))
(split-window-below -12) ;; bottom 12-line capture window
(other-window 1)
(switch-to-buffer buf)
(erase-buffer)
(insert heading)
(markdown-mode) ;; or text-mode if you prefer
(lmno-blog-capture-mode 1)
(setq-local lmno-blog-capture-destination "~/blog/puddingtime_lmno.md")
(message "Write your post. C-c C-c to save, C-c C-k to cancel.")))
The window disposition functions:
(defun lmno-blog-capture-finalize ()
"Save the capture to the blog file and close the capture window."
(interactive)
(let ((content (buffer-string))
(dest lmno-blog-capture-destination))
(with-current-buffer (find-file-noselect dest)
(goto-char (point-min))
(insert content "\n")
(save-buffer))
(lmno--close-capture-window)
(message "Blog post saved.")))
(defun lmno-blog-capture-abort ()
"Cancel the blog capture."
(interactive)
(lmno--close-capture-window)
(message "Blog capture aborted."))
(defun lmno--close-capture-window ()
"Close the capture buffer and its window."
(let ((buf (current-buffer)))
(delete-window)
(kill-buffer buf)))
Bind a menu item:
(map! :leader
:desc "Capture blog post (LMNO)"
"n b" #'lmno-capture-post)