[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: |
Thu, 24 Oct 2024 20:46:11 +0800 |
Hi Keita,
Ikumi Keita <ikumi@ikumi.que.jp> writes:
> Thank you for suggestion. I think it makes sense well. One thing I
> feel uneasy is that it can read in the log file many times, which
> isn't effective if the log file is large. So it would be nice if there
> is a solution without such redundancy. Do you see any good idea?
That is a good point. How about keeping the buffer around and reading in
the file only when it has been updated? Basically:
--8<---------------cut here---------------start------------->8---
(with-current-buffer
(get-buffer-create (format " *%s*" log-file))
(when (file-has-changed-p log-file 'TeX-help-error)
(insert-file-contents log-file nil nil nil
'replace))
; Do the work...
)
--8<---------------cut here---------------end--------------->8---
The problem here is that 'file-has-changed-p' is introduced in Emacs
29.1. So we need to backport this function. Anyway, I have updated the
patch for your testing. If you think it is good, I will prepare a new
patch with the 'file-has-changed-p' backported.
> For example, isn't is possible to temporally disable polluting the
> file list when `find-file-noselect' is called?
I am not aware of such a mechanism. 'file-file-noselect' creates a
file-visiting, non-internal buffer, which IMO is not easy to change. We
may fix the problem case by case, but I think that would be tedious.
Besides, currently with 'find-file-noselect' we also revert the buffer
each time the 'TeX-help-error' function is called, which is not so
efficient either.
Cheers,
Pengji
>From 303476e2ffd1d58c8dcdf19956baf8f5b00da731 Mon Sep 17 00:00:00 2001
From: Pengji Zhang <me@pengjiz.com>
Date: Wed, 23 Oct 2024 08:15:50 +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 | 40 +++++++++++++++++-----------------------
1 file changed, 17 insertions(+), 23 deletions(-)
diff --git a/tex.el b/tex.el
index 4e361e4c..bab06caa 100644
--- a/tex.el
+++ b/tex.el
@@ -10053,29 +10053,23 @@ 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))
+ (when (file-has-changed-p log-file 'TeX-help-error)
+ (insert-file-contents log-file nil nil nil
+ 'replace))
+ (goto-char (point-min))
+ (when (and (search-forward error nil t)
+ (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