Created
July 23, 2024 17:55
-
-
Save ashton314/f74060b00884ac9491b6944dac7bf8de to your computer and use it in GitHub Desktop.
Normalize org frontmatter with Denote
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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