Commit Graph

10289 Commits

Author SHA1 Message Date
Maxime Coste
1e38045d70 Only make cursor visible after buffer or selection change
Kakoune now does not touch cursors when scrolling. It checks
if either the buffer or selections has been modified since
last redraw.

Fixes #4124
Fixes #2844
2023-08-16 21:02:42 +10:00
Chris Webb
491d4d47ae Fix segfault when adding an invalid default-region highlighter
RegionsHighlighter::create_region() validates the highlighter type argument
but RegionsHighlighter::create_default_region() assumes it is correct,
segfaulting from dereferencing a null pointer if the given type isn't in
the highlighter registry HashMap.

@PJungkamp reported this in https://github.com/mawww/kakoune/issues/4959
with a simple recipe to reproduce:

    :add-highlighter shared/test regions
    :add-highlighter shared/test/ default-region invalid highlighter
    :add-highlighter window/test ref test

Validate the type argument in RegionsHighlighter::create_default_region()
in the same way as RegionsHighlighter::create_region().
2023-08-15 16:22:39 +01:00
Maxime Coste
6942a4c0c9 Change + command not to duplicate identical selections more than once
The current exponential behaviour does not seem that useful, it seems
more predictible that pressing `+` twice would end up with 3 copies
of the original selections instead of 4.

Fixes #4533
2023-08-14 22:50:22 +10:00
Maxime Coste
0a06d9acbd Minor formatting tweaks 2023-08-13 03:57:46 +10:00
Maxime Coste
e090131b87 Add a ProfileScope helper class to replace most profiling uses 2023-08-13 03:57:46 +10:00
Maxime Coste
e605ad8582 Kakoune 2023.08.05 2023-08-05 11:02:11 +10:00
Maxime Coste
39be51b55c Fix regression/0-mouse-during-insert test flakyness
Do not rely on timing but wait for Kakoune to redraw which is what
we actually need: Mouse clicks rely on the current display buffer
to resolve the buffer location, so we need to wait for a redraw
to happen with `ui_out`
2023-08-05 10:58:15 +10:00
Maxime Coste
d7822ea588 Removed unused captures 2023-08-05 10:39:54 +10:00
Maxime Coste
d1e189f1bf Try to fix clang build issues 2023-08-05 10:34:16 +10:00
Michał Kruszewski
521549fb69 troff: Highlight .PSPIC and .PDFPIC macros 2023-07-30 09:47:10 +02:00
Maxime Coste
f58d686066 Kakoune 2023.07.29 2023-07-29 15:53:23 +10:00
Maxime Coste
dad128e4a6 Merge remote-tracking branch 'QiBaobin/rc/windowing/wezterm' 2023-07-29 15:34:15 +10:00
Maxime Coste
90acec991f Merge remote-tracking branch 'omasanori/ocaml-lex-and-yacc' 2023-07-29 15:33:48 +10:00
Maxime Coste
991b233468 Merge remote-tracking branch 'arrufat/zig-builtin-functions' 2023-07-29 15:33:15 +10:00
Maxime Coste
f4fd1d75ca Merge remote-tracking branch 'arrufat/zig-zon' 2023-07-29 15:32:37 +10:00
Bob Qi
117f12dbd6 pass cwd for wezterm terminal 2023-07-27 13:28:37 +08:00
Masanori Ogino
8fb0a99f05 Detect .mll and .mly files as OCaml sources 2023-07-26 17:15:06 +09:00
Adrià Arrufat
fdb33e7302 zig: add c_char type 2023-07-26 12:37:35 +09:00
Adrià Arrufat
ca36d0d228 zig: update builtin functions for v0.11.0 2023-07-26 12:26:49 +09:00
Adrià Arrufat
eabc7cd2a8 Set filetype to Zig for zon files. 2023-07-25 15:30:52 +09:00
Johannes Altmanninger
12310418b0 Allow map/unmap during mapping execution
Commits e49c0fb04 (unmap: fail if the mapping is currently executing,
2023-05-14) 42be0057a (map: fail if key is currently executing,
2023-06-24) fixed potential use-after-free issues. By doing so,
it broke configurations that in practice have not triggered any
crashes [1] [2].

For example with,

	set -remove global autocomplete insert
	hook global InsertCompletionShow .* %{
	    map window insert <esc> <c-o>
	}
	hook global InsertCompletionHide .* %{
	    unmap window insert <esc> <c-o>
	}

The execution of the <esc> mapping triggers InsertCompletionHide fails
at unmapping. This seems legit and I don't see an obvious alternative
way to write it (InsertIdle would not be correct though it would work
in practice).

Fix the regression by allowing map and unmap again while keeping the
mappings alive until they have finished executing.

Applying map/unmap immediately seems like the most obvious semantics.
Alternatively, we could apply them in between key presses.

[1]: <https://github.com/kak-lsp/kak-lsp/issues/689>
[2]: <https://github.com/alexherbo2/auto-pairs.kak/issues/60>
2023-07-20 09:18:23 +02:00
Maxime Coste
e3122ab2c1 Refactor prompt history handling
Share incremental regex logic, pass the synthetized nature of keys
through to input handlers.
2023-07-05 22:00:32 +10:00
Maxime Coste
ec79864559 Merge remote-tracking branch 'krobelus/allow-history-in-mappings' 2023-07-05 20:39:39 +10:00
Maxime Coste
3fae7cd7c0 Merge remote-tracking branch 'arrufat/zig-auto-remove-empty-comments' 2023-07-04 19:33:37 +10:00
Maxime Coste
96ff68aeae Merge remote-tracking branch 'krobelus/fix-remap-uaf' 2023-07-04 19:33:10 +10:00
Adrià Arrufat
3cca4c5098 Auto-remove empty comments in Zig like in the C-family.
This makes Kakoune behave more consistently when using it for Zig.
Empty comments are already auto-removed from the C-family and Python.
In this PR, string literals that start with \\ are not removed in purpose.
2023-07-04 16:40:24 +09:00
Maxime Coste
53fed4b8b9 Only auto-insert completion when at the end of the line
Auto inserting in the middle is annoying more often than not.
2023-07-04 17:15:33 +10:00
Johannes Altmanninger
42be0057a6 map: fail if key is currently executing
If during execution of a mapping, that same mapping is replaced,
there is undefined behavior because we destroy a mapping that we are
still iterating over.

I have been using this mapping inside my kakrc to re-source the kakrc.

	map global user s %{:source "%val{config}/kakrc"<ret>} -docstring 'source "%val{config}/kakrc"'

Now <space>s happens to not trigger undefined behavior because the
mapping stays the same.

However it triggers an assertion added by Commit e49c0fb04 (unmap:
fail if the mapping is currently executing, 2023-05-14), specifically
the destructor of ScopedSetBool that guards mapping execution.

Fix these by banning map of a key that is executing, just like we
did for unmap.

