radian-software / selectrum

🔔 Better solution for incremental narrowing in Emacs.
MIT License
739 stars 33 forks source link

Is it possible to enable cycling? #570

Closed alexei-28 closed 2 years ago

alexei-28 commented 3 years ago

Linux Mint 20.2

Emacs 27.2

Install package spectrum.

Is it possible to enable cycling for selectrum-next-candidate' andselectrum-previous-candidate'? E.g when press arrow down on last candidate then start from begining on the list of candidate?

iyefrat commented 3 years ago

No, but vertico supports this feature through vertico-cycle if you're interested in it.

alexei-28 commented 3 years ago

No, but vertico supports this feature through vertico-cycle if you're interested in it.

I was on vertico but I prefer selectrum.

iyefrat commented 3 years ago

Just wondering, what do you prefer about it?

alexei-28 commented 3 years ago

Just wondering, what do you prefer about it?

https://www.youtube.com/watch?v=Af6ymyKyN4o

TikhonJelvis commented 3 years ago

Looks like there's no built-in way, but you could override the selectrum-next-candidate function to wrap instead of clamping.

Feels like a bit of a hack, but worked fine when I tested it locally.


  (defun selectrum--wrap (x lower upper)
    (cond ((< x lower) upper)
          ((> x upper) lower)
          ('t x)))

  (defun selectrum-next-candidate (&optional arg)
    "Move selection ARG candidates down, stopping at the end."
    (interactive "p")
    (when selectrum--current-candidate-index
      (setq selectrum--current-candidate-index
            (selectrum--wrap
             (+ selectrum--current-candidate-index (or arg 1))
             (if (and (selectrum--match-strictly-required-p)
                      (cond (minibuffer-completing-file-name
                             (not (selectrum--at-existing-prompt-path-p)))
                            (t
                             (not (string-empty-p selectrum--virtual-input)))))
                 0
               -1)
             (1- (length selectrum--refined-candidates))))))
okamsn commented 2 years ago

Please test whether PR #588 works for you.