Bad-ptr / persp-mode.el

named perspectives(set of buffers/window configs) for emacs
403 stars 44 forks source link

`with-persp-buffer-list` not working #14

Closed nandryshak closed 9 years ago

nandryshak commented 9 years ago

I'm trying to use this macro with next/previous-buffer, like this:

(global-set-key (kbd "<right>") (lambda ()
                                    (interactive)
                                    (with-persp-buffer-list () (next-buffer))))

But it's switching to buffers that aren't part of the current perspective. Is this broken? Or am I doing something wrong?

Bad-ptr commented 9 years ago

No, it works.) But the next-buffer uses the window-prev-buffer function to get a list of buffers. And I think it is a good idea to filter previous buffer lists for all windows when switching perspective... so I will implement this shortly.

For now you could add to your config something like this:

(add-hook 'persp-activated-hook
                 #'(lambda ()
                    (let ((pbs (safe-persp-buffers (get-frame-persp))))
                      (mapc #'(lambda (w)
                                (set-window-prev-buffers
                                 w
                                 (delete-if-not
                                  #'(lambda (bl)
                                      (memq (typecase bl
                                              (cons (car bl))
                                              (t bl))
                                            pbs))
                                  (window-prev-buffers w)))
                                (set-window-next-buffers
                                 w
                                 (delete-if-not
                                  #'(lambda (bl)
                                      (memq (typecase bl
                                              (cons (car bl))
                                              (t bl))
                                            pbs))
                                  (window-next-buffers w))))
                            (window-list)))))

Then restart emacs (or execute this code(using M-x ielm, or with eval-region or another method), then switch to another perspective and switch back), and now your binding must be working.

Bad-ptr commented 9 years ago

This is possibly fixed by a89c9c18140302052a69182210219e9147dd5202.