When doing :write -method replace, make sure we've set the correct mode,
uid and gid on the replacement file before attempting to rename it on
top of the original. This means that the original file is left in place
with correct permissions if anything fails, rather than ending up with
0700 permissions from mkstemp().
When a privileged :write is used with -method replace, it silently resets
the ownership of files to root:root. Restore the original owner and group
in the same way we restore the original permissions. Ownership needs to
be restored before permissions to avoid setuid and setgid bits being set
while the file is still owned by root, and to avoid them being subsequently
lost again on chmod(2).
If a user attempts to save a file without write permission for the
containing directory, with writemethod set as 'replace' or an explicit
':write -method replace' command, kak crashes with "terminating due to
uncaught exception of type Kakoune:runtime_error". (Note this doesn't
happen with a forced write, which fails earlier when it tries to enable
u+w permission.)
Don't raise another exception when already bailing out with a runtime
error for failing to create a temporary file or open the existing file.
Instead, make a best-efforts attempt to restore the file permissions
before raising the first exception, and only report the runtime chmod
exception if that step fails on the non-error path.
Some terminals misbehave when queried for output synchronization support,
such as Windows Terminal as reported in
https://github.com/mawww/kakoune/issues/5032
The relatively long response from a terminal which does support output-sync
is also prone to getting torn over a slow link such as a serial console,
causing stray input to the editor.
In ui_options, the terminal_synchronized option controls the use of this
feature, but unfortunately the query is unconditionally sent at startup
even when this is set false.
Skip the query at startup when terminal_synchronized is explicitly false.
We query at most once per terminal in set_ui_options so the behaviour
is correct both when kakoune is started with terminal_synchronized unset
and when it is started with terminal_synchronized set false but this is
later unset.
prompt has fuzzy filtering which is more discoverable than the menu
mode's regex filtering (because that one needs / to trigger it).
There are no important differences left, so replace the menu builtin
with a prompt-based command.
prompt does not support markup in the completion menu, so drop that
feature for now.
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.
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.
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.
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.
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.
Running an invalid command like "grep -abc" shows no output at all.
Let's give better feedback by showing the error message from grep.
We used to do this until an unrelated change, bd5955c73 (grep: remove
eventual \r, 2013-02-13).
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.
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.
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