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

feat(pickers/grep): add ltrim_text option #3369

Closed
wants to merge 1 commit into from

Conversation

thiago-negri
Copy link

Description

When I grep multiple files, pickers are usually filled with leading white space. I find it easier if all entries are vertically aligned, even if that doesn't reflect the actual line in file.

I was doing this in my config:

local make_entry = require 'telescope.make_entry'
local original_entry_maker = make_entry.gen_from_vimgrep {}
local custom_entry_maker = function(line)
  local _, _, identifier, text = string.find(line, [[(..-:%d+:%d+):(.*)]])
  text = text:gsub('^%s+', '')
  local line = identifier .. ':' .. text
  return original_entry_maker(line)
end

vim.keymap.set('n', '<leader>sw', function()
  builtin.grep_string { entry_maker = custom_entry_maker }
end, { desc = '[S]earch current [W]ord' })

Figured it would be better if I sneak a config option in the picker, so here's my attempt to do so.

I'm not familiar with Lua, Telescope nor NVim. (I'm a cool person though)
I'm very open to change code or add docs if someone can point me in the right direction.

I've tried using text.triml() but that didn't work for me, so I went with the regex. Is there a more performant way to do that in Lua/NVim?

Type of change

  • New feature (non-breaking change which adds functionality)
  • This change requires a documentation update

How Has This Been Tested?

I see grepped lines without the leading space when I set the option. Not setting it has the same effect of setting it to false, so it defaults to the current behavior (not a breaking change).

Default behavior:

image

With ltrim_text = true:

image

Configuration:

  • Neovim version (nvim --version): 0.10.2
  • Operating system and version: Windows 11 and macOS 14.7.1

Checklist:

  • My code follows the style guidelines of this project (stylua)
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation (lua annotations)

@thiago-negri
Copy link
Author

I just realized I can do that with --trim option to ripgrep.

🫠

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

Successfully merging this pull request may close these issues.

1 participant