;; 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.