In latex-mode when I use TeX-insert-macro to type a \input{...} macro, Auctex conveniently offers filename completion, which is great. However, it seems to search a lot of places to compile the completion list, because emacs hangs for almost a minute on my poor little laptop.

Is there a way for TeX-insert-macro to offer dumb filename completion?
By "dumb", I mean the one you get when calling find-file. Most of the time the file I want to input is just one directory away, so that would be more than fine.

If that's not possible, is there another way to speed it up?
I noticed when I insert the \include macro the list of filenames is much shorter, so maybe there's a way to use that list for the \input macro as well.

  • There is also cdlatex-insert-filename which comes with cdlatex package. I find it helpful for inserting graphic files into figure environments. – Vamsi Sep 26 '14 at 0:39

You have a few solutions:

First, there is a variable customizing this behavior: TeX-arg-input-file-search.

If TeX-arg-input-file should search for files. If the value is t, files in TeX's search path are searched for and provided for completion. The file name is then inserted without directory and extension. If the value is nil, the file name can be specified manually and is inserted with a path relative to the directory of the current buffer's file and with extension. If the value is ask, you are asked for the method to use every time TeX-arg-input-file is called.

This piece of documentation is, imho, quite not clear enough, but setting it to nil seems to do the job.

(setq TeX-arg-input-file-search nil)

This variable affects all functions that call TeX-arg-input-file, including input, include and usepackage. For the latter, this behavior may be unexpected.

Then there is a more hacky solution which should work for all functions: TeX-arg-input-file features a local flag for this behavior (this flag is for example set to t for include).

Apparently, you can override any other setting by just adding another entry for the command, so:

(add-hook 'LaTeX-mode-hook 
  (lambda nil 
     (TeX-add-symbols '("input" (TeX-arg-input-file "File" t)))))

A last solution, if you have long-lasting emacs sessions, is to simply let it go. It seems that the "searching files" phase caches its results, so it should be called only once per session.

| improve this answer | |
  • Awesome! I was expecting a bit of a hack, guess I underestimated auctex. – Malabarba Sep 25 '14 at 10:06
  • 1
    Hmpf, it seems that hack was indeed the way to go, see my edit. If the hacky solution suits your needs better, please tell me so that I can rearrange the answer. – T. Verron Sep 25 '14 at 11:41
  • 1
    You're right, for usepackage that would be undesirable. Thanks for the update. It does indeed cache the results, but a delay of ~1min is enough to bother me even if it is only once per buffer. – Malabarba Sep 25 '14 at 13:11
  • 1
    I rearranged the content. Looking at the code again, I was wrong, TeX-global-input-files (the variable containing the result of the search) is not buffer-local, so the search should happen only once per emacs session. Maybe this would be more interesting if it could happen asyncronously, though, a freeze of ~1min is indeed too long. – T. Verron Sep 25 '14 at 13:18

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.