Commit Graph

9911 Commits

Author SHA1 Message Date
Johannes Altmanninger
3165f28a3c Make parameter const 2022-08-29 08:01:43 +02:00
Johannes Altmanninger
1333fe21d0 Fix clang warning regarding useless braces when using HashSet
clang/clangd complain about the new HashSet type:

	hash_map.cc:98:20: warning: braces around scalar initializer [-Wbraced-scalar-init]
	        set.insert({10});
	                   ^~~~

The argument to HashSet<int>::insert is just an int, so we don't
need braces.  Only an actual HashMap would need braces to construct
a HashItem object.
2022-08-28 15:23:29 +02:00
Johannes Altmanninger
7ae31b6778 Show write -force parameter only for commands that support it
When passing a filename parameter to "write", the -force parameter
allows overwriting an existing file.
The "write!" variant (which allows writing files where the current
user does not have write permissions) already implies -force.
All other variants (like write-quit or write-all) do not take a
file parameter.
Hence -force is relevant only for "write".  Let's hide it from the
autoinfo of the other commands.

It's difficult to avoid duplication when constructing the constexpr
SwitchMap because String is not constexpr-enabled.  Today, all our
SwitchMap objects are known at compile time, so we could make SwitchMap
use StringView to work around this. In future we might want to allow
adding switches at runtime, which would need String again to avoid
lifetime issues.
2022-08-28 09:28:06 +02:00
Johannes Altmanninger
21469c553d rc ledger: don't use region highlighter for simple keywords
As reported in
https://github.com/mawww/kakoune/issues/4685#issuecomment-1200530001
ledger.kak defines a region end that matches every character of
the buffer. This causes performance issues for large buffers.
Since the affected regions are only ever filled with a single color,
just use a regex highlighter instead of a region highlighter.
This improves performance when loading the file for the first time.

