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

Filter buffers with functions. #382

Closed
wants to merge 1 commit into
base: master
from

Conversation

Projects
None yet
2 participants
@Bad-ptr
Contributor

Bad-ptr commented Feb 9, 2016

This is more flexible.
Hope it will fit int 15 lines limit.)
And here is a suggestion of how to improve this -- Create a named function to check if a buffer name is matching against ignored regexps(ivy--is-buffer-name-ignored-by-regex-p), add the :set function to the ivy-ignore-buffers variable, inside :set check if the new value is nil -- then remove that function(ivy--is-buffer-name-ignored-by-regex-p) from the ivy-ignore-buffer-functions, if non nil -- add it.

@abo-abo

This comment has been minimized.

Show comment
Hide comment
@abo-abo

abo-abo Feb 9, 2016

Owner

(defcustom ido-ignore-buffers
'("`")
"List of regexps or functions matching buffer names to ignore.
For example, traditional behavior is not to list buffers whose names begin
with a space, for which the regexp is\\= '. See the source file for
example functions that filter buffer names."
:type '(repeat (choice regexp function))
:group 'ido)

Why not just extend ivy-ignore-buffers to behave this way? Currently, it's a list of regexes. It should be a list of regexes or functions.

Owner

abo-abo commented Feb 9, 2016

(defcustom ido-ignore-buffers
'("`")
"List of regexps or functions matching buffer names to ignore.
For example, traditional behavior is not to list buffers whose names begin
with a space, for which the regexp is\\= '. See the source file for
example functions that filter buffer names."
:type '(repeat (choice regexp function))
:group 'ido)

Why not just extend ivy-ignore-buffers to behave this way? Currently, it's a list of regexes. It should be a list of regexes or functions.

@Bad-ptr

This comment has been minimized.

Show comment
Hide comment
@Bad-ptr

Bad-ptr Feb 9, 2016

Contributor

Good point.
And I have found that this filtering works only for switching buffers(C-x b), and it does not work for kill-buffer(C-x k) for example. Do you have any plans or thoughts about a "global" candidate filtering?

Contributor

Bad-ptr commented Feb 9, 2016

Good point.
And I have found that this filtering works only for switching buffers(C-x b), and it does not work for kill-buffer(C-x k) for example. Do you have any plans or thoughts about a "global" candidate filtering?

@abo-abo

This comment has been minimized.

Show comment
Hide comment
@abo-abo

abo-abo Feb 9, 2016

Owner

Do you have any plans or thoughts about a "global" candidate filtering?

Currently, the filtering works only for ivy-switch-to-buffer specifically.

  1. It could be made to work globally by checking if the collection is internal-complete-buffer.
  2. Or I could write ivy-kill-buffer and remap kill-buffer to that.

The first choice sounds kind of good since it's "supposed" to work for all completion sessions that use internal-complete-buffer. However, it sprinkles collection-specific code into the global code. And stuff like multi-actions / ivy-resume / ivy-occur won't work.

The second choice leads to cleaner and more useful code, but requires to remap every single command that uses internal-complete-buffer to ivy.

I'm inclined to go with the second choice. How many commands to you know that use buffer completion?

Owner

abo-abo commented Feb 9, 2016

Do you have any plans or thoughts about a "global" candidate filtering?

Currently, the filtering works only for ivy-switch-to-buffer specifically.

  1. It could be made to work globally by checking if the collection is internal-complete-buffer.
  2. Or I could write ivy-kill-buffer and remap kill-buffer to that.

The first choice sounds kind of good since it's "supposed" to work for all completion sessions that use internal-complete-buffer. However, it sprinkles collection-specific code into the global code. And stuff like multi-actions / ivy-resume / ivy-occur won't work.

The second choice leads to cleaner and more useful code, but requires to remap every single command that uses internal-complete-buffer to ivy.

I'm inclined to go with the second choice. How many commands to you know that use buffer completion?

@Bad-ptr

This comment has been minimized.

Show comment
Hide comment
@Bad-ptr

Bad-ptr Feb 9, 2016

Contributor

It could be made to work globally by checking if the collection is internal-complete-buffer

Yes, but a more general approach will be something like what the helm is doing:
helm-mode.el#L29
helm-mode.el#L683
This allows to override the read function to be used based on the current-command(in ivy terms it will be the caller ivy.el#L1137 as I understand). I think that this is the right place to do the filtering, and we can decide what filters to apply depending on caller.

Or I could write ivy-kill-buffer and remap kill-buffer to that.

Yes, you can). I don't know which variant is better.

How many commands to you know that use buffer completion?

Actually it will be any command that use the read-buffer internally(including user/side library defined commands).

Contributor

Bad-ptr commented Feb 9, 2016

It could be made to work globally by checking if the collection is internal-complete-buffer

Yes, but a more general approach will be something like what the helm is doing:
helm-mode.el#L29
helm-mode.el#L683
This allows to override the read function to be used based on the current-command(in ivy terms it will be the caller ivy.el#L1137 as I understand). I think that this is the right place to do the filtering, and we can decide what filters to apply depending on caller.

Or I could write ivy-kill-buffer and remap kill-buffer to that.

Yes, you can). I don't know which variant is better.

How many commands to you know that use buffer completion?

Actually it will be any command that use the read-buffer internally(including user/side library defined commands).

@Bad-ptr

This comment has been minimized.

Show comment
Hide comment
@Bad-ptr

Bad-ptr Feb 9, 2016

Contributor

And about the ivy-ignore-buffers. If it will be a mixed list of regexps/functions then in the filter function there will be an if with a check that the current item of the ivy-ignore-buffers is function or not, for every item in the list. It will be not as efficient as a function list, but maybe this is a premature optimisation).

Contributor

Bad-ptr commented Feb 9, 2016

And about the ivy-ignore-buffers. If it will be a mixed list of regexps/functions then in the filter function there will be an if with a check that the current item of the ivy-ignore-buffers is function or not, for every item in the list. It will be not as efficient as a function list, but maybe this is a premature optimisation).

@abo-abo abo-abo closed this in e92d282 Mar 21, 2016

@abo-abo

This comment has been minimized.

Show comment
Hide comment
@abo-abo

abo-abo Mar 21, 2016

Owner

Sorry for the late response. I was just going through the PR list and yours looks good. Thanks for the contribution.

Owner

abo-abo commented Mar 21, 2016

Sorry for the late response. I was just going through the PR list and yours looks good. Thanks for the contribution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment