Commit Graph

5740 Commits

Author SHA1 Message Date
Maxime Coste
43e8aadcaa Fix performance of diff-based reloading of buffers
It turns out diffing was pretty fast, but applying the diff was
sub-optimal as it was constantly inserting/erasing lines which
led to lots of unnecessary shifting. Fix this by manually tracking
a read/write iterator and only shifting when necessary (on keeps,
and inserts).
2023-12-26 21:21:01 +11:00
Maxime Coste
68e73d8a24 Take eq predicate by reference in for_each_diff 2023-12-26 21:21:01 +11:00
Maxime Coste
3c81a4a253 Small code style tweak 2023-12-26 18:49:16 +11:00
Maxime Coste
ba7059a2dc Fix wrong name 2023-12-26 18:09:25 +11:00
Maxime Coste
533f51c744 Merge remote-tracking branch 'krobelus/prefer-input-order-over-alphabet' 2023-12-12 21:27:31 +11:00
Maxime Coste
96b74d1ad6 Merge remote-tracking branch 'arachsys/hide-unmapped' 2023-12-12 21:24:47 +11:00
Maxime Coste
065e0229a9 Fix stray semicolon 2023-12-12 21:23:57 +11:00
Maxime Coste
5ed2433b9f Merge remote-tracking branch 'arachsys/unsigned-char' 2023-12-12 21:19:52 +11:00
Chris Webb
a8d5b8bd2c Fix compiler warnings when char is unsigned
In several places, we check for a control character with something like

  char c;
  [...]
  if (c >= 0 and c <= 0x1F)
    [...]

When char is signed (e.g. amd64) this is fine, but when char is unsigned
by default (e.g. arm32 and arm64) this generates warnings about the
tautologous check that an unsigned value is non-negative.

Write as

  if ((unsigned char) c <= 0x1F)
    [...]

which is both correct and not suspicious under both conventions.
2023-12-10 11:09:55 +00:00
Chris Webb
7b2772ef89 Change use of deprecated '->' operator on an iterator
In display_buffer.hh, the '->' operator is used on an iterator, but
(surprisingly) this is deprecated from C++20 because of x-value vs
l-value ambiguity. Now clang's -Wdeprecated-declarations warns about it
as we declare -std=c++2a. See

  https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1252r2.pdf

which was adopted for 2019-03.
2023-12-10 10:58:42 +00:00
Chris Webb
ee8c74c724 Add -Wno-stringop-overflow for g++
g++ 13.x is confused by the reinterpret_cast in Kakoune's memory.hh
allocator. Use -Wno-stringop-overflow to silence a large number of
verbose false alarms.
2023-12-10 10:26:37 +00:00
Chris Webb
a90d1d33f7 Mark refresh_ifn() implementation as an override in input_handler.cc
This was spotted by clang's -Winconsistent-missing-override in -Wall.
2023-12-10 09:58:40 +00:00
Chris Webb
7af2b99317 Hide empty and undocumented mappings from autoinfo
Users who rebind default keys and unmap the originals by binding them
to empty strings with empty docstrings end up with empty lines in the
autoinfo. For example, https://github.com/mawww/kakoune/issues/4918.

Hide completely null bindings which have both an empty mapping and an
empty docstring in the autoinfo, as an easy mechanism for these users to
eliminate the UI noise.

Fixes https://github.com/mawww/kakoune/issues/4918
2023-12-06 17:35:46 +00:00
Maxime Coste
7f49395cf9 Fix basename prefix flag to use smartcase eq 2023-12-04 19:22:32 +11:00
Johannes Altmanninger
658c3385a9 ranked match: prefer input order over alphabetical order for user-specified completions
When using either of

	set-option g completers option=my_option
	prompt -shell-script-candidates ...

While the search text is empty, the completions will be sorted
alphabetically.
This is bad because it means the most important entries are not listed
first, making them harder to select or even spot.

Let's apply input order before resorting to sorting alphabetically.

In theory there is a more elegant solution: sort candidates (except
if they're user input) before passing them to RankedMatch, and then
always use stable sort. However that doesn't work because we use a
heap which doesn't support stable sort.

Closes #1709, #4813
2023-12-02 10:43:59 +01:00
Johannes Altmanninger
d6215dc25d Reuse for_n_best when sorting values from complete options
While at it, remove a needless reserve() call and reserve an extra slot
because "InsertCompleter::try_complete" might add one more element.
2023-12-02 09:57:15 +01:00
Maxime Coste
94d58b2e07 Merge remote-tracking branch 'sidkshatriya/escape-curly-bracket' 2023-12-02 11:03:56 +11:00
Maxime Coste
c93c57a46f Merge remote-tracking branch 'krobelus/fuzzy-menu' 2023-12-02 10:56:29 +11:00
Maxime Coste
42fefb16af Merge remote-tracking branch 'arachsys/write-replace' 2023-12-02 10:56:11 +11:00
Maxime Coste
215aa0b2fb Fix single word detection when query is not single word 2023-12-02 10:39:23 +11:00
Chris Webb
3ba3399f94 Set replacement file permissions before moving into place
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().
2023-11-28 08:51:32 +00:00
Chris Webb
d3af9b57d4 Restore file ownership when editing with root privilege
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).
2023-11-26 18:12:52 +00:00
Chris Webb
05bbdb27c9 Fix crash when ':write -method replace' fails to create tempfile
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.
2023-11-26 17:50:32 +00:00
Chris Webb
32680e5d65 Skip output synchronization query when explicitly disabled
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.
2023-11-24 12:55:45 +00:00
Maxime Coste
990e92a5f3 Only set Prefix in RankedMatch if the full query matches 2023-11-23 17:16:24 +11:00
Maxime Coste
ac7b498c86 Merge remote-tracking branch 'krobelus/changelog' 2023-11-21 21:04:18 +11:00
Maxime Coste
5e4e23289b Fix completion menu not getting hidden on no matches 2023-11-21 17:16:38 +11:00
Johannes Altmanninger
1f11529837 rc tools menu: replace menu builtin with a prompt-based implementation
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.
2023-11-20 20:47:22 +01:00
Johannes Altmanninger
4499b26ca4 Fix use after move in HashMap::insert
Apparently GCC builds worked fine but Clang builds started failing the
"(hash == hash_value(item_key(item)))" assertion.
2023-11-18 19:07:23 +01:00
Johannes Altmanninger
0bb5b28f7e Update changelog 2023-11-17 19:41:55 +01:00
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
Sidharth Kshatriya
be7e3ccc9e changelog: escape { as \\{ otherwise '%val{window_range}' appears as '%val' in version notes startup splash 2023-11-17 03:19:14 +05:30
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