summaryrefslogtreecommitdiff
path: root/src
AgeCommit message (Collapse)Author
2022-08-24Fix synopsis of write-quit commandsJohannes Altmanninger
Like other write commands, these support the -method switch, so indicate that in the synopsis.
2022-08-21Merge remote-tracking branch 'krobelus/set-remove-autoinfo'Maxime Coste
2022-08-21Avoid calling memcpy from empty string viewsMaxime Coste
ubsan is unhappy when passing a nullptr as the source pointer to memcpy even if the length is 0. Fixes #4720
2022-08-21Bypass RegexIterator in RegionsHighlighter::add_matchesMaxime Coste
2022-08-20Add support for field width and digit grouping in formatMaxime Coste
2022-08-20Slight code style tweakMaxime Coste
2022-08-20Remove unnecessary utf8 decoding when looking for EOL in regexMaxime Coste
2022-08-20Refactor RegionsHighlighter to share regexesMaxime Coste
Instead of storing regexes in each regions, move them to the core highlighter in a hash map so that shared regexes between different regions are only applied once per update instead of once per region Also change iteration logic to apply all regex together to each changed lines to improve memory locality on big buffers. For the big_markdown.md file described in #4685 this reduces initial display time from 3.55s to 2.41s on my machine.
2022-08-17Use make_array to avoid specifying the array sizeJohannes Altmanninger
When I wrote this line I wanted to avoid adding the array size but I didn't know about make_array(). I had unsuccessfully tried some alternatives, for example Array{"a", "b", "c"} which doesn't work because we need StringView (c.f. git blame on this line) also Array<StringView>{"a", "b", "c"} doesn't work because it's missing a template argument.
2022-08-17Rename button_to_str() to the more idiomatic to_string()Johannes Altmanninger
Analogous to the parent commit. This returns StringView, but it's immortal so it's even better than String.
2022-08-17Rename key_to_str() to the more idiomatic to_string()Johannes Altmanninger
This makes the function easier to find for newcomers because to_string() is the obvious name. It enables format() to do the conversion automatically which seems like good idea (since there is no other obvious representation). Of course this change makes it a bit harder to grep but that's not a problem with clang tooling. We need to cast the function in one place when calling transform() but that's acceptable.
2022-08-16Remove stale comment about StaticRegisterJohannes Altmanninger
Commit d470bd2cc (Make numeric registers setable, 2017-02-14) removed the user-provided StaticRegister::operator= in favor of a set() member function, so this comment is no longer valid.
2022-08-05Reuse existing character classes when possible in regexMaxime Coste
2022-08-05uniquify selection contents before generating regex for '*'Maxime Coste
Avoid generating regex with the same alternative repeated multiple times.
2022-08-05Add HashSet implemented as HashMap with void value typeMaxime Coste
2022-08-05Change HashMap not to support multiple identical keys by defaultMaxime Coste
We do not seem to have any uses for this remaining, and this is better opt-in with MultiHashMap
2022-08-03Merge remote-tracking branch 'krobelus/history-in-mappings'Maxime Coste
2022-08-03Merge remote-tracking branch 'krobelus/document-history-registers'Maxime 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-08-01Do not record prompt history when executing user mode mappingsJohannes Altmanninger
Commit 217dd6a1d (Disable history when executing maps, 2015-11-10) made it so with map global normal X %{:echo 123<ret>} X does not add to prompt history (%reg{:}). Unfortunately this behavior was not extended to mappings in the "user" keymap, nor to mappings in custom user modes. In my experience, not adding to history is almost always the expected behavior for mappings. Most users achieve this by adding a leading space: map global user X %{: echo 123<ret>} but that's awkward. We should have good defaults (no nnoremap) and map should work the same way across all modes. Fix this by also disabling history when executing user mappings. This is a breaking change but I think it only breaks hypothetical scenarios. I found some uses where user mappings add to history but none of them looks intentional. https://github.com/Delapouite/dot-in-the-sky/blob/f702a641d119fba558c06b24e5aba0ac73269076/.config/kak/kakrc#L169 https://github.com/mawww/config/blob/604ef1c1c2f4722505d3d29a4fc95e763a1fddbb/kakrc#L96 https://github.com/SolitudeSF/dot/blob/d22e7d6f681091fc3737fe460802f6d818bb7d18/kak/kakrc#L71 https://grep.app/search?q=map%20%28global%7Cbuffer%7Cwindow%29%20user%20.%2A%5B%21%3A/%5D%5B%5E%20%5D.%2A%3Cret%3E&regexp=true
2022-08-01Show the default values for -save-regs in autoinfo of exec/evalJohannes Altmanninger
They are documented in ":doc execeval" but it seems like a good idea to make this info more prominent.
2022-08-01Fix typo in eval/exec codeJohannes Altmanninger
Will touch similar code
2022-07-30Use menu behavior for completing builtins where appropriateJohannes Altmanninger
This allows to select completions without pressing Tab. There are two different obvious ways to add the menu bit. 1. When creating the "Completions" object, pass the Completions::Flags::Menu parameter. 2. If there is a completer function like "complete_scope", wrap it, e.g. "menu(complete_scope)". I have settled on always using 2 if there is a completer function and 1 otherwise. The advantage of 2 over 1 is that it allows to use the completer function in a context where we don't want the menu behavior (e.g. "complete-command"). --- Now the only* completion type where we usually don't use menu behavior is file completion. Unfortunately, menu behavior has poor interaction with directories' trailing slashes. Consider this (contrived) example: define-command ls -docstring "list directory contents" -params .. %{ echo -- %sh{ls "$@"} } complete-command -menu ls file Run ":ls kakoun<ret>". The prompt expands to ":ls kakoune/" before executing. Next, run ":<c-p>". This recalls ":ls kakoune/" and immediately selects the first completion, so on validation, the command will be ":ls kakoune/colors/", which is weird. [*] Also, expansions like %val{bufname} also don't use menu behavior. It wouldn't add value since validation doesn't add a closing delimiter. I have an experimental patch that adds closing delimiters automatically but I'm not sure if that's the right direction.
2022-07-28Use menu behavior when completing change-directoryJohannes Altmanninger
This makes "cd<space><ret>" change to the first completion, not to $HOME. This might be surprising but it should make sense. I don't have a concrete motivation but this should save a Tab press in some scenarios.
2022-07-28Use menu behavior when completing scope argumentsJohannes Altmanninger
We allow to abbreviate scopes ("set g" means the same thing as "set global") but that feature is a bit obscure. Users might figure out the menu completion behavior faster, so let's maybe use it here as well?
2022-07-28Use and extract functions for completing scope argumentsJohannes Altmanninger
Not really attached to this but it enables the next commit to use menu() for completing scopes. This refactoring is possible because we always have params[token_to_complete].length() == pos_in_token --- Instead of three separate functions, I originally tried to add template arguments to complete_scope(). That worked fine with g++ 12.1 but clang 14.0 complained when wrapping a menu() around a complete_scope() that relied on defaulted template arguments: commands.cc:1087:20: error: no matching function for call to 'menu' make_completer(menu(complete_scope), menu(complete_hooks), complete_nothing, ^~~~ commands.cc:116:6: note: candidate template ignored: couldn't infer template argument 'Completer' auto menu(Completer completer) ^
2022-07-28Fix autoinfo for "set-option -remove" not showing option-specific infoJohannes Altmanninger
On a command prompt like "set-option -remove buffer aligntab " we fail to show the aligntab-specific info . Fix this by skipping a leading -remove, just like we skip -add. Add an explicit specialization of contains() because otherwise I'd need to write something like contains(Array{"-add", "remove"}, param)
2022-07-28Remove redundant handling of "-add" from set-option completerJohannes Altmanninger
Switches are removed before invoking a command's completer (look for "std::not_fn(is_switch)". Remove completer code that attempts to handle switches.
2022-07-28Merge remote-tracking branch 'krobelus/embrace-menu-2'Maxime Coste
2022-07-28Merge remote-tracking branch 'krobelus/support-prompt-menu'Maxime Coste
2022-07-28Merge remote-tracking branch 'krobelus/prompt-completion-cut-at-cursor'Maxime Coste
2022-07-28Merge remote-tracking branch 'krobelus/support-shift-backspace'Maxime Coste
2022-07-24Merge remote-tracking branch 'krobelus/startup-info'Maxime Coste
2022-07-24Merge remote-tracking branch 'krobelus/complete-expansions-in-double-quotes'Maxime Coste
2022-07-24Merge remote-tracking branch 'krobelus/no-redundant-menu'Maxime Coste
2022-07-22Support "prompt -menu" to mark completions as authoritativeJohannes Altmanninger
This gives the "prompt" command the same "-menu" switch as "complete-command" and "define-command". I don't think anyone has asked for it but it seems like a good idea?
2022-07-22Extract function for parsing completion switchesJohannes Altmanninger
Both "define-command" and "prompt" use the same logic, so share it. This will make it easy to implement "prompt -menu". This reveals a problem with PromptCompleterAdapter: when converting it to std::function and then to bool, it always evaluates to true because it has an operator(). However, it should evaluate to false if the adaptee holds no valid function (e.g. is a default-constructed std::function). Otherwise we try to call a non-existant function. Tweak PromptCompleterAdapter to work for empty inputs.
2022-07-22Move input completer when constructing PromptCompleterAdapterJohannes Altmanninger
I think we usually do this when passing completers.
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-21Update startup info with p/P breaking changeJohannes Altmanninger
2022-07-21Complete double-quoted expansions in prompt modeJohannes Altmanninger
This adds completions for :echo "%val{
2022-07-21Elide temporary vector when completing register namesJohannes Altmanninger
Just like in the parent commit, this requires us to use a non-owning type. Technically, these strings all benefit from SSO, so there is no lifetime issue, but we can't deduce that from the types. I guess we could use InplaceString just as well.
2022-07-21Use menu behavior for add-highlighter/remove-highlighter completionJohannes Altmanninger
This means that typing :add-highlighter g c 80 results in :add-highlighter global/ column 80 Paths for add-highlighter do not get the menu behavior because we want to be able to type "global/foo" even if "global/foobar" exists.
2022-07-21Elide temporary vector when completing keymap modes (user modes)Johannes Altmanninger
complete() merely iterates over its input, so we can pass it a range instead of a vector. For some reason, this requires specifying the type of the static array, or else its elements become String which triggers this assertion: static_assert(not std::is_same<decltype(*begin(container)), String>::value, "complete require long lived strings, not temporaries"); Specify the type with an explicit Array<StringView, 8>. This is pretty ugly but the alternative of appending "_sv" to every single array element seems worse? If we modify the vector of user modes while complete() is iterating over, we could crash -- but that scenario is impossible since both only happen inside the single-threaded server process.
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-07-21Deduplicate functions for completing alias namesJohannes Altmanninger
"complete_alias_name" is a better name then "complete_alias" because it's consistent with more similar names, which are: complete_client_name complete_command_name complete_module_name complete_option_name complete_register_name complete_scope complete_face
2022-07-21Make completers take "StringView" instead of "const String&" for ↵Johannes Altmanninger
compatibility with PromptCompleter We define using PromptCompleter = std::function<Completions (const Context&, CompletionFlags, StringView, ByteCount)>; Some command completers are *almost* convertible to PromptCompleter; the only difference is the string type of the prefix argument. The later commits in this series want to use menu() on the completers. Enable this by harmonizing the types.
2022-07-21Remove redundant check for menu bitJohannes Altmanninger
can_auto_insert_completion already requires the menu bit.
2022-07-19Remove out-of-date column computation in show-whitespacesMaxime Coste
Now that we compute display buffer on whole lines, it does not make sense to compute the tab padding based off the window column position Fixes #4674