9

I'd like to group my buffer list in ibuffer by project. Project is meant in the Projectile sense of the word.

I don't want to change my Emacs configuration every time I'm working on a new project. Is there a way to achieve this automatically?

ckruse
  • 457
  • 3
  • 12

3 Answers3

5

Project is meant in the Projectile sense of the word.

Using Projectile, there is a way to switch to a buffer inside a specific project C-c p b

May I suggest ibuffer-vc? A way to group your buffers by their parent vc root directory.

Nsukami _
  • 6,341
  • 2
  • 22
  • 35
  • `ibuffer-vc` is pretty near to what I'm looking for. But it overwrites my `ibuffer-saved-filter-groups`; is there a way to create the VC groups additionally to my standard groups? – ckruse Oct 15 '14 at 07:24
  • @ckruse do not know; let me dig please. – Nsukami _ Oct 15 '14 at 12:38
  • This might help: https://github.com/reinh/dotemacs/blob/master/conf/init.org#ido. Specifically the part beginning `nox/ibuffer-apply-filter-groups`. – tirocinium May 12 '17 at 12:33
5

You can define filter groups for known projects using something like this:

;; Define ibuffer filter groups for each known project
(defun my/define-projectile-filter-groups ()
  (when (boundp 'projectile-known-projects)
    (setq my/project-filter-groups
        (mapcar
         (lambda (it)
           (let ((name (file-name-nondirectory (directory-file-name it))))
             `(,name (filename . ,(expand-file-name it)))))
         projectile-known-projects))))

;; Set up default ibuffer filter groups
(setq ibuffer-saved-filter-groups
      (list
       (cons "default"
             (append
              (my/define-projectile-filter-groups)
              ;; ... whatever other groups you want, e.g.
              '(("dired" (mode . dired-mode))
                ("erc" (mode . erc-mode)))
              ))))

;; Enable default groups by default
(add-hook 'ibuffer-mode-hook
              (lambda ()
                (ibuffer-switch-to-saved-filter-groups "default")))

;; You probably don't want to see empty project groups
(setq ibuffer-show-empty-filter-groups nil)

Update

Since I originally wrote this answer, @sanityinc has created a variant of ibuffer-vc that creates filter groups by projectile project root. You can find ibuffer-projectile on MELPA or on GitHub.

glucas
  • 20,175
  • 1
  • 51
  • 83
  • This is exaktly what I've been looking for, thanks! – ckruse Oct 16 '14 at 07:23
  • This could be merged into Projectile. – Tu Do Oct 16 '14 at 08:43
  • Yes, I should submit a pull request to support ibuffer groups. It came up once before but I didn't follow up. :D I'll take a closer look, it might make more sense to do something like ibuffer-vc and build the groups based on current buffers rather than the known project list. But a simple option would be to have projectile define a named filter group from known projects as shown here. – glucas Oct 16 '14 at 14:27
  • As @Silex noted in another answer, someone already added ibuffer support earlier this year -- I had missed that. It's a different approach in that it filters ibuffer for the current project only, but looks handy. – glucas Oct 16 '14 at 14:35
  • @glucas well but I think the current Ibuffer behaviors in Projectile is redundant with `projectile-switch-buffer`. Ibuffer is meant for managing large amount of buffers, and that's why it has grouping and filtering. I like the current approach that it groups based on known project list, making it more consistent with Projectile. – Tu Do Oct 18 '14 at 16:13
  • @tu-du Yes, I prefer having a way to group by project rather than only filter by project. My simplistic approach of creating a group per known project could be improved by creating groups on the fly based on the open buffers list. That would avoid having lots of empty projects; and would also work when you create a new project that wasn't known when you first started ibuffer. – glucas Oct 20 '14 at 14:47
3

Using projectile, you can simply type C-c p I (projectile-ibuffer) and only the buffers for that project will show up in ibuffer.

Silex
  • 801
  • 6
  • 6