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

Is it possible to apply file masks to counsel search without modifying the base command? #1688

Closed
ztlevi opened this issue Jul 31, 2018 · 10 comments

Comments

@ztlevi
Copy link

ztlevi commented Jul 31, 2018

I am wondering if we have an existing feature supports file masks during searching using counsel. A similar example is rgrep.

I don't see any customizable options there for counsel file masks. But I feel like this is really useful.

@basil-conto
Copy link
Collaborator

basil-conto commented Jul 31, 2018

Counsel is a library providing multiple search commands (e.g. counsel-ag), are you asking that they all provide a uniform interface to specifying tool-specific file-filtering flags? I think that this won't be worth implementing after #1559 lands. If that's not what you meant, can you please be more specific / provide more details of what exactly you envision, and how it will be used?

Note also that some (maybe all, I haven't checked) Counsel search commands already accept a prefix argument C-u which allows you to specify extra flags, such as file extension regexps, prior to completion.

See also discussion in #1408 (comment).

@ztlevi
Copy link
Author

ztlevi commented Jul 31, 2018

This is exactly what I want. Since the args are passed via inputs, we can go back to the previous with M-p any time we want to. Thank you!

Do we have this feature documented somewhere? Cuz this is really helpful.

@basil-conto
Copy link
Collaborator

basil-conto commented Jul 31, 2018

Do we have this feature documented somewhere?

Which feature are you referring to? The prefix argument? If so, I don't think it's clearly documented anywhere (although you might be able to infer it from the optional arguments listed for commands like C-hfcounsel-agRET).

Doc fix PRs are always welcome (as a mere user/contributor, I won't be personally inclined to improve documentation in this area until I have time to think more about the wishlist redesign mentioned in #1408 and #1559).

@ztlevi
Copy link
Author

ztlevi commented Jul 31, 2018

Yes. That's what I mean.

But even the function args are documented like this:

(counsel-rg &optional INITIAL-INPUT INITIAL-DIRECTORY EXTRA-RG-ARGS RG-PROMPT)

We are not likely to know how to apply the extra args.

But it's alright. Useful tips like M-n, M-p are the hidden power of ivy. I also doubt extra args is documented in the mannual. But I would like to blog these features. 😂

@ztlevi ztlevi closed this as completed Jul 31, 2018
@ztlevi
Copy link
Author

ztlevi commented Aug 1, 2018

I didn't test counsel-ag but counsel-rg doesn't work this way. But Spacemacs has counsel-search functions, and they can apply args via input. It's so weird.

image

For counsel-rg, I have to define it in the function, e.g. (counsel-rg "list" "." "--type-add 'logs:*.{org}' -t logs").

@ztlevi ztlevi reopened this Aug 1, 2018
@basil-conto
Copy link
Collaborator

basil-conto commented Aug 1, 2018

We are not likely to know how to apply the extra args.

Like I said:

you might be able to infer it

;)

Useful tips like M-n, M-p are the hidden power of ivy.

Actually, those are well-documented Emacs features that Ivy just adapts to its own needs; see (emacs) Minibuffer History.

I also doubt extra args is documented in the mannual.

The relevant search commands (counsel-ag et al.) are not documented in the manual to begin with, let alone their treatment of prefix arguments.

I didn't test counsel-ag but counsel-rg doesn't work this way.

What way? Please try to be more specific when describing issues, it's not always clear what you're referring to.

If you're talking about prefix argument handling, then counsel-rg works just like counsel-ag for me, i.e. it first prompts for a working directory, then for extra command-line options, and finally starts a ripgrep completion session.

But Spacemacs has counsel-search functions, and they can apply args via input.

Can you please elaborate? Do you mean that the search term can be mixed together with extra command-line options, like in #1559?

For counsel-rg, I have to define it in the function

What does "it" refer to? Again, please be more explicit when describing issues/scenarios and expected vs actual behaviour.

@ztlevi
Copy link
Author

ztlevi commented Aug 1, 2018

Oh, sorry. Let me fix my issue.

What I mean is counsel-rg cannot take extra command line options, like in #1559. Shown in the picture below. And I need to use functions to define extra prefix, e.g. (counsel-rg "list" "." "--type-add 'logs:*.{org}' -t logs").

image

But spacemacs/search-rg can apply extra command line options. Here is the function used in Spacemacs to genereate counsel-search functions.

image

Thank you!

@basil-conto
Copy link
Collaborator

basil-conto commented Aug 1, 2018

counsel-rg cannot take extra command line options, like in #1559.

That's to be expected, given that #1559 hasn't landed yet.

And I need to use functions to define extra prefix

WDYM by "use functions" and "define extra prefix"? You can programmatically set a prefix argument by setting prefix-arg and calling call-interactively; see (elisp) Interactive Call and (elisp) Prefix Command Arguments.

(counsel-rg "list" "." "--type-add 'logs:*.{org}' -t logs")

No need for "." in Elisp; either pass nil for this argument, or use default-directory.

But spacemacs/search-rg can apply extra command line options.

Won't this also be possible with vanilla Counsel after #1559 lands?

If #1559 doesn't address all your voiced concerns, can you please clarify the purpose of this issue / why you reopened it?

@ztlevi
Copy link
Author

ztlevi commented Aug 1, 2018

Oh, I don't have any issues anymore. Once #1559 is merged, we can apply the extra command line options in the input. But I'm fine to define my own custom counsel search function to do add the options.

Thanks a lot!

@basil-conto
Copy link
Collaborator

You could also leave this issue open until #1559 lands, I was just trying to clarify what you were after. I've now mentioned this issue in that PR, so it's up to you.

DEADB17 added a commit to DEADB17/swiper that referenced this issue Aug 4, 2018
abo-abo pushed a commit that referenced this issue Aug 13, 2018
Example for `counsel-rg' in this repo:

        -g*.el -- require
        -g*.org -- require
        -g!*.el -- require

Fixes #1408
Fixes #1512
Fixes #1688
Fixes #1559
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

2 participants