lmno.lol does have a feature for hiding posts, but the last time I did blogging out of a monolithic file I struggled to remember to toggle that, so when I started working on a post that got longer and longer I ended up moving the work into a scratch buffer. That was annoying to me, so there’s this:
(defvar mph/blog-drafts-file (expand-file-name "drafts_lmno.md" "~/journal/blog/"))
(defvar mph/blog-published-file (expand-file-name "lmno.md" "~/journal/blog/"))
(defun mph/move-heading-between-draft-and-published ()
"Move current Markdown L1 heading to the other blog file (drafts_lmno.md or lmno.md).
If in drafts_lmno.md, moves to lmno.md. If in lmno.md, moves to drafts_lmno.md.
Always inserts at the beginning of the file."
(interactive)
(let* ((current-file (buffer-file-name))
(target-file (cond
((string= (file-truename current-file) (file-truename mph/blog-drafts-file)) mph/blog-published-file)
((string= (file-truename current-file) (file-truename mph/blog-published-file)) mph/blog-drafts-file)
(t (user-error "This file is not drafts_lmno.md or lmno.md")))))
;; Save and cut the heading
(save-excursion
;; Find the beginning of the current L1 heading
(beginning-of-line)
(while (and (not (looking-at "^# ")) (not (bobp)))
(forward-line -1))
(unless (looking-at "^# ")
(user-error "Not on a Markdown L1 heading"))
(let ((start (point)))
;; Find the end of the current heading (next L1 heading or end of buffer)
(forward-line 1)
(while (and (not (looking-at "^# ")) (not (eobp)))
(forward-line 1))
;; Cut the heading and its content
(let ((heading-text (buffer-substring-no-properties start (point))))
(delete-region start (point))
;; Paste into target file at beginning
(with-current-buffer (find-file-noselect target-file)
(goto-char (point-min))
(insert heading-text)
(save-buffer)))))
(message "Moved heading to %s" (file-name-nondirectory target-file))))
;; Doom leader key setup
(map! :leader
:desc "Blog commands"
"l" '(:ignore t :which-key "blog")
:desc "Move heading to other blog file"
"l r" #'mph/move-heading-between-draft-and-published
:desc "New lmno blog entry (md)"
"l b" #'lmno-capture-post)
Just, SPC l r
on a given l1 heading to shuttle it to either the drafts file or the main blog file.