[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/marginalia 06ae3b4 204/241: Some minor improvements on
From: |
Stefan Monnier |
Subject: |
[elpa] externals/marginalia 06ae3b4 204/241: Some minor improvements on the fix |
Date: |
Fri, 28 May 2021 20:49:27 -0400 (EDT) |
branch: externals/marginalia
commit 06ae3b4c466801962b7611c851e62bf0c749fbbf
Author: Omar AntolĂn <omar.antolin@gmail.com>
Commit: Daniel Mendler <mail@daniel-mendler.de>
Some minor improvements on the fix
1. Use expand-file-name to deal with the case where the user deletes
the initial / or ~/ and the minibuffer therefore contains only a
relative path.
2. Call completion-boundaries not on the entire minibuffer-contents,
but only the part before point, specifying the part after point as a
suffix. This is to get the correct count of components to replace when
the user is completing a component that is not the last one.
---
marginalia.el | 55 +++++++++++++++++++++++++++++--------------------------
1 file changed, 29 insertions(+), 26 deletions(-)
diff --git a/marginalia.el b/marginalia.el
index d815dc8..ffc68b2 100644
--- a/marginalia.el
+++ b/marginalia.el
@@ -635,39 +635,42 @@ The string is transformed according to
`marginalia-bookmark-type-transformers'."
:truncate (/ marginalia-truncate-width 2)
:face 'marginalia-file-name))))
-;; At some point we might want to revisit how this function is implemented.
Maybe we come up with a
-;; more direct way to implement it. While Emacs does not use the notion of
"full candidate", there
-;; is a function `completion-boundaries' to compute them, and in (info
"(elisp)Programmed
-;; Completion") it is documented how a completion table should respond to
boundaries requests.
-;; See the discussion at
https://github.com/minad/marginalia/commit/4ba98045dd33bcf1396a888dbbae2dc801dce7c5
-(defun marginalia--full-file (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."
+;; This function is only used for file candidates and is necessary
+;; because otherwise file-attributes won't find the file. It is
+;; complicated by the partial-completion completion style, which can
+;; complete /u/s/d/w to /usr/share/dict/words. This means that we need
+;; to replace some of the path components in the minibuffer contents
+;; with those from the completion candidate.
+(defun marginalia--full-file (file)
+ "Return full path to completion candidate FILE."
(if-let (win (active-minibuffer-window))
(with-current-buffer (window-buffer win)
(let* ((contents (minibuffer-contents-no-properties))
+ (pt (- (point) (minibuffer-prompt-end)))
+ (before (substring contents 0 pt))
+ (after (substring contents pt))
(bounds (completion-boundaries
- contents
+ before
minibuffer-completion-table
minibuffer-completion-predicate
- ""))
- (components (split-string (substring contents 0 (car bounds))
"/")))
- (string-join (append
- (cl-subseq components 0 (max 0
- (- (length components)
- (if (string-suffix-p
"/" cand)
- (cl-count ?/ cand)
- (1+ (cl-count ?/
cand))))))
- (list cand)) "/")))
- ;; no minibuffer is active, trust that cand already conveys all
+ after))
+ (components (split-string (substring before 0 (car bounds))
"/"))
+ (num-replace (if (string-suffix-p "/" file)
+ (cl-count ?/ file)
+ (1+ (cl-count ?/ file))) ))
+ ;; use expand-file-name in case path is relative, to get the
+ ;; correct default-directory from the minibuffer (normally,
+ ;; say for find-file, the path is only relative if the user
+ ;; deletes the initial / or ~/)
+ (expand-file-name
+ (string-join
+ (append
+ (cl-subseq components 0 (max 0 (- (length components)
num-replace)))
+ (list file))
+ "/"))))
+ ;; no minibuffer is active, trust that FILE already conveys all
;; necessary information (there's not much else we can do)
- cand))
+ file))
(defun marginalia--remote-p (path)
"Return t if PATH is a remote path."
- [elpa] externals/marginalia 1077dba 123/241: update comment, (continued)
- [elpa] externals/marginalia 1077dba 123/241: update comment, Stefan Monnier, 2021/05/28
- [elpa] externals/marginalia 54a61c7 137/241: update marginalia comment, Stefan Monnier, 2021/05/28
- [elpa] externals/marginalia 35a42dc 142/241: improve buffer directory annotation, Stefan Monnier, 2021/05/28
- [elpa] externals/marginalia 909b731 160/241: fix #42 - wrapping/alignment problem at the right margin, Stefan Monnier, 2021/05/28
- [elpa] externals/marginalia c5e89cf 168/241: describe-symbol: add indicator for obsolete variables/functions, Stefan Monnier, 2021/05/28
- [elpa] externals/marginalia d489f4c 171/241: fix #55, use string-width instead of length for alignment, Stefan Monnier, 2021/05/28
- [elpa] externals/marginalia 7a0c2c6 173/241: marginalia-cycle: remove minibuffer local behavior, Stefan Monnier, 2021/05/28
- [elpa] externals/marginalia 86c0461 180/241: consult-multi annotator should delegate to original annotation function, Stefan Monnier, 2021/05/28
- [elpa] externals/marginalia 2f977a1 181/241: readme: add illustration, Stefan Monnier, 2021/05/28
- [elpa] externals/marginalia e741b24 194/241: Version 0.4, Stefan Monnier, 2021/05/28
- [elpa] externals/marginalia 06ae3b4 204/241: Some minor improvements on the fix,
Stefan Monnier <=
- [elpa] externals/marginalia a8e73d9 198/241: Fix overly wide docstring warning, Stefan Monnier, 2021/05/28
- [elpa] externals/marginalia 5126ba6 223/241: Version 0.5, Stefan Monnier, 2021/05/28
- [elpa] externals/marginalia 9389f38 217/241: completion-all-completions: Last cdr can also be nil, Stefan Monnier, 2021/05/28
- [elpa] externals/marginalia 287a369 221/241: Use more strict definition of the affixation function., Stefan Monnier, 2021/05/28
- [elpa] externals/marginalia d1b836d 225/241: Go back to obsolete function project-roots, Stefan Monnier, 2021/05/28
- [elpa] externals/marginalia 0c24618 233/241: marginalia-bookmark-type-transformers: Use more precise type, Stefan Monnier, 2021/05/28
- [elpa] externals/marginalia 43c85dc 229/241: README: More documentation, Stefan Monnier, 2021/05/28
- [elpa] externals/marginalia d400032 228/241: README: Document lightweight annotator usage, Stefan Monnier, 2021/05/28
- [elpa] externals/marginalia 529aee6 241/241: Require subr-x only at compile time, Stefan Monnier, 2021/05/28