mirror of
https://github.com/org-roam/org-roam
synced 2025-08-01 12:17:21 -05:00
add node display template
This commit is contained in:
@ -141,6 +141,22 @@ BEG and END are markers for the beginning and end regions."
|
|||||||
read-only t)
|
read-only t)
|
||||||
(marker-buffer beg))))
|
(marker-buffer beg))))
|
||||||
|
|
||||||
|
;;; Formatting
|
||||||
|
(defun org-roam--process-display-format (format)
|
||||||
|
"Pre-calculate minimal widths needed by the FORMAT string."
|
||||||
|
(let* ((fields-width 0)
|
||||||
|
(string-width
|
||||||
|
(string-width
|
||||||
|
(s-format format
|
||||||
|
(lambda (field)
|
||||||
|
(setq fields-width
|
||||||
|
(+ fields-width
|
||||||
|
(string-to-number
|
||||||
|
(or (cadr (split-string field ":"))
|
||||||
|
""))))
|
||||||
|
"")))))
|
||||||
|
(cons format (+ fields-width string-width))))
|
||||||
|
|
||||||
;;; Diagnostics
|
;;; Diagnostics
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun org-roam-version (&optional message)
|
(defun org-roam-version (&optional message)
|
||||||
|
36
org-roam.el
36
org-roam.el
@ -489,6 +489,38 @@ nodes."
|
|||||||
(org-roam-node-aliases node) alias-info))
|
(org-roam-node-aliases node) alias-info))
|
||||||
node))
|
node))
|
||||||
|
|
||||||
|
(defcustom org-roam-node-display-template
|
||||||
|
"${tags:10} ${title:48}"
|
||||||
|
"Configures display formatting for Org-roam node."
|
||||||
|
:group 'org-roam
|
||||||
|
:type 'string)
|
||||||
|
|
||||||
|
(defun org-roam-node--format-entry (node width)
|
||||||
|
"Formats NODE for display in the results list.
|
||||||
|
WIDTH is the width of the results list."
|
||||||
|
(let* ((format
|
||||||
|
(org-roam--process-display-format org-roam-node-display-template)))
|
||||||
|
(s-format
|
||||||
|
(car format)
|
||||||
|
(lambda (field)
|
||||||
|
(let* ((field (split-string field ":"))
|
||||||
|
(field-name (car field))
|
||||||
|
(field-width (cadr field))
|
||||||
|
(getter (intern (concat "org-roam-node-" field-name)))
|
||||||
|
(field-value (or (funcall getter node) "")))
|
||||||
|
(when (and (equal field-name "tags")
|
||||||
|
field-value)
|
||||||
|
(setq field-value (string-join field-value " ")))
|
||||||
|
(if (not field-width)
|
||||||
|
field-value
|
||||||
|
(setq field-width (string-to-number field-width))
|
||||||
|
(truncate-string-to-width
|
||||||
|
field-value
|
||||||
|
(if (> field-width 0)
|
||||||
|
field-width
|
||||||
|
(- width (cdr format)))
|
||||||
|
0 ?\s)))))))
|
||||||
|
|
||||||
(defun org-roam-node-preview (file point)
|
(defun org-roam-node-preview (file point)
|
||||||
"Get preview content for FILE at POINT."
|
"Get preview content for FILE at POINT."
|
||||||
(save-excursion
|
(save-excursion
|
||||||
@ -551,7 +583,9 @@ is the `org-roam-node'."
|
|||||||
:title title
|
:title title
|
||||||
:point pos
|
:point pos
|
||||||
:tags (gethash id tags-table))))
|
:tags (gethash id tags-table))))
|
||||||
(cons (propertize alias 'node node) node)))))
|
(cons (propertize alias
|
||||||
|
'node node
|
||||||
|
'display (org-roam-node--format-entry node (1- (frame-width)))) node)))))
|
||||||
|
|
||||||
(defun org-roam-node-read (&optional initial-input filter-fn require-match)
|
(defun org-roam-node-read (&optional initial-input filter-fn require-match)
|
||||||
"Read and return an `org-roam-node'.
|
"Read and return an `org-roam-node'.
|
||||||
|
Reference in New Issue
Block a user