Bad-ptr / persp-mode.el

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

Switch buffers hides special buffers #67

Closed vkz closed 7 years ago

vkz commented 7 years ago

Normally I'd say hiding special buffers is great, so as to avoid Magit and friends polluting your workspace. But I can't figure out how to get my Dired buffers. When I switch buffers they don't show up and I was unable to uncover where they go. I don't have any special auto-perspectives setup. Thought maybe persp-common-buffer-filter-functions was doing some funky filtering, but not so. How do I get some of those special buffers back? Thanks

Bad-ptr commented 7 years ago

What completion system(ido/ivy/helm) are you using? Can you provide an example of what you want starting from emacs -Q? See the persp-toggle-read-buffer-filter-keys variable and try to press this key sequence when emacs waits for a buffer name from you.

vkz commented 7 years ago

I use ivy, but running in a clean env with emacs -Q seems to result in the same behavior:

I am able to explicitly add dired buffers to a perspective, then they do show up.

Unfortunately, I couldn't get persp-toggle-read-buffer-filter-keys to work. C-x C-p is shadowed by mark-page but even when global-undefined it seems to have no effect. Setting persp-toggle-read-buffer-filter-keys to another key-binding seems to have no effect either. Is it because these are marked obsolete? 🤷‍♂️

Bad-ptr commented 7 years ago

Ok, I see now.) It was a bug. Can you test develop branch, please? https://github.com/Bad-ptr/persp-mode.el/tree/develop

Is it because these are marked obsolete

You are right, it is now controlled by persp-read-multiple-keys.

vkz commented 7 years ago

Doesn't look like it makes a difference. But glad it wasn't just me going mad :)

vkz commented 7 years ago

So, here're some findings. Please, tell me if this sheds any light on the investigation. I manually edebugged the two functions that are supposed to be triggered by hooks and ostensibly add just opened buffer to current perspective as a result:

which tells me that the find-file-hook must never even run for dired buffers? Weird, but there we are. I did manage to trigger persp-add-buffer on special buffers by setting persp-add-buffer-on-after-change-major-mode to, say, 'free, so that when after-major-mode-change-hook fires persp-add-buffer is called. This works, but I suspect I've abused some emacs internals. Perhaps you can suggest a proper solution.

Bad-ptr commented 7 years ago

the find-file-hook must never even run for dired buffers?

Yes, because find-file-hook only run when you open a file(using find-file or find-file-noselect). Dired buffers are created by create-buffer and they doesn't visit any file. There is no hook to catch create-buffer, except the buffer-list-update-hook, but it runs too frequently.

by setting persp-add-buffer-on-after-change-major-mode to, say, 'free, so that when after-major-mode-change-hook fires persp-add-buffer is called. This works, but I suspect I've abused some emacs internals. Perhaps you can suggest a proper solution.

I think this is the best solution if you want to add all created buffers to current perspective.

Doesn't look like it makes a difference

Maybe I was not clear what I want you to check). I believe that I fixed C-x C-p(while reading buffer) in develop branch. I use ivy and it works for me. Does it really don't work for you?

vkz commented 7 years ago

I think bringing some special buffers by setting after-major-mode-change-hook works well. Of course this keeps bringing ephemeral stuff like *magit ...* buffers into perspective, which can be solved by:

(add-hook 'persp-common-buffer-filter-functions
            #'(lambda (b) (string-prefix-p "*" (buffer-name b))))

Since there could be other persp-mode users who'd like similar behavior and, in fact, may be puzzled whet they don't find some buffers in their perspectives, I would suggest adding a note and relevant code-snippets to the README. What do you think? If this is of interest I'll write it up and submit a PR.

Bad-ptr commented 7 years ago

If this is of interest I'll write it up and submit a PR.

Yes, I think this will be useful. I will welcome your contribution.