Bad-ptr / persp-mode.el

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

C-x m composes a message in a different perspective to the frame #34

Open russell opened 8 years ago

russell commented 8 years ago

Hi,

When i press C-x m it starts to compose a message, the message ends up in the nil perspective, and the frame is in still in my current perspective. This totally confuses things because when I try to kill the buffer or do anything, it's in the wrong perspective so the current buffer is omitted from the list.

get-buffer-create seems to be the low level function being used to create the buffer, but I'm not sure how to advise it to work with persp-mode.

Bad-ptr commented 8 years ago

Hello.

You can achieve what you want in 3 ways: 1) Using the after-change-major-mode-hook(not sure if it will work for all cases):

(add-hook 'after-change-major-mode-hook
          #'(lambda ()
              (let ((buf (current-buffer)))
                (unless (string-prefix-p " " (buffer-name buf))
                  (persp-add-buffer buf)))))

2) By advising the switch-to-buffer function(not sure if it will work for all cases): https://github.com/Bad-ptr/persp-mode.el#switch-to-buffer-display-buffer-hook-and-other-advices

3)

get-buffer-create seems to be the low level function being used to create the buffer, but I'm not sure how to advise it

This will work for most cases, I think, but will be triggered very frequently:

(defadvice get-buffer-create (after persp-add-buffer-after-get-buffer-create activate)
  (let ((buf ad-return-value))
    (unless (string-prefix-p " " (buffer-name buf))
      (persp-add-buffer buf))))
Bad-ptr commented 8 years ago

Another variants... buffer-list-update-hook(called very frequently), advising set-window-buffer.