Hi all, I noticed that error navigation (via 'C-c `') does not work correctly in narrowed buffers.
The main issue is that in a buffer where the current restriction omits N lines at the top, 'C-c `' moves to N lines beyond where it should, due to the difference between relative and absolute line numbers. A secondary issue is that 'C-c `' does not navigate to errors outside the current restriction. The patch addresses both in the expected way. For the secondary issue, it made sense to widen when jumping to errors outside the current restriction because this behavior mirrors that of similar commands in Emacs (e.g., grep + next-error). Any feedback welcome. Thanks, best, Paul
>From ddab8605baefada76c52d8cc89718901fea4e213 Mon Sep 17 00:00:00 2001 From: Paul Nelson <[email protected]> Date: Tue, 2 Dec 2025 06:06:53 +0100 Subject: [PATCH] Fix navigation to errors in narrowed buffers * tex.el (TeX-find-display-help): When searching for errors, widen temporarily. If the error lies outside the current restriction, then widen to make the error visible before navigating to it. --- tex.el | 55 +++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 35 insertions(+), 20 deletions(-) diff --git a/tex.el b/tex.el index 7c14a135..8560a1fb 100644 --- a/tex.el +++ b/tex.el @@ -9788,26 +9788,41 @@ value is not used here." (setq-local TeX-command-buffer command-buffer) ;; Find the location of the error or warning. - (when TeX-translate-location-line - (goto-char (point-min)) - (forward-line (+ TeX-translate-location-offset - TeX-translate-location-line -1)) - (cond - ;; Error. - ((equal type 'error) - (if (not (string= TeX-translate-location-string " ")) - (search-forward TeX-translate-location-string nil t))) - ;; Warning or bad box. - (t - (beginning-of-line 0) - (setq start (point)) - (goto-char (point-min)) - (forward-line (+ TeX-translate-location-offset - line-end -1)) - (end-of-line) - (when TeX-translate-location-string - (search-backward TeX-translate-location-string start t) - (search-forward TeX-translate-location-string nil t)))))) + (let ((narrowed (buffer-narrowed-p)) + (visible-start (point-min)) + (visible-end (point-max)) + target-pos) + (when TeX-translate-location-line + (save-restriction + (widen) + (goto-char (point-min)) + (forward-line (+ TeX-translate-location-offset + TeX-translate-location-line -1)) + (cond + ;; Error. + ((equal type 'error) + (if (not (string= TeX-translate-location-string " ")) + (search-forward TeX-translate-location-string nil t))) + ;; Warning or bad box. + (t + (beginning-of-line 0) + (setq start (point)) + (goto-char (point-min)) + (forward-line (+ TeX-translate-location-offset + line-end -1)) + (end-of-line) + (when TeX-translate-location-string + (search-backward TeX-translate-location-string start t) + (search-forward TeX-translate-location-string nil t)))) + (setq target-pos (point)))) + (when (and target-pos + narrowed + (or (< target-pos visible-start) + (> target-pos visible-end))) + ;; The error lies outside the restriction, so widen first. + (widen)) + (when target-pos + (goto-char target-pos)))) ;; When the file cannot be determined stay here but issue a ;; warning. (message "Could not determine file for %s" -- 2.50.1 (Apple Git-155)
_______________________________________________ bug-auctex mailing list [email protected] https://lists.gnu.org/mailman/listinfo/bug-auctex
