Last active

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

ibuffer grouping support for persp-mode

View persp-mode-ibuffer-groups.el
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
;; Simplified variant. Add only current perspective group.
 
(with-eval-after-load "ibuffer"
 
(require 'ibuf-ext)
 
(define-ibuffer-filter persp
"Toggle current view to buffers of current perspective."
(:description "persp-mode"
:reader (persp-prompt (safe-persp-name (get-frame-persp)) t))
(find buf (safe-persp-buffers (persp-get-by-name qualifier))))
 
(defun persp-update-or-add-ibuffer-group ()
(let ((perspslist (list (safe-persp-name (get-frame-persp))
(cons 'persp (safe-persp-name (get-frame-persp))))))
(setq ibuffer-saved-filter-groups
(delete* "persp-mode" ibuffer-saved-filter-groups
:test 'string= :key 'car))
(add-to-list 'ibuffer-saved-filter-groups (list "persp-mode" perspslist))))
 
(add-hook 'ibuffer-mode-hook
#'(lambda ()
(persp-update-or-add-ibuffer-group)
(ibuffer-switch-to-saved-filter-groups "persp-mode"))))
 
 
;; Shows groups for all perspectives. But can't show same buffer in multiple groups.
 
(with-eval-after-load "ibuffer"
 
(require 'ibuf-ext)
 
(define-ibuffer-filter persp
"Toggle current view to buffers of current perspective."
(:description "persp-mode"
:reader (persp-prompt (safe-persp-name (get-frame-persp)) t))
(find buf (safe-persp-buffers (persp-get-by-name qualifier))))
 
(defun persp-update-or-add-ibuffer-group ()
(let ((perspslist (mapcar #'(lambda (pn)
(list pn (cons 'persp pn)))
(persp-names-sorted))))
(setq ibuffer-saved-filter-groups
(delete* "persp-mode" ibuffer-saved-filter-groups
:test 'string= :key 'car))
(add-to-list 'ibuffer-saved-filter-groups (cons "persp-mode" perspslist))))
 
(add-hook 'ibuffer-mode-hook
#'(lambda ()
(persp-update-or-add-ibuffer-group)
(ibuffer-switch-to-saved-filter-groups "persp-mode"))))
 

First of all: Thanks for this fast implementation

Second: Since I'm really new to clojure, emacs, elisp and all, please forgive me if the following part contains somewhat 'stupid' stuff ;)

Third (because I am sure about that): there is a typo in the description of the filter pers-mode -> persp-mode

Fourth: This is just a snippet and shouldn't work, right? (Otherwise something is wrong with my setup and/or my current knowledge about (e)lisp)

Fifth: where does ibuf-ext come from or what does it do? it is mentioned on emacswiki (http://www.emacswiki.org/emacs/IbufferMode), but google didn't find anything else about it. The same is true for delete*. Where can I find out more about things like this?

Sixth: I don't understand everything, but if it does (will do) what I think it does, that would be great. Another idea: what about grouping all buffers by all (active) perspectives? That would allow for cleaning up all perspectives at once. (Don't know if it is a problem if some appear twice)

Looks great and works like a charm!! Thanks for that and the hint over there. I actually didn't get a change notification..
I still don't fully understand it, because of missing documentation of the functions used, but I see the idea for showing all perspectives was not mine ;)
One more question: is it possible to show the same buffer multiple times? i.e. the same file opened in different perspectives. Don't even know if that would be good, but I think about a situation where I only should remove a buffer from a perspective rather than closing it.
Many thanks!

Owner

@LiFlash

is it possible to show the same buffer multiple times?

seems like ibuffer don't support it. :(

where does ibuf-ext come from

it's part of ibuffer where some additional functions and variables defined, that must be imported before defining new ibuffer filters with define-ibuffer-filter.

delete*

You can read function documentation with: C-h f delete*(in case if you don't know); C-h k to find what function binded to key or key sequence, for example C-h k M-x.
I found function delete* with google query: 'elisp remove assoc', and next step from google's search result was -- http://stackoverflow.com/a/9812591/1171163

Hi @Bad-ptr,

sorry that I didn't write earlier. Even though you mentioned my name I didn't get a mail :(

seems like ibuffer don't support it. :(

Ok, but thank you very much for trying. In the end this situation should not occur very often.

You can read function documentation with: C-h f delete*

facepalm again. I only googled it and there was nothing found.
One question to the behaviour of persp-mode: When starting emacs (and automatically restoring the files), the individual major- and minor-mode hooks are not executed, right? I'm not sure about this, because some things already work when starting, others only work when manually loading a new file (e.g. a clj file -> clojure mode hooks).
And one last question: Will you merge this gist into persp-mode?

Greetings,

Joe

Owner

Even though you mentioned my name I didn't get a mail :(

Looks like there is no notifications on gist.github.com . I wasn't notified about your comments too.

When starting emacs (and automatically restoring the files), the individual major- and minor-mode hooks are not executed, right?

Yes, hooks is something like event handlers.
Mode hooks are run when something 'enables' mode. You can do it manually through M-x: my-mode or it could be enabled in config (my-mode).
When you open file(or file opened from elisp code, for example when restoring perspectives) emacs matches filename against entries in auto-mode-alist and sets matched major mode for buffer, major mode hooks must be executed at that point.

Will you merge this gist into persp-mode?

Don't know, I think it would be better if it stay separate as it seems that not many people need it and it don't work well(can't show same buffer in multiple perspectives, and more it can't properly kill buffer that not in your current perspective).

When you open file(or file opened from elisp code, for example when restoring perspectives) emacs matches filename against entries in auto-mode-alist and sets matched major mode for buffer, major mode hooks must be executed at that point.

Yes, I thought it works like that. So there should be no difference between opening a file by hand and persp-mode opening them (i.e. restoring a perspective)? So I will have a look into the setup...

(can't show same buffer in multiple perspectives, and more it can't properly kill buffer that not in your current perspective)

Good point. So I will treat it as a personal gift ;)
Thank's again for all your help. Because of people like you I already love this community :)

Greetings

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.