From 7304a8de8f8859913b2e6662d4e1ea9795f8cd93 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Thu, 10 Feb 2022 19:37:48 +0100 Subject: [PATCH] tweak(org): separate roam tags from types - No longer hard-code fontification of tags and types in roam completion. - Prefix types with @ and tags with # -- makes them easier to search for in completion -- and swap types and hierarchy columns. I.e. before: TYPE TITLE [TAG [TAG...]] after: TITLE @TYPE [#TAG [#TAG...]] - Exclude unwanted (i.e. meta) tags from public display, like ATTACH, ARCHIVE, or anything in org-num-skip-tags. --- modules/lang/org/autoload/contrib-roam2.el | 46 +++++++++++++--------- modules/lang/org/contrib/roam2.el | 7 +++- 2 files changed, 34 insertions(+), 19 deletions(-) diff --git a/modules/lang/org/autoload/contrib-roam2.el b/modules/lang/org/autoload/contrib-roam2.el index 82266dbda..1618931de 100644 --- a/modules/lang/org/autoload/contrib-roam2.el +++ b/modules/lang/org/autoload/contrib-roam2.el @@ -35,27 +35,37 @@ If some elements are missing, they will be stripped out." (cl-defmethod org-roam-node-doom-subdirs ((node org-roam-node)) "Return subdirectories of `org-roam-directory' in which NODE resides in. If there's none, return an empty string." - (if-let ((dirs (thread-first node - (org-roam-node-file) - (file-relative-name org-roam-directory) - (file-name-directory)))) - dirs - "")) + (thread-first + node + (org-roam-node-file) + (file-relative-name org-roam-directory) + (file-name-directory))) ;;;###autoload (autoload 'org-roam-node-doom-tags "lang/org/autoload/contrib-roam2" nil t) (cl-defmethod org-roam-node-doom-tags ((node org-roam-node)) - "Return tags formatted in the same way how they appear in org files. -Treat subdirectories as tags too. If there's no elements to build -the tags of, return an empty string." - (let ((tags (org-roam-node-tags node)) - (subdirs (org-roam-node-doom-subdirs node))) - (when tags - (setq tags (propertize (concat (mapconcat (lambda (s) (concat ":" s)) tags nil) ":") - 'face 'shadow))) - (unless (string-empty-p subdirs) - (setq subdirs (propertize (concat ":" (replace-regexp-in-string "/\\|\\\\" ":" subdirs)) - 'face '(shadow italic)))) - (replace-regexp-in-string ":+" (propertize ":" 'face 'shadow) (concat subdirs tags)))) + "Return tags formatted in the same way how they appear in org files." + (when-let* ((tags (org-roam-node-tags node)) + (tags (cl-remove-if + (doom-rpartial + #'member (delq + nil (append + (list (bound-and-true-p org-archive-tag) + (bound-and-true-p org-attach-auto-tag)) + (bound-and-true-p org-num-skip-tags)))) + tags))) + tags)) + +;;;###autoload (autoload 'org-roam-node-doom-type "lang/org/autoload/contrib-roam2" nil t) +(cl-defmethod org-roam-node-doom-type ((node org-roam-node)) + "Return the directory relative to `org-roam-directory' as a note's \"type\"." + (when-let (dir (thread-first + node + (org-roam-node-file) + (file-relative-name org-roam-directory) + (file-name-directory))) + (directory-file-name dir))) + + ;; diff --git a/modules/lang/org/contrib/roam2.el b/modules/lang/org/contrib/roam2.el index 179219231..dfb6d9c5a 100644 --- a/modules/lang/org/contrib/roam2.el +++ b/modules/lang/org/contrib/roam2.el @@ -72,12 +72,17 @@ In case of failure, fail gracefully." (file-truename) (file-name-as-directory)) org-roam-node-display-template - "${doom-hierarchy:*} ${doom-tags:45}" + (format "${doom-hierarchy:*} %s %s" + (propertize "${doom-type:15}" 'face 'font-lock-keyword-face) + (propertize "${doom-tags:-1}" 'face 'org-tag)) org-roam-completion-everywhere t org-roam-db-gc-threshold most-positive-fixnum ;; Reverse the default to favor faster searchers over slower ones. org-roam-list-files-commands '(fd fdfind rg find)) + (add-to-list 'org-roam-node-template-prefixes '("doom-tags" . "#")) + (add-to-list 'org-roam-node-template-prefixes '("doom-type" . "@")) + (setq-hook! 'org-roam-find-file-hook org-id-link-to-org-use-id +org-roam-link-to-org-use-id)