Skip to content

Instantly share code, notes, and snippets.

@pdxmph
Created April 22, 2025 03:27
Show Gist options
  • Save pdxmph/4072412b8517b5d4e2b6c6fa4595d73c to your computer and use it in GitHub Desktop.
Save pdxmph/4072412b8517b5d4e2b6c6fa4595d73c to your computer and use it in GitHub Desktop.
lmno blogging capture tool

lmno blogging

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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment