Commit Graph

5709 Commits

Author SHA1 Message Date
Maxime Coste
296ab1a1ff Improve WordDB performance by precomputing hashes
Avoid multiple computation of string hashes by making it possible
to pre-compute and pass hashes to interned strings and hash maps.
2023-11-17 17:01:51 +11:00
Maxime Coste
b10a935b8c Drop last character for basename matching
If the candidate ends with a slash we still look at the previous
component as the basename.
2023-11-16 12:59:55 +11:00
Maxime Coste
a42aa1e47e Slight cleanup of RankedMatch code 2023-11-15 12:48:23 +11:00
Maxime Coste
1cfe5273f3 Do not use range adaptor to gather ranked matches
This ends up constructing RankedMatch twice, once when computing
the number of elements then once when actually filling the vector.
2023-11-15 12:46:28 +11:00
Maxime Coste
4a1a3ee06e Refactor fuzzy matcher ranking further
Remove FirstCharMatch which does not impact any of the test cases
and explicitely detect paths by using a BaseName flag when we match
the basename of the path.
2023-11-15 12:27:48 +11:00
Maxime Coste
11f0ace9b6 Make shell-script-candidates completer run in the background
Read output from the script as it comes and update the candidate
list progressively.

Disable updating of the list when a completion has been explicitely
selected.
2023-11-14 21:39:03 +11:00
Maxime Coste
719512b308 Use a separate copy of the command completer for each completion
This make the completer lifetime tied to the Prompt mode and removes
the need for the Start flag. It also makes it possible to cleanup
on completer destruction.
2023-11-14 21:39:03 +11:00
Maxime Coste
79f3f5b046 Merge remote-tracking branch 'krobelus/quote-regex-option-value-completions' 2023-11-14 21:38:26 +11:00
Johannes Altmanninger
cac2a32ba2 Fix completion pager not rendering after <a-semicolon> in prompt
Usually, the prompt resets "m_line_changed" after invoking the
change handler:

	if (m_line_changed)
	{
	    m_callback(m_line_editor.line(), PromptEvent::Change, context());
	    m_line_changed = false;
	}

but with

	prompt '' '' -on-change %{ execute-keys <a-semicolon>vl } -shell-script-candidates %{ seq 100 }

the change handler pushes a normal mode with "<a-semicolon>" and then
hands back control to the event loop. Later when the normal mode is
popped we run "Prompt::on_enabled()" but don't actually redraw the
completion pager.
Since the <a-semicolon> excursion by definition did not change our
prompt state, we don't need to recompute completions, only render them.
Do that.

This helps commands that use preview the selected completion via a
"prompt -on-change" handler.
2023-11-14 10:20:08 +01:00
Johannes Altmanninger
118459db59 Quote completions of regex options
Recent changes to `make_error_pattern` added a space to the default
value. This means that

	set g make_error_pattern <tab>

