Selectrum: Insert dirs, select files

Created on 23 Oct 2020  路  2Comments  路  Source: raxod502/selectrum

Is it possible to customize the selection behavior (for find-file minibuffer): it should be the inserting for directories but the ordinary selection for files?

Most helpful comment

It is but currently there is currently no straightforward way, see also #178. For now you could use the following (only tested it shortly, please test):

(add-hook 'minibuffer-setup-hook
          (defun selectrum-setup+ ()
            (when (and selectrum-active-p
                       minibuffer-completing-file-name)
              (let ((map (copy-keymap (current-local-map))))
                (define-key map (kbd "RET") 'selectrum-select-current-candidate+)
                (use-local-map map)))))

(defun selectrum-select-current-candidate+ (&optional arg)
  (interactive "P")
  (let* ((index (selectrum--index-for-arg arg))
         (candidate (selectrum--get-candidate index))
         (path (selectrum--get-full candidate)))
    (call-interactively
     (if (file-directory-p path)
         'selectrum-insert-current-candidate
       'selectrum-select-current-candidate))))

All 2 comments

It is but currently there is currently no straightforward way, see also #178. For now you could use the following (only tested it shortly, please test):

(add-hook 'minibuffer-setup-hook
          (defun selectrum-setup+ ()
            (when (and selectrum-active-p
                       minibuffer-completing-file-name)
              (let ((map (copy-keymap (current-local-map))))
                (define-key map (kbd "RET") 'selectrum-select-current-candidate+)
                (use-local-map map)))))

(defun selectrum-select-current-candidate+ (&optional arg)
  (interactive "P")
  (let* ((index (selectrum--index-for-arg arg))
         (candidate (selectrum--get-candidate index))
         (path (selectrum--get-full candidate)))
    (call-interactively
     (if (file-directory-p path)
         'selectrum-insert-current-candidate
       'selectrum-select-current-candidate))))

It seems to work, thank you!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mohkale picture mohkale  路  11Comments

clemera picture clemera  路  5Comments

Vurp picture Vurp  路  4Comments

Compro-Prasad picture Compro-Prasad  路  7Comments

Luis-Henriquez-Perez picture Luis-Henriquez-Perez  路  11Comments