Skip to content

Instantly share code, notes, and snippets.

@ashton314
Created July 23, 2024 17:55
Show Gist options
  • Save ashton314/f74060b00884ac9491b6944dac7bf8de to your computer and use it in GitHub Desktop.
Save ashton314/f74060b00884ac9491b6944dac7bf8de to your computer and use it in GitHub Desktop.
Normalize org frontmatter with Denote
(defun aw/denote-normalize-org-frontmatter ()
"Normalize the front-matter in an org-mode file."
(interactive)
(when-let* ((file (buffer-file-name))
(denote-filename-is-note-p file)
(type (denote-filetype-heuristics file))
(title (denote-retrieve-title-value file type))
(id (denote-retrieve-filename-identifier file)))
(let ((kwds (denote-retrieve-keywords-value file type)))
(delete-matching-lines "^#\\+title:.*$" (point-min) (point-max))
(delete-matching-lines "^#\\+date:.*$" (point-min) (point-max))
(delete-matching-lines "^#\\+identifier:.*$" (point-min) (point-max))
(delete-matching-lines "^#\\+filetags:.*$" (point-min) (point-max))
(denote--add-front-matter file title kwds id type)
(delete-matching-lines "^$" (point) (- (point) 1)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment