On Thu, Feb 12, 2026 at 15:54 (+0100), Arash Esbati wrote:

> Hi Jim,

> Jim Diamond <[email protected]> writes:

>> after some further poking and prodding, it seemed to me that some
>> significant development was needed.  Aside from the issues I mentioned
>> previously, in ConTeXt Mk IV and LMTX, the error message format is
>> different than (e.g., pdftex) (and Hans Hagen confirmed that the old
>> error message format is not coming back to this world).

> Many thanks for working on this; I hope you had fun hacking on Emacs
> again :-)

>> I have modified tex.el and context.el, and it now works (more or less) as
>> expected.  I want to do a bit more testing, but I think I am close to done.

> Great!

>> When I am done, how do I get my changes accepted?
>> -> Should I email the new files (or diffs) to someone?  If so, who?
>> -> Should I email the files (or diffs) to this bug report?

> We appreciate 'git format-patch' method attached to a mail sent to this
> bug report.  We closely follow Emacs in this regard, so if you're
> looking for details, have a look at this file[1].

> I can't check right now, have you signed the FSF copyright assignment?
> We need that for larger changes, otherwise we can't incorporate your
> change.

> Best, Arash

> Footnotes:
> [1]  https://cgit.git.savannah.gnu.org/cgit/emacs.git/tree/CONTRIBUTE

Hi,

attached is a patch that I created with git format-patch.  I hope this is
the expected format for the patch.

If there are any questions, please let me know.

Cheers.
                                Jim

P.S. I filled in the form to do the copyright assignment yesterday, but I
haven't received anything back yet on that.  But I guess whomever needs to
review this patch can do so without the copyright assignment, in
expectation that it will appear soon.
>From d0b0fe34f9350db07944a7cdf4773333842b378f Mon Sep 17 00:00:00 2001
From: Jim Diamond <[email protected]>
Date: Fri, 13 Feb 2026 21:34:52 -0400
Subject: [PATCH] Updates to make C-c ` work in ConTeXt (LMTX and probably Mk
 IV).

---
 context.el | 127 +++++++++++++++++++++++++++++++++++------------------
 tex.el     |  91 +++++++++++++++++++++++++++++++++-----
 2 files changed, 164 insertions(+), 54 deletions(-)

diff --git a/context.el b/context.el
index 25cbeb34..7ff3f1cc 100644
--- a/context.el
+++ b/context.el
@@ -567,50 +567,91 @@ for a label to be inserted after the sectioning command."
 
 
 ;; Various
+
+(defun TeX-ConTeXt-sentinel-check (process name)
+  "Check ConTeXt (LMTX) output buffer after running TeX.
+  Return  t  if errors were found."
+
+  ;; First, determine which page was being worked on when an error happened,
+  ;; if any.  Also determine the extension of the output file.
+  (save-excursion
+      (goto-char (point-max))
+      (if (re-search-backward " > flushing realpage \\([0-9]+\\), " nil t)
+             (setq TeX-current-page (TeX-match-buffer 1))
+         (setq TeX-current-page "0")
+      )
+      ;; Unlike pdftex (and similar), ConTeXt LMTX only outputs page
+      ;; information as each one is successfully output.  Deal with it.
+      (setq TeX-current-page 
+           (concat "{" 
+                   (number-to-string 
+                    (+ 1 (string-to-number TeX-current-page)))
+                   "}"))
+      (setq TeX-output-extension "pdf")   ;; for the last 200 years now, +/-.
+  )
+
+  (if process (TeX-format-mode-line process))
+  
+  (if (catch 'found
+        (while (re-search-forward 
+               "^\\(?:.*tex error on line [0-9]+ in file \\(.+?\\):\\)" nil t)
+            (if (or (not (match-beginning 1))
+                  ;; Ignore non-error warning. (bug#55065)
+                  (file-exists-p (TeX-match-buffer 1)))
+              (throw 'found t))))
+         (progn
+              (if TeX-error-overview-open-after-TeX-run
+                     ;; Don't leave inconsistent message.
+                     (message nil)
+                 (message "%s errors in `%s'. Use %s to display." 
+                          name (buffer-name) 
+                          (substitute-command-keys
+                           "\\<TeX-mode-map>\\[TeX-next-error]"))
+              )
+        (setq TeX-command-next TeX-command-default)
+        ;; error reported to TeX-error-report-switches
+        (setq TeX-error-report-switches
+              (plist-put TeX-error-report-switches
+                         (intern (plist-get TeX-error-report-switches
+                                            'TeX-current-master))
+                         t))
+        t)
+    ;; In case that there were only non-error warnings of type
+    ;; bug#55065, restore point to the initial position.
+    (goto-char (point-min))
+    (setq TeX-command-next TeX-command-Show)
+    nil)
+)
+
+
+
 (defun TeX-ConTeXt-sentinel (process name)
-  "Cleanup TeX output buffer after running ConTeXt."
-  (cond
-   ;; Mark IV
-   ((with-current-buffer TeX-command-buffer
-      (string= ConTeXt-Mark-version "IV"))
-    (cond ((TeX-TeX-sentinel-check process name))
-          ((re-search-forward "fatal error: " nil t)
-           (message (concat name ": problems after "
-                            (TeX-current-pages)))
-           (setq TeX-command-next TeX-command-default))
-          (t
-           (message (concat name ": successfully formatted "
-                            (TeX-current-pages)))
-           (setq TeX-command-next TeX-command-Show))))
-   ;; Mark II
-   (t
-    (cond ((TeX-TeX-sentinel-check process name))
-          ((save-excursion
-             ;; in a full ConTeXt run there will multiple texutil
-             ;; outputs.  Just looking for "another run needed" would
-             ;; find the first occurence
-             (goto-char (point-max))
-             (re-search-backward "TeXUtil " nil t)
-             (re-search-forward "another run needed" nil t))
-           (message (concat "You should run ConTeXt again "
-                            "to get references right, "
-                            (TeX-current-pages)))
-           (setq TeX-command-next TeX-command-default))
-          ((re-search-forward "removed files :" nil t)
-           (message "sucessfully cleaned up"))
-          ((re-search-forward "^ ?TeX\\(Exec\\|Util\\)" nil t) ;; strange 
regexp --pg
-           (message (concat name ": successfully formatted "
-                            (TeX-current-pages)))
-           (setq TeX-command-next TeX-command-Show))
-          (t
-           (message (concat name ": problems after "
-                            (TeX-current-pages)))
-           (setq TeX-command-next TeX-command-default)))))
-  (unless TeX-error-list
-    (run-hook-with-args 'TeX-after-compilation-finished-functions
-                        (with-current-buffer TeX-command-buffer
-                          (expand-file-name
-                           (TeX-active-master (TeX-output-extension)))))))
+  "Cleanup TeX output buffer after running ConTeXt.
+
+   Parse the output buffer to collect errors and warnings if the
+   variable `TeX-parse-all-errors' is non-nil.
+
+   Open the error overview if
+   `TeX-error-overview-open-after-TeX-run' is non-nil and there are
+   errors or warnings to show."
+  
+  (if (TeX-ConTeXt-sentinel-check process name)
+      (progn
+       ;; Since ConTeXt LMTX stops after 1 error, it might make sense to
+       ;; just call (TeX-parse-error) once (and set the other variables
+       ;; as seen in (TeX-parse-all-errors)).
+        (if TeX-parse-all-errors
+            (TeX-parse-all-errors))
+        (if (and (with-current-buffer TeX-command-buffer
+                   TeX-error-overview-open-after-TeX-run)
+                 (TeX-error-overview-make-entries
+                  (TeX-master-directory) (TeX-active-buffer)))
+            (TeX-error-overview)))
+
+      (message (concat name ": formatted " (TeX-current-pages)))
+      (setq TeX-command-next TeX-command-Show)
+   )
+)
 
 
 ;;; Environments
