summaryrefslogtreecommitdiff
path: root/src/command_manager.cc
AgeCommit message (Collapse)Author
2024-10-28Only check for ascii horizontal blanks during command parsingMaxime Coste
The general is_horizontal_blank supports various unicode blanks, but passing an utf8 continuation byte to it can lead to surprising results as we can match with 0xA0 (when char is unsigned). Fixes #5250
2024-10-22Remove now unused CompletionFlagsMaxime Coste
Since shell-script-completions now runs the script asynchronously and unconditionally, there is no use for the CompletionFlags::Fast anymore which means we can remove that type altogether.
2024-08-26Do not gather full input data in a single string when pipingMaxime Coste
Refactor ShellManager and pipe to feed lines from the buffer directly, this should reduce memory use when piping big chunks of buffers. The pipe output is still provided as a single big buffer.
2024-08-12Move debug utils to debug.hh/debug.ccMaxime Coste
Lots of code includes buffer_utils.hh just for write_to_debug_buffer which pulls many unnecessary dependencies. Reorganise to reduce compile times.
2023-11-14Use a separate copy of the command completer for each completionMaxime Coste
This make the completer lifetime tied to the Prompt mode and removes the need for the Start flag. It also makes it possible to cleanup on completer destruction.
2023-11-11small code cleanupMaxime Coste
2023-11-03Fix "%val{selections_desc}" being joined by nul instead of spaceJohannes Altmanninger
This should fix a bug in lint.kak though I didn't check.
2023-11-03Use explicit target types for gather calls to bypass clang regressionMaxime Coste
Since clang-16 there has been a regression in the P0522R0 support. (Bug report at https://github.com/llvm/llvm-project/issue/63281) Closes #4892
2023-08-13Add a ProfileScope helper class to replace most profiling usesMaxime Coste
2023-05-04Add support for recursive expansions with %exp{...}Maxime Coste
%exp{...} just expands its content the same way double quoted strings do, but using a named expansion type makes it possible to use the more quoting mechanism to avoid quoting hell.
2023-02-17Complete arguments to "echo -to-file"Johannes Altmanninger
Including this here because grandparent parent commit broke completions for "edit -fifo".
2023-02-17Do not complete redundant switchesJohannes Altmanninger
2023-02-17Use parameter parser to skip switch args in completionJohannes Altmanninger
The command line "hook -group xyz " should get scope completions but it actually gets hook completions because "xyz" is wrongly interpreted as positional argument. Fix this by using the parameters parser to compute positional arguments. Fixes #4840
2023-02-14Immediately execute ModuleLoaded hooks for already loaded modulesMaxime Coste
This is trickier than expected because ModuleLoaded hooks can (as any other hooks) use arbitrary regular expressions for their filter. Fixes #4841
2022-12-15Support adding ByteCount to void/char pointers without castingMaxime Coste
2022-08-01Do not complete command switches after --Johannes Altmanninger
Recently, switch completion were given the menu behavior. Unfortunately this breaks cases like :echo -- -mark<ret> where the hypothetical user wanted to actually display "-mark", not "-markup". Simply bail if there is a double-dash. This is not fully correct, for example it wrongly disables switch completion on echo -to-file -- - but that's minor, we can fix it later. In future, we should reuse the ParametersParser when computing completions, which will obsolete this workaround.
2022-07-28Merge remote-tracking branch 'krobelus/embrace-menu-2'Maxime Coste
2022-07-28Merge remote-tracking branch 'krobelus/prompt-completion-cut-at-cursor'Maxime Coste
2022-07-21Compute prompt completion only from characters left of the cursorJohannes Altmanninger
If I type :echo -mx I get no completions, even when I move the cursor on the x. If I replace the x with a k, I get a completion "-markup". The odd thing is that if I accept the completion while the cursor is on the k, then the commandline will be :echo markupk Evidently, the characters under cursor (x/k) influence the completion (actually all letters right of the cursor do), but they are not incorporated in the final result, which is weird. I think there are two consistent behaviors: 1. Compute completions only from characters left of the cursor. We already do this in insert mode completion, and when completing the command name in a prompt. 2. Compute completions from the whole token, and when accepting a completion, replace the whole token. Most readline-style completion systems out there implement 1. A notable exception is fish's tab-completion. I think we should stick to 1 because it's more predictable and familiar. Do that. This allows us to get rid of a special case for completing command names, because the new behavior subsumes it. In fact, I think this would allow us to get rid of most "pos_in_token" or "cursor_pos" completer parameters. I believe the only place where we it's actually different from the end of the query is in "shell-script" completers, where we expose "$kak_pos_in_token". I think we can still remove that parameter and just cut the commandline at the cursor position before passing it to a "shell-script" completer. Then we also don't need "$kak_token_to_complete" (but we can still keep expose them for backwards compatibility).
2022-07-21Complete double-quoted expansions in prompt modeJohannes Altmanninger
This adds completions for :echo "%val{
2022-07-21Use menu behavior for completion of switchesJohannes Altmanninger
We already use the menu behavior in complete_command_name(); let's do the same for switches, since we can complete all valid inputs and it can save a Tab key in some scenarios. CommandManager::complete is fairly complex. We can't expect callers to add the menu bit when appropriate, so we currently do it here.
2022-07-21Offer "--" as completion when completing switchesJohannes Altmanninger
The next commit will give switch completions the menu behavior, so this is necessary so we can still type "echo --" without an auto-expansion to "echo -to-file".
2022-05-30Fix switch completionMaxime Coste
2022-05-26Filter out switches when completing commandsMaxime Coste
Fixes #4625 Fixes #4209 Fixes #4040
2022-05-05Fix parsing of INT_MIN %argMaxime Coste
Fixes #4601
2022-03-08Fix buffer overflow in parse_quotedtomKPZ
This fixes a crash when using kak-lsp with bash-language-server. The issue is that the second read() in parse_quoted may read past the end of the string. If this happens and the condition on line 126 is false, then the loop on line 119 will continue to read past the end of the buffer since it checks for state.pos != end instead of state.pos < end, which will likely result in a crash. The fix is to add a check for the buffer end before the second read. The added test fails without the change and passes with the change.
2022-03-06Add a complete-command command to configure command completionMaxime Coste
This makes it possible to change command completion in hooks and paves the way to more flexibility in how custom commands can be completed
2021-11-25Templatize parse_quoted to avoid utf8 decoding with ascii delimiterMaxime Coste
2021-11-21More C++20 refactoringsMaxime Coste
Use CTAD instead of make functions, requires instead of enable_if
2021-08-09Restore prompt completion for "%opt{"Johannes Altmanninger
Commit 2289f350 ("Remove command parsing Reader and just track a ParserState") introduced a small regression in parse_percent_token() because we failed to recognize a token like %val{ as percent-expansion. I tried to add a test case but a UI test doesn't seem possible, e.g. kak -ui json -e "exec ':echo %opt{<tab>}<ret>'" prints: 'exec': option not found: ''
2021-07-20Generate different parse_quoted_balanced for each quote pairMaxime Coste
This seems to slightly improve parse speed which is where kakoune spends most of its time during startup.
2021-07-09Remove command parsing Reader and just track a ParserStateMaxime Coste
The Reader abstraction was leading to suboptimal code by encouraging decoding utf8 separately from advancing to next codepoint.
2021-07-09Avoid temporary vector in expand_tokenMaxime Coste
Instead of return a vector, take the target vector as a parameter and push tokens to it.
2021-07-09Avoid copying token content strings in expand_tokenMaxime Coste
We can move that data instead of copying
2021-06-24Only compute command coordinates when necessaryMaxime Coste
Tracking the line/column of each token takes a surprising big part of the command parsing logic runtime and is only necessary when we hit an error.
2021-06-24Fix invalid command profiling logicMaxime Coste
2021-05-18Fix completion past explicitely closed tokensMaxime Coste
This fixes an issue where completion would still be provided after the closing character of a token, which could then get frustrating combined with auto-insertion of completions. For example, inserting `%{<newline>}` for a command-completed token (such as the commands for a hook) would still trigger completion right after the `}` and that completion would get auto-inserted **replacing** that closing `}`.
2021-03-31Profile individual command runtimeMaxime Coste
Different approach than the one suggested by eraserhd Closes $4095
2021-03-31Tweak completion quoting behaviour once againMaxime Coste
Quote by wrapping in quotes if we are replacing the whole token, using backspaces if the completion only adds to it. This ensure that the inserted completion will be correctly parsed once validated. Fixes #4121
2021-03-02Re-tweak command name completion behaviourMaxime Coste
It turns out the fix for #4061 was breaking auto-selection with space of command names.
2021-02-25Tweak requoting behaviourMaxime Coste
Only requote when completion is replacing the whole token Do not requote command names as they should not require it, tag them as quoted. Fixes #4061
2021-02-01Fix resizing strings to -1 lengthMaxime Coste
Fixes #4042
2021-01-02command_manager: only remove last eol in %sh{} expansionsCole Helbling
This makes it possible to keep significant EOL in shell expansions (e.g. for use with clipboard helpers).
2020-11-18Restore auto-select on return, add a flag to disable that for commandsMaxime Coste
Fixes #3849 Again
2020-10-19Auto-insert best completion on space for menu completionsMaxime Coste
The menu flag signifies that only the completions are valid arguments, hence it makes sense to auto insert the best one on space. Because full match is always considered the best match in completion ranking, this should always have a reasonable behaviour. This makes it harder to enter a hidden command, but completion can always be disabled via <c-o> or by quoting in those rare cases.
2020-07-19Code style tweaksMaxime Coste
2020-06-16A module is not loaded after failing during loadMaxime Coste
distinguish the loading from loaded state, detect recursive loading.
2020-06-01Replace some tag dispatch with if constexprMaxime Coste
2020-03-13Merge remote-tracking branch 'lenormf/fix-completion-escaping'Maxime Coste
2020-03-13Handle invalid utf8 in command line a bit betterMaxime Coste
Reduce the amount of decoding by working directly on bytes. Fixes #3388