Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[REQUEST] Add "right hand side" mapping to :debug mappings #5152

Open
dontlaugh opened this issue Apr 23, 2024 · 4 comments · May be fixed by #5164
Open

[REQUEST] Add "right hand side" mapping to :debug mappings #5152

dontlaugh opened this issue Apr 23, 2024 · 4 comments · May be fixed by #5164

Comments

@dontlaugh
Copy link
Contributor

dontlaugh commented Apr 23, 2024

Feature

Currently, when you run :debug mappings it prints something like the following to the *debug* buffer.

 * normal m: 

This is the corresponding kakscript mapping from my config

# remap movement keys for Colemak-DH
map global normal m h  # move left

Here is the output that could be better:

 * normal m h: 

Adding the right hand side to :debug mappings would tell me not only that a mapping was changed, but what it was changed to.

For mappings to more complex commands, perhaps we introduce quotes. So this kakscript mapping

# run gofmt
map buffer user 'f' ':format-buffer<ret>' -docstring 'go: run gofmt'

...becomes this output in *debug*

 * user 'f' ':format-buffer<ret>': go: run gofmt

This is a small, specific change spawned from the larger discussion in #5150

@dontlaugh
Copy link
Contributor Author

I've got the right hand side printing with the Kakoune to_string function. The output seems valid, but to_string expands to the "named" values like <minus>, which makes it look a little strange.

 * lsp =: '<esc>:<space>lsp<minus>range<minus>formatting<ret>' format selections

Here's the change so far dontlaugh@039544d

debug mappings output
*** This is the debug buffer, where debug info will be written ***
Mappings:
 * normal <left>: 'h' 
 * normal <right>: 'l' 
 * normal <down>: 'j' 
 * normal <up>: 'k' 
 * normal <s-left>: 'H' 
 * normal <s-right>: 'L' 
 * normal <s-down>: 'J' 
 * normal <s-up>: 'K' 
 * normal <end>: '<a-l>' 
 * normal <home>: '<a-h>' 
 * normal <s-end>: '<a-L>' 
 * normal <s-home>: '<a-H>' 
 * normal m: 'h' 
 * normal n: 'j' 
 * normal e: 'k' 
 * normal i: 'l' 
 * normal M: 'H' 
 * normal N: 'J' 
 * normal E: 'K' 
 * normal I: 'L' 
 * normal k: 'n' 
 * normal K: 'N' 
 * normal ': 'm' 
 * normal h: 'i' 
 * normal H: 'I' 
 * normal l: 'e' 
 * normal L: 'E' 
 * goto d: '<esc>:lsp<minus>definition<ret>' definition
 * goto r: '<esc>:lsp<minus>references<ret>' references
 * goto y: '<esc>:lsp<minus>type<minus>definition<ret>' type definition
 * goto m: 'h' start of line
 * goto n: 'j' end of buffer
 * goto e: 'k' top of buffer
 * goto i: 'l' end of line
 * user s: ':siblings<minus>tree<minus>repl<ret>' List buffile siblings in repl
 * user /: ':comment<minus>line<ret>' comment line (toggle)
 * user c: ':' command prompt
 * user i: '<a-i>' select within
 * user w: ':w<ret>' write buffer
 * user q: ':q<ret>' quit
 * user Q: ':q!<ret>' quit without saving
 * man g: ':man<minus>jump<ret>' Jump to a man page using selected man page link
 * man j: ':man<minus>link<minus>next<ret>' Go to next man page link
 * man k: ':man<minus>link<minus>prev<ret>' Go to previous man page link
 * man m: ':man<space>' Look up a man page
 * lsp a: '<esc>:<space>lsp<minus>code<minus>actions<ret>' show code actions for current position
 * lsp c: '<esc>:<space>lsp<minus>capabilities<ret>' show language server capabilities
 * lsp d: '<esc>:<space>lsp<minus>definition<ret>' go to definition
 * lsp e: '<esc>:<space>lsp<minus>diagnostics<ret>' list project errors, info, hints and warnings
 * lsp f: '<esc>:<space>lsp<minus>formatting<ret>' format buffer
 * lsp h: '<esc>:<space>lsp<minus>hover<ret>' show info for current position
 * lsp H: '<esc>:<space>lsp<minus>hover<minus>buffer<ret>' show info for current position in a scratch buffer
 * lsp i: '<esc>:<space>lsp<minus>implementation<ret>' go to implementation
 * lsp j: '<esc>:<space>lsp<minus>outgoing<minus>calls<ret>' list outgoing call for function at cursor
 * lsp k: '<esc>:<space>lsp<minus>incoming<minus>calls<ret>' list incoming call for function at cursor
 * lsp l: '<esc>:<space>lsp<minus>code<minus>lens<ret>' apply a code lens from the current selection
 * lsp o: '<esc>:<space>lsp<minus>workspace<minus>symbol<minus>incr<ret>' search project symbols
 * lsp n: '<esc>:<space>lsp<minus>find<minus>error<ret>' find next error
 * lsp p: '<esc>:<space>lsp<minus>find<minus>error<space><minus><minus>previous<ret>' find previous error
 * lsp q: '<esc>:<space>lsp<minus>exit<ret>' exit session
 * lsp r: '<esc>:<space>lsp<minus>references<ret>' list symbol references
 * lsp R: '<esc>:<space>lsp<minus>rename<minus>prompt<ret>' rename symbol
 * lsp s: '<esc>:<space>lsp<minus>goto<minus>document<minus>symbol<ret>' jump to document symbol
 * lsp S: '<esc>:<space>lsp<minus>document<minus>symbol<ret>' list document symbols
 * lsp v: '<esc>:<space>lsp<minus>selection<minus>range<ret>' select inner/outer nodes
 * lsp V: '<esc>:<space>lsp<minus>selection<minus>range<space>cached<ret>' select inner/outer nodes (re-use previous call)
 * lsp y: '<esc>:<space>lsp<minus>type<minus>definition<ret>' go to type definition
 * lsp [: '<esc>:<space>lsp<minus>hover<minus>previous<minus>symbol<ret>' show hover for previous symbol
 * lsp ]: '<esc>:<space>lsp<minus>hover<minus>next<minus>symbol<ret>' show hover for next symbol
 * lsp {: '<esc>:<space>lsp<minus>previous<minus>symbol<ret>' goto previous symbol
 * lsp }: '<esc>:<space>lsp<minus>next<minus>symbol<ret>' goto next symbol
 * lsp 9: '<esc>:<space>lsp<minus>hover<minus>previous<minus>function<ret>' show hover for previous function
 * lsp 0: '<esc>:<space>lsp<minus>hover<minus>next<minus>function<ret>' show hover for next function
 * lsp (: '<esc>:<space>lsp<minus>previous<minus>function<ret>' goto previous function
 * lsp ): '<esc>:<space>lsp<minus>next<minus>function<ret>' goto next function
 * lsp &: '<esc>:<space>lsp<minus>highlight<minus>references<ret>' lsp-highlight-references
 * lsp =: '<esc>:<space>lsp<minus>range<minus>formatting<ret>' format selections
 * lsp-selection-range j: '<esc>:<space>lsp<minus>selection<minus>range<minus>select<space>down<ret>' select inner node
 * lsp-selection-range k: '<esc>:<space>lsp<minus>selection<minus>range<minus>select<space>up<ret>' select outer node
 * lsp-selection-range b: '<esc>:<space>lsp<minus>selection<minus>range<minus>select<space>bottom<ret>' select innermost node
 * lsp-selection-range t: '<esc>:<space>lsp<minus>selection<minus>range<minus>select<space>top<ret>' select outermost node
