]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix bug in 'sieve-manage--append-to-log'
authorKai Tetzlaff <emacs@tetzco.de>
Thu, 19 Jan 2023 02:16:14 +0000 (03:16 +0100)
committerEli Zaretskii <eliz@gnu.org>
Thu, 19 Jan 2023 13:40:42 +0000 (15:40 +0200)
* lisp/net/sieve-manage.el (sieve-manage--append-to-log): Fix
log buffer creation.  (Bug#54154)  Do not merge to master.

lisp/net/sieve-manage.el

index 5bee4f4c4ad524a18b65b35d837c312633bd92b6..4866f788bffca1601ad5a443c5daf6c14b4e8bab 100644 (file)
@@ -168,19 +168,25 @@ Valid states are `closed', `initial', `nonauth', and `auth'.")
 
 ;; Internal utility functions
 (defun sieve-manage--append-to-log (&rest args)
-  "Append ARGS to sieve-manage log buffer.
+  "Append ARGS to `sieve-manage-log' buffer.
 
 ARGS can be a string or a list of strings.
-The buffer to use for logging is specifified via
-`sieve-manage-log'. If it is nil, logging is disabled."
+The buffer to use for logging is specifified via `sieve-manage-log'.
+If it is nil, logging is disabled.
+
+When the `sieve-manage-log' buffer doesn't exist, it gets created (and
+configured with some initial settings)."
   (when sieve-manage-log
-    (with-current-buffer (or (get-buffer sieve-manage-log)
-                             (with-current-buffer
-                                 (get-buffer-create sieve-manage-log)
-                               (set-buffer-multibyte nil)
-                               (buffer-disable-undo)))
-      (goto-char (point-max))
-      (apply #'insert args))))
+    (let* ((existing-log-buffer (get-buffer sieve-manage-log))
+           (log-buffer (or existing-log-buffer
+                           (get-buffer-create sieve-manage-log))))
+      (with-current-buffer log-buffer
+        (unless existing-log-buffer
+          ;; Do this only once, when creating the log buffer.
+          (set-buffer-multibyte nil)
+          (buffer-disable-undo))
+        (goto-char (point-max))
+        (apply #'insert args)))))
 
 (defun sieve-manage--message (format-string &rest args)
   "Wrapper around `message' which also logs to sieve manage log.