"Leave only (1) this buffer from all the indirect ones sharing the same base and (2) the base buffer itself."
(defun my-kill-other-indirect-bufs ()
"Kill all indirect buffers other than the current buffer."
(interactive)
(dolist (buf (buffer-list))
(when (and (buffer-base-buffer buf) (not (eq (current-buffer) buf)))
(kill-buffer buf))))
If you use Icicles then the commands that provide completion for buffer names let you use C-x i -
and C-x i +
to remove and keep only, respectively, indirect buffers.
This is one of a set of on-the-fly filtering keys for buffer-name candidates. You can add to or remove from this set by customizing option icicle-buffer-candidate-key-bindings
.
For example, you could add a key that filters to show only indirect buffers other than the current one, and then you could use multi-command icicle-kill-buffer
(bound to C-x k
in Icicle mode, by default) to kill all such buffers.
You would just add an entry such as this to icicle-buffer-candidate-key-bindings
:
Key: C-x I
Command: my-remove-buffer-cands-for-other-indirect
Condition: t
Where command my-remove-buffer-cands-for-other-indirect
would be, e.g.:
(defun my-remove-buffer-cands-for-other-indirect ()
"Remove buffer-name candidates for indirect buffers except current."
(interactive)
(setq icicle-must-pass-after-match-predicate
(lambda (buf) (or (eq (current-buffer) (get-buffer buf))
(not (buffer-base-buffer (get-buffer buf))))))
(icicle-complete-again-update))
That filters buffer-name completion candidates to allow only the current buffer and non-indirect buffers.