auctex-devel
[Top][All Lists]
Advanced

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

Re: Use temporary buffer for log file?


From: Pengji Zhang
Subject: Re: Use temporary buffer for log file?
Date: Fri, 25 Oct 2024 19:05:54 +0800

Hi Keita,

Ikumi Keita <ikumi@ikumi.que.jp> writes:

> Thank you, it seems promising and worked well for my brief testing.

Thank you for testing it!

> Thanks. Have you signed FSF copyright assignment form for AUCTeX (or
> Emacs) before? If not, please follow the instruction here:
> https://git.savannah.gnu.org/cgit/gnulib.git/tree/doc/Copyright/request-assign.future

I have completed the copyright assignment for Emacs, and I have
contributed to Emacs before.

> I'll wait for your update and install it when you tell us the
> assignment is complete.

Please find the attached patch. I think it should suffice to just record
and check the modification time, so it is simpler than I originally
thought.

Regards,
Pengji

>From c3bea464633ab75a7f2aab2df14279cdd2486aa8 Mon Sep 17 00:00:00 2001
From: Pengji Zhang <me@pengjiz.com>
Date: Fri, 25 Oct 2024 18:49:55 +0800
Subject: [PATCH] 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.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)))
-- 
2.47.0


reply via email to

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