Alternative solution: we could allow mapping (and even unmapping)
keys at any time and keep them alive by moving them into a trash can,
like we do for clients and others.
2023-07-03 19:03:11 +02:00
Maxime Coste
661d1a0905 Merge common docstring in key mapping assistant
Fixes #4942
2023-07-03 20:48:59 +10:00
Maxime Coste
4b605c582c Merge remote-tracking branch 'omasanori/fixup-undo-doc' 2023-07-03 20:14:21 +10:00
Maxime Coste
4f60a828cd Merge remote-tracking branch 'ericv8v9s/master' 2023-07-03 20:06:01 +10:00
Maxime Coste
74b0bf6c9e Merge remote-tracking branch 'GrantMoyer/patch-1' 2023-07-03 20:04:00 +10:00
Maxime Coste
2cd14860e0 Merge remote-tracking branch 'newsch/sql-comments' 2023-07-03 20:02:47 +10:00
Eric
a9b52b315c Fixed lisp highlighter marking everything as variable 2023-07-01 15:27:13 +08:00
Eric
eca127cfab Eric Copyright Waiver
I dedicate any and all copyright interest in this software to the
public domain.  I make this dedication for the benefit of the public at
large and to the detriment of my heirs and successors.  I intend this
dedication to be an overt act of relinquishment in perpetuity of all
present and future rights to this software under copyright law.
2023-07-01 15:11:24 +08:00
Sergey Fedorov
dca5043812 Unbreak build on ppc
Fixes: https://github.com/mawww/kakoune/issues/4937
2023-06-27 12:29:45 +08:00
Johannes Altmanninger
84ea52e46e Support CSI u numpad keys
Normally page-down is sent as \033[6~ but some terminals
send a CSI u encoding for the page-down on the numpad. See
https://codeberg.org/dnkl/foot#keypad for example.

Treat them as the underlying key; we could add a modifier if anyone
cares about the distinction.
2023-06-24 22:18:49 +02:00
Grant Moyer
7115858093
Quote doc file path in doc-render command
Without quoting the file path,
the `doc` command fails to display any docs with spaces or backslashs (on Cygwin) in their paths.
2023-06-23 12:38:19 -04:00
Evan Lloyd New-Schmidt
c1e6fe4ca1 Add standard SQL comments 2023-06-21 16:48:24 -07:00
Maxime Coste
e06e409dc1 Another small structured binding conversion 2023-06-21 17:36:33 +10:00
Masanori Ogino
58058d1213 Fixup documentation on history navigation commands
Co-authored-by: Johannes Altmanninger <aclopte@gmail.com>
2023-06-21 10:25:59 +09:00
Maxime Coste
e365c42b4b Small structured binding conversion 2023-06-20 19:32:06 +10:00
Maxime Coste
d43268fbeb Fix invalid access of display line end
When a line only contains non-range atoms we can end-up accessing
past the end atom.

Add a test that shows the issue when run with valgrind, it is
unfortunately quite hard to trigger a crash because the invalidly
accessed byte usually leads to the correct code path being taken
(when != DisplayAtom::Range) so we have only 1 in 255 chance of
triggerring a crash.

Fixes #4927
2023-06-20 13:09:03 +10:00
Maxime Coste
e58592f00a Fix highlighters being applied to empty display buffers
In some cases such as with folding we can end-up with regions
not having any atoms to highlight which can trigger a crash as
we assume display buffers not to be empty

Fixes #4926
2023-06-19 12:55:55 +10:00
Johannes Altmanninger
163eb6dbc6 Disable history only for prompts that are never shown in the UI
My terminal allows to map <c-[> and <esc> independently.  I like
to use <c-[> as escape key so I have this mapping:

	map global prompt <c-[> <esc>

Unfortunately, this is not equivalent to <esc>.  Since mappings are
run with history disabled, <c-[> will not add the command to the
prompt history.

So disabling command history inside mappings is wrong in case the
command prompt was created before mapping execution. The behavior
should be: "a prompt that is both created and closed inside a
noninteractive context does not add to prompt history", where
"noninteractive" means inside a mapping, hook, command, execute-keys
or evaluate-commands.

Implement this behavior, it should better meet user expectations.
Scripts can always use "set-register" to add to history.

Here are my test cases:

1. Basic regression test (needs above mapping):

	:nop should be added to history<c-[>

---

2. Create the prompt in a noninteractive context:

	:exec %{:}

now we're back in the interactive context, so we can type:

	nop should be added to history<ret>

---

3. To check if it works for nested prompts, first set up this mapping.

	map global prompt <c-j> '<a-semicolon>:nop should NOT be added to history<ret>'
	map global prompt <c-h> '<a-semicolon>:nop should be added to history first'

Then type

	:nop should be added to history second<c-j><c-h><ret><ret>

the inner command run by <c-j> should not be added to history because
it only existed in a noninteractive context.

---

See also the discussion https://github.com/mawww/kakoune/pull/4692

We could automate the tests if we had a test setup that allowed
feeding interactive key input into Kakoune instead of using
"execute-commands". Some projects use tmux, or maybe we can mock
the terminal.
2023-06-17 11:21:41 +02:00
Johannes Altmanninger
6563b82092 Use auto to avoid repeating type of dynamic cast
I think the clang-tidy lint is called modernize-use-auto
2023-06-17 11:21:16 +02:00
Johannes Altmanninger
00490cd084 Rename "disable_history" stack state to "noninteractive"
The commit after next will fix a bug where we wrongly disable prompt
history in some scenarios. The root cause is that life span of
"disable_history" does not model when we actually want to disable
history.

Let's rename the state variable to "noninteractive". It's set whenever
we are executing a hook, mapping or command.

Note that it's also active inside ":prompt"'s callback, which doesn't
play well with the new name :(
2023-06-17 11:21:16 +02:00
Maxime Coste
7027cccf82 Fix typo in README 2023-06-17 18:14:15 +10:00
Maxime Coste
5901d2e06b Revert "Switch undo storage from a tree to a plain list"
Moving across history moved to <c-j>/<c-k> to keep <a-u>/<a-U>
for selection undo/redo

This reverts commit e0d33f51b3.
2023-06-17 17:31:57 +10:00
Maxime Coste
b2a853cfc2 Add a few missing entries to the changelog 2023-06-17 17:10:05 +10:00