Skip to content

Commit

Permalink
Merge pull request #16 from desdic/feature/count
Browse files Browse the repository at this point in the history
feat: support v:count when running macro
  • Loading branch information
desdic authored Feb 12, 2025
2 parents 3fe6af8 + 8d1401a commit c3f4982
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/docgen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
matrix:
include:
- os: ubuntu-24.04
url: https://github.com/neovim/neovim/releases/download/nightly/nvim-linux64.tar.gz
url: https://github.com/neovim/neovim/releases/download/nightly/nvim-linux-x86_64.tar.gz
steps:
- uses: actions/checkout@v4
- run: date +%F > todays-date
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ require("telescope").extensions = {
| <C-h> | Show key bindings |
| <C-n> | Rename selected entry |
| <C-q> | Run macro on files in quickfix list |
| <C-r> | Run macro |
| <C-r> | Run macro (supports v:count) |
| <C-s> | Save a macro/register |
| <C-x> | Edit register (<C-c> can be used to copy the register as printable) |

Expand Down
6 changes: 4 additions & 2 deletions lua/macrothis/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -207,10 +207,11 @@ end
---
---@usage `require('macrothis').run()`
macrothis.run = function()
local count = vim.v.count1
local menuelem = macrothis.generate_menu_items()

vim.ui.select(menuelem, {
prompt = "Run on quickfix list",
prompt = "Run macro",
format_item = function(item)
return ("%s: %s"):format(item.label, item.value)
end,
Expand All @@ -219,7 +220,8 @@ macrothis.run = function()
utils.run_macro(
macrothis.opts,
macrothis.opts.run_register,
description.label
description.label,
count
)
macrothis.opts.last_used = description.label
end
Expand Down
9 changes: 7 additions & 2 deletions lua/macrothis/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,15 @@ utils.remove_entry = function(opts, description)
utils.save_data(opts, data)
end

utils.run_macro = function(opts, register, description)
utils.run_macro = function(opts, register, description, count)
utils.load_register(opts, register, description)
vim.api.nvim_feedkeys(
vim.api.nvim_replace_termcodes("@" .. register, true, false, true),
vim.api.nvim_replace_termcodes(
count .. "@" .. register,
true,
false,
true
),
"n",
false
)
Expand Down

0 comments on commit c3f4982

Please sign in to comment.