Subject: bug#48144: 13.0.11; TeX-run-format signals error in sentinel

From: "Basil L. Contovounesios" <[email-masked]>
Date: Wed, 05 May 2021 13:38:39 +0100

Arash Esbati <[email-masked]> writes:

> "Basil L. Contovounesios" <[email-masked]> writes:
>
>> I was experimenting with configuring latexmk as best I could in
>> TeX-command-list when I noticed an inconsistency between TeX-run-format
>> and its sentinel.  Here's a recipe to illustrate what I mean:
>>
>> 0. emacs -Q
>> 1. M-x package-initialize RET
>> 2. (progn
>>      (setq debug-on-error t)
>>      (add-hook 'LaTeX-mode-hook
>>                (lambda () (setq TeX-command-default "Latexmk")))
>>      (with-eval-after-load 'tex
>>        (push '("Latexmk"
>>                "latexmk%(file-line-error) %(extraopts)%(mode) %t"
>>                TeX-run-format nil (latex-mode))
>>              TeX-command-list)))
>> 3. C-x C-e
>> 4. C-x C-f /tmp/helloworld.tex RET
>> 5. M-x auto-insert RET RET article RET RET RET
>> 6. \helloworld
>> 7. C-c C-c y RET
>>
>>   Debugger entered--Lisp error: (wrong-type-argument stringp nil)
>>     intern(nil)
>>     TeX-TeX-sentinel-check(#<process Latexmk> "Latexmk")
>>     TeX-TeX-sentinel(#<process Latexmk> "Latexmk")
>>     TeX-command-sentinel(#<process Latexmk> "exited abnormally with code 12\n")
>>
>> AFAICT, this is because TeX-run-format uses TeX-TeX-sentinel, which
>> calls TeX-TeX-sentinel-check, which expects TeX-error-report-switches to
>> have been initialised by TeX-run-TeX, but we're not using TeX-run-TeX!
>>
>> I'm not sure whether the TeX-error-report-switches initialisation should
>> be moved to TeX-run-format, or TeX-TeX-sentinel-check should guard
>> against an uninitialised TeX-error-report-switches.
>>
>> Are my assumptions about or use of TeX-run-format wrong?  E.g., should I
>> just be using TeX-run-command for this purpose instead?
>
> I'm not familiar with Latexmk, but I think you want to use `TeX-run-TeX'
> instead of `TeX-run-format'.  Can you please try it with something like
> this:
>
> (with-eval-after-load 'tex
>   (add-to-list 'TeX-command-list
> 	       '("Latexmk"
> 		 "latexmk%(file-line-error) %(extraopts)%(mode) %t"
> 		 TeX-run-TeX nil (latex-mode))))

Thanks for the suggestion, but this doesn't address the OP.

Ideally TeX-run-TeX would indeed be the most appropriate function, but
it is not practical with latexmk because the sentinel of TeX-run-TeX
unconditionally picks up all the errors and warnings from all the runs
that latexmk invokes, rather than just from the last (successful) run.
This means that TeX-run-TeX never sets the next command to "View".
TeX-run-TeX also does not recognise the output of latexmk when there is
nothing to do for the current file.

The bug report is about the inconsistency between TeX-run-format and its
sentinel TeX-TeX-sentinel.  In some cases the latter expects
TeX-error-report-switches to be initialised, but TeX-run-format never
does this.  IMO if TeX-TeX-sentinel is going to be used with
TeX-run-format then it should not assume that its process was started by
TeX-run-TeX.  Unless I'm missing something?

[ BTW since submitting the OP I have indeed resorted to using the
  auctex-latexmk package, which seems to work reliably well.  ]

Thanks,

-- 
Basil