Skip to content

Commit e2bfe88

Browse files
committed
chore(docs): prepare :h navigator-nvim
1 parent 4a10430 commit e2bfe88

File tree

8 files changed

+206
-38
lines changed

8 files changed

+206
-38
lines changed

.github/workflows/ci.yaml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: ci
2+
3+
on:
4+
push:
5+
paths:
6+
- "**.lua"
7+
branches:
8+
- master
9+
10+
env:
11+
PLUGIN_NAME: Navigator
12+
13+
jobs:
14+
docs:
15+
runs-on: ubuntu-latest
16+
name: emmylua to help doc
17+
steps:
18+
- uses: actions/checkout@v2
19+
20+
- name: Generating help
21+
shell: bash
22+
run: |
23+
curl -Lq https://github.com/numToStr/lemmy-help/releases/latest/download/lemmy-help-x86_64-unknown-linux-gnu.tar.gz | tar xz
24+
./lemmy-help -fact lua/Navigator/init.lua lua/Navigator/mux/{vi,tmux,wezterm}.lua > doc/${{env.PLUGIN_NAME}}.txt
25+
26+
- name: Commit
27+
uses: stefanzweifel/git-auto-commit-action@v4
28+
with:
29+
branch: ${{ github.head_ref }}
30+
commit_message: "chore(docs): auto-generate `:help` doc"
31+
file_pattern: doc/*.txt

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
![Navigator](https://user-images.githubusercontent.com/24727447/157040356-1f44323a-c7b6-4955-8207-5e6cade08c9e.gif "Navigating to the moon")
55

6-
This plugin provides a set of [functions](#lua-api) and [commands](#commands) that allows you to seemlessly navigate between neovim and different [terminal multiplexers](#multiplexers).
6+
`Navigator.nvim` provides set of [functions](#lua-api) and [commands](#commands) that allows you to seemlessly navigate between neovim and different [terminal multiplexers](#multiplexers).
77

88
### 🚀 Installation
99

@@ -54,7 +54,7 @@ vim.keymap.set('n', '<A-p>', '<CMD>NavigatorPrevious<CR>')
5454
> **Note** - This plugin doesn't provide any configuration for multiplexers, feel free to use (and modify) the snippet for multiplexer of your choice by following the links below.
5555
5656
- [Tmux](https://github.com/numToStr/Navigator.nvim/wiki/Tmux-Integration)
57-
- [Wezterm](https://github.com/numToStr/Navigator.nvim/wiki/WezTerm-Integration)
57+
- [WezTerm](https://github.com/numToStr/Navigator.nvim/wiki/WezTerm-Integration)
5858

5959
#### Configuration (optional)
6060

@@ -90,6 +90,8 @@ Following options can be given when calling `setup({config})`. Below is the defa
9090
- `NavigatorDown` - Go to down split/pane
9191
- `NavigatorPrevious` - Go to previous split/pane
9292

93+
> Read `:h navigator.commands` for more info
94+
9395
#### Lua API
9496

9597
```lua
@@ -100,6 +102,8 @@ require('Navigator').down()
100102
require('Navigator').previous()
101103
```
102104

105+
> Read `:h navigator.api` for more info
106+
103107
### 💐 Credits
104108

105109
- [vim-tmux-navigator](https://github.com/christoomey/vim-tmux-navigator) - Motivator and Vimscript cousin

doc/Navigator.txt

Whitespace-only changes.

lua/Navigator/init.lua

Lines changed: 104 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,125 @@
1+
---@brief [[
2+
---*navigator-nvim.txt* For Neovim version 0.7 Last change: 2020 Dec 16
3+
---
4+
---
5+
--- |\ | _. o _ _. _|_ _ ._ ._ o ._ _
6+
--- | \| (_| \/ | (_| (_| |_ (_) | o | | \/ | | | |
7+
--- _|
8+
---
9+
--- · Smoothly navigate between neovim and multipexers ·
10+
---
11+
---@brief ]]
12+
13+
---@toc navigator.contents
14+
15+
---@mod navigator-nvim Introduction
16+
---@brief [[
17+
---Navigator.nvim provides set of functions and commands that allows you to seemlessly
18+
---navigate between neovim and different terminal multiplexers. It also allows you to
19+
---integrate your own custom multipexer.
20+
---@brief ]]
21+
22+
---@mod navigator.commands Commands
23+
---@brief [[
24+
---This plugin provides the following commands:
25+
---
26+
--- *NavigatorLeft* - Go to left split/pane
27+
--- *NavigatorRight* - Go to right split/pane
28+
--- *NavigatorUp* - Go to upper split/pane
29+
--- *NavigatorDown* - Go to down split/pane
30+
--- *NavigatorPrevious* - Go to previous split/pane
31+
---@brief ]]
32+
33+
---@mod navigator.api API and Config
134
local n = require('Navigator.navigate')
35+
local Nav = {}
236

3-
local N = {
4-
setup = n.setup,
5-
}
37+
---@class Config
38+
---Save modified buffer(s) when moving
39+
---to mux from neovim (default: `nil`)
40+
---@field auto_save? '"current"'|'"all"'
41+
---Disable navigation when the current
42+
---mux pane is zoomed in (default: `false`)
43+
---@field disable_on_zoom boolean
44+
---@field mux '"auto"'|Vi Multiplexer to use (default: "auto")
45+
46+
---Enum of navigation direction analogous of neovim window movement
47+
---@alias Direction
48+
---| '"p"' # Previous Pane
49+
---| '"h"' # Left Pane
50+
---| '"j"' # Lower Pane
51+
---| '"k"' # Upper Pane
52+
---| '"l"' # Right Pane
53+
54+
---Configure the plugin
55+
---@param opts Config
56+
---@usage [[
57+
----- With default config
58+
---require('Navigator').setup()
59+
---
60+
----- With custom config
61+
---require('Navigator').setup({
62+
--- auto_save = 'current'
63+
--- disable_on_zoom = true
64+
---})
65+
---@usage ]]
66+
function Nav.setup(opts)
67+
n.setup(opts)
68+
end
669

770
---Go to left split/pane
8-
function N.left()
71+
---@usage [[
72+
---require('Navigator').left()
73+
---
74+
----- With keybinding
75+
---vim.keymap.set({'n', 't'}, '<A-h>', require('Navigator').left)
76+
---@usage ]]
77+
function Nav.left()
978
n.navigate('h')
1079
end
1180

12-
---Go to above split/pane
13-
function N.up()
81+
---Go to upper split/pane
82+
---@usage [[
83+
---require('Navigator').up()
84+
---
85+
----- With keybinding
86+
---vim.keymap.set({'n', 't'}, '<A-k>', require('Navigator').up)
87+
---@usage ]]
88+
function Nav.up()
1489
n.navigate('k')
1590
end
1691

1792
---Go to right split/pane
18-
function N.right()
93+
---@usage [[
94+
---require('Navigator').right()
95+
---
96+
----- With keybinding
97+
---vim.keymap.set({'n', 't'}, '<A-l>', require('Navigator').right)
98+
---@usage ]]
99+
function Nav.right()
19100
n.navigate('l')
20101
end
21102

22-
---Go to below split/pane
23-
function N.down()
103+
---Go to down split/pane
104+
---@usage [[
105+
---require('Navigator').down()
106+
---
107+
----- With keybinding
108+
---vim.keymap.set({'n', 't'}, '<A-j>', require('Navigator').down)
109+
---@usage ]]
110+
function Nav.down()
24111
n.navigate('j')
25112
end
26113

27114
---Go to previous split/pane
28-
function N.previous()
115+
---@usage [[
116+
---require('Navigator').previous()
117+
---
118+
----- With keybinding
119+
---vim.keymap.set({'n', 't'}, '<A-p>', require('Navigator').previous)
120+
---@usage ]]
121+
function Nav.previous()
29122
n.navigate('p')
30123
end
31124

32-
return N
125+
return Nav

lua/Navigator/mux/tmux.lua

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
---@mod navigator.tmux Tmux navigator
2+
---@brief [[
3+
---This module provides navigation and interaction for Tmux, and uses |navigator.vi|
4+
---as a base class. This is used automatically when tmux is detected on host
5+
---system but can also be used to manually override the mux.
6+
---Read also: https://github.com/numToStr/Navigator.nvim/wiki/Tmux-Integration
7+
---@brief ]]
8+
9+
---@private
110
---@class Tmux: Vi
211
---@field private pane string
312
---@field private direction table<Direction, string>
@@ -6,6 +15,15 @@ local Tmux = require('Navigator.mux.vi'):new()
615

716
---Creates a new Tmux navigator instance
817
---@return Tmux
18+
---@usage [[
19+
---local ok, tmux = pcall(function()
20+
--- return require('Navigator.mux.tmux'):new()
21+
---end)
22+
---
23+
---require('Navigator').setup({
24+
--- mux = ok and tmux or 'auto'
25+
---})
26+
---@usage ]]
927
function Tmux:new()
1028
local instance = os.getenv('TMUX')
1129
local pane = os.getenv('TMUX_PANE')
@@ -34,7 +52,7 @@ function Tmux:zoomed()
3452
end
3553

3654
---Switch pane in tmux
37-
---@param direction Direction
55+
---@param direction Direction See |navigator.api.Direction|
3856
---@return Tmux
3957
function Tmux:navigate(direction)
4058
self.execute(string.format("select-pane -t '%s' -%s", self.pane, self.direction[direction]))

lua/Navigator/mux/vi.lua

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,35 @@
1+
---@mod navigator.vi Neovim navigator
2+
---@brief [[
3+
---This module provides navigation and interaction for Neovim. This also acts
4+
---as a base class for other multiplexer implementation.
5+
---
6+
---Read: https://github.com/numToStr/Navigator.nvim/wiki/Custom-Multiplexer
7+
---@brief ]]
8+
9+
---@private
110
---@class Vi
211
local Vi = {}
12+
local cmd = vim.api.nvim_command
313

414
---Creates new Neovim navigator instance
5-
---NOTE: This can be used as a base for other navigators
615
---@return Vi
716
function Vi:new()
817
self.__index = self
918
return setmetatable({}, self)
1019
end
1120

1221
---Checks whether neovim is maximized
13-
---NOTE: This is only useful for `tmux`, for other mux(s) return false would suffice
22+
---NOTE: For neovim, this always returns `false`.
1423
---@return boolean
1524
function Vi.zoomed()
1625
return false
1726
end
1827

1928
---Navigate inside neovim
20-
---@param direction Direction
29+
---@param direction Direction See |navigator.api.Direction|
2130
---@return Vi
2231
function Vi:navigate(direction)
23-
vim.api.nvim_command('wincmd ' .. direction)
32+
cmd('wincmd ' .. direction)
2433
return self
2534
end
2635

lua/Navigator/mux/wezterm.lua

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,29 @@
1+
---@mod navigator.wezterm WezTerm navigator
2+
---@brief [[
3+
---This module provides navigation and interaction for WezTerm, and uses |navigator.vi|
4+
---as a base class. This is used automatically when wezterm is detected on host system
5+
---but can also be used to manually override the mux.
6+
---
7+
---Read also: https://github.com/numToStr/Navigator.nvim/wiki/WezTerm-Integration
8+
---@brief ]]
9+
10+
---@private
111
---@class WezTerm: Vi
212
---@field private direction table<Direction, string>
313
---@field private execute fun(arg: string): unknown
414
local WezTerm = require('Navigator.mux.vi'):new()
515

616
---Creates a new WezTerm navigator instance
717
---@return WezTerm
18+
---@usage [[
19+
---local ok, wezterm = pcall(function()
20+
--- return require('Navigator.mux.wezterm'):new()
21+
---end)
22+
---
23+
---require('Navigator').setup({
24+
--- mux = ok and wezterm or 'auto'
25+
---})
26+
---@usage ]]
827
function WezTerm:new()
928
assert(os.getenv('TERM_PROGRAM') == 'WezTerm', '[Navigator] WezTerm is not running!')
1029

@@ -23,7 +42,7 @@ function WezTerm:new()
2342
end
2443

2544
---Switch pane in wezterm
26-
---@param direction Direction
45+
---@param direction Direction See |navigator.api.Direction|
2746
---@return WezTerm
2847
function WezTerm:navigate(direction)
2948
self.execute(string.format('activate-pane-direction %s', self.direction[direction]))

lua/Navigator/navigate.lua

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
11
local A = vim.api
22
local cmd = A.nvim_command
33

4-
---Loads mux
4+
---State and defaults
5+
---@class Nav
6+
---@field last_pane boolean
7+
---@field config? Config
8+
local N = {
9+
last_pane = false,
10+
config = nil,
11+
}
12+
13+
---Detect and load correct mux
514
---@return Vi
615
local function load_mux()
716
local ok_tmux, tmux = pcall(function()
@@ -19,25 +28,10 @@ local function load_mux()
1928
return require('Navigator.mux.vi'):new()
2029
end
2130

22-
---@alias Direction 'p'|'h'|'k'|'l'|'j'
23-
24-
---@class Config
25-
---@field auto_save? '"current"'|'"all"' Save modified buffer(s) when moving to mux
26-
---@field disable_on_zoom boolean Disable navigation when the current mux pane is zoomed in
27-
---@field mux 'auto'|Vi Multiplexer to use
28-
29-
---State and defaults
30-
---@class Nav
31-
---@field last_pane boolean
32-
---@field config? Config
33-
local N = {
34-
last_pane = false,
35-
config = nil,
36-
}
37-
3831
---For setting up the plugin with the user provided options
3932
---@param opts Config
4033
function N.setup(opts)
34+
---@type Config
4135
local config = {
4236
disable_on_zoom = false,
4337
auto_save = nil,
@@ -65,7 +59,7 @@ end
6559
---Checks whether we need to move to the nearby mux pane
6660
---@param at_edge boolean
6761
---@return boolean
68-
function N.back_to_mux(at_edge)
62+
local function back_to_mux(at_edge)
6963
if N.config.disable_on_zoom and N.config.mux:zoomed() then
7064
return false
7165
end
@@ -89,7 +83,7 @@ function N.navigate(direction)
8983
-- then we can assume that we hit the edge
9084
-- there is mux pane besided the edge
9185
-- So we can navigate to the mux pane
92-
if N.back_to_mux(at_edge) then
86+
if back_to_mux(at_edge) then
9387
N.config.mux:navigate(direction)
9488

9589
local save = N.config.auto_save

0 commit comments

Comments
 (0)