Skip to content
Open
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
26 changes: 14 additions & 12 deletions rc/tools/jump.kak
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ declare-option -docstring "name of the client in which utilities display informa

provide-module jump %{

declare-option -hidden str jump_current_buffer ''
declare-option -hidden int jump_current_line 0

define-command -hidden jump %{
Expand All @@ -14,24 +15,25 @@ define-command -hidden jump %{
execute-keys ',xs^([^:\n]+):(\d+):(\d+)?<ret>'
set-register a %reg{1} %reg{2} %reg{3}
}
set-option global jump_current_buffer %val{bufname}
set-option buffer jump_current_line %val{cursor_line}
evaluate-commands -try-client %opt{jumpclient} -verbatim -- edit -existing -- %reg{a}
try %{ focus %opt{jumpclient} }
}
}
}

define-command jump-next -params 1.. -docstring %{
define-command jump-next -params .. -docstring %{
jump-next <bufname>: jump to next location listed in the given *grep*-like location list buffer.
} %{
evaluate-commands -try-client %opt{jumpclient} -save-regs / %{
buffer %arg{@}
jump-select-next
jump
evaluate-commands -try-client %opt{jumpclient} -save-regs / %sh{
args='%arg{@}'
[ "$#" -eq 0 ] && args='%opt{jump_current_buffer}'
printf %s\\n "buffer $args" jump-select-next jump
}
try %{
evaluate-commands -client %opt{toolsclient} %{
buffer %arg{@}
buffer %opt{jump_current_buffer}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as written, this breaks users who override jump in buffer scope,
for example the kakoune-lsp plugin

creates some scratch buffers with
alias buffer jump "%val{hook_param_capture_1}-jump"

where the rhs can be one of

lsp-goto-jump
lsp-document-symbol-jump
lsp-diagnostics-jump

which are not aware of %opt{jump_current_buffer}

So it seems if we want this, we should set jump_current_buffer outside jump because that's intended to be overridden (as are jump-select-next and jump-select-previous).

Overall I'm not sure if this PR is worth it. It introduces extra implicit state.
Consider that other commands like :buffer have no memory either; but we do have generic command history which should cover some of your need.
I'm not against DWIM but it can be a lot of work to get right.

Does the jump-next -matching ... approach not work for the same use case?
We should definitely document that better.

execute-keys gg %opt{jump_current_line}g
}
}
Expand All @@ -44,17 +46,17 @@ define-command -hidden jump-select-next %{
execute-keys ge %opt{jump_current_line}g<a-l> /^[^:\n]+:\d+:<ret>
}

define-command jump-previous -params 1.. -docstring %{
define-command jump-previous -params .. -docstring %{
jump-previous <bufname>: jump to previous location listed in the given *grep*-like location list buffer.
} %{
evaluate-commands -try-client %opt{jumpclient} -save-regs / %{
buffer %arg{@}
jump-select-previous
jump
evaluate-commands -try-client %opt{jumpclient} -save-regs / %sh{
args='%arg{@}'
[ "$#" -eq 0 ] && args='%opt{jump_current_buffer}'
printf %s\\n "buffer $args" jump-select-previous jump
}
try %{
evaluate-commands -client %opt{toolsclient} %{
buffer %arg{@}
buffer %opt{jump_current_buffer}
execute-keys gg %opt{jump_current_line}g
}
}
Expand Down
Loading