branch: externals/marginalia commit 4ba98045dd33bcf1396a888dbbae2dc801dce7c5 Author: Omar AntolÃn Camarena <omar.anto...@gmail.com> Commit: Omar AntolÃn Camarena <omar.anto...@gmail.com>
Fix bug: file annotations were only shown for current directory The file annotations where only being displayed for files in the current directory. This was because the candidates in file completion are not the full path, but rather just the last path component. The function file-attributes wants either a full path or a path relative to the current directory. To fix this bug I added a general function to calculate the "full candidate", i.e, what the minibuffer contents would be if a given candidate is chosen. For most types of completion, the completion candidates are already full candidates. The main exception is file name completion, where the candidates are one path component of the full candidate, which is a full path. (There are other exceptions, such as environment variable name completion inside file name completion.) --- marginalia.el | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/marginalia.el b/marginalia.el index 9ae5354..862867a 100644 --- a/marginalia.el +++ b/marginalia.el @@ -262,9 +262,29 @@ determine it." "") marginalia-file-name-width)))) +(defun marginalia--full-candidate (cand) + "Return completion candidate CAND in full. +For some completion tables, the completion candidates offered are +meant to be only a part of the full minibuffer contents. For +example, during file name completion the candidates are one path +component of a full file path. + +This function returns what would be the minibuffer contents after +using `minibuffer-force-complete' on the candidate CAND." + (let* ((contents (minibuffer-contents)) + (pt (- (point) (minibuffer-prompt-end))) + (bounds (completion-boundaries + (substring contents 0 pt) + minibuffer-completion-table + minibuffer-completion-predicate + (substring contents pt)))) + (concat (substring contents 0 (car bounds)) + cand + (substring contents (+ pt (cdr bounds)))))) + (defun marginalia-annotate-file (cand) "Annotate file CAND with its size and modification time." - (when-let (attributes (file-attributes cand)) + (when-let ((attributes (file-attributes (marginalia--full-candidate cand)))) (concat (marginalia--align 7 ;; size marginalia-separator-width