minad / marginalia

:scroll: marginalia.el - Marginalia in the minibuffer
GNU General Public License v3.0
780 stars 27 forks source link

`marginalia-annotate-file` annotations wrap line on long paths #152

Closed gusbrs closed 1 year ago

gusbrs commented 1 year ago

When doing file completion and the path gets long enough to need a second line, the marginalia annotations are disrupted and also wrap lines. To reproduce:

Start with emacs -Q, do a minimal setup:

(add-to-list 'load-path "~/.emacs.d/elpa/vertico-1.0.0.20230115.42853")
(add-to-list 'load-path "~/.emacs.d/elpa/marginalia-1.0.0.20230115.42821")
(add-to-list 'load-path "~/.emacs.d/elpa/compat-29.1.1.1")
(require 'vertico)
(require 'marginalia)
(define-key minibuffer-local-map (kbd "M-A") 'marginalia-cycle)
(vertico-mode)
(marginalia-mode)

Start find-file, and navigate to a path deep enough that the prompt plus current completed path wraps the line. As an example, I get:

Screenshot from 2023-01-15 16-16-43

toggle-truncate-lines ("C-x x t") does not help here, marginalia-cycle does:

Screenshot from 2023-01-15 16-19-45

Probably related to https://github.com/minad/marginalia/issues/142 , but I tried line truncation with both toggle-truncate-lines and with:

(add-hook 'minibuffer-setup-hook
          (lambda () (setq truncate-lines t)))

With no change. Besides, if truncation affected the prompt line, I would no longer see what I'm completing.

(Running GNU Emacs 28.2 (build 2, x86_64-pc-linux-gnu, GTK+ Version 3.24.20, cairo version 1.16.0) of 2022-09-12, and the packages' versions loaded above).

minad commented 1 year ago

When doing file completion and the path gets long enough to need a second line, the marginalia annotations are disrupted and also wrap lines. To reproduce:

The behavior is as intended. The point is that the prompt should be visible completely (truncate-lines=nil). We sacrifice readability of the annotations.

Besides, if truncation affected the prompt line, I would no longer see what I'm completing.

Indeed. That's why.

See https://github.com/minad/vertico/blob/eba9e47947f2ea24c6b1c48b1c9475c220fc24a7/vertico.el#L549

gusbrs commented 1 year ago

Ok, thanks for taking a look.

But there's still something I don't understand, and perhaps I haven't chosen the best path example because the files inside the directory are also long. However, even if the file names are short, the annotation wrapping occurs, for example:

Screenshot from 2023-01-15 17-13-08

Is this because the annotations have been pushed to the right along the completion path? If that's the case, would it be possible to "reset" the annotations' padding every time we change directory level?

Edit: Indeed, if I start the completion from the test/ directory, the result is different:

Screenshot from 2023-01-15 17-20-02

minad commented 1 year ago

I don't know. I assume this has to do with the alignment (space display property pushes the annotation to the right). If you have an idea to improve this, please let me know (I mean concretely in the form of code).

Is this because the annotations have been pushed to the right along the completion path? If that's the case, would it be possible to "reset" the annotations' padding every time we change directory level?

EDIT: Indeed, that's the reason. Marginalia remembers the width of the candidates. EDIT2: Fixed in https://github.com/minad/marginalia/commit/98deaa8fad107c564b8ab9a5b13386d05f9415da.

gusbrs commented 1 year ago

I think my thought there would be interesting. For file name completion, whenever we change directories, we got a new set of candidates, so the padding of the annotations for the previous directory level is not really that relevant. I presume regularly marginalia doesn't "shrink" the annotations back along the completion session because it would be jarring. But in the case of file names and paths that would make sense. Don't you think? What I don't know is there's a way to know when we changed directory levels. Do you?

minad commented 1 year ago

@gusbrs Yes, it is trivial and already fixed.

gusbrs commented 1 year ago

Oh! You commit faster than I can comment back! :-) Thank you!