Git Product home page Git Product logo

Comments (6)

bbatsov avatar bbatsov commented on June 19, 2024

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

from crux.

mambolevis avatar mambolevis commented on June 19, 2024

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

from crux.

azzamsa avatar azzamsa commented on June 19, 2024

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

from crux.

azzamsa avatar azzamsa commented on June 19, 2024

any updates regarding this feature request ?

from crux.

azzamsa avatar azzamsa commented on June 19, 2024

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

from crux.

azzamsa avatar azzamsa commented on June 19, 2024

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

from crux.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.