now produces an invalid command because regexes are not quoted.  We do
quote strings; regexes are not all that different so quote them too.
2023-11-13 23:42:39 +01:00
Johannes Altmanninger
70e96c272e Avoid unnecessary copy of completion candidates 2023-11-13 23:42:39 +01:00
Maxime Coste
ed1e2f2e08 Add missing include for std::array 2023-11-13 23:03:03 +11:00
Maxime Coste
c2fb0738d3 Merge remote-tracking branch 'krobelus/fix-noincsearch' 2023-11-13 22:56:06 +11:00
Maxime Coste
c7d887d9d1 Rename stdin/stdout/stderr in Shell a they conflicts with macros
Fixes #5023
2023-11-13 20:19:55 +11:00
Maxime Coste
fc7be678ed Change window_range to emit each element as a separate string 2023-11-13 19:22:33 +11:00
Johannes Altmanninger
c597a056d0 Fix spurious incremental search when incsearch=false
Regressed in a2c41593a (Fix partial regex text being pushed in history,
2023-11-02).
2023-11-11 14:37:32 +01:00
Maxime Coste
2261b48e35 Fix SingleWord handling in RankedMatch
subsequence_match_smart_case does not necessarily find the word,
but we then check for a contiguous match in which case, if the query
is a word, we also have a single word match.
2023-11-11 18:59:11 +11:00
Maxime Coste
c45a1d435a small code cleanup 2023-11-11 18:46:15 +11:00
Maxime Coste
fbbced5ed0 Support building ArrayView from contigous iterators 2023-11-10 16:35:46 +11:00
Maxime Coste
feeacd8de9 Refactor spawn_shell to return the relevant FDs
This removes the need for the setup_child callback which is quite
tricky as it cannot touch any memory due to vfork, and removes the
Pipe abstraction in favor of a more general UniqueFd one.
2023-11-05 22:47:17 +11:00
Maxime Coste
25a00bf2a9 Remove ignored packed attribute and static_assert on Node size
This static_assert is not necessary for the code to work and is
not valid on every platform.
2023-11-05 12:38:39 +11:00
Maxime Coste
0880399fbe Replace snprintf with format_to 2023-11-05 12:30:54 +11:00
Johannes Altmanninger
b0ddbfc2df Do not poll command sockets while shell command is running
Accepter is a wrapper around a socket watcher. It always uses
EventMode::Urgent, so it will be included in pselect(2) (via
EventManager::handle_next_events()) even while we are waiting for a
(blocking) shell command.  However we will not execute the command
received on this socket until after the shell command is done.

