auctex-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

main 9629a2ca: Use internal buffer for log file


From: Ikumi Keita
Subject: main 9629a2ca: Use internal buffer for log file
Date: Fri, 25 Oct 2024 08:31:41 -0400 (EDT)

branch: main
commit 9629a2cae8e0b027b9db03abbe82b6e27a85c572
Author: Pengji Zhang <me@pengjiz.com>
Commit: Ikumi Keita <ikumi@ikumi.que.jp>

    Use internal buffer for log file
    
    * tex.el (TeX-help-error): Insert contents of log file into an
    internal buffer (whose name starts with a space) instead of
    visiting the file.  This is to avoid polluting, for example, the
    user's buffer list and recentf list.
    (TeX--log-file-readin-modtime): New internal variable.
---
 tex.el | 49 ++++++++++++++++++++++++++-----------------------
 1 file changed, 26 insertions(+), 23 deletions(-)

diff --git a/tex.el b/tex.el
index 4e361e4c..f95930a8 100644
--- a/tex.el
+++ b/tex.el
@@ -10011,6 +10011,11 @@ It must end with a fallback entry that matches any 
error, for example
   '((t (:inherit TeX-error-description-tex-said)))
   "Face for \"Help\" string in error descriptions.")
 
+(defvar-local TeX--log-file-readin-modtime nil
+  "Recorded modification time of the TeX log file.
+It is updated each time the file is read into the buffer, and is to
+avoid unnecessary reads of the log file.")
+
 (defun TeX-help-error (error output runbuffer type)
   "Print ERROR in context OUTPUT from RUNBUFFER in another window.
 TYPE is a symbol specifing if ERROR is a real error, a warning or
@@ -10053,29 +10058,27 @@ a bad box."
                    'TeX-error-description-help)
        (let ((help (cdr (nth TeX-error-pointer
                              error-description-list))))
-         (save-excursion
-           (if (and (= (1+ TeX-error-pointer)
-                       (length error-description-list))
-                    (let* ((log-buffer (find-buffer-visiting log-file)))
-                      (if log-buffer
-                          (progn
-                            (set-buffer log-buffer)
-                            (revert-buffer t t))
-                        (setq log-buffer
-                              (find-file-noselect log-file))
-                        (set-buffer log-buffer))
-                      (auto-save-mode nil)
-                      (setq buffer-read-only t)
-                      (goto-char (point-min))
-                      (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))))
-             help)))))
+         (or (and (= (1+ TeX-error-pointer)
+                     (length error-description-list))
+                  (with-current-buffer
+                      (get-buffer-create (format " *%s*" log-file))
+                    (let ((modtime (file-attribute-modification-time
+                                    (file-attributes log-file))))
+                      (unless (and TeX--log-file-readin-modtime
+                                   (time-equal-p TeX--log-file-readin-modtime
+                                                 modtime))
+                        (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)
+                               (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)))))))
+             help))))
     (goto-char (point-min))
     (TeX-special-mode)
     (TeX-pop-to-buffer old-buffer nil t)))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]