summaryrefslogtreecommitdiff
path: root/src
AgeCommit message (Collapse)Author
2022-12-26Remove a check for inclusivity in select_to_reverse.potatoalienof13
It turns out that neither <a-f> or <a-t> make sense when run at the beginning of the buffer. When I first created the check, I thought that <a-f> made sense if the character under the cursor was the character being searched for. I was wrong, <a-f> should always go at least one character backwards.
2022-12-25<a-t> should not succeed when run on the first character of a file.potatoalienof13
2022-12-22Fix Buffer::advance out of bounds access.potatoalienof13
This commit fixes a bug in Buffer::advance where it would first access m_lines[-1], and then check whether or not that access would have segfaulted. This commit moves the check to before the segfault would occur.
2022-12-22Merge remote-tracking branch 'krobelus/fix-cd-after-backspace'Maxime Coste
2022-12-21This commit attempts to fix a crash with -f. Specifically when kakounepotatoalienof13
is run as > ./kak -f '2oK.k<c-n><ret><c-n>' /dev/null The crash occurs because when <c-n> is pressed for the second time, it attempts to use m_completions from the first press of <c-n>. This only happens when kakoune is run with -f, because when this is done interactively, there is a client, which means that m_completions gets reset. This removes the check that causes that difference. I am not *completely* sure that this is the best way to solve the problem, since I am not completely sure why that check was put there in the first place.
2022-12-17Merge remote-tracking branch 'krobelus/no-selection-history-in-draft-context'Maxime Coste
2022-12-15Speed up expand_unprintable by avoiding BufferIteratorMaxime Coste
Using BufferIterator adds overhead, but we know that DisplayAtoms cannot span multiple buffer lines and hence we can directly iterate using char pointers.
2022-12-15Support adding ByteCount to void/char pointers without castingMaxime Coste
2022-12-15Optimize TabulationHighlighterMaxime Coste
2022-12-13Fix a couple bugs with underline highlightingMaxime Coste
Add missing curly_underline attribute to json-rpc Fix underline color not correct after attrbute only change
2022-12-10Do not record selection history in draft contextJohannes Altmanninger
Each draft context gets its own private copy of the selections. Any selection changes will be thrown away when the draft context is disposed. Since selection-undo is only supported as top-level command, it can never be used inside a draft context, so let's stop recording it. No functional change.
2022-12-06Cleanup expand_unprintable and avoid calling iswprint on base asciiMaxime Coste
2022-12-06Avoid calculating atom length in DisplayLine::trim_fromMaxime Coste
Calculating the length of an atom means we need to decode every codepoint and compute its column width. This can prove quite expensive in trim_from as we can have full buffer lines, so on buffer with long lines we might have to go through megabytes of undisplayed data.
2022-12-06Load buffer in command line orderMaxime Coste
Pass the first buffer on the the command line explicitely to client creation. This ensure the buffer list matches the command line, which makes buffer-next/buffer-previous a bit more useful. Fixes #2705
2022-12-03Rework StringOps::substr implementationMaxime Coste
Avoid iterating over the whole string when the length is not provided just use the end iterator directly.
2022-11-29Use some template magic to automatically deserialize UI messagesMaxime Coste
We always deserialize arguments in order, and we can extract argument types from the type of the pointer to method.
2022-11-28Fix pasting after when selections are overlappingMaxime Coste
With overlapping selections, pasting after breaks assumption of SelectionList::for_each as our changes are no longer happening in increasing locations. We hence cannot rely on the ForwardChangeTracker in that case and have to rely on the more general (and more costly) ranges update logic. This interacts poorly with paste linewise pastes and we try to preserve the current behaviour by tracking the last paste position. Overall, this change really begs for overlapping selections to be removed, but we will fix them like that for now. Fixes #4779
2022-11-20Change BufferIterator comparison to assert same bufferMaxime Coste
Comparing iterators between buffers should never happen, and the only place we did was with default constructed BufferIterator which we replace by casting the iterator to bool. This should improve performance on iterator heavy code.
2022-11-19Print OS error when ":write -force" fails to change permissionsJohannes Altmanninger
When the file system runs out of space, "write -force" will fail but doesn't print "No space left on device". Let's fix this by including such an underlying error. Untested. Backstory: I alias "w" to a command that runs "write -force %arg{@}". so I can overwrite files that already exist outside the editor (I should probably get used to the new behavior).
2022-11-19Accept "cd dir/" again instead of using a subdirectoryJohannes Altmanninger
Commit 69053d962 (Use menu behavior when completing change-directory, 2022-07-19) made ":cd dir/" actually run ":cd dir/first-subdir", which can be surprising. This is usually irrelevant because you rarely type the trailing slash. However it does happen after correcting an error with `<backspace>` and friends. For for example, :cd d<tab>/f<backspace> results in :cd dir/ We should probably fix user expectations here. Do this by adding "dir/" as valid completion. This requires us to allow empty candidates in "RankedMatch" but there's no harm in that. This means we need to filter out empty completions from shell-script-candidates elsewhere. Alternative fix: we could revert 69053d962. This would remove the convenient menu behavior but that wouldn't be a huge deal. Fixes #4775
2022-11-10Merge remote-tracking branch 'krobelus/undo-selection-change'Maxime Coste
2022-11-04Add a %val{selection_count} expansionOlivier Perret
2022-11-04Remove wrong rejection of upper case mappings in goto modeMaxime Coste
Mapping upper case keys is legitimate, for exampled so that they behave the same as a lower case mapping. The current rejection of those mappings is a misguided attempt to prevent mapping *to* upper case keys as those will never get triggered. Closes #4769
2022-11-04Add -to-shell-script echo switchMaxime Coste
This feature simplifies various small use cases and is a good companion to the existing -to-file switch.
2022-10-31Kakoune 2022.10.31Maxime Coste
2022-10-29Fix memory domain for cached command completionMaxime Coste
2022-10-19Merge remote-tracking branch 'krobelus/write-autoinfo2'Maxime Coste
2022-10-19Refactor insert_output command to avoid intermediate vectorMaxime Coste
This is like a paste with a different source, so the same logic should work. This means we now correctly fix overflowing selections. Fixes #4750
2022-10-19Remove unused History MemoryDomainMaxime Coste
2022-10-17Fix splitting of display atoms accross multi-columns codepointMaxime Coste
Honor the split request by inserting an empty atom to make sure client code can assume splitting does replace one atom with two Fixes #4753
2022-10-16Allow to put switches after :write's positional argumentJohannes Altmanninger
After a failed :write file-that-already-exists a user might want to type ":<up> -f<ret>" to force-overwrite. This doesn't work because :write's switches must precede the filename. It's dual :edit does not have this restriction. Some commands require switches to precede positional arguments for a good reason; for example because positional arguments might start with "-" (like ":echo 1 - 1"). There seems to be no reason for the :write restriction, so remove it. Same for :enter-user-mode. Thanks to alexherbo2 for reporting.
2022-10-11Merge remote-tracking branch 'vsyl/c_description'Maxime Coste
2022-10-11Correct and unify descriptions of normal mode C key behaviorJakub Wasilewski
Fixes #4747
2022-10-02Fix compilation failure with clang 12 and debug=yesHampus Fröjdholm
The pointer type alias was missing from FlattenedView::Iterator causing std::iterator_traits to be an empty class.
2022-09-17Merge remote-tracking branch 'krobelus/faster-update-matches'Maxime Coste
2022-09-17Fix quadratic runtime when updating region highlighter matchesJohannes Altmanninger
Running %sYeti<ret>casdf on file [example.journal.txt](https://github.com/mawww/kakoune/issues/4685#issuecomment-1193243588) can cause noticeable lag. This is because we insert text at 6000 selections, which means we need to update highlighters in those lines. The runtime for updating range highlighters is quadratic in the number of selections: for each selection, we call on_new_range(), which calls add_matches(), which calls std::rotate(), which needs needs linear time. Fix the quadratic runtime by calling std::inplace_merge() once instead of repeatedly calling std::rotate(). This is works because ranges are already sorted. I used this script to benchmark the improvements. (In hindsight I could have just used "-ui json" instead of tmux). #!/bin/sh set -ex N=${1:-100} kak=${2:-./kak.opt} for i in $(seq "$N") do echo -n "\ 2022-02-06 * Earth expense:electronics:audio 116.7 USD liability:card -116.7 USD 2022-02-06 * Blue Yeti USB Microphone expense:electronics:audio 116.7 USD liability:card -116.7 USD " done > big-journal.ledger echo > .empty-tmux.conf 'set -sg escape-time 5' test_tmux() { tmux -S .tmux-socket -f .empty-tmux.conf "$@" } test_tmux new-session -d "$kak" big-journal.ledger test_tmux send-keys '%sYeti' Enter c 1234567890 sleep .2 test_tmux send-keys Escape while ! test_tmux capture-pane -p | grep 123 do sleep .1 done test_tmux send-keys ':wq' Enter while test_tmux ls do sleep .1 done rm -f .tmux-socket .empty-tmux.conf This script's runtime used to grow super-linearly but now it grows linearly: kak.old kak.new N=10000 1.142 0.897 N=20000 2.879 1.400 Detailed results: $ hyperfine -w 1 './bench.sh 10000 ./kak.opt.'{old,new} Benchmark 1: ./bench.sh 10000 ./kak.opt.old Time (mean ± σ): 1.142 s ± 0.072 s [User: 0.252 s, System: 0.059 s] Range (min … max): 1.060 s … 1.242 s 10 runs Benchmark 2: ./bench.sh 10000 ./kak.opt.new Time (mean ± σ): 897.2 ms ± 19.3 ms [User: 241.6 ms, System: 57.4 ms] Range (min … max): 853.9 ms … 923.6 ms 10 runs Summary './bench.sh 10000 ./kak.opt.new' ran 1.27 ± 0.09 times faster than './bench.sh 10000 ./kak.opt.old' $ hyperfine -w 1 './bench.sh 20000 ./kak.opt.'{old,new} Benchmark 1: ./bench.sh 20000 ./kak.opt.old Time (mean ± σ): 2.879 s ± 0.065 s [User: 0.553 s, System: 0.126 s] Range (min … max): 2.768 s … 2.963 s 10 runs Benchmark 2: ./bench.sh 20000 ./kak.opt.new Time (mean ± σ): 1.400 s ± 0.018 s [User: 0.428 s, System: 0.083 s] Range (min … max): 1.374 s … 1.429 s 10 runs Summary './bench.sh 20000 ./kak.opt.new' ran 2.06 ± 0.05 times faster than '../repro.sh 20000 ./kak.opt.old'
2022-09-17Avoid potentially quadratic runtime when updating selections after modificationJohannes Altmanninger
LineRangeSet::add_range() calls Vector::erase() in a loop over the same vector. This could cause performance problems when there are many selections. Fix this by only calling Vector::erase() once. I didn't measure anything because my benchmark is dominated by another issue (see next commit). LineRangeSet::remove_range() also has a suspicious call to erase() but that one is only used in test code, so it doesn't matter.
2022-09-17Fix crash when trying to display the menu in a tiny windowAdrià Arrufat
2022-09-09Merge remote-tracking branch 'krobelus/embrace-menu-3'Maxime Coste
2022-09-09Merge remote-tracking branch 'krobelus/to-string'Maxime Coste
2022-09-09Merge remote-tracking branch 'krobelus/write-autoinfo'Maxime Coste
2022-09-09Merge remote-tracking branch 'krobelus/hashset-no-braces'Maxime Coste
2022-09-09Merge remote-tracking branch 'krobelus/cleanup'Maxime Coste
2022-09-02Allow to undo and redo selection changesJohannes Altmanninger
From the issue: > It often happens to me that I carefully craft a selection with multiple > cursors, ready to make changes elegantly, only to completely mess it > up by pressing a wrong key (by merging the cursors for example). Being > able to undo the last selection change (even if only until the previous > buffer change) would make this much less painful. Fix this by recording selection changes and allowing simple linear undo/redo of selection changes. The preliminary key bindings are <c-h> and <c-k>. Here are some other vacant normal mode keys I considered X Y <backspace> <minus> # ^ = <plus> ' unfortunately none of them is super convenient to type. Maybe we can kick out some other normal mode command? --- This feature has some overlap with the jump list (<c-o>/<c-i>) and with undo (u) but each of the three features have their moment. Currently there's no special integration with either peer feature; the three histories are completely independent. In future we might want to synchronize them so we can implement Sublime Text's "Soft undo" feature. Note that it is possible to restore selections that predate a buffer modification. Depending on the buffer modification, the selections might look different of course. (When trying to apply an old buffer's selection to the new buffer, Kakoune computes a diff of the buffers and updates the selection accordingly. This works quite well for many practical examples.) This makes us record the full history of all selections for each client. This seems wasteful, we could set a limit. I don't expect excessive memory usage in practice (we also keep the full history of buffer changes) but I could be wrong. Closes #898
2022-09-02Prepare to record selection changes as perceived by the userJohannes Altmanninger
To be able to undo selection changes, we want to record selections from all commands that modify selections. Each such command will get its own private copy of the selections object. This copy will live until the command is finished executing. All child commands that are run while the command is executing, will also use the same copy, because to the user it's all just one selection change anyway. Add an RAII object in all places where we might modify selections. The next commit will use this to create the private selections copy in the constructor (if there is none) and remove redundant history items in the destructor. We could avoid the RAII object in some places but that seems worse. For lifetimes that don't correspond to a lexical scope, we use a std::unique_ptr. For lambdas that require conversion to std::function, we use std::shared_ptr because we need something that's copyable.
2022-08-29Access selections via helper methodsJohannes Altmanninger
The next commit changes the selections to a history of selections. Today we directly access the selections data member. Let's instead use an accessor method, to reduce the number of changes in the next commit.
2022-08-29Pass entire context to select_coordJohannes Altmanninger
This allows a following commit to record selection history inside select_coord() instead of at every call site.
2022-08-29Make parameter constJohannes Altmanninger
2022-08-28Fix clang warning regarding useless braces when using HashSetJohannes Altmanninger
clang/clangd complain about the new HashSet type: hash_map.cc:98:20: warning: braces around scalar initializer [-Wbraced-scalar-init] set.insert({10}); ^~~~ The argument to HashSet<int>::insert is just an int, so we don't need braces. Only an actual HashMap would need braces to construct a HashItem object.
2022-08-28Show write -force parameter only for commands that support itJohannes Altmanninger
When passing a filename parameter to "write", the -force parameter allows overwriting an existing file. The "write!" variant (which allows writing files where the current user does not have write permissions) already implies -force. All other variants (like write-quit or write-all) do not take a file parameter. Hence -force is relevant only for "write". Let's hide it from the autoinfo of the other commands. It's difficult to avoid duplication when constructing the constexpr SwitchMap because String is not constexpr-enabled. Today, all our SwitchMap objects are known at compile time, so we could make SwitchMap use StringView to work around this. In future we might want to allow adding switches at runtime, which would need String again to avoid lifetime issues.