>> I can't remember a specific change in this area, but that's doesn't
>> really surprise me because the behavior of
>> `LaTeX--arguments-completion-at-point` is rather odd/cornercase in this
>> regard,
> Can you please elaborate why or what is rather odd/cornercase?
Because as you fill a completion, the text considered as the
"to-be-completed" area jumps around.
The design of CAPF is that the function returns 2 things: the text area
where completion takes place and the completion-table holding the set
of candidates. You currently have 2 competing notions of "the area to
be completed" in `\setlength{\FOO}`: one says that `\FOO` is the area to
be completed as an arg of `\setlength` and the other says that `FOO` is
the area to be completed as a backslashed command name.
Pick one, i.e. either never complete arguments of `\setlength` or never
complete the argument of `\setlength` as a backslashed command name.
As long as you sometimes use one sometimes the other, some UI out there
will get confused.
> I think the issue is the value of `completion-at-point-functions' in
> LaTeX-mode:
>
> (TeX--completion-at-point t LaTeX--arguments-completion-at-point
> ispell-completion-at-point)
That might make things worse, indeed, but even if you swap the two
(which does sound like a good idea, BTW), you'll still see
similar problems because `LaTeX--arguments-completion-at-point` also
returns different boundaries for `\setlength{\ba}`.
See below my quick attempt at tracking down the problem.
Stefan
diff --git a/latex.el b/latex.el
index 9973c1a483..5daa2ca073 100644
--- a/latex.el
+++ b/latex.el
@@ -7859,11 +7859,12 @@ COLLECTION is an list of strings."
(LaTeX-completion-macro-delimiters))
(up-list -1))
(forward-char)
+ ;; FIXME: When completing the arg of \setlength{\ba}, this skips
+ ;; the backslash which is wrong because the COLLECTION is a set of
lengths
+ ;; each one of them starting with a backslash.
(skip-chars-forward "^a-zA-Z0-9" end)
(setq beg (point)))
- (list beg end (completion-table-dynamic
- (lambda (_)
- collection)))))
+ (list beg end collection)))
(defun LaTeX-completion-documentclass-usepackage (entry)
"Return completion candidates for \\usepackage and \\documentclass arguments.
@@ -8163,11 +8164,16 @@ taken."
(defun LaTeX--arguments-completion-at-point ()
"Capf for arguments of LaTeX macros and environments.
Completion for macros starting with `\\' is provided by the
-function `TeX--completion-at-point' which should come first in
+function `TeX--completion-at-point' which should come later in
`completion-at-point-functions'."
;; Exit if not inside an argument or in a comment:
(when (and (LaTeX-completion-find-argument-boundaries)
(not (nth 4 (syntax-ppss))))
+ ;; FIXME: AFAICT, `LaTeX-what-macro` already has to do a lot of the parsing
+ ;; needed to know the boundaries we should return. But it doesn't
+ ;; return the info, so we end up re-computing it in places
+ ;; like `LaTeX-completion-candidates-completing-read` where we don't
+ ;; know any more what it is we're parsing so we risk doing it incorrectly.
(let ((entry (LaTeX-what-macro)))
(cond ((and entry
(member (car entry) '("usepackage" "RequirePackage"
@@ -8539,10 +8545,9 @@ function would return non-nil and `(match-string 1)'
would return
;; Moved after `run-mode-hooks'. (bug#65750)
;; (LaTeX-indent-commands-regexp-make)
- ;; Standard Emacs completion-at-point support. We append the entry
- ;; in order to let `TeX--completion-at-point' be first in the list:
+ ;; Standard Emacs completion-at-point support.
(add-hook 'completion-at-point-functions
- #'LaTeX--arguments-completion-at-point 5 t)
+ #'LaTeX--arguments-completion-at-point nil t)
(setq-local LaTeX-item-list '(("description" . LaTeX-item-argument)
("thebibliography" . LaTeX-item-bib)