diff --git a/tex.el b/tex.el
index 513c527b..fd806c66 100644
--- a/tex.el
+++ b/tex.el
@@ -8620,7 +8620,7 @@ Return nil only if no errors were found."
         (while (and (re-search-forward "^\\(?:!\\|\\(.+?\\):[0-9]+:\\) " nil t)
                     (not (looking-at-p
                           (mapconcat #'identity
-                                     '("ignored\\(?: error\\)?: "
+                                     '("ignored error: "
                                        "Infinite glue shrinkage found in box 
being split")
                                      "\\|"))))
           (if (or (not (match-beginning 1))
@@ -9667,7 +9667,12 @@ Return non-nil if an error or warning is found."
           ;;   Vertical bad box.  See also `TeX-warning'.
           "\\\\vbox ([ a-z0-9]+) has occurred while \\\\output is active 
\\[[^]]+\\]\\)\\)\\|"
           ;; LaTeX warning
-          "^\\(" LaTeX-warnings-regexp ".*\\)"))
+          "^\\(" LaTeX-warnings-regexp ".*\\)"
+         ;; ConTeXt error; sample output line:
+         ;; tex error       > tex error on line 5 in file /tmp/bbb.tex: ! 
Undefined control sequence
+         ;; Matches 9 and 10:
+         "\\|^\\(tex error .* in file \\([^:]*\\): \\)"
+         ))
         (error-found nil))
     (while
         (cond
@@ -9680,17 +9685,25 @@ Return non-nil if an error or warning is found."
             (TeX-pop-to-buffer old))
           nil)
          ;; TeX error
-         ((match-beginning 1)
-          (if (or (not (match-beginning 2))
-                  ;; Ignore non-error warning. (bug#55065)
-                  (file-exists-p (TeX-match-buffer 2)))
+         ((or (match-beginning 1) (match-beginning 9))
+          (if (or (or (not (match-beginning 2))
+                      ;; Ignore non-error warning. (bug#55065)
+                      (file-exists-p (TeX-match-buffer 2)))
+                 (or (not (match-beginning 10))
+                      ;; Ignore non-error warning. (bug#55065)
+                      (file-exists-p (TeX-match-buffer 10)))
+             )
               (progn
-                (when (match-beginning 2)
+                (when (or (match-beginning 2) (match-beginning 10))
                   (unless TeX-error-file
                     (push nil TeX-error-file)
                     (push nil TeX-error-offset))
                   (unless (car TeX-error-offset)
-                    (rplaca TeX-error-file (TeX-match-buffer 2))))
+                    (rplaca TeX-error-file
+                      (if (match-beginning 2)
+                              (TeX-match-buffer 2)
+                          (TeX-match-buffer 10)
+                          ))))
                 (setq error-found t)
                 (if (looking-at "Preview ")
                     t
@@ -9864,6 +9877,21 @@ value is not used here."
           (t
            (message "! %s" TeX-translate-location-error)))))
 
+
+;; TeX and ConTeXt LMTX error messages are formatted differently (and thus
+;; some tweakings are necessary for ConTeXt error messages to be parsed).
+;; E.g., in TeX:
+;; ./file.tex:9: Undefined control sequence.
+;; l.9 blah blah \undefinedINplainTEX
+;;                                       <<< line with many initial spaces
+;; and in ConTeXt:
+;; tex error       > tex error on line 9 in file ./file.tex: Undefined control 
sequence
+;;                                       <<<--- empty line here
+;; <line 3.9> 
+;;    aardvark \undefinedINcontext
+;;                                       <<<--- empty line here
+;; Because of how the parsing is done below, these formatting differences
+;; must be handled.
 (defun TeX-error (&optional store)
   "Display an error.
 
@@ -9890,16 +9918,44 @@ information in `TeX-error-list' instead of displaying 
the error."
                    (re-search-backward ":\\([0-9]+\\): "
                                        (line-beginning-position) t))
                  (string-to-number (TeX-match-buffer 1)))
+               ;; ConTeXt: ^<line n.[linenum]>\n +[error message]'
+               ((re-search-forward "^<line [^.]+[.]\\([0-9]+\\)>" nil t)
+                ;; Need this in the ConTeXt case for the 'string' search
+                ;; (just below here) to work correctly (FWIW):
+                (forward-line)
+                 (setq context-available t)
+                ;; ConTeXt has a blank line where pdftex does not; adjust:
+                (setq context-start (1+ context-start))
+                 (string-to-number (TeX-match-buffer 1)))
                 ;; nothing found
                 (t 1)))
 
          ;; And a string of the context to search for.
