Selectrum: Honor completion-ignored-extensions

Created on 10 Aug 2020  路  5Comments  路  Source: raxod502/selectrum

With default completion, files ending with extensions listed in completion-ignored-extensions are not shown unless they are the only results. Maybe we could port this concept and also extend it by using a similar feature as used by selectrum-read-buffer which shows hidden buffers by typing a leading space. There could also be a user option to hide dotfiles by default as well. Maybe we could also have a command which allows to toggle file hiding.

Most helpful comment

Just a ping, I'd like to see selectrum honor completion-ignored-extensions

All 5 comments

This might work well, but we have to be a bit careful. For example, with this feature then .git would be hidden by default, and it might be very surprising because with Selectrum you expect to actually see all the files at once. I wonder if there is an elegant and performant way to force certain candidates to be sorted at the end? If so, perhaps that would be a better solution. Then again, if you actually navigate into .git, we probably want to sort it first when using selectrum-prescient.el. I do not know if there is a good compromise.

the following hack lets selectrum honor completion-ignored-extensions for the time being:

(defun my-filename-good-p (fn)
  "check if given filename FN is good for completion reads (and should not be ignored
according to `completion-ignored-extensions')."
  (not (seq-contains-p completion-ignored-extensions (file-name-extension fn t))))

(defun my-advice-selectrum-read-file-name (oldfun
                       prompt &optional dir default-filename mustmatch initial predicate)
  "advice making `selectrum-read-file-name' honoring `completion-ignored-extensions'."
  (let* ((predicate-new (if predicate
                (lambda (fn) (and (funcall predicate fn)
                          (my-filename-good-p fn)))
              #'my-filename-good-p)))
    (funcall oldfun prompt dir default-filename mustmatch initial predicate-new)))

  (advice-add #'selectrum-read-file-name :around
          #'my-advice-selectrum-read-file-name)

edit: fixed a bug in line 10.

Thanks, note that adjusting the predicate can slow down file completions significantly for tramp and slow file systems, see #335

I think a combination of what @ddugue proposed and the ideas mentioned above could work to incorporate completion-ignored-extensions into Selectrum, to summarize the ideas so far:

  • With a leading space after a / show only the ignored files
  • When you have input that matches ignored files they should be included
  • When your input don't matches ignored files keep them hidden from view
  • Always show the ignored files but sort them last

Just a ping, I'd like to see selectrum honor completion-ignored-extensions

Was this page helpful?
0 / 5 - 0 ratings

Related issues

piranha picture piranha  路  7Comments

angrybacon picture angrybacon  路  10Comments

adrianparvino picture adrianparvino  路  4Comments

Compro-Prasad picture Compro-Prasad  路  7Comments

ashton314 picture ashton314  路  12Comments