mirror of
https://github.com/neovim/neovim.git
synced 2025-10-22 17:11:49 +00:00
Merge #29238 from clason/feat/help-toc
This commit is contained in:
@@ -47,8 +47,8 @@ TREESITTER_LUA_URL https://github.com/tree-sitter-grammars/tree-sitter-lua/archi
|
|||||||
TREESITTER_LUA_SHA256 230cfcbfa74ed1f7b8149e9a1f34c2efc4c589a71fe0f5dc8560622f8020d722
|
TREESITTER_LUA_SHA256 230cfcbfa74ed1f7b8149e9a1f34c2efc4c589a71fe0f5dc8560622f8020d722
|
||||||
TREESITTER_VIM_URL https://github.com/neovim/tree-sitter-vim/archive/v0.4.0.tar.gz
|
TREESITTER_VIM_URL https://github.com/neovim/tree-sitter-vim/archive/v0.4.0.tar.gz
|
||||||
TREESITTER_VIM_SHA256 9f856f8b4a10ab43348550fa2d3cb2846ae3d8e60f45887200549c051c66f9d5
|
TREESITTER_VIM_SHA256 9f856f8b4a10ab43348550fa2d3cb2846ae3d8e60f45887200549c051c66f9d5
|
||||||
TREESITTER_VIMDOC_URL https://github.com/neovim/tree-sitter-vimdoc/archive/v2.5.1.tar.gz
|
TREESITTER_VIMDOC_URL https://github.com/neovim/tree-sitter-vimdoc/archive/v3.0.0.tar.gz
|
||||||
TREESITTER_VIMDOC_SHA256 063645096504b21603585507c41c6d8718ff3c11b2150c5bfc31e8f3ee9afea3
|
TREESITTER_VIMDOC_SHA256 a639bf92bf57bfa1cdc90ca16af27bfaf26a9779064776dd4be34c1ef1453f6c
|
||||||
TREESITTER_QUERY_URL https://github.com/tree-sitter-grammars/tree-sitter-query/archive/v0.4.0.tar.gz
|
TREESITTER_QUERY_URL https://github.com/tree-sitter-grammars/tree-sitter-query/archive/v0.4.0.tar.gz
|
||||||
TREESITTER_QUERY_SHA256 d3a423ab66dc62b2969625e280116678a8a22582b5ff087795222108db2f6a6e
|
TREESITTER_QUERY_SHA256 d3a423ab66dc62b2969625e280116678a8a22582b5ff087795222108db2f6a6e
|
||||||
TREESITTER_PYTHON_URL https://github.com/tree-sitter/tree-sitter-python/archive/v0.21.0.tar.gz
|
TREESITTER_PYTHON_URL https://github.com/tree-sitter/tree-sitter-python/archive/v0.21.0.tar.gz
|
||||||
|
@@ -293,7 +293,7 @@ loaded by Vim: >
|
|||||||
ftplugin/sql.vim
|
ftplugin/sql.vim
|
||||||
syntax/sqlinformix.vim
|
syntax/sqlinformix.vim
|
||||||
indent/sql.vim
|
indent/sql.vim
|
||||||
>
|
<
|
||||||
Notice indent/sqlinformix.sql was not loaded. There is no indent file
|
Notice indent/sqlinformix.sql was not loaded. There is no indent file
|
||||||
for Informix, Vim loads the default files if the specified files does not
|
for Informix, Vim loads the default files if the specified files does not
|
||||||
exist.
|
exist.
|
||||||
@@ -349,7 +349,7 @@ The defaults static maps are: >
|
|||||||
The use of "<C-C>" can be user chosen by using the following in your |init.vim|
|
The use of "<C-C>" can be user chosen by using the following in your |init.vim|
|
||||||
as it may not work properly on all platforms: >
|
as it may not work properly on all platforms: >
|
||||||
let g:ftplugin_sql_omni_key = '<C-C>'
|
let g:ftplugin_sql_omni_key = '<C-C>'
|
||||||
>
|
<
|
||||||
The static maps (which are based on the syntax highlight groups) follow this
|
The static maps (which are based on the syntax highlight groups) follow this
|
||||||
format: >
|
format: >
|
||||||
imap <buffer> <C-C>k <C-\><C-O>:call sqlcomplete#Map('sqlKeyword')<CR><C-X><C-O>
|
imap <buffer> <C-C>k <C-\><C-O>:call sqlcomplete#Map('sqlKeyword')<CR><C-X><C-O>
|
||||||
@@ -664,7 +664,7 @@ your |init.vim|: >
|
|||||||
filetype is changed temporarily to SQL, the sqlcompletion plugin
|
filetype is changed temporarily to SQL, the sqlcompletion plugin
|
||||||
will cache the syntax groups listed in the List specified in this
|
will cache the syntax groups listed in the List specified in this
|
||||||
option.
|
option.
|
||||||
>
|
|
||||||
|
|
||||||
------------------------------------------------------------------------------
|
------------------------------------------------------------------------------
|
||||||
4.5 SQL Maps *sql-completion-maps*
|
4.5 SQL Maps *sql-completion-maps*
|
||||||
|
@@ -188,7 +188,7 @@ Local additions ~
|
|||||||
*local-additions*
|
*local-additions*
|
||||||
|
|
||||||
------------------------------------------------------------------------------
|
------------------------------------------------------------------------------
|
||||||
*bars* Bars example
|
Bars example *bars*
|
||||||
|
|
||||||
Now that you've jumped here with CTRL-] or a double mouse click, you can use
|
Now that you've jumped here with CTRL-] or a double mouse click, you can use
|
||||||
CTRL-T, CTRL-O, g<RightMouse>, or <C-RightMouse> to go back to where you were.
|
CTRL-T, CTRL-O, g<RightMouse>, or <C-RightMouse> to go back to where you were.
|
||||||
@@ -200,5 +200,5 @@ You can use CTRL-] on any word (even if it is not within "|") and Nvim will
|
|||||||
try to find help for it. Especially for options in single quotes, e.g.
|
try to find help for it. Especially for options in single quotes, e.g.
|
||||||
'hlsearch'.
|
'hlsearch'.
|
||||||
|
|
||||||
------------------------------------------------------------------------------
|
|
||||||
vim:tw=78:isk=!-~,^*,^\|,^\":ts=8:noet:ft=help:norl:
|
vim:tw=78:isk=!-~,^*,^\|,^\":ts=8:noet:ft=help:norl:
|
||||||
|
@@ -366,7 +366,7 @@ tag char note action in Normal mode ~
|
|||||||
or start of putted text
|
or start of putted text
|
||||||
|`]| `] 1 cursor to the end of last operated text or
|
|`]| `] 1 cursor to the end of last operated text or
|
||||||
end of putted text
|
end of putted text
|
||||||
|``| `` 1 cursor to the position before latest jump
|
|``| "``" 1 cursor to the position before latest jump
|
||||||
|`{| `{ 1 cursor to the start of the current paragraph
|
|`{| `{ 1 cursor to the start of the current paragraph
|
||||||
|`}| `} 1 cursor to the end of the current paragraph
|
|`}| `} 1 cursor to the end of the current paragraph
|
||||||
|a| a 2 append text after the cursor N times
|
|a| a 2 append text after the cursor N times
|
||||||
@@ -1136,7 +1136,7 @@ tag command action ~
|
|||||||
|:!!| :!! repeat last ":!" command
|
|:!!| :!! repeat last ":!" command
|
||||||
|:#| :# same as ":number"
|
|:#| :# same as ":number"
|
||||||
|:&| :& repeat last ":substitute"
|
|:&| :& repeat last ":substitute"
|
||||||
|:star| :* use the last Visual area, like :'<,'>
|
|:star| :* use the last Visual area, like ":'<,'>"
|
||||||
|:<| :< shift lines one 'shiftwidth' left
|
|:<| :< shift lines one 'shiftwidth' left
|
||||||
|:=| := print the last line number
|
|:=| := print the last line number
|
||||||
|:>| :> shift lines one 'shiftwidth' right
|
|:>| :> shift lines one 'shiftwidth' right
|
||||||
|
@@ -87,7 +87,7 @@ The ":tags" command shows the list of tags that you traversed through:
|
|||||||
1 1 write_line 8 write_block.c ~
|
1 1 write_line 8 write_block.c ~
|
||||||
2 1 write_char 7 write_line.c ~
|
2 1 write_char 7 write_line.c ~
|
||||||
> ~
|
> ~
|
||||||
>
|
<
|
||||||
Now to go back. The CTRL-T command goes to the preceding tag. In the example
|
Now to go back. The CTRL-T command goes to the preceding tag. In the example
|
||||||
above you get back to the "write_line" function, in the call to "write_char".
|
above you get back to the "write_line" function, in the call to "write_char".
|
||||||
This command takes a count argument that indicates how many tags to jump
|
This command takes a count argument that indicates how many tags to jump
|
||||||
|
@@ -26,3 +26,7 @@ elseif vim.endswith(bufname, '/doc/lsp.txt') then
|
|||||||
{ start = [[\*lsp-semantic-highlight\*]], stop = '^======', match = '^@[%w%p]+' },
|
{ start = [[\*lsp-semantic-highlight\*]], stop = '^======', match = '^@[%w%p]+' },
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
vim.keymap.set('n', 'gO', function()
|
||||||
|
require('vim.vimhelp').show_toc()
|
||||||
|
end, { buffer = 0, silent = true })
|
||||||
|
@@ -21,77 +21,5 @@ endif
|
|||||||
" Prefer Vim help instead of manpages.
|
" Prefer Vim help instead of manpages.
|
||||||
setlocal keywordprg=:help
|
setlocal keywordprg=:help
|
||||||
|
|
||||||
if !exists('g:no_plugin_maps')
|
|
||||||
function! s:show_toc() abort
|
|
||||||
let bufname = bufname('%')
|
|
||||||
let info = getloclist(0, {'winid': 1})
|
|
||||||
if !empty(info) && getwinvar(info.winid, 'qf_toc') ==# bufname
|
|
||||||
lopen
|
|
||||||
return
|
|
||||||
endif
|
|
||||||
|
|
||||||
let toc = []
|
|
||||||
let lnum = 2
|
|
||||||
let last_line = line('$') - 1
|
|
||||||
let last_added = 0
|
|
||||||
let has_section = 0
|
|
||||||
let has_sub_section = 0
|
|
||||||
|
|
||||||
while lnum && lnum <= last_line
|
|
||||||
let level = 0
|
|
||||||
let add_text = ''
|
|
||||||
let text = getline(lnum)
|
|
||||||
|
|
||||||
if text =~# '^=\+$' && lnum + 1 < last_line
|
|
||||||
" A de-facto section heading. Other headings are inferred.
|
|
||||||
let has_section = 1
|
|
||||||
let has_sub_section = 0
|
|
||||||
let lnum = nextnonblank(lnum + 1)
|
|
||||||
let text = getline(lnum)
|
|
||||||
let add_text = text
|
|
||||||
while add_text =~# '\*[^*]\+\*\s*$'
|
|
||||||
let add_text = matchstr(add_text, '.*\ze\*[^*]\+\*\s*$')
|
|
||||||
endwhile
|
|
||||||
elseif text =~# '^[A-Z0-9][-A-ZA-Z0-9 .][-A-Z0-9 .():]*\%([ \t]\+\*.\+\*\)\?$'
|
|
||||||
" Any line that's yelling is important.
|
|
||||||
let has_sub_section = 1
|
|
||||||
let level = has_section
|
|
||||||
let add_text = matchstr(text, '.\{-}\ze\s*\%([ \t]\+\*.\+\*\)\?$')
|
|
||||||
elseif text =~# '\~$'
|
|
||||||
\ && matchstr(text, '^\s*\zs.\{-}\ze\s*\~$') !~# '\t\|\s\{2,}'
|
|
||||||
\ && getline(lnum - 1) =~# '^\s*<\?$\|^\s*\*.*\*$'
|
|
||||||
\ && getline(lnum + 1) =~# '^\s*>\?$\|^\s*\*.*\*$'
|
|
||||||
" These lines could be headers or code examples. We only want the
|
|
||||||
" ones that have subsequent lines at the same indent or more.
|
|
||||||
let l = nextnonblank(lnum + 1)
|
|
||||||
if getline(l) =~# '\*[^*]\+\*$'
|
|
||||||
" Ignore tag lines
|
|
||||||
let l = nextnonblank(l + 1)
|
|
||||||
endif
|
|
||||||
|
|
||||||
if indent(lnum) <= indent(l)
|
|
||||||
let level = has_section + has_sub_section
|
|
||||||
let add_text = matchstr(text, '\S.\{-}\ze\s\=\~$')
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
|
|
||||||
let add_text = substitute(add_text, '\s\+$', '', 'g')
|
|
||||||
if !empty(add_text) && last_added != lnum
|
|
||||||
let last_added = lnum
|
|
||||||
call add(toc, {'bufnr': bufnr('%'), 'lnum': lnum,
|
|
||||||
\ 'text': repeat("\u00a0\u00a0", level) . add_text})
|
|
||||||
endif
|
|
||||||
let lnum = nextnonblank(lnum + 1)
|
|
||||||
endwhile
|
|
||||||
|
|
||||||
call setloclist(0, toc, ' ')
|
|
||||||
call setloclist(0, [], 'a', {'title': 'Help TOC'})
|
|
||||||
lopen
|
|
||||||
let w:qf_toc = bufname
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
nnoremap <silent><buffer> gO :call <sid>show_toc()<cr>
|
|
||||||
endif
|
|
||||||
|
|
||||||
let &cpo = s:cpo_save
|
let &cpo = s:cpo_save
|
||||||
unlet s:cpo_save
|
unlet s:cpo_save
|
||||||
|
@@ -30,4 +30,42 @@ function M.highlight_groups(patterns)
|
|||||||
vim.fn.setpos('.', save_cursor)
|
vim.fn.setpos('.', save_cursor)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- Show a table of contents for the help buffer in a loclist
|
||||||
|
function M.show_toc()
|
||||||
|
local bufnr = vim.api.nvim_get_current_buf()
|
||||||
|
local parser = vim.treesitter.get_parser(bufnr, 'vimdoc')
|
||||||
|
local query = vim.treesitter.query.parse(
|
||||||
|
parser:lang(),
|
||||||
|
[[
|
||||||
|
(h1 (heading) @h1)
|
||||||
|
(h2 (heading) @h2)
|
||||||
|
(h3 (heading) @h3)
|
||||||
|
(column_heading (heading) @h4)
|
||||||
|
]]
|
||||||
|
)
|
||||||
|
local root = parser:parse()[1]:root()
|
||||||
|
local headings = {}
|
||||||
|
for id, node, _, _ in query:iter_captures(root, bufnr) do
|
||||||
|
local text = vim.treesitter.get_node_text(node, bufnr)
|
||||||
|
local capture = query.captures[id]
|
||||||
|
local row, col = node:start()
|
||||||
|
-- only column_headings at col 1 are headings, otherwise it's code examples
|
||||||
|
local is_code = (capture == 'h4' and col > 0)
|
||||||
|
-- ignore tabular material
|
||||||
|
local is_table = (capture == 'h4' and (text:find('\t') or text:find(' ')))
|
||||||
|
-- ignore tag-only headings
|
||||||
|
local is_tag = node:child_count() == 1 and node:child(0):type() == 'tag'
|
||||||
|
if not (is_code or is_table or is_tag) then
|
||||||
|
table.insert(headings, {
|
||||||
|
bufnr = bufnr,
|
||||||
|
lnum = row + 1,
|
||||||
|
text = (capture == 'h3' or capture == 'h4') and ' ' .. text or text,
|
||||||
|
})
|
||||||
|
end
|
||||||
|
end
|
||||||
|
vim.fn.setloclist(0, headings, ' ')
|
||||||
|
vim.fn.setloclist(0, {}, 'a', { title = 'Help TOC' })
|
||||||
|
vim.cmd.lopen()
|
||||||
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
@@ -1,13 +1,19 @@
|
|||||||
(h1) @markup.heading.1
|
(h1
|
||||||
|
(delimiter) @markup.heading.1
|
||||||
|
(heading) @markup.heading.1)
|
||||||
|
|
||||||
(h2) @markup.heading.2
|
(h2
|
||||||
|
(delimiter) @markup.heading.2
|
||||||
|
(heading) @markup.heading.2)
|
||||||
|
|
||||||
(h3) @markup.heading.3
|
(h3
|
||||||
|
(heading) @markup.heading.3)
|
||||||
(column_heading) @markup.heading.4
|
|
||||||
|
|
||||||
(column_heading
|
(column_heading
|
||||||
"~" @markup.heading.4
|
(heading) @markup.heading.4)
|
||||||
|
|
||||||
|
(column_heading
|
||||||
|
(delimiter) @markup.heading.4
|
||||||
(#set! conceal ""))
|
(#set! conceal ""))
|
||||||
|
|
||||||
(tag
|
(tag
|
||||||
|
Reference in New Issue
Block a user