Improve display of custom templates in the minibuffer

This commit is contained in:
Wetlize 2021-07-24 17:52:25 +03:00
parent 13f0c4785e
commit c6e4ffb929
2 changed files with 26 additions and 13 deletions

View file

@ -2,10 +2,10 @@
;;;###if (featurep! +roam2) ;;;###if (featurep! +roam2)
;;; Custom node accessors ;;; Custom node accessors
;;;###autoload (autoload 'org-roam-node-doom-filetitle "lang/org/autoload/contrib-roam2" nil t) ;;;###autoload (autoload 'org-roam-node-doom-filetitle "lang/org/autoload/contrib-roam2" nil t)
(cl-defmethod org-roam-node-doom-filetitle ((node org-roam-node)) (cl-defmethod org-roam-node-doom-filetitle ((node org-roam-node))
"Return NODE's file level \"#+title:\"." "Return the value of \"#+title:\" (if any) from file that NODE resides in.
If there's no file-level title in the file, return empty string."
(or (if (= (org-roam-node-level node) 0) (or (if (= (org-roam-node-level node) 0)
(org-roam-node-title node) (org-roam-node-title node)
(org-roam-get-keyword "TITLE" (org-roam-node-file node))) (org-roam-get-keyword "TITLE" (org-roam-node-file node)))
@ -13,25 +13,28 @@
;;;###autoload (autoload 'org-roam-node-doom-hierarchy "lang/org/autoload/contrib-roam2" nil t) ;;;###autoload (autoload 'org-roam-node-doom-hierarchy "lang/org/autoload/contrib-roam2" nil t)
(cl-defmethod org-roam-node-doom-hierarchy ((node org-roam-node)) (cl-defmethod org-roam-node-doom-hierarchy ((node org-roam-node))
"Return NODE's hierarchy, constructed of its file-title, OLP and title. "Return hierarchy for NODE, constructed of its file title, OLP and direct title.
This will automatically strip out any missing elements or If some elements are missing, they will be stripped out."
duplicates from the hierarchy."
(let ((title (org-roam-node-title node)) (let ((title (org-roam-node-title node))
(olp (org-roam-node-olp node)) (olp (org-roam-node-olp node))
(level (org-roam-node-level node)) (level (org-roam-node-level node))
(filetitle (org-roam-node-doom-filetitle node))) (filetitle (org-roam-node-doom-filetitle node))
;; TODO Add 'face based text properties for each type? (separator (propertize " > " 'face 'shadow)))
(cl-case level (cl-case level
;; node is a top-level file ;; node is a top-level file
(0 filetitle) (0 filetitle)
;; node is a level 1 heading ;; node is a level 1 heading
(1 (concat filetitle " > " title)) (1 (concat (propertize filetitle 'face '(shadow italic))
separator title))
;; node is a heading with an arbitrary outline path ;; node is a heading with an arbitrary outline path
(t (concat filetitle " > " (string-join olp " > ") " > " title))))) (t (concat (propertize filetitle 'face '(shadow italic))
separator (propertize (string-join olp " > ") 'face '(shadow italic))
separator title)))))
;;;###autoload (autoload 'org-roam-node-doom-subdirs "lang/org/autoload/contrib-roam2" nil t) ;;;###autoload (autoload 'org-roam-node-doom-subdirs "lang/org/autoload/contrib-roam2" nil t)
(cl-defmethod org-roam-node-doom-subdirs ((node org-roam-node)) (cl-defmethod org-roam-node-doom-subdirs ((node org-roam-node))
"Return NODE's subdirectories, relative to `org-roam-directory'." "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 (if-let ((dirs (thread-first node
(org-roam-node-file) (org-roam-node-file)
(file-relative-name org-roam-directory) (file-relative-name org-roam-directory)
@ -41,5 +44,15 @@ duplicates from the hierarchy."
;;;###autoload (autoload 'org-roam-node-doom-tags "lang/org/autoload/contrib-roam2" nil t) ;;;###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)) (cl-defmethod org-roam-node-doom-tags ((node org-roam-node))
"Return tags formatted in the same way how they appear in org files." "Return tags formatted in the same way how they appear in org files.
(mapconcat (lambda (s) (concat ":" s)) (org-roam-node-tags node) nil)) 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))))

View file

@ -75,7 +75,7 @@ In case of failure, fail gracefully."
(or org-roam-db-location (or org-roam-db-location
(concat doom-etc-dir "org-roam.db")) (concat doom-etc-dir "org-roam.db"))
org-roam-node-display-template org-roam-node-display-template
"${doom-hierarchy:*} ${doom-tags:35} ${doom-subdirs}" "${doom-hierarchy:*} ${doom-tags:45}"
org-roam-completion-everywhere t org-roam-completion-everywhere t
org-roam-mode-section-functions org-roam-mode-section-functions
#'(org-roam-backlinks-section #'(org-roam-backlinks-section