[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/logview d64abdd8a9 1/4: Fix refreshing log buffer contents
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/logview d64abdd8a9 1/4: Fix refreshing log buffer contents often resulting in an error on Emacs 30. |
Date: |
Thu, 6 Mar 2025 10:03:57 -0500 (EST) |
branch: elpa/logview
commit d64abdd8a95c2b7b6051852628bdbfc4b5b4d4ef
Author: Paul Pogonyshev <pogonyshev@gmail.com>
Commit: Paul Pogonyshev <pogonyshev@gmail.com>
Fix refreshing log buffer contents often resulting in an error on Emacs 30.
---
logview.el | 5 ++++-
test/logview.el | 24 ++++++++++++++++++++++--
2 files changed, 26 insertions(+), 3 deletions(-)
diff --git a/logview.el b/logview.el
index 7cb8c14e4e..fb32cd3882 100644
--- a/logview.el
+++ b/logview.el
@@ -2985,7 +2985,10 @@ returns non-nil."
;; zero-based offset.
(compare-from-bytes (1- (position-bytes compare-from))))
(with-temp-buffer
- (insert-file-contents file nil compare-from-bytes nil)
+ ;; As of Emacs 30 this fails when trying to read past the end of the
file (in earlier Emacs versions it
+ ;; works, but doesn't insert anything). Don't care to report anything
to Emacs-devel (maybe it's even
+ ;; intentional in this case, don't know), just work with either behavior
by suppressing all errors.
+ (ignore-errors (insert-file-contents file nil compare-from-bytes nil))
(let ((temporary (current-buffer))
(temporary-size (buffer-size)))
(if (and (>= temporary-size reassurance-chars)
diff --git a/test/logview.el b/test/logview.el
index 1a0f62e02f..f258e7362e 100644
--- a/test/logview.el
+++ b/test/logview.el
@@ -127,12 +127,14 @@ buffer if the test needs that."
;; results. Of course, this has no visible effect when running
;; tests from command line, as customization never takes place in
;; this case to begin with.
- (let (erase-customizations
+ (let (visit-it
+ erase-customizations
extra-customizations
warning-handling
buffer-mode)
(while (keywordp (car body))
(pcase-exhaustive (pop body)
+ (:visit-it (setf visit-it (pop body)))
(:extra-customizations (setf extra-customizations (eval (pop body) t)))
(:warning-handling (setf warning-handling (pop body)))
(:buffer-mode (setf buffer-mode (pop body)))))
@@ -150,7 +152,7 @@ buffer if the test needs that."
(`standard (apply
original arguments))
(_ (error
"Warning elevated to an error: %S" arguments)))))
(with-temp-buffer
- (insert-file-contents (expand-file-name ,filename
logview--test-directory))
+ (insert-file-contents (expand-file-name ,filename
logview--test-directory) ,visit-it)
(,(or buffer-mode 'logview-mode))
(should (eq major-mode ',(or buffer-mode 'logview-mode)))
,@body)))))
@@ -385,6 +387,24 @@ buffer if the test needs that."
(should-error (logview-next-entry) :type 'user-error)))
+(ert-deftest logview-refresh-shrunk-log-file ()
+ (let ((file (make-temp-file "log")))
+ ;; Insert the contents of `log4j/en-1.log' over and over again, so that
the `file' is long enough.
+ (with-temp-file file
+ (insert-file-contents (expand-file-name "log4j/en-1.log"
logview--test-directory))
+ (let ((contents (buffer-string)))
+ (dotimes (_ 1000)
+ (insert contents)))
+ (should (> (buffer-size) logview-reassurance-chars)))
+ (logview--test-with-file file
+ :visit-it t
+ (should (equal logview--submode-name "SLF4J"))
+ ;; This essentially erases file contents.
+ (with-temp-file file)
+ (logview-refresh-buffer-as-needed)
+ (should (equal (buffer-size) 0)))))
+
+
;; RFC 5424 levels.
;;
;; The mock log file should have a list of log messages in the default