Skip to content

Commit

Permalink
Merge branch 'nvim-telescope:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
ngpong authored Jul 3, 2024
2 parents 71c127f + 8ad632f commit 16ab1b2
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 7 deletions.
13 changes: 11 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,20 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## UNRELEASED
## 1.1.0 - 2024-06-09

### Added

- New shortcut functions `grep_word_under_cursor_current_buffer` and `grep_word_visual_selection_current_buffer` (#82) - contributed by @LLMChild

### Changed

- Mention `to_fuzzy_refine` shortcut in README (#80) - contributed by @ilan-schemoul
- Shortcut functions do now support opts (#82) - contributed by @LLMChild

### Fixed

- Visual selection now also works when selecting backwards
- Visual selection now also works when selecting backwards (#69) - contributed by @ajenkinski

## 1.0.0 - 2023-08-28

Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,9 @@ Available shortcuts:
| Name | Action | Options |
| --- | --- | --- |
| `grep_word_under_cursor` | Start live grep with word under cursor | <ul><li>`postfix`: postfix value to add; defaults to ` -F ` (Treat the pattern as a literal string)</li><li>`quote`: Whether to quote the value; defaults to true</li><li>`trim`: Whether to trim the value; defaults to true</li></ul> |
| `grep_word_under_cursor_current_buffer` | Same as `grep_word_under_cursor` but for the file of the current buffer | |
| `grep_visual_selection` | Start live grep with visual selection | see `grep_word_under_cursor` |
| `grep_word_visual_selection_current_buffer` | Same as `grep_visual_selection` but for the file of the current buffer | |


## Development
Expand Down
28 changes: 23 additions & 5 deletions lua/telescope-live-grep-args/shortcuts.lua
Original file line number Diff line number Diff line change
Expand Up @@ -38,22 +38,40 @@ local function process_grep_under_text(value, opts)
value = value .. opts.postfix
end

return value
opts["default_text"] = value

return opts
end

local M = {}

M.grep_word_under_cursor = function(opts)
opts = opts or {}
local word_under_cursor = vim.fn.expand("<cword>")
word_under_cursor = process_grep_under_text(word_under_cursor, opts)
live_grep_args.live_grep_args({ default_text = word_under_cursor })
opts = process_grep_under_text(word_under_cursor, opts)
live_grep_args.live_grep_args(opts)
end

M.grep_visual_selection = function(opts)
opts = opts or {}
local visual = get_visual()
local text = visual[1] or ""
text = process_grep_under_text(text, opts)
live_grep_args.live_grep_args({ default_text = text })
opts = process_grep_under_text(text, opts)
live_grep_args.live_grep_args(opts)
end

M.grep_word_visual_selection_current_buffer = function(opts)
opts = opts or {}
local curr_path = vim.fn.expand("%")
opts["search_dirs"] = { curr_path }
M.grep_visual_selection(opts)
end

M.grep_word_under_cursor_current_buffer = function(opts)
opts = opts or {}
local curr_path = vim.fn.expand("%")
opts["search_dirs"] = { curr_path }
M.grep_word_under_cursor(opts)
end

return M

0 comments on commit 16ab1b2

Please sign in to comment.