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

Flag expansion #27

Closed
steliyan opened this issue Aug 9, 2022 · 2 comments
Closed

Flag expansion #27

steliyan opened this issue Aug 9, 2022 · 2 comments

Comments

@steliyan
Copy link
Contributor

steliyan commented Aug 9, 2022

I've requested a similar feature to ripgrep: BurntSushi/ripgrep#2273

Here is the short summary from the linked issue:

I am using ripgrep through neovim and telescope, both for finding files and for searching in files.

When I search in files I want a non-regex match, hence I use the --fixed-strings flag. Sometimes, I want to perform a regex search and it would be useful to have a shorthand name for the --no-fixed-strings flag. I thinking -NF as in "No -F"?

I think it would be useful to create custom expansions (or token replacements, maybe?!).

Does this make sense to include it in this plugin?

I can think of many use cases actually:
-NF -> --no-fixed-strings
-NM -> --g '**/node_modules/**' --no-ignore

I think this can be achieved relatively easily, by trying to replace exact matches in each prompt part.

@weeman1337
Copy link
Collaborator

Does one of these option solve your request?

You can set an initial prompt: live_grep_raw.live_grep_raw({ default_text ='-no-fixed-strings "'})
This can be mapped to a keyboard shortcut if you want.

You can define custom quote shortcuts, like for instance

      mappings = {
        i = {
          ["your-shortcut-here"] = actions.quote_prompt({ postfix = ' --no-fixed-strings ' }),
        }
      }

@steliyan
Copy link
Contributor Author

My preferred usage would be --no-fixed-strings "<PROMPT_VALUE>. This is relatively easy to achieve, add a prefix option to the quote_prompt action.

Initially, I was thinking of adding a double-dash (--) as a delimiter and treat everything on the left as separate args and everything after the double-dash as the search string, but now I've played a little bit more, I think your approach is better and more intuitive.

Why?

Well, you can actually do --no-fixed-strings "<PROMPT_VALUE> and this will be parsed as { "--no-fixed-strings" , ""<PROMPT_VALUE>" }, which actually is pretty great! You're in the position of live tweaking the regex or scope down your search by filetype (e.g. exclude test files or include only JS files). This wouldn't be the case with the double-dash, or at least it would be very weird and counter-intuitive.

Here's what I am using:

local semi_quote = function(opts)
  opts = opts or {}
  opts = vim.tbl_extend('force', default_opts, opts)

  return function(prompt_bufnr)
    local picker = action_state.get_current_picker(prompt_bufnr)
    local prompt = picker:_get_prompt()
    if opts.trim then
      prompt = vim.trim(prompt)
    end
    prompt = prompt:gsub(opts.quote_char, '\\' .. opts.quote_char)
    prompt = opts.prefix .. opts.quote_char .. prompt
    picker:set_prompt(prompt)
  end
end

I've found a couple of small annoyances (at least for me). I will submit PRs and leave it up to you to decide if they make sense.

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