Git Product home page Git Product logo

Comments (20)

minad avatar minad commented on August 17, 2024 2

You can use this advice https://github.com/minad/vertico/blob/buffer-display/buffer.el to get a display action as in Selectrum which I wrote as a prototype. But it is not upside down.


In case you really want it upside down you can reverse the candidates using nreverse. And then you have to remap the up down keys. You can try it out. I didn't really like it tbh.

(defun vertico--display-in-buffer (candidates)
  (let ((buffer (get-buffer-create (format " *vertico-%s*" (- (recursion-depth) 1)))))
    (with-current-buffer buffer
      (setq-local display-line-numbers nil
                  show-trailing-whitespace nil
                  inhibit-modification-hooks t)
      (erase-buffer)
      (insert (string-join (nreverse candidates))) ;; NOTE: Reverse the candidates!
      (goto-char (point-min)))
    (display-buffer buffer
                    `(display-buffer-in-side-window
                      (window-parameters (mode-line-format . none))
                      (window-height . ,vertico-count)
                      (side . bottom)
                      (slot . -1)))))

(advice-add #'vertico--display-candidates
            :override #'vertico--display-in-buffer)

(define-key vertico-map [up] #'vertico-next)
(define-key vertico-map [down] #'vertico-previous)

from vertico.

milkypostman avatar milkypostman commented on August 17, 2024 1

Follow up here.

I redid this and added some spacing. @grolongo

(use-package vertico
  :ensure
  :bind (:map vertico-map
	      ("C-n" . vertico-previous)
	      ("C-p" . vertico-next)
	      ([up] . vertico-next)
	      ([down] . vertico-previous))

  :init
  (defun vertico--display-in-buffer (candidates)
    (let ((buffer (get-buffer-create (format " *vertico-%s*" (- (recursion-depth) 1))))
	  (fill-rows (max 0 (- vertico-count (length candidates)))))
      (with-current-buffer buffer
	(setq-local display-line-numbers nil
		    show-trailing-whitespace nil
		    inhibit-modification-hooks t)
	(erase-buffer)
	(insert (apply #'concat (make-list fill-rows "\n")))
	(insert (string-join (nreverse candidates))) ;; NOTE: Reverse the candidates!
	(goto-char (point-min)))
      (display-buffer buffer
		      `(display-buffer-in-side-window
			(window-parameters (mode-line-format . none))
			(window-height . ,vertico-count)
			(side . bottom)
			(slot . -1)))))

  (advice-add #'vertico--display-candidates
	      :override #'vertico--display-in-buffer))

This actually looks really nice.

@minad is there a way to customize the indentation besides modifying this function more? also, I'd like to change the formatting of the currently selected item (maybe prefix with >). But so far, it's working well.

from vertico.

grolongo avatar grolongo commented on August 17, 2024

Hey that works fine thanks!

Is there a way to automatically resize the buffer so there is no gap between the results and prompt? Maybe I'm wrong but is it because for the reverse display we're using a custom buffer while by default we're using the minibuffer, therefore (setq resize-mini-windows t) doesn't apply anymore?

verticotest

from vertico.

minad avatar minad commented on August 17, 2024

Is there a way to automatically resize the buffer so there is no gap between the results and prompt? Maybe I'm wrong but is it because for the reverse display we're using a custom buffer while by default we're using the minibuffer, therefore (setq resize-mini-windows t) doesn't apply anymore?

Yes, you may want to add your own resizing code to the function vertico--display-in-buffer.

I close this issue since I don't have an intention to add this functionality to the package itself as of now. In case you want more ootb configurability/functionality, there is also Selectrum as you are aware.

from vertico.

minad avatar minad commented on August 17, 2024

There is currently no possibility to modify the formatting of the candidates. You could do it in this display function or advise vertico--format-candidates.

I could split vertico--format-candidates and introduce some helper functions which could be advised additionally to affect the formatting of individual candidates.

from vertico.

minad avatar minad commented on August 17, 2024

@milkypostman I split up vertico--format-candidates a little bit, you can do this now:

(advice-add #'vertico--format-candidate :around
            (lambda (orig cand prefix suffix index)
              (setq cand (funcall orig cand prefix suffix index))
              (concat
               (if (= vertico--index index)
                   (propertize "> " 'face 'vertico-current)
                 "  ")
               cand)))

Note that using advices for these individual adjustments can be a bit brittle. I am not making guarantees that these internals won't change at some point. But Vertico is simple enough, such that it should be no big deal to follow potential changes.

from vertico.

milkypostman avatar milkypostman commented on August 17, 2024

yeah advice is whatever. this is pretty great though thank you!

from vertico.

grolongo avatar grolongo commented on August 17, 2024

This is great! Thank you for this.

Something I noticed, how could I disable the cursor in the candidates buffer? It doesn't show up by default (without using the function). You can see what I'm talking about in the screenshot I posted above (cursor is top left over vertico-exit-input).

from vertico.

minad avatar minad commented on August 17, 2024

Something I noticed, how could I disable the cursor in the candidates buffer? It doesn't show up by default (without using the function). You can see what I'm talking about in the screenshot I posted above (cursor is top left over vertico-exit-input).

You can adjust cursor-in-non-selected-window. Another alternative one may want to consider is to show the candidates in an overlay above the prompt instead of an additional buffer. I will try this, maybe this is even easier than the solution given here.

from vertico.

grolongo avatar grolongo commented on August 17, 2024

I figured it out by adding cursor-in-non-selected-windows to nil in the setq-local list of variables.

Maybe you have this set globally so you don't have to do this.

edit: thanks minad looks like we were answering at the same time :)

