Hongyi Zhao <[email protected]> writes:

> First, I'd like to express my immense appreciation for your incredible
> work on AUCTeX. It is an indispensable tool.

Thanks for your kind words.

> **The Problem:**
> In my setup, the standard automatic completion chain
> (`completion-at-point-functions`) is unreliable for file paths inside
> commands like `\include{./}` or `\addbibresource{./}`.

What is in this case unreliable?

> My extensive debugging suggests this is due to a "short-circuiting" effect:
> 1.  Higher-priority completion backends (like `lsp-mode` or
> `cape-dabbrev`) are triggered first.
> 2.  Even if they find no relevant candidates for a prefix like `./`,
> they seem to return a "successful but empty" result.
> 3.  This "successful" result prevents the completion chain from
> proceeding to lower-priority, more specialized backends like
> `completion-file-name-table`. The file completion backend is never
> given a chance to run.

You should try to assemble a minimal recipe how to reproduce this,
starting with "emacs -Q", and then report that as a bug to the relevant
developers.

> **My Questions:**
>
> While my solution is effective, I am keen to know if it is the optimal
> or most idiomatic approach.
>
> 1.  Is my analysis of the "short-circuit" problem in the automatic
> completion chain correct?

How can others tell without knowing your setup?  Again, the only way to
track this down is a reproduceable recipe, starting with "emacs -Q".

> 2.  Is this manual, key-bound command the recommended way to solve
> this problem within the AUCTeX ecosystem?
> 3.  Does AUCTeX perhaps have a built-in command, variable, or
> mechanism to handle this exact scenario, which I may have missed in
> the documentation?

No, AUCTeX simply adds 2 functions to `completion-at-point-functions',
so you're basically free to add or remove any function from it.

> 4.  Is there a more elegant way to configure
> `completion-at-point-functions` itself to grant file completion higher
> priority in these specific command-argument contexts?

This is my setup for the cape package:

(use-package cape
  :defer t
  :init
  (add-hook 'completion-at-point-functions #'cape-file 95)

  :custom
  (cape-file-prefix '("file:" "./" "../" "~/"))

  :bind (:map corfu-map
              ("C-c p f" . cape-file)))

Not sure if it is an elegant way, but it works for me.

Best, Arash

Reply via email to