radian-software / selectrum

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

Previous / Next group navigation for multi-sources #554

Closed inigoserna closed 2 years ago

inigoserna commented 3 years ago

Regarding my comment on https://github.com/minad/consult/issues/6#issuecomment-848589198 and https://github.com/minad/vertico/issues/47#issue-902529172

What do you think about adding this feature?

(defun completion--metadata-group-name (cand)
  (let* ((metadata (completion-metadata (minibuffer-contents)
                                        minibuffer-completion-table
                                        minibuffer-completion-predicate))
         (groupfun (completion-metadata-get metadata 'group-function)))
    (when groupfun
      (funcall groupfun cand nil))))

(defun selectrum-next-group ()
  (interactive)
  (let ((group (completion--metadata-group-name (selectrum-get-current-candidate)))
        (total (length (selectrum-get-current-candidates)))
        (loop t))
    (while (and group loop)
      (if (= selectrum--current-candidate-index (1- total))
          (progn
            (selectrum-goto-beginning)
            (setq loop nil))
        (selectrum-next-candidate)
        (unless (string= group (completion--metadata-group-name (selectrum-get-current-candidate)))
          (setq loop nil))))))

(defun selectrum-previous-group ()
  (interactive)
  (let ((group (completion--metadata-group-name (selectrum-get-current-candidate)))
        (loop t))
    (while (and group loop)
      (if (zerop selectrum--current-candidate-index)
          (progn
            (selectrum-goto-end)
            (setq loop nil))
        (selectrum-previous-candidate)
        (unless (string= group (completion--metadata-group-name (selectrum-get-current-candidate)))
          (setq loop nil))))))

(define-key selectrum-minibuffer-map [remap backward-paragraph] 'selectrum-previous-group)
(define-key selectrum-minibuffer-map [remap forward-paragraph]  'selectrum-next-group)
isamert commented 2 years ago

I was quite surprised when I found out that selectrum did not have default keybindings or even the commands for this functionality. Just wanted to give a friendly nudge on this issue @raxod502.

raxod502 commented 2 years ago

I'm not familiar with the primary maintainers' development roadmap but I am guessing that there aren't any objections to the feature, but it just hasn't been gotten to yet.

okamsn commented 2 years ago

Please check whether PR #588 works for you.

inigoserna commented 2 years ago

Sorry, I don't use selectrum nowdays.

okamsn commented 2 years ago

That's fine. I'll just close this issue when I merge the PR.