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: add Precognition command #58

Merged
merged 2 commits into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,21 +64,37 @@ Any hints that could appear in the same place as others should have unique prior

## ❔Usage

`precognition` can be controlled with the `Precognition` user command, as well as programmatically via the Lua API.

### Toggling

The hints can be toggled on and off with

```vim
:Precognition toggle
```
:lua require("precognition").toggle()

or

```lua
require("precognition").toggle()
```

The subcommands and functions `show` and `hide` are also available.

### Peeking

The hints can be peeked, this means that the hint will be show until the next
cursor movement.

```vim
:Precognition peek
```
:lua require("precognition").peek()

or

```lua
require("precognition").peek()
```

## 💻 Supported Versions
Expand Down
35 changes: 35 additions & 0 deletions lua/precognition/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,39 @@ local function on_buf_leave(ev)
dirty = true
end

local function create_command()
local subcommands = {
peek = M.peek,
toggle = M.toggle,
show = M.show,
hide = M.hide,
}

local function execute(args)
local cmd_args = args.fargs
local subcmd = cmd_args[1]
if not subcmd then
return
end
if subcommands[subcmd] then
subcommands[subcmd]()
else
vim.notify("Invalid subcommand: " .. subcmd, vim.log.levels.ERROR, {
title = "Precognition",
})
end
end

local function complete(_line, _len, _arg_lead)
return vim.tbl_keys(subcommands)
end

vim.api.nvim_create_user_command("Precognition", execute, {
nargs = "*",
complete = complete,
})
end

--- Show the hints until the next keypress or CursorMoved event
function M.peek()
display_marks()
Expand Down Expand Up @@ -395,6 +428,8 @@ function M.setup(opts)
local hl_name = "PrecognitionHighlight"
vim.api.nvim_set_hl(0, hl_name, config.highlightColor)

create_command()

if config.startVisible then
M.show()
end
Expand Down
Loading