from vertico.

minad avatar minad commented on August 17, 2024

See https://github.com/minad/vertico/wiki#show-candidates-in-an-overlay-above-the-prompt for a solution which uses the overlay instead of a separate buffer. You may prefer this since it is more lightweight and since it does not introduce the cursor issue. This is probably also interesting for @milkypostman.

from vertico.

milkypostman avatar milkypostman commented on August 17, 2024

wow this is amazing.

To put them at the bottom of the overlay.

  (defun vertico--display-above-prompt (lines)
      (move-overlay vertico--candidates-ov (point-min) (point-min))
      (overlay-put vertico--candidates-ov 'before-string
		   (concat (make-string (- vertico-count (length lines)) ?\n)
			   (apply #'concat (nreverse lines))))
      (vertico--resize-window (length lines)))

from vertico.

grolongo avatar grolongo commented on August 17, 2024

@minad maybe I'm wrong but shouldn't the new variable vertico-resize you introduced work for both @milkypostman's vertico--display-in-buffer function and your overlay solution too?

Or does vertico-resize only act on the *Completions* buffer when used with vertico like resize-mini-windows do by default?

from vertico.

minad avatar minad commented on August 17, 2024

vertico-resize works only for the minibuffer/overlay. vertico--display-in-buffer is not taking the variable into account, but you can add this of course.

from vertico.

milkypostman avatar milkypostman commented on August 17, 2024

@grolongo to clarify the previous comments, the height of the buffer generated by my code is specified in the call to display-buffer where the line used is (window-height . ,vertico-count).

from vertico.

minad avatar minad commented on August 17, 2024

I decided to add Vertico extensions to the repository: These are small packages, which extend Vertico but which are not part of the opinionated main package. I won't use these extensions but I feel more comfortable maintaining them as part of the repository in contrast to the wiki.

See https://github.com/minad/vertico/blob/main/extensions/vertico-reverse.el which offers the vertico-reverse-mode.

from vertico.

milkypostman avatar milkypostman commented on August 17, 2024

very cool. thanks for that!

I agree it's probably better to have some story about this. I think the extensions are nice.

from vertico.

minad avatar minad commented on August 17, 2024

Yes, I think extensions fit the spirit very well here, since these allow you to plug together your own completion system and the core is kept simple. One of the main ideas of Vertico/Consult/Marginalia/Orderless/Embark/... is that you have these pluggable components.

from vertico.

grolongo avatar grolongo commented on August 17, 2024

Compartmentalized and organized, that's very good.
Also great for discoverability, I didn't know about the other options.
Is the ido extension for vertico similar to fido-mode for icomplete?

from vertico.

minad avatar minad commented on August 17, 2024

@grolongo No, vertico-directory (as it is now called) only provides better directory navigation commands. But there are also other extensions which give you a more ido-like look (e.g. vertico-flat).

from vertico.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.