crux
crux copied to clipboard
including dired in crux-kill-other-buffers
Hi,
I think it is good idea to consider dired buffers in crux-kill-other-buffers
function:
Something like this:
(defun kill-dired-buffers ()
(interactive)
(mapc (lambda (buffer)
(when (eq 'dired-mode (buffer-local-value 'major-mode buffer))
(kill-buffer buffer)))
(buffer-list)))
Thanks Levis
You want a command to kill just buffers with a particular major mode or what?
Let me explain it with one example.
Consider that your current file is main.cpp
and you have a total of 6 buffers open:
mean.cpp, header.h, src, project, *scratch*, *Messsages*
If you call crux-kill-other-buffers
only header.h
will be killed.
I think it is also good idea to kill src
and project
which are dired buffers.
One possible solution is like you said, considering the setup of a particular major mode in crux-kill-other-buffers
I also need crux command. something like crux-kill-other-dirs
any updates regarding this feature request ?
For now I can use
-
list buffer from helm
-
select all buffer
-
delete
-
C-x b
-
C-u
C-SPACE -
M-S-D
@mambolevis maybe you need this
(defun kill-other-buffers ()
"Kill all other buffers."
(interactive)
(mapc 'kill-buffer (delq (current-buffer) (buffer-list))))
Taken from Kill Other Buffers
But it will kill everything. crux-kill-other-buffers doesn't kill everything. Because it use (seq-filter #'buffer-file-name (buffer-list))
which will only return 'visited-buffer'. So that the dired buffer doesn't get kill.
The above code will kill everything. Because it just kill whatever (buffer-list)
return. I come with my own solution:
(require 'cl)
;;;###autoload
(defun noprompt-kill-buffers ()
"Kill buffers matching REGEXP without asking for confirmation."
(interactive)
(flet ((kill-buffer-ask (buffer) (kill-buffer buffer)))
(kill-matching-buffers "^[^\*]"))) ;;all buffers that doesn't start with *
I think I can improve the regex value to make it more robust.
Update:
Fresh new version :)
;;;###autoload
(defun aza-kill-other-buffers ()
"Kill all buffers but current buffer and special buffers"
(interactive)
(dolist (buffer (delq (current-buffer) (buffer-list)))
(let ((name (buffer-name buffer)))
(when (string-match "^[^\*]" name)
(funcall 'kill-buffer buffer)))))