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.
This commit is contained in:
Henrik Lissner 2022-02-10 19:37:48 +01:00
parent 11cc896e8f
commit 7304a8de8f
2 changed files with 34 additions and 19 deletions

View file

@ -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
(thread-first
node
(org-roam-node-file)
(file-relative-name org-roam-directory)
(file-name-directory))))
dirs
""))
(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)))
;;

View file

@ -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)