+        ;; plain TeX example of what we are looking at:
+        ;; ((point) before ' aard...')
+        ;; l.9 aardvark \undefinedINplainTEX
+        ;;                                  \n
+        ;; ConTeXt:
+        ;; ((point) before '    aard...')
+        ;;     aardvark \undefinedINcontext
+        ;; \n
+        ;; Because of the space chars on the line following the TeX error
+        ;; message, the regexp below doesn't include the \n at the end of
+        ;; the line(s).  However, since ConTeXt has no blanks, the match
+        ;; includes the \n.
+        ;; Having said all that, is 'string' ever used anywhere?
          (string (progn
                    (beginning-of-line)
                    (re-search-forward " \\(\\([^ \t]*$\\)\\|\\($\\)\\)")
+                  ;; Adjust (point) (but not the match itself!) for ConTeXt
+                  ;; so that 'context' gets set correctly below.
+                  (if (bolp) (backward-char 1))
                    (TeX-match-buffer 1)))
 
-         ;; And we have now found to the end of the context.
+         ;; (point) is now positioned at the end of the end of the input line
+        ;; which caused this error (TeX) or the beginning of the next 
+        ;; line (ConTeXt).  To find the error context, rather than searching 
+        ;; just use (point) and locations we saved above.
          (context (if context-available
                       (buffer-substring context-start (progn (forward-line 1)
                                                              (end-of-line)
@@ -10200,14 +10256,27 @@ a bad box."
                         (insert-file-contents log-file nil nil nil 'replace)
                         (setq TeX--log-file-readin-modtime modtime)))
                     (goto-char (point-min))
-                    (when (and (search-forward error nil t 1)
+                    (if (and (search-forward error nil t 1)
                                (re-search-forward "^l\\." nil t)
                                (re-search-forward "^ [^\n]+$" nil t))
                       (let ((start (1+ (point))))
                         (forward-char 1)
                         (re-search-forward "^$")
                         (concat "From the .log file...\n\n"
-                                (buffer-substring start (point)))))))
+                                (buffer-substring start (point))))
+                   ;; ConTeXt case: assume just one error per run,
+                    ;; since it requires some ConTeXt wizardry to not stop on
+                    ;; the first error, and, if the run doesn't stop on the 
+                    ;; first error, getting meaningful info from the log file
+                    ;; is very difficult.
+                   (goto-char (point-max))
+                   (if (re-search-backward "^[0-9]+ ")
+                     (progn
+                         (end-of-line)
+                         (let ((start (1+ (point))))
+                             (goto-char (point-max))
+                              (concat "From the .log file...\n\n"
+                                      (buffer-substring start (point)))))))))
              help))))
     (goto-char (point-min))
     (TeX-special-mode)
-- 
2.46.4

_______________________________________________
bug-auctex mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/bug-auctex

Reply via email to