Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

including dired in crux-kill-other-buffers #49

Open
mambolevis opened this issue Sep 1, 2017 · 6 comments
Open

including dired in crux-kill-other-buffers #49

mambolevis opened this issue Sep 1, 2017 · 6 comments

Comments

@mambolevis
Copy link

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

@bbatsov
Copy link
Owner

bbatsov commented Dec 30, 2017

You want a command to kill just buffers with a particular major mode or what?

@mambolevis
Copy link
Author

mambolevis commented Dec 30, 2017

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

@azzamsa
Copy link

azzamsa commented May 14, 2018

I also need crux command. something like crux-kill-other-dirs

@azzamsa
Copy link

azzamsa commented Aug 19, 2018

any updates regarding this feature request ?

@azzamsa
Copy link

azzamsa commented Aug 22, 2018

For now I can use

  1. list buffer from helm

  2. select all buffer

  3. delete

  4. C-x b

  5. C-u C-SPACE

  6. M-S-D

@azzamsa
Copy link

azzamsa commented Sep 22, 2018

@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)))))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants