initial commit
This commit is contained in:
19
LICENSE
Normal file
19
LICENSE
Normal file
@@ -0,0 +1,19 @@
|
||||
Copyright 2025 Łukasz Pankowski <lukpank at o2 dot pl>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a
|
||||
copy of this software and associated documentation files (the "Software"),
|
||||
to deal in the Software without restriction, including without limitation
|
||||
the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
and/or sell copies of the Software, and to permit persons to whom the
|
||||
Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
DEALINGS IN THE SOFTWARE.
|
||||
64
README.md
Normal file
64
README.md
Normal file
@@ -0,0 +1,64 @@
|
||||
# vis-pin-files
|
||||
|
||||
A [vis-plugin](https://github.com/martanne/vis/wiki/Plugins/) to pin a file to a number
|
||||
with a key (default: `␣p1` ... `␣p9`). The number may be later used to bring back the file with another key (default: `␣1` ... `␣9`).
|
||||
|
||||
Keys are configurable. The pins does not persist after editor restart (but both keys and files table are available in module namespace for customization).
|
||||
|
||||
The plugin is basic implementation of the idea of [neovim](https://neovim.io/) plugin [harpoon](https://github.com/ThePrimeagen/harpoon/tree/harpoon2)
|
||||
(there are also many other similar neovim plugins, such as [arrow](https://github.com/otavioschwanck/arrow.nvim)).
|
||||
|
||||
The package could be used with its default settings by cloning the project directory
|
||||
into the `plugins` subdirectory in the directory of your `visrc.lua` file and importing it
|
||||
with
|
||||
|
||||
```lua
|
||||
require('plugins/vis-pin-files')
|
||||
```
|
||||
|
||||
See the *Default keys and configuration* section for default key bindings and possible customization.
|
||||
|
||||
## Commands
|
||||
|
||||
The plugin adds single command `:pin-files [command] [num]`
|
||||
|
||||
Where `[command]` is either:
|
||||
|
||||
- `pin`, then the current file is pinned to the given number `[num]` (i.e., its path, if any, is stored for later use), or
|
||||
- any other command (such as `e`, `o`, `split`, `vsplit`), in this case the command is called with the filename
|
||||
pinned to the given `[num]` (or message is displayed that the pin is empty).
|
||||
|
||||
Actually `[num]` is converted to a number if possible, otherwise it is used as a string.
|
||||
|
||||
The `[num]` is optional, if not given the number should be given as the count argument of the command, if both are missing, only the info message is displayed
|
||||
and nothing happens.
|
||||
|
||||
## Default keys and configuration
|
||||
|
||||
The default set of keys consists of two groups:
|
||||
- `␣p1` ... `␣p9` -- pin current file to given number,
|
||||
- `␣1` ... `␣9` -- switch to given file with `e` command,
|
||||
|
||||
The default keys defined in the plugin are equivallent to the following
|
||||
settings in your `visrc.lua`:
|
||||
```lua
|
||||
local pin = require('plugins/vis-pin-files')
|
||||
|
||||
pin.keys = {
|
||||
[' p%d'] = '<vis-prompt-show>pin-files pin %d<Enter>',
|
||||
[' %d'] = '<vis-prompt-show>pin-files e %d<Enter>',
|
||||
}
|
||||
```
|
||||
|
||||
where keys with `%d` in them are filled with numbers from 1 to 9 in the key and in the command.
|
||||
If `%d` is not found in the key then the single key (without number interpolation) is bind
|
||||
to the given command.
|
||||
|
||||
To remove the given key just set it to `nil`, for example:
|
||||
```lua
|
||||
pin.keys[' p%d'] = nil
|
||||
```
|
||||
to remove all default keys (so you can set them yourself):
|
||||
```lua
|
||||
pin.keys = nil
|
||||
```
|
||||
55
init.lua
Normal file
55
init.lua
Normal file
@@ -0,0 +1,55 @@
|
||||
local M = {}
|
||||
|
||||
M.keys = {
|
||||
[' p%d'] = '<vis-prompt-show>pin-files pin %d<Enter>',
|
||||
[' %d'] = '<vis-prompt-show>pin-files e %d<Enter>',
|
||||
}
|
||||
|
||||
M.files = {}
|
||||
|
||||
local function pin_file(num, file)
|
||||
if file ~= nil then
|
||||
M.files[num] = file
|
||||
vis:info('[' .. num .. '] pin')
|
||||
else
|
||||
vis:info('Window has no file')
|
||||
end
|
||||
end
|
||||
|
||||
local function open_file(num, cmd)
|
||||
local file = M.files[num]
|
||||
if not file then
|
||||
vis:info('[' .. num .. '] empty')
|
||||
elseif file == vis.win.file.path and cmd == 'e' then
|
||||
vis:info('[' .. num .. '] already opened')
|
||||
else
|
||||
vis:info('[' .. num .. '] ' .. cmd)
|
||||
vis:command(string.format('%s %q', cmd or 'o', file))
|
||||
end
|
||||
end
|
||||
|
||||
vis:command_register('pin-files', function(argv, force, win, selection, range)
|
||||
local cmd = argv[1] or 'o'
|
||||
local num = tonumber(argv[2]) or argv[2] or vis.count
|
||||
if not num then
|
||||
vis:info('No file number given')
|
||||
elseif cmd == 'pin' then
|
||||
pin_file(num, win.file.path)
|
||||
else
|
||||
open_file(num, cmd)
|
||||
end
|
||||
end)
|
||||
|
||||
vis.events.subscribe(vis.events.INIT, function()
|
||||
for key, cmd in pairs(M.keys or {}) do
|
||||
if key:find('%%d') then
|
||||
for num = 1, 9 do
|
||||
vis:map(vis.modes.NORMAL, string.format(key, num), string.format(cmd, num))
|
||||
end
|
||||
else
|
||||
vis:map(vis.modes.NORMAL, key, cmd)
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
return M
|
||||
Reference in New Issue
Block a user