Simplify Gnus buffer liveness checking and killing

* lisp/gnus/gnus-agent.el (gnus-agent-synchronize-group-flags):
Fix indentation.
* lisp/gnus/gnus-util.el (gnus-buffer-exists-p): Define as obsolete
alias of gnus-buffer-live-p.
(gnus-buffer-live-p): If the given argument is or names a live
buffer, return the corresponding buffer object instead of a boolean.
* lisp/gnus/gnus-win.el (gnus-delete-windows-in-gnusey-frames)
(gnus-remove-some-windows): Simplify.
* lisp/gnus/gnus.el (gnus-prune-buffers): Redefine as alias of
gnus-buffers.
(gnus-kill-buffer, gnus-buffers, gnus-group-find-parameter):
* lisp/gnus/gnus-art.el (gnus-kill-sticky-article-buffers)
(gnus-request-article-this-buffer):
* lisp/gnus/gnus-bcklg.el (gnus-backlog-shutdown):
* lisp/gnus/gnus-cus.el (gnus-group-customize)
(gnus-agent-customize-category):
* lisp/gnus/gnus-draft.el (gnus-draft-edit-message):
* lisp/gnus/gnus-group.el (gnus-group-set-mode-line)
(gnus--abort-on-unsaved-message-buffers, gnus-group-compact-group):
* lisp/gnus/gnus-msg.el (gnus-inews-add-send-actions)
(gnus-summary-supersede-article, gnus-copy-article-buffer):
* lisp/gnus/gnus-score.el (gnus-score-edit-current-scores)
(gnus-score-edit-file):
* lisp/gnus/gnus-spec.el (gnus-update-format-specifications):
* lisp/gnus/gnus-srvr.el (gnus-server-compact-server):
* lisp/gnus/gnus-start.el (gnus-clear-system, gnus-dribble-enter)
(gnus-dribble-save, gnus-dribble-clear, gnus-save-newsrc-file):
* lisp/gnus/gnus-sum.el (gnus-summary-setup-buffer)
(gnus-update-summary-mark-positions, gnus-summary-exit)
(gnus-deaden-summary, gnus-kill-or-deaden-summary)
(gnus-summary-next-group):
* lisp/gnus/gnus-win.el (gnus-configure-frame):
* lisp/gnus/mail-source.el (mail-source-movemail):
* lisp/gnus/message.el (message-with-reply-buffer)
(message-with-reply, message-send-and-exit)
(message-send-mail-with-sendmail, message-pop-to-buffer)
(message-do-send-housekeeping, message-forward-make-body-plain)
(message-forward-make-body-mml):
* lisp/gnus/mm-decode.el (mm-display-external, mm-remove-part):
* lisp/gnus/nnbabyl.el (nnbabyl-server-opened)
(nnbabyl-possibly-change-newsgroup, nnbabyl-read-mbox)
(nnbabyl-check-mbox):
* lisp/gnus/nndiary.el (nndiary-save-nov):
* lisp/gnus/nndoc.el (nndoc-close-group)
(nndoc-possibly-change-buffer):
* lisp/gnus/nnfolder.el (nnfolder-close-group, nnfolder-save-nov):
* lisp/gnus/nnimap.el (nnimap-make-process-buffer, nnimap-keepalive)
(nnimap-find-connection):
* lisp/gnus/nnmail.el (nnmail-cache-open, nnmail-cache-close):
* lisp/gnus/nnmbox.el (nnmbox-close-server, nnmbox-server-opened)
(nnmbox-possibly-change-newsgroup, nnmbox-read-mbox):
* lisp/gnus/nnml.el (nnml-save-incremental-nov, nnml-open-nov)
(nnml-save-nov):
* lisp/gnus/nnoo.el (nnoo-server-opened):
* lisp/gnus/nntp.el (nntp-kill-buffer, nntp-make-process-buffer)
(nntp-open-connection, nntp-async-trigger):
* lisp/net/mairix.el (mairix-gnus-fetch-field): Simplify buffer
liveness checking and killing, replacing buffer-name with
buffer-live-p and gnus-buffer-exists-p with gnus-buffer-live-p or
equivalent where applicable.
parent 46a17616
Pipeline #1832 failed with stage
in 49 minutes and 45 seconds
......@@ -1193,7 +1193,7 @@ This can be added to `gnus-select-article-hook' or
;;;
(defun gnus-agent-synchronize-group-flags (group actions server)
"Update a plugged group by performing the indicated actions."
"Update a plugged group by performing the indicated actions."
(let* ((gnus-command-method (gnus-server-to-method server))
(info
;; This initializer is required as gnus-request-set-mark
......@@ -1227,18 +1227,21 @@ This can be added to `gnus-select-article-hook' or
((memq mark '(tick))
(let ((info-marks (assoc mark (gnus-info-marks info))))
(unless info-marks
(gnus-info-set-marks info (cons (setq info-marks (list mark)) (gnus-info-marks info))))
(setcdr info-marks (funcall (if (eq what 'add)
'gnus-range-add
'gnus-remove-from-range)
(cdr info-marks)
range))))))))
;;Marks can be synchronized at any time by simply toggling from
;;unplugged to plugged. If that is what is happening right now, make
;;sure that the group buffer is up to date.
(when (gnus-buffer-live-p gnus-group-buffer)
(gnus-group-update-group group t)))
(gnus-info-set-marks
info (cons (setq info-marks (list mark))
(gnus-info-marks info))))
(setcdr info-marks
(funcall (if (eq what 'add)
'gnus-range-add
'gnus-remove-from-range)
(cdr info-marks)
range))))))))
;; Marks can be synchronized at any time by simply toggling from
;; unplugged to plugged. If that is what is happening right now,
;; make sure that the group buffer is up to date.
(when (gnus-buffer-live-p gnus-group-buffer)
(gnus-group-update-group group t)))
nil))
(defun gnus-agent-save-active (method &optional groups-p)
......
......@@ -4799,11 +4799,10 @@ If a prefix ARG is given, ask for confirmation."
(interactive "P")
(dolist (buf (gnus-buffers))
(with-current-buffer buf
(when (derived-mode-p 'gnus-sticky-article-mode)
(if (not arg)
(gnus-kill-buffer buf)
(when (yes-or-no-p (concat "Kill buffer " (buffer-name buf) "? "))
(gnus-kill-buffer buf)))))))
(and (derived-mode-p 'gnus-sticky-article-mode)
(or (not arg)
(yes-or-no-p (format "Kill buffer %s? " buf)))
(gnus-kill-buffer buf)))))
;;;
;;; Gnus MIME viewing functions
......@@ -6979,9 +6978,7 @@ If given a prefix, show the hidden text instead."
;; doesn't belong in this newsgroup (possibly), so we find its
;; message-id and request it by id instead of number.
(when (and (numberp article)
gnus-summary-buffer
(get-buffer gnus-summary-buffer)
(gnus-buffer-exists-p gnus-summary-buffer))
(gnus-buffer-live-p gnus-summary-buffer))
(with-current-buffer gnus-summary-buffer
(let ((header (gnus-summary-article-header article)))
(when (< article 0)
......@@ -7015,11 +7012,9 @@ If given a prefix, show the hidden text instead."
(cond
;; Refuse to select canceled articles.
((and (numberp article)
gnus-summary-buffer
(get-buffer gnus-summary-buffer)
(gnus-buffer-exists-p gnus-summary-buffer)
(eq (cdr (with-current-buffer gnus-summary-buffer
(assq article gnus-newsgroup-reads)))
(gnus-buffer-live-p gnus-summary-buffer)
(eq (with-current-buffer gnus-summary-buffer
(cdr (assq article gnus-newsgroup-reads)))
gnus-canceled-mark))
nil)
;; We first check `gnus-original-article-buffer'.
......
......@@ -46,8 +46,7 @@
(defun gnus-backlog-shutdown ()
"Clear all backlog variables and buffers."
(interactive)
(when (get-buffer gnus-backlog-buffer)
(gnus-kill-buffer gnus-backlog-buffer))
(gnus-kill-buffer gnus-backlog-buffer)
(setq gnus-backlog-articles nil))
(defun gnus-backlog-enter-article (group number buffer)
......
......@@ -369,7 +369,7 @@ category."))
(unless (or topic (setq info (gnus-get-info group)))
(error "Killed group; can't be edited"))
;; Ready.
(gnus-kill-buffer (gnus-get-buffer-create "*Gnus Customize*"))
(gnus-kill-buffer "*Gnus Customize*")
(switch-to-buffer (gnus-get-buffer-create "*Gnus Customize*"))
(gnus-custom-mode)
(make-local-variable 'gnus-custom-group)
......@@ -1021,9 +1021,7 @@ articles in the thread.
(cons 'agent-low-score gnus-agent-low-score)
(cons 'agent-high-score gnus-agent-high-score))))
(let ((old (get-buffer "*Gnus Agent Category Customize*")))
(when old
(gnus-kill-buffer old)))
(gnus-kill-buffer "*Gnus Agent Category Customize*")
(switch-to-buffer (gnus-get-buffer-create
"*Gnus Agent Category Customize*"))
......@@ -1051,7 +1049,7 @@ articles in the thread.
(when (get-buffer gnus-category-buffer)
(switch-to-buffer (get-buffer gnus-category-buffer))
(gnus-category-list)))
"Done")
"Done")
(widget-insert
"\n Note: Empty fields default to the customizable global\
variables.\n\n")
......
......@@ -94,14 +94,13 @@
(save-restriction
(message-narrow-to-headers)
(message-remove-header "date")))
(let ((message-draft-headers
(delq 'Date (copy-sequence message-draft-headers))))
(let ((message-draft-headers (remq 'Date message-draft-headers)))
(save-buffer))
(let ((gnus-verbose-backends nil))
(gnus-request-expire-articles (list article) group t))
(push
`((lambda ()
(when (gnus-buffer-exists-p ,gnus-summary-buffer)
(when (gnus-buffer-live-p ,gnus-summary-buffer)
(save-excursion
(set-buffer ,gnus-summary-buffer)
(gnus-cache-possibly-remove-article ,article nil nil nil t)))))
......
......@@ -1743,8 +1743,7 @@ already. If INFO-UNCHANGED is non-nil, dribble buffer is not updated."
gnus-tmp-header ;Dummy binding for user-defined formats
;; Get the resulting string.
(modified
(and gnus-dribble-buffer
(buffer-name gnus-dribble-buffer)
(and (buffer-live-p gnus-dribble-buffer)
(buffer-modified-p gnus-dribble-buffer)
(with-current-buffer gnus-dribble-buffer
(not (zerop (buffer-size))))))
......@@ -4362,15 +4361,13 @@ The hook `gnus-exit-gnus-hook' is called before actually exiting."
(defun gnus--abort-on-unsaved-message-buffers ()
(dolist (buffer (gnus-buffers))
(when (gnus-buffer-exists-p buffer)
(with-current-buffer buffer
(when (and (derived-mode-p 'message-mode)
(buffer-modified-p)
(not (y-or-n-p
(format "Message buffer %s unsaved, continue exit? "
(buffer-name)))))
(error "Gnus exit aborted due to unsaved %s buffer"
(buffer-name)))))))
(with-current-buffer buffer
(when (and (derived-mode-p 'message-mode)
(buffer-modified-p)
(not (y-or-n-p
(format "Message buffer %s unsaved, continue exit? "
buffer))))
(error "Gnus exit aborted due to unsaved buffer %s" buffer)))))
(defun gnus-group-quit ()
"Quit reading news without updating .newsrc.eld or .newsrc.
......@@ -4754,8 +4751,7 @@ Compacting group %s... (this may take a long time)"
;; Invalidate the "original article" buffer which might be out of date.
;; #### NOTE: Yes, this might be a bit rude, but since compaction
;; #### will not happen very often, I think this is acceptable.
(let ((original (get-buffer gnus-original-article-buffer)))
(and original (gnus-kill-buffer original)))
(gnus-kill-buffer gnus-original-article-buffer)
;; Update the group line to reflect new information (art number etc).
(gnus-group-update-group-line))))
......
......@@ -607,7 +607,7 @@ instead."
(message-add-action
`(progn
(setq gnus-current-window-configuration ',winconf-name)
(when (gnus-buffer-exists-p ,buffer)
(when (gnus-buffer-live-p ,buffer)
(set-window-configuration ,winconf)))
'exit 'postpone 'kill)
(let ((to-be-marked (cond
......@@ -617,7 +617,7 @@ instead."
(article (if (listp article) article (list article)))
(t nil))))
(message-add-action
`(when (gnus-buffer-exists-p ,buffer)
`(when (gnus-buffer-live-p ,buffer)
(with-current-buffer ,buffer
,(when to-be-marked
(if (eq config 'forward)
......@@ -902,7 +902,7 @@ header line with the old Message-ID."
(message-supersede)
(push
`((lambda ()
(when (gnus-buffer-exists-p ,gnus-summary-buffer)
(when (gnus-buffer-live-p ,gnus-summary-buffer)
(with-current-buffer ,gnus-summary-buffer
(gnus-cache-possibly-remove-article ,article nil nil nil t)
(gnus-summary-mark-as-read ,article gnus-canceled-mark)))))
......@@ -922,8 +922,7 @@ header line with the old Message-ID."
(mm-enable-multibyte))
(let ((article-buffer (or article-buffer gnus-article-buffer))
end beg)
(if (not (and (get-buffer article-buffer)
(gnus-buffer-exists-p article-buffer)))
(if (not (gnus-buffer-live-p article-buffer))
(error "Can't find any article buffer")
(with-current-buffer article-buffer
(let ((gnus-newsgroup-charset (or gnus-article-charset
......
......@@ -1098,7 +1098,7 @@ EXTRA is the possible non-standard header."
(if (not gnus-current-score-file)
(error "No current score file")
(let ((winconf (current-window-configuration)))
(when (buffer-name gnus-summary-buffer)
(when (buffer-live-p gnus-summary-buffer)
(gnus-score-save))
(gnus-make-directory (file-name-directory file))
(setq gnus-score-edit-buffer (find-file-noselect file))
......@@ -1126,7 +1126,7 @@ EXTRA is the possible non-standard header."
(interactive
(list (read-file-name "Edit score file: " gnus-kill-files-directory)))
(gnus-make-directory (file-name-directory file))
(when (buffer-name gnus-summary-buffer)
(when (buffer-live-p gnus-summary-buffer)
(gnus-score-save))
(let ((winconf (current-window-configuration)))
(setq gnus-score-edit-buffer (find-file-noselect file))
......
......@@ -150,7 +150,7 @@ Return a list of updated types."
(let ((buffer (intern (format "gnus-%s-buffer" type))))
(when (and (boundp buffer)
(setq val (symbol-value buffer))
(gnus-buffer-exists-p val))
(gnus-buffer-live-p val))
(set-buffer val))
(setq new-format (symbol-value
(intern (format "gnus-%s-line-format" type)))))
......
......@@ -1086,8 +1086,7 @@ Requesting compaction of %s... (this may take a long time)"
;; Invalidate the original article buffer which might be out of date.
;; #### NOTE: Yes, this might be a bit rude, but since compaction
;; #### will not happen very often, I think this is acceptable.
(let ((original (get-buffer gnus-original-article-buffer)))
(and original (gnus-kill-buffer original))))))
(gnus-kill-buffer gnus-original-article-buffer))))
(defun gnus-server-toggle-cloud-server ()
"Toggle whether the server under point is replicated in the Emacs Cloud."
......
......@@ -720,11 +720,10 @@ the first newsgroup."
;; Kill Gnus buffers.
(do-auto-save t)
(dolist (buffer (gnus-buffers))
(when (gnus-buffer-exists-p buffer)
(with-current-buffer buffer
(set-buffer-modified-p nil)
(when (local-variable-p 'kill-buffer-hook)
(setq kill-buffer-hook nil))))
(with-current-buffer buffer
(set-buffer-modified-p nil)
(when (local-variable-p 'kill-buffer-hook)
(setq kill-buffer-hook nil)))
(gnus-kill-buffer buffer))
;; Remove Gnus frames.
(gnus-kill-gnus-frames))
......@@ -842,8 +841,7 @@ prompt the user for the name of an NNTP server to use."
"Enter STRING into the dribble buffer.
If REGEXP is given, lines that match it will be deleted."
(when (and (not gnus-dribble-ignore)
gnus-dribble-buffer
(buffer-name gnus-dribble-buffer))
(buffer-live-p gnus-dribble-buffer))
(let ((obuf (current-buffer)))
(set-buffer gnus-dribble-buffer)
(when regexp
......@@ -935,14 +933,13 @@ If REGEXP is given, lines that match it will be deleted."
(set-buffer-modified-p nil)))))
(defun gnus-dribble-save ()
(when (and gnus-dribble-buffer
(buffer-name gnus-dribble-buffer))
(when (buffer-live-p gnus-dribble-buffer)
(with-current-buffer gnus-dribble-buffer
(when (> (buffer-size) 0)
(save-buffer)))))
(defun gnus-dribble-clear ()
(when (gnus-buffer-exists-p gnus-dribble-buffer)
(when (gnus-buffer-live-p gnus-dribble-buffer)
(with-current-buffer gnus-dribble-buffer
(erase-buffer)
(set-buffer-modified-p nil)
......@@ -2726,8 +2723,7 @@ values from `gnus-newsrc-hashtb', and write a new value of
(save-excursion
(if (and (or gnus-use-dribble-file gnus-slave)
(not force)
(or (not gnus-dribble-buffer)
(not (buffer-name gnus-dribble-buffer))
(or (not (buffer-live-p gnus-dribble-buffer))
(zerop (with-current-buffer gnus-dribble-buffer
(buffer-size)))))
(gnus-message 4 "(No changes need to be saved)")
......
......@@ -3519,8 +3519,7 @@ Returns non-nil if the setup was successful."
(dead-name (concat "*Dead Summary "
(gnus-group-decoded-name group) "*")))
;; If a dead summary buffer exists, we kill it.
(when (gnus-buffer-live-p dead-name)
(gnus-kill-buffer dead-name))
(gnus-kill-buffer dead-name)
(if (get-buffer buffer)
(progn
(set-buffer buffer)
......@@ -3622,7 +3621,7 @@ buffer that was in action when the last article was fetched."
(defun gnus-update-summary-mark-positions ()
"Compute where the summary marks are to go."
(save-excursion
(when (gnus-buffer-exists-p gnus-summary-buffer)
(when (gnus-buffer-live-p gnus-summary-buffer)
(set-buffer gnus-summary-buffer))
(let ((spec gnus-summary-line-format-spec)
pos)
......@@ -7326,7 +7325,7 @@ If FORCE (the prefix), also save the .newsrc file(s)."
(gnus-summary-update-info))
(gnus-close-group group)
;; Make sure where we were, and go to next newsgroup.
(when (buffer-live-p (get-buffer gnus-group-buffer))
(when (gnus-buffer-live-p gnus-group-buffer)
(set-buffer gnus-group-buffer))
(unless quit-config
(gnus-group-jump-to-group group))
......@@ -7501,8 +7500,7 @@ The state which existed when entering the ephemeral is reset."
(defun gnus-deaden-summary ()
"Make the current summary buffer into a dead summary buffer."
;; Kill any previous dead summary buffer.
(when (and gnus-dead-summary
(buffer-name gnus-dead-summary))
(when (buffer-live-p gnus-dead-summary)
(with-current-buffer gnus-dead-summary
(when gnus-dead-summary-mode
(kill-buffer (current-buffer)))))
......@@ -7520,7 +7518,7 @@ The state which existed when entering the ephemeral is reset."
(defun gnus-kill-or-deaden-summary (buffer)
"Kill or deaden the summary BUFFER."
(save-excursion
(when (and (buffer-name buffer)
(when (and (buffer-live-p buffer)
(not gnus-single-article-buffer))
(with-current-buffer buffer
(gnus-kill-buffer gnus-article-buffer)
......@@ -7529,12 +7527,12 @@ The state which existed when entering the ephemeral is reset."
;; Kill the buffer.
(gnus-kill-summary-on-exit
(when (and gnus-use-trees
(gnus-buffer-exists-p buffer))
(gnus-buffer-live-p buffer))
(with-current-buffer buffer
(gnus-tree-close)))
(gnus-kill-buffer buffer))
;; Deaden the buffer.
((gnus-buffer-exists-p buffer)
((gnus-buffer-live-p buffer)
(with-current-buffer buffer
(gnus-deaden-summary))))))
......@@ -7605,7 +7603,7 @@ previous group instead."
(and unreads (not (zerop unreads))))
(gnus-summary-read-group
target-group nil no-article
(and (buffer-name current-buffer) current-buffer)
(and (buffer-live-p current-buffer) current-buffer)
nil backward))
(setq entered t)
(setq current-group target-group
......
......@@ -109,12 +109,6 @@ This is a compatibility function for different Emacsen."
(defsubst gnus-goto-char (point)
(and point (goto-char point)))
(defmacro gnus-buffer-exists-p (buffer)
`(let ((buffer ,buffer))
(when buffer
(funcall (if (stringp buffer) 'get-buffer 'buffer-name)
buffer))))
(defun gnus-delete-first (elt list)
"Delete by side effect the first occurrence of ELT as a member of LIST."
(if (equal (car list) elt)
......@@ -562,8 +556,12 @@ If N, return the Nth ancestor instead."
(match-string 1 references))))))
(defsubst gnus-buffer-live-p (buffer)
"Say whether BUFFER is alive or not."
(and buffer (buffer-live-p (get-buffer buffer))))
"If BUFFER names a live buffer, return its object; else nil."
(and buffer (buffer-live-p (setq buffer (get-buffer buffer)))
buffer))
(define-obsolete-function-alias 'gnus-buffer-exists-p
'gnus-buffer-live-p "27.1")
(defun gnus-horizontal-recenter ()
"Recenter the current buffer horizontally."
......
......@@ -270,7 +270,7 @@ See the Gnus manual for an explanation of the syntax used.")
(error "Invalid buffer type: %s" type))
(let ((buf (gnus-get-buffer-create
(gnus-window-to-buffer-helper buffer))))
(when (buffer-name buf)
(when (buffer-live-p buf)
(cond
((eq buf (window-buffer (selected-window)))
(set-buffer buf))
......@@ -430,20 +430,13 @@ See the Gnus manual for an explanation of the syntax used.")
(defun gnus-delete-windows-in-gnusey-frames ()
"Do a `delete-other-windows' in all frames that have Gnus windows."
(let ((buffers (gnus-buffers)))
(mapcar
(lambda (frame)
(unless (eq (cdr (assq 'minibuffer
(frame-parameters frame)))
'only)
(select-frame frame)
(let (do-delete)
(walk-windows
(lambda (window)
(when (memq (window-buffer window) buffers)
(setq do-delete t))))
(when do-delete
(delete-other-windows)))))
(frame-list))))
(dolist (frame (frame-list))
(unless (eq (frame-parameter frame 'minibuffer) 'only)
(select-frame frame)
(when (get-window-with-predicate
(lambda (window)
(memq (window-buffer window) buffers)))
(delete-other-windows))))))
(defun gnus-all-windows-visible-p (split)
"Say whether all buffers in SPLIT are currently visible.
......@@ -491,11 +484,10 @@ should have point."
(nth 1 (window-edges window)))
(defun gnus-remove-some-windows ()
(let ((buffers (gnus-buffers))
buf bufs lowest-buf lowest)
(let (bufs lowest-buf lowest)
(save-excursion
;; Remove windows on all known Gnus buffers.
(while (setq buf (pop buffers))
(dolist (buf (gnus-buffers))
(when (get-buffer-window buf)
(push buf bufs)
(pop-to-buffer buf)
......@@ -506,8 +498,8 @@ should have point."
(when lowest-buf
(pop-to-buffer lowest-buf)
(set-buffer nntp-server-buffer))
(mapcar (lambda (b) (delete-windows-on b t))
(delq lowest-buf bufs)))))
(dolist (b (delq lowest-buf bufs))
(delete-windows-on b t)))))
(defun gnus-get-buffer-window (buffer &optional frame)
"Return a window currently displaying BUFFER, or nil if none.
......
......@@ -665,26 +665,15 @@ be used directly.")
(defmacro gnus-kill-buffer (buffer)
"Kill BUFFER and remove from the list of Gnus buffers."
`(let ((buf ,buffer))
(when (gnus-buffer-exists-p buf)
(when (gnus-buffer-live-p buf)
(kill-buffer buf)
(gnus-prune-buffers))))
(defun gnus-prune-buffers ()
(dolist (buf gnus-buffers)
(unless (buffer-live-p buf)
(setq gnus-buffers (delete buf gnus-buffers)))))
(defun gnus-buffers ()
"Return a list of live Gnus buffers."
(while (and gnus-buffers
(not (buffer-name (car gnus-buffers))))
(pop gnus-buffers))
(let ((buffers gnus-buffers))
(while (cdr buffers)
(if (buffer-name (cadr buffers))
(pop buffers)
(setcdr buffers (cddr buffers)))))
gnus-buffers)
(setq gnus-buffers (seq-filter #'buffer-live-p gnus-buffers)))
(defalias 'gnus-prune-buffers #'gnus-buffers)
;;; Splash screen.
......@@ -3638,9 +3627,8 @@ If SYMBOL, return the value of that symbol in the group parameters.
If you call this function inside a loop, consider using the faster
`gnus-group-fast-parameter' instead."
(with-current-buffer (if (buffer-live-p (get-buffer gnus-group-buffer))
gnus-group-buffer
(current-buffer))
(with-current-buffer (or (gnus-buffer-live-p gnus-group-buffer)
(current-buffer))
(if symbol
(gnus-group-fast-parameter group symbol allow-list)
(nconc
......
......@@ -722,8 +722,7 @@ Deleting old (> %s day(s)) incoming mail file `%s'." diff bfile)
(buffer-string) result))
(error "%s" (buffer-string)))
(setq to nil)))))))
(when (and errors
(buffer-name errors))
(when (buffer-live-p errors)
(kill-buffer errors))
;; Return whether we moved successfully or not.
to)))
......
......@@ -2034,8 +2034,7 @@ see `message-narrow-to-headers-or-head'."
(defmacro message-with-reply-buffer (&rest forms)
"Evaluate FORMS in the reply buffer, if it exists."
`(when (and (bufferp message-reply-buffer)
(buffer-name message-reply-buffer))
`(when (buffer-live-p message-reply-buffer)
(with-current-buffer message-reply-buffer
,@forms)))
......@@ -3229,8 +3228,7 @@ or in the synonym headers, defined by `message-header-synonyms'."
"Widen the reply to include maximum recipients."
(interactive)
(let ((follow-to
(and (bufferp message-reply-buffer)
(buffer-name message-reply-buffer)
(and (buffer-live-p message-reply-buffer)
(with-current-buffer message-reply-buffer
(message-get-reply-headers t)))))
(save-excursion
......@@ -4027,7 +4025,7 @@ It should typically alter the sending method in some way or other."
(let ((buf (current-buffer))
(actions message-exit-actions))
(when (and (message-send arg)
(buffer-name buf))
(buffer-live-p buf))
(message-bury buf)
(if message-kill-buffer-on-exit
(kill-buffer buf))
......@@ -4740,7 +4738,7 @@ that instead."
(if (not (zerop (buffer-size)))
(error "Sending...failed to %s"
(buffer-string))))))
(when (bufferp errbuf)
(when (buffer-live-p errbuf)
(kill-buffer errbuf)))))
(defun message-send-mail-with-qmail ()
......@@ -6377,8 +6375,7 @@ moved to the beginning "
(defun message-pop-to-buffer (name &optional switch-function)
"Pop to buffer NAME, and warn if it already exists and is modified."
(let ((buffer (get-buffer name)))
(if (and buffer
(buffer-name buffer))
(if (buffer-live-p buffer)
(let ((window (get-buffer-window buffer 0)))
(if window
;; Raise the frame already displaying the message buffer.
......@@ -6409,7 +6406,7 @@ moved to the beginning "
(>= (length message-buffer-list) message-max-buffers))
;; Kill the oldest buffer -- unless it has been changed.
(let ((buffer (pop message-buffer-list)))
(when (and (buffer-name buffer)
(when (and (buffer-live-p buffer)
(not (buffer-modified-p buffer)))
(kill-buffer buffer))))
;; Rename the buffer.
......@@ -7376,9 +7373,7 @@ Optional DIGEST will use digest to forward."
(unless (multibyte-string-p contents)
(error "Attempt to insert unibyte string from the buffer \"%s\"\
to the multibyte buffer \"%s\""
(if (bufferp forward-buffer)
(buffer-name forward-buffer)
forward-buffer)
forward-buffer
(buffer-name)))
(insert (mm-with-multibyte-buffer
(insert contents)
......@@ -7440,9 +7435,7 @@ Optional DIGEST will use digest to forward."
(unless (multibyte-string-p contents)
(error "Attempt to insert unibyte string from the buffer \"%s\"\
to the multibyte buffer \"%s\""
(if (bufferp forward-buffer)
(buffer-name forward-buffer)
forward-buffer)
forward-buffer
(buffer-name)))
(insert (mm-with-multibyte-buffer
(insert contents)
......
......@@ -893,8 +893,7 @@ external if displayed external."
(if method
(progn
(when (and (boundp 'gnus-summary-buffer)
(bufferp gnus-summary-buffer)
(buffer-name gnus-summary-buffer))
(buffer-live-p gnus-summary-buffer))
(when attachment-filename
(with-current-buffer mm
(rename-buffer (format "*mm* %s" attachment-filename) t)))
......@@ -1152,9 +1151,8 @@ external if displayed external."
(ignore-errors (delete-file (car object)))
(ignore-errors (delete-directory (file-name-directory
(car object)))))
((bufferp object)
(when (buffer-live-p object)
(kill-buffer object)))))
((buffer-live-p object)
(kill-buffer object))))
(mm-handle-set-undisplayer handle nil))))
(defun mm-display-inline (handle)
......
......@@ -145,10 +145,8 @@
(deffoo nnbabyl-server-opened (&optional server)
(and (nnoo-current-server-p 'nnbabyl server)
nnbabyl-mbox-buffer
(buffer-name nnbabyl-mbox-buffer)
nntp-server-buffer
(buffer-name nntp-server-buffer)))
(buffer-live-p nnbabyl-mbox-buffer)
(buffer-live-p nntp-server-buffer)))
(deffoo nnbabyl-request-article (article &optional newsgroup server buffer)
(nnbabyl-possibly-change-newsgroup newsgroup server)
......@@ -452,8 +450,7 @@
(when (and server
(not (nnbabyl-server-opened server)))
(nnbabyl-open-server server))
(when (or (not nnbabyl-mbox-buffer)
(not (buffer-name nnbabyl-mbox-buffer)))
(unless (buffer-live-p nnbabyl-mbox-buffer)
(save-excursion (nnbabyl-read-mbox)))
(unless nnbabyl-group-alist
(nnmail-activate 'nnbabyl))
......@@ -556,8 +553,7 @@
(nnmail-activate 'nnbabyl)
(nnbabyl-create-mbox)
(unless (and nnbabyl-mbox-buffer
(buffer-name nnbabyl-mbox-buffer)
(unless (and (buffer-live-p nnbabyl-mbox-buffer)
(with-current-buffer nnbabyl-mbox-buffer
(= (buffer-size) (nnheader-file-size nnbabyl-mbox-file))))
;; This buffer has changed since we read it last. Possibly.
......@@ -627,8 +623,7 @@
(let ((idents (gnus-make-hashtable 1000))
id)
(save-excursion
(when (or (not nnbabyl-mbox-buffer)
(not (buffer-name nnbabyl-mbox-buffer)))
(unless (buffer-live-p nnbabyl-mbox-buffer)
(nnbabyl-read-mbox))
(set-buffer nnbabyl-mbox-buffer)
(goto-char (point-min))
......
......@@ -1015,7 +1015,7 @@ all. This may very well take some time.")
(defun nndiary-save-nov ()
(save-excursion
(while nndiary-nov-buffer-alist
(when (buffer-name (cdar nndiary-nov-buffer-alist))
(when (buffer-live-p (cdar nndiary-nov-buffer-alist))
(set-buffer (cdar nndiary-nov-buffer-alist))
(when (buffer-modified-p)
(nnmail-write-region 1 (point-max) nndiary-nov-buffer-file-name
......
......@@ -309,8 +309,7 @@ from the document.")
(deffoo nndoc-close-group (group &optional server)
(nndoc-possibly-change-buffer group server)
(and nndoc-current-buffer
(buffer-name nndoc-current-buffer)
(and (buffer-live-p nndoc-current-buffer)
(kill-buffer nndoc-current-buffer))
(setq nndoc-group-alist (delq (assoc group nndoc-group-alist)
nndoc-group-alist))
......@@ -335,8 +334,7 @@ from the document.")
(let (buf)
(cond
;; The current buffer is this group's buffer.
((and nndoc-current-buffer
(buffer-name nndoc-current-buffer)
((and (buffer-live-p nndoc-current-buffer)
(eq nndoc-current-buffer
(setq buf (cdr (assoc group nndoc-group-alist))))))
;; We change buffers by taking an old from the group alist.
......@@ -344,8 +342,7 @@ from the document.")
(buf
(setq nndoc-current-buffer buf))
;; It's a totally new group.
((or (and (bufferp nndoc-address)
(buffer-name nndoc-address))
((or (buffer-live-p nndoc-address)
(and (stringp nndoc-address)
(file-exists-p nndoc-address)
(not (file-directory-p nndoc-address))))
......
......@@ -328,8 +328,7 @@ all. This may very well take some time.")
(delq inf nnfolder-buffer-alist))
(setq nnfolder-current-buffer (cadr inf)
nnfolder-current-group (car inf))))
(when (and nnfolder-current-buffer
(buffer-name nnfolder-current-buffer))
(when (buffer-live-p nnfolder-current-buffer)
(with-current-buffer nnfolder-current-buffer
;; If the buffer was modified, write the file out now.
(nnfolder-save-buffer)
......@@ -1110,7 +1109,7 @@ This command does not work if you use short group names."
(defun nnfolder-save-nov ()
(save-excursion
(while nnfolder-nov-buffer-alist
(when (buffer-name (cdar nnfolder-nov-buffer-alist))
(when (buffer-live-p (cdar nnfolder-nov-buffer-alist))
(set-buffer (cdar nnfolder-nov-buffer-alist))
(when (buffer-modified-p)
(gnus-make-directory (file-name-directory
......
......@@ -346,7 +346,7 @@ textual parts.")
(with-current-buffer
(generate-new-buffer (format " *nnimap %s %s %s*"