mirror of
https://github.com/org-roam/org-roam
synced 2025-08-01 12:17:21 -05:00
(fix)completions: fix highlighting of formatted/truncated strings (#1895)
* (fix)org-roam-unlinked-references-section: Use truncate-string-ellipsis The variable can be set to a unicode ellipsis. * (fix)org-roam-node-read--format-entry: Fix highlighting for truncation Fix #1801. The truncated part of the string is made invisible. Matching on the whole string remains possible. * (fix)org-roam-format-template: Preserve string properties like format If the variable value carries properties itself, these properties take precedence. Display templates can be properties with this change. (setq org-roam-node-display-template (concat (propertize "${title:*}" 'face 'font-lock-keyword-face) " " (propertize "${tags:10}" 'face 'font-lock-constant-face)))
This commit is contained in:
@ -684,7 +684,7 @@ References from FILE are excluded."
|
|||||||
(oset section row row)
|
(oset section row row)
|
||||||
(oset section col col)
|
(oset section col col)
|
||||||
(insert (propertize (format "%s:%s:%s"
|
(insert (propertize (format "%s:%s:%s"
|
||||||
(truncate-string-to-width (file-name-base f) 15 nil nil "...")
|
(truncate-string-to-width (file-name-base f) 15 nil nil t)
|
||||||
row col) 'font-lock-face 'org-roam-dim)
|
row col) 'font-lock-face 'org-roam-dim)
|
||||||
" "
|
" "
|
||||||
(org-roam-fontify-like-in-org-mode
|
(org-roam-fontify-like-in-org-mode
|
||||||
|
@ -536,12 +536,20 @@ Uses `org-roam-node-display-template' to format the entry."
|
|||||||
;; empty string results in an empty string and misalignment for candidates that
|
;; empty string results in an empty string and misalignment for candidates that
|
||||||
;; don't have some field. This uses the actual display string, made of spaces
|
;; don't have some field. This uses the actual display string, made of spaces
|
||||||
;; when the field-value is "" so that we actually take up space.
|
;; when the field-value is "" so that we actually take up space.
|
||||||
(if (or (not field-width) (equal field-value ""))
|
(unless (or (not field-width) (equal field-value ""))
|
||||||
field-value
|
(let* ((truncated (truncate-string-to-width field-value field-width 0 ?\s))
|
||||||
;; Remove properties from the full candidate string, otherwise the display
|
(tlen (length truncated))
|
||||||
;; formatting with pre-propertized field-values gets messed up.
|
(len (length field-value)))
|
||||||
(let ((display-string (truncate-string-to-width field-value field-width 0 ?\s)))
|
(if (< tlen len)
|
||||||
(propertize (substring-no-properties field-value) 'display display-string))))))))
|
;; Make the truncated part of the string invisible. If strings
|
||||||
|
;; are pre-propertized with display or invisible properties, the
|
||||||
|
;; formatting may get messed up. Ideally, truncated strings are
|
||||||
|
;; not preformatted with these properties. Face properties are
|
||||||
|
;; allowed without restriction.
|
||||||
|
(put-text-property tlen len 'invisible t field-value)
|
||||||
|
;; If the string wasn't truncated, but padded, use this string instead.
|
||||||
|
(setq field-value truncated))))
|
||||||
|
field-value)))))
|
||||||
|
|
||||||
(defun org-roam-node-read--process-display-format (format)
|
(defun org-roam-node-read--process-display-format (format)
|
||||||
"Pre-calculate minimal widths needed by the FORMAT string."
|
"Pre-calculate minimal widths needed by the FORMAT string."
|
||||||
|
@ -127,7 +127,9 @@ value (possibly nil). Adapted from `s-format'."
|
|||||||
(let ((v (progn
|
(let ((v (progn
|
||||||
(set-match-data saved-match-data)
|
(set-match-data saved-match-data)
|
||||||
(funcall replacer var default-val))))
|
(funcall replacer var default-val))))
|
||||||
(if v (format "%s" v) (signal 'org-roam-format-resolve md)))
|
(if v
|
||||||
|
(format (apply #'propertize "%s" (text-properties-at 0 var)) v)
|
||||||
|
(signal 'org-roam-format-resolve md)))
|
||||||
(set-match-data replacer-match-data))))
|
(set-match-data replacer-match-data))))
|
||||||
(if (functionp template)
|
(if (functionp template)
|
||||||
(funcall template)
|
(funcall template)
|
||||||
|
Reference in New Issue
Block a user