mirror of
https://github.com/org-roam/org-roam
synced 2025-08-01 12:17:21 -05:00
(feat): org-roam-doctor: add ROAM_TAGS and ROAM_ALIAS checks (#680)
This commit is contained in:
@ -51,6 +51,8 @@
|
||||
(declare-function org-roam--get-roam-buffers "org-roam")
|
||||
(declare-function org-roam--list-all-files "org-roam")
|
||||
(declare-function org-roam--org-roam-file-p "org-roam")
|
||||
(declare-function org-roam--parse-tags "org-roam")
|
||||
(declare-function org-roam--parse-alias "org-roam")
|
||||
|
||||
(defvar org-roam-verbose)
|
||||
|
||||
@ -66,7 +68,53 @@
|
||||
:description "Fix broken links."
|
||||
:actions '(("d" . ("Unlink" . org-roam-doctor--remove-link))
|
||||
("r" . ("Replace link" . org-roam-doctor--replace-link))
|
||||
("R" . ("Replace link (keep label)" . org-roam-doctor--replace-link-keep-label))))))
|
||||
("R" . ("Replace link (keep label)" . org-roam-doctor--replace-link-keep-label))))
|
||||
(make-org-roam-doctor-checker
|
||||
:name 'org-roam-doctor-check-tags
|
||||
:description "Check #+ROAM_TAGS.")
|
||||
(make-org-roam-doctor-checker
|
||||
:name 'org-roam-doctor-check-alias
|
||||
:description "Check #+ROAM_ALIAS.")))
|
||||
|
||||
(defun org-roam-doctor-check-tags (ast)
|
||||
"Checker for detecting invalid #+ROAM_TAGS.
|
||||
AST is the org-element parse tree."
|
||||
(let (reports)
|
||||
(org-element-map ast 'keyword
|
||||
(lambda (kw)
|
||||
(when (string= (org-element-property :key kw) "ROAM_TAGS")
|
||||
(let* ((s (org-element-property :value kw))
|
||||
(tags (org-roam--parse-tags s))
|
||||
(bad-tags (-remove #'stringp tags)))
|
||||
(when bad-tags
|
||||
(push
|
||||
`(,(org-element-property :begin kw)
|
||||
,(concat "Invalid tags: "
|
||||
(prin1-to-string bad-tags)
|
||||
(when (s-contains? "," s)
|
||||
"\nCheck that your tags are not comma-separated.")))
|
||||
reports))))))
|
||||
reports))
|
||||
|
||||
(defun org-roam-doctor-check-alias (ast)
|
||||
"Checker for detecting invalid #+ROAM_ALIAS.
|
||||
AST is the org-element parse tree."
|
||||
(let (reports)
|
||||
(org-element-map ast 'keyword
|
||||
(lambda (kw)
|
||||
(when (string= (org-element-property :key kw) "ROAM_ALIAS")
|
||||
(let* ((s (org-element-property :value kw))
|
||||
(aliases (org-roam--parse-alias s))
|
||||
(bad-aliases (-remove #'stringp aliases)))
|
||||
(when bad-aliases
|
||||
(push
|
||||
`(,(org-element-property :begin kw)
|
||||
,(concat "Invalid aliases: "
|
||||
(prin1-to-string bad-aliases)
|
||||
(when (s-contains? "," s)
|
||||
"\nCheck that your aliases are not comma-separated.")))
|
||||
reports))))))
|
||||
reports))
|
||||
|
||||
(defun org-roam-doctor-broken-links (ast)
|
||||
"Checker for detecting broken links.
|
||||
|
@ -347,12 +347,14 @@ it as FILE-PATH."
|
||||
(when title
|
||||
(list title))))
|
||||
|
||||
(defalias 'org-roam--parse-alias 'org-roam--str-to-list)
|
||||
|
||||
(defun org-roam--extract-titles-alias ()
|
||||
"Return the aliases from the current buffer.
|
||||
Reads from the \"ROAM_ALIAS\" property."
|
||||
(let* ((prop (org-roam--extract-global-props '("ROAM_ALIAS")))
|
||||
(aliases (cdr (assoc "ROAM_ALIAS" prop))))
|
||||
(org-roam--str-to-list aliases)))
|
||||
(org-roam--parse-alias aliases)))
|
||||
|
||||
(defun org-roam--extract-titles-headline ()
|
||||
"Return the first headline of the current buffer."
|
||||
@ -395,10 +397,12 @@ The final directory component is used as a tag."
|
||||
(file-relative-name file org-roam-directory))))
|
||||
(last (f-split dir-relative))))
|
||||
|
||||
(defalias 'org-roam--parse-tags 'org-roam--str-to-list)
|
||||
|
||||
(defun org-roam--extract-tags-prop (_file)
|
||||
"Extract tags from the current buffer's \"#ROAM_TAGS\" global property."
|
||||
(let* ((prop (org-roam--extract-global-props '("ROAM_TAGS"))))
|
||||
(org-roam--str-to-list (cdr (assoc "ROAM_TAGS" prop)))))
|
||||
(org-roam--parse-tags (cdr (assoc "ROAM_TAGS" prop)))))
|
||||
|
||||
(defcustom org-roam-tag-sort nil
|
||||
"When non-nil, sort the tags in the completions.
|
||||
|
Reference in New Issue
Block a user