Speedup on [example.journal.txt](https://github.com/mawww/kakoune/issues/4685#issuecomment-1193243588)

	$ HOME=$PWD hyperfine -w 1 'git checkout HEAD'{~,}' -- :/rc/filetype/ledger.kak && ./kak.opt example.journal.txt -e "modeline-parse; hook global NormalIdle .* quit" -ui dummy'
	Benchmark 1: git checkout HEAD~ -- :/rc/filetype/ledger.kak && ./kak.opt example.journal.txt -e "modeline-parse; hook global NormalIdle .* quit" -ui dummy
	  Time (mean ± σ):     362.1 ms ±   5.1 ms    [User: 336.6 ms, System: 30.2 ms]
	  Range (min … max):   352.6 ms … 369.1 ms    10 runs
	 
	Benchmark 2: git checkout HEAD -- :/rc/filetype/ledger.kak && ./kak.opt example.journal.txt -e "modeline-parse; hook global NormalIdle .* quit" -ui dummy
	  Time (mean ± σ):     271.2 ms ±  16.7 ms    [User: 252.8 ms, System: 24.0 ms]
	  Range (min … max):   253.9 ms … 305.0 ms    10 runs
	 
	Summary
	  'git checkout HEAD -- :/rc/filetype/ledger.kak && ./kak.opt example.journal.txt -e "modeline-parse; hook global NormalIdle .* quit" -ui dummy' ran
	    1.33 ± 0.08 times faster than 'git checkout HEAD~ -- :/rc/filetype/ledger.kak && ./kak.opt example.journal.txt -e "modeline-parse; hook global NormalIdle .* quit" -ui dummy'
2022-08-28 08:21:57 +02:00
Johannes Altmanninger
348b3f9d9d Fix synopsis of write-quit commands
Like other write commands, these support the -method switch, so
indicate that in the synopsis.
2022-08-24 22:21:06 +02:00
Maxime Coste
884490aaa3 Merge remote-tracking branch 'm-kru/vhdl_real_type' 2022-08-21 18:47:25 +02:00
Maxime Coste
48408de698 Merge remote-tracking branch 'm-kru/vhdl_file_type_fixes' 2022-08-21 18:47:18 +02:00
Maxime Coste
c762a00967 Merge remote-tracking branch 'krobelus/markdown-fixes' 2022-08-21 18:45:17 +02:00
Maxime Coste
dbe9fe4f10 Merge remote-tracking branch 'krobelus/doc-keymap-new-space' 2022-08-21 18:39:15 +02:00
Maxime Coste
13a95b0ba0 Merge remote-tracking branch 'krobelus/set-remove-autoinfo' 2022-08-21 18:38:28 +02:00
Maxime Coste
d076c033e7 Avoid calling memcpy from empty string views
ubsan is unhappy when passing a nullptr as the source pointer to
memcpy even if the length is 0.

Fixes #4720
2022-08-21 17:52:51 +02:00
Maxime Coste
efa45f8bdd Bypass RegexIterator in RegionsHighlighter::add_matches 2022-08-21 10:25:51 +02:00
Maxime Coste
021da117cf Add support for field width and digit grouping in format 2022-08-20 11:03:03 +02:00
Maxime Coste
0c1d4808fa Slight code style tweak 2022-08-20 11:03:03 +02:00
Maxime Coste
21047db4a0 Remove unnecessary utf8 decoding when looking for EOL in regex 2022-08-20 11:03:03 +02:00
Maxime Coste
c8c8051bd0 Refactor RegionsHighlighter to share regexes
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-20 11:02:59 +02:00
Johannes Altmanninger
ce985062bc doc keymap: update for <space>/, swap 2022-08-17 00:48:12 +02:00
Johannes Altmanninger
02058e0427 Clarify changelog on user mode prompt history
This wording was valid for an old version of that patch that foolishly
add a switch to "map" to allow recording history.  Happily we found
a better solution. Now commands inside user mappings never add to
prompt history (unless you use "set-register"), so be clear about that.
2022-08-17 00:48:12 +02:00
Johannes Altmanninger
d324e506e3 Use make_array to avoid specifying the array size
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-17 00:42:12 +02:00
Johannes Altmanninger
0eb4e68c40 Rename button_to_str() to the more idiomatic to_string()
Analogous to the parent commit.

This returns StringView, but it's immortal so it's even better
than String.
2022-08-17 00:38:58 +02:00
Johannes Altmanninger
feb912fb9f rc markdown: use language highlighting also for indented code blocks inside lists 2022-08-17 00:38:58 +02:00
Johannes Altmanninger
01f3d7cbda Rename key_to_str() to the more idiomatic to_string()
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-17 00:38:58 +02:00
Johannes Altmanninger
615ec3ef7e rc markdown: use language highlighting also for indented code blocks 2022-08-17 00:38:58 +02:00
Johannes Altmanninger
9d362b8b3e rc markdown: fix loading language highlighter module given multiple code blocks
After opening a markdown file

	```b
	```
	```c
	int main() {}
	```

markdown-load-languages will run an "evaluate-commands -itersel".
The first selection makes us run "require-module b", which fails
because that module can't be found.  Since -itersel only ignores the
"no selection remaining" error we fail to run "require-module c". Fix
this by ignoring errors.
2022-08-17 00:38:58 +02:00
Johannes Altmanninger
b633b6f9c3 rc restructuredtext: fix code block regex
Commit 9ea6b88c1 (Fix remaining kak scripts to use the new highlighter
syntax, 2018-07-01) changed the regex that detects HTML code blocks
from

	\.\.\h*code::\h*html\h*\n

to

	\.\.\h*html::\h*c\h*\n

the stray c looks wrong. According to
https://www.sphinx-doc.org/en/master/usage/restructuredtext/directives.html#showing-code-examples
a code block looks like

	.. code-block:: html

	   Some HTML code.

Correct the regex accordingly.

The original version used "code" instead of "cod- block".  That was
incorrect because "code" requires a different syntax (no "..") and
creates inline code blocks (for which we could add highlighting
later), see
https://www.sphinx-doc.org/en/master/usage/restructuredtext/roles.html#role-code
2022-08-17 00:38:58 +02:00
Johannes Altmanninger
08ea6d07e4 Remove stale comment about StaticRegister
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-16 19:15:22 +02:00
Ameer Ghani
91cadb2150 rc/filetype/dockerfile: detect filenames that contain special characters
Dockerfiles of the form `Dockerfile.foo-bar` were not detected for syntax
highlighting.

Mainly meaning for this to capture _ and -, but I don't see why we wouldn't
capture any special character.
2022-08-16 11:50:30 -04:00
Michał Kruszewski
ce18ac9918 VHDL filetype: Fix if statement behavior. 2022-08-15 13:41:07 +02:00
Michał Kruszewski
f3a05d41cb VHDL filetype: Fix behavior for case statement. 2022-08-15 13:37:28 +02:00
Michał Kruszewski
ed7078230f VHDL filetype: Fix adding closing tags. 2022-08-15 12:45:32 +02:00
Michał Kruszewski
0f3aaa0ecd VHDL filetype: Don't increase indent after when in case statement. 2022-08-15 10:39:13 +02:00
Maxime Coste
ca71d8997d Reuse existing character classes when possible in regex 2022-08-05 20:31:39 +10:00
Maxime Coste
26d14d52bb uniquify selection contents before generating regex for '*'
Avoid generating regex with the same alternative repeated multiple
times.
2022-08-05 20:10:11 +10:00
Maxime Coste
89cd3c52eb Add HashSet implemented as HashMap with void value type 2022-08-05 20:06:34 +10:00
Maxime Coste
9fb7d90449 Change HashMap not to support multiple identical keys by default
We do not seem to have any uses for this remaining, and this is
better opt-in with MultiHashMap
2022-08-05 19:20:00 +10:00
Michał Kruszewski
ae991e8a94 VHDL filetype: Highlight real type. 2022-08-03 13:44:53 +02:00
Maxime Coste
31e9fc3cef Merge remote-tracking branch 'krobelus/history-in-mappings' 2022-08-03 20:37:44 +10:00
Maxime Coste
fa209a9a97 Merge remote-tracking branch 'krobelus/document-history-registers' 2022-08-03 19:51:22 +10:00
Maxime Coste
4361a7e120 Merge remote-tracking branch 'krobelus/no-switches-after-ddash' 2022-08-03 19:50:00 +10:00
Johannes Altmanninger
e13b435783 Do not complete command switches after --
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-01 12:34:22 +02:00
Johannes Altmanninger
c335712e4e doc registers: document prompt history registers
So far they have only been talked about in source code
(HistoryRegister), not in documentation.

Let's give them an official name so users can find them better;
"prompt history register" seems better than "history register" since
the former gives more context. OTOH, in future other registers (like @)
could grow into history registers, so I'm not sure.

State that the history registers are only changed by _interactive_
prompts; that's not quite true yet for user modes but I'll push a
separate fix for that.
2022-08-01 10:15:52 +02:00
Johannes Altmanninger
395f438378 Remove unnecessary leading space in prompt from mappings
We often use the pattern «map global normal ": foo"».  The space
after the colon is unnecessary since execution of the mapping won't
add to history anyway, since 217dd6a1d (Disable history when executing
maps, 2015-11-10).
With the parent commit, the space is no longer necessary for user
mappings, so there is no reason to continue the cargo-cult.

Remove the space from mappings to set a good example.
2022-08-01 07:37:02 +02:00
Johannes Altmanninger
a36473f4bb Do not record prompt history when executing user mode mappings
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.

f702a641d1/.config/kak/kakrc (L169)
604ef1c1c2/kakrc (L96)
d22e7d6f68/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-01 07:37:02 +02:00
Johannes Altmanninger
253b13281e Show the default values for -save-regs in autoinfo of exec/eval
They are documented in ":doc execeval" but it seems like a good idea
to make this info more prominent.
2022-08-01 07:15:08 +02:00
Johannes Altmanninger
d999a00b0c Fix typo in eval/exec code
Will touch similar code
2022-08-01 07:15:08 +02:00
Johannes Altmanninger
f435b2b70a doc execeval: mention that the colon register is saved by default 2022-08-01 07:15:08 +02:00
Johannes Altmanninger
487056daf7 doc registers: fix asciidoc syntax for <a-*>
GitHub renders this as

	*, <a->*, s

while :doc renders it as

	*, <a->, *s

with this fix it's

	*, <a-*>, s
2022-07-30 22:18:37 +02:00
Johannes Altmanninger
545c8429e0 doc keys: avoid pleonasm 2022-07-30 22:18:37 +02:00
Johannes Altmanninger
45aad1ed2c rc man: fix man-jump when selection contains first character of man link
If I use "man dirname" and select "basename" 

	SEE ALSO
	       basename(1), readlink(1)
	       ^------^

then pressing <ret> to trigger man-jump selects everything from "ALSO"
until "basename(1)" Obviously that's not the name of a man page,
so it fails. When I select only "asename" it works.

The bad selection happens because we use a combination of <a-?> and ?
to extend the selection to a full link. This is more complicated than
it needs to be; let's just select the surrounding WORD.  This works
fine because man page links never start mid-word, and trailing
characters are ignored anyway.
2022-07-30 22:17:32 +02:00
Johannes Altmanninger
031de6d28c Use menu behavior for completing builtins where appropriate
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-30 22:17:32 +02:00