radian-software / selectrum

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

Quick keys by default #574

Closed agenbite closed 2 years ago

agenbite commented 3 years ago

Is there a way to have quick keys shown by default? I've seen that I can activate selectrum-show-indices in order to see numbers, but it'd be great to be able to have quick keys instead...

Thanks for the great work!!

okamsn commented 2 years ago

selectrum-show-indices can be a function that returns a string to show.

(setq selectrum-show-indices
      (lambda (i) ; From 1.
        (format "%c " (nth (1- i) selectrum-quick-keys))))

To always have bindings available (instead of needing to activate the quick keys), you can do something like

(require 'seq)
(defvar selectrum-minibuffer-map)
(defvar selectrum-quick-keys)
(with-eval-after-load 'selectrum 
  (seq-do-indexed (lambda (char idx)
                    (define-key selectrum-minibuffer-map
                      (kbd (format "C-M-%c" char))
                      `(lambda ()
                         (interactive)
                         ;; First candidate is item 1.
                         ;; User input is item 0.
                         (selectrum-select-current-candidate ,(1+ idx)))))
                  selectrum-quick-keys))

Does this answer your question?

agenbite commented 2 years ago

Works like a charm. Thanks!!