Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: Perspective-specific next/prev buffer switch #63

Closed
Ailrun opened this issue Dec 20, 2016 · 9 comments
Closed

Feature Request: Perspective-specific next/prev buffer switch #63

Ailrun opened this issue Dec 20, 2016 · 9 comments

Comments

@Ailrun
Copy link

Ailrun commented Dec 20, 2016

At least I know, perspective doesn't have features that is like switch-to-next-buffer or switch-to-prev-buffer using specific perspective.

In detail, there is no simple way to change C-x <C-left> (switch-to-prev-buffer) to perspective-relative one.
For example, suppose that I have 2 perspective perspA and perspB, and there are 5 buffers in perspA, and there are 7 buffers in perspB. In this case, I can't traverse my buffers only which are in perspA, and while traversing, all buffers of perspB will join to perspA and everything is messed up.

Could you add these features(next/prev) to this wonderful package?

@inigoserna
Copy link

inigoserna commented Aug 15, 2017

I use these functions to achieve the same behaviour you are asking for:

(defun isr/persp-get-buffers-list ()
  "Get filtered list of buffers, sorted alphabetically."
  (sort
   (cl-remove-if '(lambda (b) (if (stringp b) (string-match "^\[* \]" b) t))
                 (mapcar 'buffer-name (persp-buffers persp-curr)))
   'string<))

(defun isr/persp-next-buffer ()
  "My own version of `next-buffer'. Don't show internal buffers."
  (interactive)
  (let ((buffername (buffer-name (current-buffer)))
        (bufferlist (isr/persp-get-buffers-list)))
    (switch-to-buffer (or (cadr (member buffername bufferlist)) (car bufferlist)))))

(defun isr/persp-previous-buffer ()
  "My own version of `next-buffer'. Don't show internal buffers"
  (interactive)
  (let ((buffername (buffer-name (current-buffer)))
        (bufferlist (reverse (isr/persp-get-buffers-list))))
    (switch-to-buffer (or (cadr (member buffername bufferlist)) (car bufferlist)))))

@Ailrun
Copy link
Author

Ailrun commented Aug 21, 2017

@inigoserna
Thx for your info! I will try it!
Why don't you send a PR?

@inigoserna
Copy link

IMO it's a personal customization, not something everyone could be interested in.

@Ailrun
Copy link
Author

Ailrun commented Aug 26, 2017

But it's useful to have, isn't it?

@inigoserna
Copy link

Well, I use it daily ;)

@Ailrun
Copy link
Author

Ailrun commented Aug 27, 2017

@inigoserna I mean, it's useful, so there's worth to send a PR with this feature, isn't it?

@tonycpsu
Copy link

Looking for something like this myself, and the functions above seem to not be compatible with current versions of perspective. I'm getting Symbol’s value as variable is void: persp-curr.

@gcv
Copy link
Collaborator

gcv commented Jan 28, 2020

A few thoughts on this.

To address @tonycpsu's comment about @inigoserna's code not working with current Perspective. You can fix it by changing persp-curr to (persp-curr). If that's the functionality you want, that should be enough.

However, I don't think that code really does the right thing with regard to going to the "next" or "previous" buffer. Since it sorts buffers alphabetically, it actually goes to the next or previous buffer in alphabetical order, not in chronological last-viewed order as the Emacs built-in switch-to-next-buffer and switch-to-previous-buffer do.

Writing an implementation of persp-next-buffer and persp-previous-buffer which does the right thing with regard to chronological sorting is tricky. The equivalent Emacs built-ins are quite complex (and IMO have bad behavior with regard to uninteresting and temporary buffers anyway), and I don't see an easy way to make them respect Perspective.

I recently added Perspective-aware implementations of several buffer switchers, in addition to the Ido support which has been available for a long time. See the updated README for details. Would those work instead of a mechanism for iterating through all of a perspective's buffers in a given window?

@gcv
Copy link
Collaborator

gcv commented Feb 13, 2020

Closing this unless someone convinces me that Perspective-aware buffer switchers are inadequate, and that there's a reasonably simple implementation path.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants