1

Is it possible to make load-library's TAB completion to ignore backup files (.el~)?

1

The function load-library is just a few lines long. If we type M-x find-function RET load-library RET we see that the variable completion-ignored-extensions is let-bound to nil. Therefore, a new function would be needed that either sets completion-ignored-extensions on a let-bound basis to the desired value(s) or eliminates the variable entirely from the function so its default values will shine through. Instead of creating a function with a new name such as load-library-one or load-library-two, it is possible to use the same name (i.e., load-library) to replace the prior function with the newly defined function. Or, use defalias if so desired.

For more information on the variable completion-ignored-extensions, type M-x describe-variable or C-h v.

Permit the default value of completion-ignored-extensions to shine through:

(defun load-library-one (library)
  "Load the Emacs Lisp library named LIBRARY.
LIBRARY should be a string.
This is an interface to the function `load'.  LIBRARY is searched
for in `load-path', both with and without `load-suffixes' (as
well as `load-file-rep-suffixes').

See Info node `(emacs)Lisp Libraries' for more details.
See `load-file' for a different interface to `load'."
  (interactive
     (list (completing-read "Load library: "
                            (apply-partially 'locate-file-completion-table
                                             load-path
                                             (get-load-suffixes)))))
  (load library))

Let-bind the value of completion-ignored-extensions to something specific:

(defun load-library-two (library)
  "Load the Emacs Lisp library named LIBRARY.
LIBRARY should be a string.
This is an interface to the function `load'.  LIBRARY is searched
for in `load-path', both with and without `load-suffixes' (as
well as `load-file-rep-suffixes').

See Info node `(emacs)Lisp Libraries' for more details.
See `load-file' for a different interface to `load'."
  (interactive
   (let ((completion-ignored-extensions '(".o" "~")))
     (list (completing-read "Load library: "
                            (apply-partially 'locate-file-completion-table
                                             load-path
                                             (get-load-suffixes))))))
  (load library))
3
  • The default value of completion-ignored-extensions includes ".elc", so both of your examples will ignore compiled libraries. This is probably not what you want to do for load-library, and I expect that may be why the original function ignored completion-ignored-extensions in the first place.
    – Tyler
    May 14 '18 at 16:32
  • @Tyler -- It was just an arbitrary list (based on the default value) that I shortened for purposes of creating a short example so the O.P. can see how to customize the variable on a let-bound basis. I have now shortened the list some more and removed the ".elc".
    – lawlist
    May 14 '18 at 16:45
  • Understood! I was half-way through a similar answer when I realized this, and gave it up as being too involved to deal with properly in the time available. I suspect this is a bug
    – Tyler
    May 14 '18 at 17:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.