doc.kak: Support jumping on links using <ret>

This commit is contained in:
Maxime Coste 2017-11-06 20:52:24 +08:00
parent 19cda837ff
commit 73182de20c

View File

@ -1,7 +1,8 @@
declare-option -docstring "name of the client in which documentation is to be displayed" \ declare-option -docstring "name of the client in which documentation is to be displayed" \
str docsclient str docsclient
declare-option -hidden range-specs doc_render_ranges declare-option -hidden range-specs doc_ranges
declare-option -hidden range-specs doc_links
define-command -hidden -params 4 doc-render-regex %{ define-command -hidden -params 4 doc-render-regex %{
evaluate-commands -draft %{ try %{ evaluate-commands -draft %{ try %{
@ -10,12 +11,40 @@ define-command -hidden -params 4 doc-render-regex %{
execute-keys "%arg{3}" execute-keys "%arg{3}"
%sh{ %sh{
ranges=$(echo "$kak_selections_desc" | sed -e "s/:/|$4:/g; s/\$/|$4/") ranges=$(echo "$kak_selections_desc" | sed -e "s/:/|$4:/g; s/\$/|$4/")
echo "update-option buffer doc_render_ranges" echo "update-option buffer doc_ranges"
echo "set-option -add buffer doc_render_ranges '$ranges'" echo "set-option -add buffer doc_ranges '$ranges'"
} }
} } } }
} }
define-command -hidden doc-parse-links %{
evaluate-commands -draft %{ try %{
execute-keys \%s <lt><lt>(.*?)#,.*?<gt><gt> <ret>
execute-keys -draft s <lt><lt>.*,|<gt><gt> <ret> d
execute-keys H
set-option buffer doc_links %val{timestamp}
evaluate-commands -itersel %{
set-option -add buffer doc_links "%val{selection_desc}|%reg{1}"
}
} }
}
define-command doc-jump %{
update-option buffer doc_links
%sh{
printf "%s" "$kak_opt_doc_links" | awk -v RS=':' -v FS='[.,|]' '
BEGIN {
l=ENVIRON["kak_cursor_line"];
c=ENVIRON["kak_cursor_column"];
}
l >= $1 && c >= $2 && l <= $3 && c <= $4 {
print "doc " $5
exit
}
'
}
}
define-command -params 1 -hidden doc-render %{ define-command -params 1 -hidden doc-render %{
edit! -scratch *doc* edit! -scratch *doc*
execute-keys "!cat %arg{1}<ret>gg" execute-keys "!cat %arg{1}<ret>gg"
@ -26,22 +55,23 @@ define-command -params 1 -hidden doc-render %{
# Remove some line end markers # Remove some line end markers
try %{ execute-keys -draft \%s \h*(\+|:{2,})$ <ret> d } try %{ execute-keys -draft \%s \h*(\+|:{2,})$ <ret> d }
# Setup the doc_render_ranges option # Setup the doc_ranges option
set-option buffer doc_render_ranges %val{timestamp} set-option buffer doc_ranges %val{timestamp}
doc-render-regex \B(?<!\\)\*[^\n]+?(?<!\\)\*\B \A|.\z 'H' default+b doc-render-regex \B(?<!\\)\*[^\n]+?(?<!\\)\*\B \A|.\z 'H' default+b
doc-render-regex \b(?<!\\)_[^\n]+?(?<!\\)_\b \A|.\z 'H' default+i doc-render-regex \b(?<!\\)_[^\n]+?(?<!\\)_\b \A|.\z 'H' default+i
doc-render-regex \B(?<!\\)`[^\n]+?(?<!\\)`\B \A|.\z 'H' mono doc-render-regex \B(?<!\\)`[^\n]+?(?<!\\)`\B \A|.\z 'H' mono
doc-render-regex ^=\h+[^\n]+ ^=\h+ '~' title doc-render-regex ^=\h+[^\n]+ ^=\h+ '~' title
doc-render-regex ^={2,}\h+[^\n]+ ^={2,}\h+ '' header doc-render-regex ^={2,}\h+[^\n]+ ^={2,}\h+ '' header
doc-render-regex ^-{2,}\n.*?^-{2,}\n ^-{2,}\n '' block doc-render-regex ^-{2,}\n.*?^-{2,}\n ^-{2,}\n '' block
doc-render-regex <lt><lt>.*?<gt><gt> <lt><lt>.*,|<gt><gt> 'H' link doc-parse-links
# Remove escaping of * and ` # Remove escaping of * and `
try %{ execute-keys -draft \%s \\((?=\*)|(?=`)) <ret> d } try %{ execute-keys -draft \%s \\((?=\*)|(?=`)) <ret> d }
set-option buffer readonly true set-option buffer readonly true
add-highlighter buffer ranges doc_render_ranges add-highlighter buffer ranges doc_ranges
add-highlighter buffer wrap -word -indent add-highlighter buffer wrap -word -indent
map buffer normal <ret> :doc-jump<ret>
} }
define-command -params 1 \ define-command -params 1 \