selectrum icon indicating copy to clipboard operation
selectrum copied to clipboard

Honor completion-ignored-extensions

Open clemera opened this issue 5 years ago โ€ข 7 comments

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.

clemera avatar Aug 10 '20 10:08 clemera

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.

raxod502 avatar Aug 14 '20 14:08 raxod502

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.

lsth avatar Jan 11 '21 15:01 lsth

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

clemera avatar Jan 11 '21 16:01 clemera

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

clemera avatar Jan 13 '21 18:01 clemera

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

hmelman avatar Jun 08 '21 13:06 hmelman

+1 for this issue. Some compilers produce a lot of intermediate files (eg coqc produces 5), leading to an overwhelming amount of clutter. I'll be using the above advice for now, I can always get to my ignored files via dired if I really need to.

"Always showing ignored files but sorting them last" will cause the files to show up in, for instance, embark collections. Sounds like a bad idea to me. Likewise, showing them as soon as the input matches will be a nuisance: you type "o" and now your completion list is full of .o files. A manual toggle could be user friendly enough, showing ignored files only when there are no other matches also sounds okay. Just my 2ยข.

haselwarter avatar Aug 27 '21 16:08 haselwarter

showing them as soon as the input matches will be a nuisance: you type "o" and now your completion list is full of .o files.

agreed. The way default emacs does it is you only get to see ignored files if the only matches are all in the ignored list (e.g. if you ignore .bin and you filter by .bin$ then you get to see them)

unhammer avatar Jun 20 '22 11:06 unhammer