1
1
mirror of https://github.com/mawww/kakoune.git synced 2024-09-11 13:00:41 +03:00
Commit Graph

5820 Commits

Author SHA1 Message Date
Maxime Coste
727d2391c7 Small regex code cleanup 2024-05-31 12:38:47 +10:00
Maxime Coste
5c97efacb9 Add v< and v> to scroll cursor to the leftmost/rightmost column 2024-05-31 12:38:28 +10:00
Maxime Coste
83be9a03bc Merge remote-tracking branch 'dontlaugh/debug_mapping_output' 2024-05-29 21:44:07 +10:00
Coleman McFarland
7818ea0cbb Add right hand side mapping to "debug mappings" 2024-05-22 18:45:54 -04:00
Maxime Coste
1bd50261c8 Kakoune 2024.05.18 2024-05-18 14:43:06 +10:00
Johannes Altmanninger
7a90473267 Revert "Make TerminalUI::get_next_key() helpers static"
On macOS, backspace reportedly no longer works after <c-z> and fg.
The value of m_original_termios.c_cc[VERASE] seems to be wrong
in a static lambda that captures a singleton "this".
Not sure what's the problem. I thought that it is guaranteed that
"static auto convert = [this]() { ... }" is initialized lazily,
hence it should capture the correct address. Maybe the address
changes somehow or it's UB / a compiler bug.

This reverts commit ad36585b7a

Closes #5155
2024-05-18 11:35:48 +10:00
Chris Webb
4e5631daf3 Handle binary path detection errors on non-/proc platforms
On FreeBSD and NetBSD, sysctl() can return -1 when the path is too long,
leaving the buffer unitialised.

On macOS, both _NSGetExecutablePath() and realpath() can fail with
pathological paths or if memory is exhausted.

On Haiku, the kak_assert(status == B_OK) check will be compiled out in
non-debug builds.

Detect all of these cases and error out, reshaping get_kak_binary_path()
to avoid multiple repetitions of the same fatal error message.
2024-05-12 21:59:56 +10:00
Chris Webb
97a5d68adf Fix error handling when reading binary path from /proc
On Linux, Hurd, Cygwin, DragonFly BSD and Solaris/Illumos, Kakoune obtains
a path to its binary by reading the appropriate /proc symlink target.
readlink() can fail or it can fill the entire buffer, silently truncating
the path if the buffer is too small.

kak_assert() is compiled out in non-debug builds so we ignore a readlink()
failure, corrupt the stack by writing to buffer[-1] then return a string
from the uninitialised buffer.

If readlink() succeeds and the binary path is sizeof(buffer) long, we write
a \0 terminator beyond its end. If it is longer, we also truncate the path.

Throw a fatal error on startup in all these unlikely failure cases.
2024-05-12 21:59:52 +10:00
Maxime Coste
7be22f1ec2 Fix tests for OpenBSD
Using the diff provided by @krobelus on #5173

Close #5173
2024-05-12 11:14:17 +10:00
Maxime Coste
8bb0f44c2b Kakoune 2024.05.09 2024-05-09 20:15:32 +10:00
Maxime Coste
1c71fc0c09 Add local scope to user commands 2024-04-29 12:21:02 +10:00
Maxime Coste
e8ad943532 Ensure re-used fifo buffers makes that buffer the latest opened 2024-04-27 16:31:40 +10:00
Maxime Coste
5fd9bb59e3 Add buffer -matching switch 2024-04-27 16:31:40 +10:00
Johannes Altmanninger
aad0c7cef8 Don't capture local-scoped faces in prompt
ASan shows that we resolve a face spec owned by a freed stack variable.

    =================================================================
    ==2263300==ERROR: AddressSanitizer: stack-use-after-return on address 0x7a9316c33918 at pc 0x633ea421d8ea bp 0x7ffca001e980 sp 0x7ffca001e970
    READ of size 8 at 0x7a9316c33918 thread T0
        ...
        #6 0x633ea421d8e9 in Kakoune::FaceRegistry::resolve_spec(Kakoune::FaceSpec const&) const src/face_registry.cc:128
        ...

    Address 0x7a9316c33918 is located in stack of thread T0 at offset 2328 in frame
        #0 0x633ea427a095 in operator() src/commands.cc:2267

      This frame has 26 object(s):
        [32, 36) '<unknown>'
        ...
        [544, 560) 'disable_hooks' (line 2269)
        ...
        [928, 2432) 'local_scope' (line 2271) <== Memory access at offset 2328 is inside this variable
2024-04-27 16:29:57 +10:00
Maxime Coste
63addb7faa Use a nested command completer for the evaluate-commands command 2024-04-19 15:40:33 +10:00
Maxime Coste
b4fbfba246 Complete complete-command completer type 2024-04-19 15:36:23 +10:00
Maxime Coste
3d7d0fecca Introduce "local" scope in evaluate-commands
When using `eval` a new scope named 'local' gets pushed for the
whole evaluation, this makes it possible to temporarily set
an option/hook/alias...

Local scopes nest so nested evals do work as expected.

Remove the now trivial with-option command
2024-04-12 15:28:40 +10:00
Maxime Coste
b1c114bf6d Make removing an unknown highlighter an error
Fail instead of silently doing nothing, this makes it easier to
toggle highlighters using a try/catch
2024-04-12 15:28:40 +10:00
Maxime Coste
7f556c1e87 Rotate through strings when pasting instead of repeating the last
This seems like a better overall behaviour.

Closes #5135
2024-04-12 15:28:22 +10:00
Maxime Coste
e34735a350 Add missing <bit> include 2024-04-01 11:41:50 +11:00
Maxime Coste
6626d1cfa6 Fix std::optional used instead of Optional 2024-04-01 11:33:51 +11:00
Maxime Coste
917db454d9 Change mode_info to contain an optional NormalParams
As @topisani pointed out in #5131, it is more user friendly to always
provide a %val{register} and %val{count} regardless of the mode.
2024-04-01 11:03:22 +11:00
Maxime Coste
303d879785 Support exposing some env vars as part of the mode information
This should implement what #5131 proposed in a different way.

Closes #5131
2024-03-31 21:38:51 +11:00
Maxime Coste
7d0f25a99c Merge remote-tracking branch 'topisani/session-client-rename-hooks' 2024-03-31 20:55:21 +11:00
Johannes Altmanninger
5d00b80d1a Revert "Send SIGTERM on <c-c>, to more reliably kill background jobs"
Overloading SIGTERM like that causes issues; specifically if the
editor is invoked (without exec) from a wrapper script.

By sending SIGTERM to whole process group, we kill our parent process
(the wrapper script) which then sends SIGTERM to Kakoune.  By this
time Kakoune has already reset the SIGTERM handler to the default
action and terminates.

We can use a different fix for the problem that some shells don't
cancel "make", see the next patch.

This reverts commit ec44d98347.
2024-03-31 20:13:35 +11:00
Tobias Pisani
a1880a5441 Add SessionRenamed hook 2024-03-27 17:59:05 +01:00
Tobias Pisani
5515383ae4 Add ClientRenamed hook 2024-03-27 17:59:05 +01:00
Maxime Coste
9faad8c023 Slight code cleanup in the DynamicRegexHighlighter 2024-03-27 22:10:04 +11:00
Maxime Coste
2f7568485f Merge remote-tracking branch 'topisani/indent-guides' 2024-03-27 21:56:25 +11:00
Maxime Coste
390bff3435 Do not make cursor visible when not dragging
Fixes #5130
2024-03-27 19:07:09 +11:00
Tobias Pisani
b9c60e2578 Add -indent option to show-whitespace highlighter
A couple of semi-opinionated choices were made in this implementation:

 1. The guide is hidden in the first column.
 2. The indent guides are highlighted using a new `WhitespaceIndent` face.
 3. Nothing is done to continue the guide through empty lines. I believe this to be the correct approach,
    at least as long as it is kept as a part of the show-whitespaces highlighter. However some people's
    oppinion may differ, and if so, that could be implemented.
 4. The guides default to on, like the other show-whitespace options. Default character is "│".
 5. Spaces between the indent guides are currently highlighted as other spaces.
    Other reasonable options would be no replacement, -tabpad, or a similar -indentpad.
 6. Guides are disabled by passing `-indent ""`.
 7. Indent guides are separate from tab highlighting.

Additionally, we could consider adding a separate face for the "current" indent level as many editors do,
but this is a bit harder in kakoune because of multiple selections.

Closes #2323
2024-03-27 04:07:12 +01:00
Maxime Coste
699c70ac91 Add some missing ScopedEdition and fix redo
tabs <-> space conversion functions did not create a ScopedEdition
leading to uncommited modifications. Fixing this did fix the
interactive error, but that error still existed in non interactive
context so redo now considers there there is no redo child if there
are uncommited modifiations (which is correct as this means we are
currently creating a new leaf in the undo tree)

Fixes #5124
2024-03-23 20:07:41 +11:00
Maxime Coste
6e4bb5fbc5 Refactor last insert recording logic
Only record non-synthetized insertions, removing the need to
re-record on replay and fixing the last replay getting dropped by
macro execution.

Fixes #5122
2024-03-23 16:29:03 +11:00
Maxime Coste
6598d7b1b2 Fix invalid access when recording keys
<c-n>/<c-p> handling in insert was always dropping the last key in
the last_insert() vector (in order to replace it with the actual
completion text inserted), this was not valid for synthetized keys
that are not added to that vector in the first place.

Take the opportunity to merge insert completion handling code between
<c-n>/<c-p> and direct menu selection.

Fixes #5120
2024-03-22 22:06:11 +11:00
Maxime Coste
d5f7cbad87 Do not generate more lines to display than window size
The wrap highlighter was pulling all lines until the cursor, regardless
of whether the cursor was going to be made visible, this could lead to
a display buffer containing much more lines than the actual viewport
which eventually could lead to menu being anchored out of view that
was leading to past-the-end buffer accesses.

Fix the wrap higlighter not to pull lines up to the cursor when it
is not tasked with making the cursor visible, and always trim the
eventual extra lines after highlighting.

Fixes #5118
2024-03-22 21:44:37 +11:00
Maxime Coste
a1e6799aa9 Fix DisplayLines not tracking their buffer range correctly
After extracting the whole buffer content, a line can end up with
only non-range highlgihters pending which makes its range become
0.0,0.0, after running highlighting on the extracted range it gets
re-inserted but taking the min of existing range and inserted range
wrongly returns 0.0. Avoid this by detecting that the 0.0,0.0 range
does not actually mean anything when we have no ranged atoms.

Fixes #5001
2024-03-22 21:03:58 +11:00
Maxime Coste
7e75c9a1df Match Op declaration order in switches 2024-03-22 20:05:43 +11:00
Maxime Coste
2dd69b3d96 Make CompiledRegex not a RefCountable
Keep this closer to the point of use, avoid pull ref_ptr.hpp into
regex_impl.hpp
2024-03-22 19:54:25 +11:00
Maxime Coste
ca7471c25d Compute StartDesc with an offset to effective start
This means `.{2,4}foo` will now consider 4 or less before f as
a start candidate instead of every characters
2024-03-21 19:18:20 +11:00
Maxime Coste
ee364d911f Only push a first instruction thread when on a potential start
There is no need to push threads for each codepoint when we know
they will fail as the current codepoint is not a start candidate.
2024-03-21 18:09:00 +11:00
Maxime Coste
f6762724ea Revert "Always allocate saves"
This crashes in unit tests

This reverts commit cde5f5a258.
2024-03-15 22:03:52 +11:00
Johannes Altmanninger
24d719bf13 Fix off-by-two error in max size of frameless infoboxes
Framed info boxes need one cell for the border and one for inner
space padding.  That's 4 extra columns when counting both sides.
Frameless boxes have neither border nor padding so 0 columns here.

Closes #5106
2024-03-15 21:54:59 +11:00
Johannes Altmanninger
bdca6760fe Fail "define-command -menu" unless a completer is given
The "define-command -menu" flag does not do anything unless there is
a completer flag.  Let's reject it.
2024-03-15 21:54:26 +11:00
Maxime Coste
cde5f5a258 Always allocate saves
This sometimes allocates saves too eagerly, but it removes a branch
in release saves that executes on every thread failing which seems
slightly better.
2024-03-15 21:53:17 +11:00
Maxime Coste
83f12fc8e9 Avoid clearing iterator buffer on saves allocation
When creating a new save, we had to clear all iterators to have valid
values. This operation is relatively costly because it gets optimized
to a memset whose call overhead is pretty high (as we usually have
less than 32 bytes to clear). Bypass this by storing a bitmap of
valid iterators.
2024-03-13 23:45:51 +11:00
Maxime Coste
c4df0fac52 Simplify and accelerate start desc map
Store values for all possible bytes and fill utf8 multi byte start
values when necessary.
2024-03-13 17:29:05 +11:00
Maxime Coste
c956413046 Fix quantifier parsing bug 2024-03-13 07:14:33 +11:00
Maxime Coste
b06834bf47 Small cleanup 2024-03-12 21:15:30 +11:00
Maxime Coste
6264b049d9 Simplify Quantifier logic in regex parsing
Remove redundant type enum
2024-03-12 20:39:39 +11:00
Maxime Coste
e06acd3dc8 Simplify Split regex op handling by swapping target 2024-03-11 21:47:14 +11:00