This is implemented with an early return:

	void handle_available_input(EventMode mode)
	{
	    while (not m_reader.ready() and fd_readable(sock))
	        m_reader.read_available(sock);

	    if (mode != EventMode::Normal or not m_reader.ready())
	        return;

so we read available data but don't close the socket.
When using this reproducer

	{
		sleep 1 && echo 'nop' | kak -p session
	} &
	kak -n -s session -e '%sh{sleep 7}'

the first "m_reader.read_available(sock);" will read "nop".  Then
"m_reader.ready()" is true but the socket is still readable. This
means that pselect(2) will return it every time, without blocking.

This means that the shell manager runs a hot loop between pselect(2)
and waitpid(2).

Fix this problem demoting command socket watchers from
EventMode::Urgent. This means that we won't pselect(2) it when handling
only urgent events. Control-C still works, I'm not sure why.

Alternative fix: we could read the commands but then disable the
socket. I tried this but it seems too complex.

Closes #5014
2023-11-04 17:48:25 +01:00
Maxime Coste
6a39ac224b Merge remote-tracking branch 'krobelus/fix-quoted-vals-expand' 2023-11-03 21:51:36 +11:00
Maxime Coste
f7499ccf45 Add support for 0-padding in format and replace uses of sprintf 2023-11-03 20:27:41 +11:00
Johannes Altmanninger
8a3613e5a0 Fix "%val{selections_desc}" being joined by nul instead of space
This should fix a bug in lint.kak though I didn't check.
2023-11-03 06:45:02 +01:00
Maxime Coste
7577fa1b66 Use explicit target types for gather calls to bypass clang regression
Since clang-16 there has been a regression in the P0522R0 support.
(Bug report at https://github.com/llvm/llvm-project/issue/63281)

Closes #4892
2023-11-03 13:08:44 +11:00
Maxime Coste
c889c0329c Replace std::lexicographical_compare_three_way with custom code
On latest MacOS this function is still not implemented
2023-11-03 13:08:26 +11:00
Maxime Coste
ba0cd553ba Display a message on the tty directly on fatal error
Remove the xmessage/MessageBox based implementation.
2023-11-02 18:16:43 +11:00
Maxime Coste
a2c41593aa Fix partial regex text being pushed in history 2023-11-02 13:00:12 +11:00
Maxime Coste
8cc4de5bb3 Always ensure we do not scroll past the last line
An assert fails from time to time after reloading fifo buffers due
to being scrolled past the last line of the buffer. A repro case was
not found but this should fix the underlying issue.
2023-11-01 17:24:54 +11:00
Maxime Coste
2fa55be40a Default comparison operators that can be 2023-10-25 21:06:52 +11:00
Maxime Coste
96884193dd Remove redundant comparison operators
Since C++20 (a != b) get automatically rewritten as !(a == b) if
the != operator does not exist.
2023-10-25 20:40:04 +11:00
Maxime Coste
d1c8622dc7 Clear buffer values on fifo buffer recreation
The cached WordDB/Highlighters/FifoReader are not relevant and are
better fully rebuilt than updated. This speeds up rebuilding the
WordDB of big fifo buffers such as a `git log`.
2023-10-25 12:53:55 +11:00
Maxime Coste
be33dee211 Speed up WordSplitter
Only do utf8 decoding once per codepoint instead of twice, limit
the byte length instead of the codepoint length.
2023-10-25 12:52:14 +11:00
Maxime Coste
b33b673f10 Remove unnecessary operator (since C++20) 2023-10-25 12:51:59 +11:00
Maxime Coste
18902b15af Refactor regex_prompt logic and fix function being called on abort
Fixes #4993
2023-10-04 21:03:10 +11:00
Loric Brevet
a2fd401cfa
Add an InlineInformation face distinct from Information 2023-09-28 15:06:29 +02:00
Maxime Coste
23afed056b Add a daemonize-session command and refactor local client handling
Make it possible to move the current session to a daemon one after
the fact, which is useful to ensure the session state survives client
disconnecting, for example when working from ssh.
2023-09-26 17:50:56 +10:00
Maxime Coste
3bf16c0fb1 Merge remote-tracking branch 'krobelus/foot-custom-keypad-sequences' 2023-09-23 21:31:01 +10:00
Chris Webb
9a0c7cea47 Fix quoting of arguments to kak -c SESSION
Filename arguments to kak -c SESSION are passed to the remote sessions
as commands like

  edit 'FILENAME';

but single-quotes in FILENAME are incorrectly escaped as \' instead of
being doubled-up. Fix this so kak -c SESSION "foo'bar" becomes

  edit 'foo''bar';

instead of

  edit 'foo\'bar';

Reported by @FlyingWombat in https://github.com/mawww/kakoune/issues/4980
2023-09-22 13:40:58 +01:00
Maxime Coste
871631bb00 Trigger auto completion refresh when necessary on completion select
This removes the timing dependent behaviour where `Tab` would only
display the completion menu if pressed before the prompt idle timeout

This means `exec :dc<tab>` now expands 'dc' to 'define-command'
instead of just showing the completion menu a few millis early.
2023-09-19 17:15:11 +10:00
Maxime Coste
541c385aa4 Revert "Do not make cursor visible on force redraw"
This unfortunately breaks the testing framework, more work
necessary before we can do that.

This reverts commit 9b1f4f5f20.
2023-09-08 05:54:32 +10:00
Maxime Coste
dd5b624003 Merge remote-tracking branch 'divarvel/show-trailing-whitespace' 2023-09-08 05:50:11 +10:00
Maxime Coste
9787756619 Use last display setup instead of recomputing for window_range
Fixes #4964
2023-09-08 05:24:56 +10:00
Maxime Coste
9b1f4f5f20 Do not make cursor visible on force redraw 2023-09-08 05:24:56 +10:00
Maxime Coste
20a2bca52e Do not make cursor visible after mouse scrolling and view commands
ensure cursor is visible after user input except if the command
implementation opted-out. Hooks and timers should not enforce
visible cursor.

PageUp/PageDown and `<c-f>` / `<c-b>` commands still move the cursor
as this seemed a desired behaviour.
2023-09-02 12:55:57 +10:00
Maxime Coste
6990270005 Still inkorrect inglish
Hopefully thats better now
2023-08-31 04:56:50 +10:00
Maxime Coste
a212fd25a0 Fix incorrect inglish 2023-08-29 03:24:27 +10:00
Maxime Coste
e4d7b884cd Cleanup SIGHUP handling and forking server to background
Ensure we ignore SIGHUP once the TerminalUI is gone as it will be
sent again on fork, fix the parent process terminating due to trying
to write to stdout after it was closed.

Fixes #4960
2023-08-27 08:47:33 +10:00