Commit Graph

10413 Commits

Author SHA1 Message Date
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
71b003b684 Try to fix flaky test 2024-03-23 11:40:44 +11:00
Maxime Coste
d4e93b6f47 Merge branch 'patch-1' of https://github.com/jbrains/kakoune 2024-03-22 22:11:13 +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
794e7ce51c Fix Makefile dist file generation 2024-03-22 17:30:43 +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
c3856ad3d9 Make src/kak a .PHONY target to always set the symlink
This ensures `make debug=yes`, `make debug=no` always update the
symlink even if the binary was already built.
2024-03-21 18:06:43 +11:00
J. B. Rainsberger
c65eda3d8a
Update README to match new make install command
It appears that the command to specify the `PREFIX` variable to the makefile has changed.

I had to run `make PREFIX=$HOME/.local install` in order to override the hardcoded `PREFIX` value in the makefile. I infer that the instructions need to be changed for those who don't know. (TIL. ;) )
2024-03-20 10:31:54 -03: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
Johannes Altmanninger
4d8de48ec3 rc tools doc: use menu behavior for completion again
Commit e43c7d6ab (Use complete-command for the :doc command,
2022-10-19) forgot to carry over the "-menu" flag, which means that
:doc completions are no longer auto-selected, even though they are
the only valid inputs.

Fix that.

Closes #4790
2024-03-15 21:54:16 +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
Maxime Coste
84fc2844a1 Fix installation of doc pages 2024-03-11 20:56:36 +11:00
Maxime Coste
f25b3c005e flatten ThreadedRegexVM::codepoint
Profiling shows that this does not always get the utf8::read_codepoint
call inlined and that almost doubles the time spent in the function.
2024-03-11 20:52:56 +11:00
Maxime Coste
9cc2f47e31 Modularize grep.kak, make.kak and jump.kak 2024-03-11 20:51:27 +11:00
Maxime Coste
2b9b74091d Fix gziping man page in Makefile 2024-03-09 11:25:09 +11:00
Maxime Coste
2ebaaaa454 Merge remote-tracking branch '2xsaiko/outgoing/appleterminal' 2024-03-09 10:31:46 +11:00
Maxime Coste
d299a7059e Fix clang compilation by enabling sized deallocations 2024-03-08 20:19:55 +11:00
Johannes Altmanninger
ec44d98347 Send SIGTERM on <c-c>, to more reliably kill background jobs
Consider

    sh -c 'sleep 5 & sleep inf'

Since the shell is non-interactive, there is no job control.
This makes the shell spawn the "sleep 5" process in the shell's own
process group[1] - presumably, because only interactive shells have
a need to forward signals to all processes in its foreground job.

When this non-interactive shell process is cancelled with SIGINT,
"sleep 5" keeps running [2]. At least the dash shell implements this
by running "signal(SIGINT, SIG_IGN)" in the forked child.  Unless the
child process explicitly overrides that (to SIG_DFL for example), it
will ignore SIGINT. Probably the reason for this behavior is to feign
consistency with interactive shells, without needing to actually run
background jobs in a dedicated process group like interactive shells
do. Bash documents this behavior[3]:

> When job control is not in effect, asynchronous commands ignore
> SIGINT and SIGQUIT in addition to these inherited handlers.

Several of our scripts[4] - most prominently ":make" - use the
"</dev/null >/dev/null 2>&1 &" pattern to run potentially long-running
processes in the background, without blocking the editor.

On <c-c>, we send SIGINT to our process group.
As explained above, this will generally not terminate any background processes.

This problem has been masked by a behavior that is unique to using
both Bash and its "eval" builtin. Given

    nop %sh{
        rm -f /tmp/fifo
        mkfifo /tmp/fifo
        (
            eval make >/tmp/fifo 2>&1 &
        ) >/dev/null 2>&1 </dev/null
    }
    edit -fifo /tmp/fifo *my-fifo*

When running this and pressing Control+C, Bash actually terminates
the Make processes. However if I remove the "eval", it no longer does.
This doesn't seems like something we should rely on.
Other commands like ":git blame" don't use "eval" so they cannot be
cancelled today.

Fix these issues by sending SIGTERM instead of SIGINT, which should
apply to the whole process group with pretty much the same effect.
Barely tested, let's see if this breaks some weird build system.

In future we might allow more fine-grained control over which processes
are cancelled by <c-c>.

{{{

Alternative solution:

With the above fix, scripts can opt-out of being terminated by <c-c>
by using setsid (though that's not POSIX unfortunately, and may
require nesting quotes) or the classic Unix double-forking trick to
create a daemon process.

Though it is certainly possible that someone expects commands like
this to survive <c-c>:

    nop %sh{ tail -f my-log </dev/null 2>&1 | grep some-error > some-file 2>&1 & }

I think it would be ideal to stick to SIGINT and match semantics of
a noninteractive shell, to avoid muddying the waters.

Background processes could still **opt into** being terminated by
<c-c>. For example by providing a simple program in libexec/ that does

    // interruptible.c
    int main(int argc, char** argv) {
        signal(SIGINT, SIG_DFL);
        execv(argv[1], &argv[1]);
    }

used as

    diff --git a/rc/tools/make.kak b/rc/tools/make.kak
    index b88f7e538..f6e041908 100644
    --- a/rc/tools/make.kak
    +++ b/rc/tools/make.kak
    @@ -16,3 +16,3 @@ define-command -params .. \
          mkfifo ${output}
    -     ( eval "${kak_opt_makecmd}" "$@" > ${output} 2>&1 & ) > /dev/null 2>&1 < /dev/null
    +     ( eval "interruptible ${kak_opt_makecmd}" "$@" > ${output} 2>&1 & ) > /dev/null 2>&1 < /dev/null

Unfortunately, it's inconvenient to add "interruptible" to commands
like clang-parse and git-blame because they background a whole subshell
with many commands, so we'd need to nest quotes.  Also I'm not sure
if this brings any benefit.

So I didn't explore this further yet although we can definitely do that.

}}}

Fixes #3751

[1]: https://stackoverflow.com/questions/45106725/why-do-shells-ignore-sigint-and-sigquit-in-backgrounded-processes/45106961#45106961
[2]: https://unix.stackexchange.com/questions/372541/why-doesnt-sigint-work-on-a-background-process-in-a-script/677742#677742
[3]: https://www.gnu.org/software/bash/manual/html_node/Signals.html
[4]: clang-parse, ctags-*, git blame, git log, gopls references,
     grep, jedi-complete, lint-*, make; I don't think any of these
     should be uninterruptible.
2024-03-08 20:10:15 +11:00
Johannes Altmanninger
f26d4ea4bf rc windowing tmux: remove redundant backgrounding
The tmux-terminal commands typically run

    tmux split-window kak -c ${kak_session} </dev/null >/dev/null 2>&1 &

The tmux process runs in the background with output silenced.  This is
not necessary because "tmux split-window" is a thin client that
merely forwards its arguments to the tmux server. All our wrappers
for other terminal-servers (kitty, iterm, screen, wezterm, zellij)
simply run in the foreground, not silencing any errors.

The tmux backgrounding was added in 208b91627 (Move client.kak as
x11.kak and change tmux.kak to be its peer, 2015-11-17), probably for
consistency with x11.kak. That one is different however because it
potentially spawns a full terminal, not just a client that briefly
talks to a terminal server - that's why x11-terminal needs to use
"setsid," to avoid killing said terminal when we signal our process
group.

Remove the backgrounding from tmux.kak for consistency and to reduce
surprise.
2024-03-08 20:10:10 +11:00
Maxime Coste
a1c52e08a4 Reduce Save access indirections
Most Save access are to modify the refcount. Now that the freelist
is index based it is not necessary to keep Save objects at fixed
memory locations.
2024-03-07 20:40:24 +11:00
Marco Rebhan
9363a84ed5
Add Terminal.app support 2024-03-06 01:24:34 +01:00
Johannes Altmanninger
c81266d4f6 jump{,-next,-previous} cmds to navigate any grep-like buffer
`grep-next-match` works only on the `*grep*` buffer so it can't be used
on buffers that were preserved by renaming or on other grep-flavored
buffers created by 3rd party plugins kakoune-find and kakoune-lsp,
like `*find*` and `*references*`.

Let's generalize `grep-next-match` with a `jump-next` command that
takes a buffer argument.

This renames some options but I think they're not commonly used.
kakoune-lsp is an exception that uses grep_current_line but it's no big
deal, things will fail loud and early if options are missing.

Since grep.kak and friends now depend on jump.kak, move the jumpclient
declaration there as well.
2024-03-06 08:04:35 +11:00
Maxime Coste
7ebf7cfccf RFC2822 compliant email address highlighting 2024-03-06 07:56:09 +11:00
Maxime Coste
dda908c478 Slight simplification of ThreadedRegexVM::exec
Remove redundant checking for end and double indirection to get
instructions pointer.
2024-03-05 22:37:04 +11:00
Maxime Coste
e24b969704 Use lookbehinds in ninja highlighters
This speeds up regex execution and seems more correct for those
regions end
2024-03-05 22:19:08 +11:00
Maxime Coste
685bce4321 Re-enable debug symbols in release builds 2024-03-05 22:18:37 +11:00
Maxime Coste
dbda8d6dc8 Ensure ReadOnly buffer flag get reflected to readonly option
Fixes #5110
2024-03-04 09:01:19 +11:00
Maxime Coste
e9bd708327 Merge remote-tracking branch 'arrufat/fix-kakrc-install' 2024-03-02 15:08:37 +11:00
Maxime Coste
e38becb5a1 Fix GCC detection in Makefile
When called as `c++`, gcc will not output `g++` which breaks detection,
it will have GCC in the output so look for that string instead.
2024-03-01 12:08:04 +11:00
Maxime Coste
504b074aa7 More FreeBSD Make fixes 2024-02-29 23:06:05 +11:00
Adrià Arrufat
455a94ce51 update README 2024-02-29 20:51:11 +09:00
Adrià Arrufat
64b3433905 fix install of kakrc 2024-02-29 20:49:50 +09:00
Maxime Coste
395dd8c73f Try to fix FreeBSD make support 2024-02-29 21:05:45 +11:00
Maxime Coste
159b0a3d96 Fix sourcehut builds to use posix make 2024-02-29 20:24:32 +11:00
Maxime Coste
10b6b7eb71 Rework Makefile compile type tag handling
Rename suffix to tag as it ends up not being the filename suffix,
apply that tag to .o and .d files so that changing the build type
does not wipe/reuse files from another build type.

Make .d file hidden files, this does not seem possible for the .o
files as they are targets and posix support inference rules when only
the suffix changes. This is not a big issue as Kakoune ignores those
files by default.
2024-02-29 19:53:39 +11:00
Maxime Coste
165cdba67c Merge remote-tracking branch 'svmhdvn/posix-make' 2024-02-29 18:56:07 +11:00