flyin1501 · 2022-05-15 17:09
After I updated to Emacs 28, the completions offered by `find-library` became quite cluttered. ".elc" files are now listed, even "README.md" files, or even "./":
https://i.imgur.com/jl8TWP5.png
This is also the case in `emacs -Q`:
https://i.imgur.com/pKeKqDS.png
I was able to remove the clutter after replacing a line in `locate-file-completion-table` ([files.el::L1007](https://git.savannah.gnu.org/cgit/emacs.git/tree/lisp/files.el?h=emacs-28#n1007)) with nil:
https://i.imgur.com/nmq2wOo.png
But I don't know if my change is just a hack or not, as the line was [added in 2010](https://git.savannah.gnu.org/cgit/emacs.git/commit/?id=118cf45490e054aa813300e101650021b63cbb93) and clearly did not have the same effect back then.
Why does `find-library` work like this in Emacs 28?
nv-elisp · 2022-05-15 18:27
Check etc/NEWS
Alan_Shutko · 2022-05-15 23:51
It looks like a new option was added, which defaults to true:
`find-library-include-other-files`
Set that to nil. It doesn't appear to be mentioned in the NEWS file.
kaushalmodi · 2022-05-16 02:31
This was added on the master branch few months back in https://git.savannah.gnu.org/cgit/emacs.git/commit/?id=eea93a8aaac30690c6e864f2556010d3b62f4eee. So this change will be available in Emacs 29.1 release (or if you build Emacs from master branch).
**Update**: .. but you can still get this feature on older Emacs version by porting the change from that commit.. like I just did [here in my Emacs config](https://github.com/kaushalmodi/.emacs.d/blob/7cb6c4286f5ec2a4cd0852f7d49a8ff1c28f98ae/setup-files/setup-search.el#L159-L218).
Thanks /u/Alan_Shutko for making me aware of `find-library-include-other-files` and Lars Ingebrigtsen for implementing this!
rswgnu · 2022-05-16 04:59
Why is the default true, as won't that make find-library return a different set of files than it did in prior Emacs versions, breaking any automated calls that rely on some pattern in the results?
organic-bookworm · 2022-05-16 06:03
The [NEWS](https://git.savannah.gnu.org/cgit/emacs.git/tree/etc/NEWS?id=1fc1d8b88994303ac7c1aac673cb3fead5ff4d9e#n319) actually says:
>The default is t, which preserves previous behavior, whereby non-library files could also be included.
flyin1501 · 2022-05-16 10:42
It only affects the completion in the prompt (`read-library-name`), so nothing changes if `find-library` is called from Lisp.
flyin1501 · 2022-05-16 17:59
I ended up [doing this](https://gitlab.com/kisaragi-hiu/.emacs.d/-/blob/a13f601aa3c1e8999d5d7d25673b30a1bfdf3638/.emacs.d/init.el#L1345):
(define-advice read-library-name (:around (func) exclude-irrelevant)
"Only show files matching value returned from `find-library-suffixes'."
(cl-letf* ((suffix (concat (regexp-opt (find-library-suffixes) t)
"\\'"))
(orig (symbol-function 'file-name-all-completions))
((symbol-function 'file-name-all-completions)
(lambda (file directory)
(--filter
(string-match suffix it)
(funcall orig file directory)))))
(funcall func)))
It's horrible (`letf`-ing a `symbol-function`), but it works... I'm looking forward to ditching this after Emacs 29 comes out.