Error: buffer is read-only

We want the <named> version in many cases like <ret>, but not in cases like <minus>. Maybe we need a new function to print things this way.

@Screwtapello
Copy link
Contributor

Screwtapello commented Apr 26, 2024

I guess <minus> has a long name so you can use it at the beginning of the right-hand side of a mapping:

# This works
map global normal x <minus>blorp

# This fails with "unknown option '-blorp'"
map global normal x -blorp

It's not necessary in other circumstances, but at least it's unambiguous, and it might be preferable than trying to teach to_string() about all the circumstances where escaping might be necessary.

@krobelus
Copy link
Contributor

Interesting. It is certainly a possibility to use the non-named (non-canonical) versions
for plus/minus/semicolon/percent in a multi-key context (which as of today is only used for recorded macros).
Unless minus is the very first character.
Raw ; should be fine given that we also include raw " and ' so the string must be escaped already before evaluation.

So I think that would be a fine workaround.

An alternative is to preserve the input sequence (store it separately from the parsed version).

I think your change is good but overall there are limits to what :debug mappings can do.
I'm not sure if we want to encourage using it outside of some debugging scenarios (I've actually never used it).
If you instead navigate to the kakrc where you define your mapping, you will get a strictly better UI.
You get extra context from adjacent code and comments etc., exactly how you chose to lay it out in your config file.


Maybe the LSP plugin should stop pre-defining mappings.
Instead include recommended mappings in the documentation (perhaps viewable with doc lsp or similar), suitable for pasting into your config.
That might simplify things - it's weird that some functionality is exposed both as default mapping and as command.
I'm not sure.

@dontlaugh
Copy link
Contributor Author

I agree that teaching to_string to print a different way from what it does right now is not worth it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants