summaryrefslogtreecommitdiff
path: root/src/buffer_utils.cc
AgeCommit message (Collapse)Author
2024-04-27Ensure re-used fifo buffers makes that buffer the latest openedMaxime Coste
2024-02-28Use std::find when detecting end of line formatMaxime Coste
2024-02-28Templatize StringData::createMaxime Coste
This improves performance by letting the compiler optimize most use cases where string count and length are known are compile time.
2024-02-18Try to fix crash due to fifo read regressionJohannes Altmanninger
I saw a crash when running git log --oneline %arg{@} hook -once buffer NormalIdle .* %{ execute-keys -draft \ %{gk!} \ %{git diff --quiet || echo "Unstaged changes";} \ %{git diff --quiet --cached || echo "Staged changes";} \ <ret> } Backtrace (I still have GDB attached): #4 0x00006502c740b13f in Kakoune::operator- (rhs=..., lhs=...) at /home/johannes/git/kakoune/src/units.hh:33 33 { return RealType(lhs.m_value - rhs.m_value); } (gdb) up #5 Kakoune::Buffer::next (coord=..., this=0x6502c90d7ff0) at /home/johannes/git/kakoune/src/buffer.inl.hh:18 18 if (coord.column < m_lines[coord.line].length() - 1) (gdb) up #6 FifoWatcher::read_fifo (this=0x6502c90d9e48) at buffer_utils.cc:252 252 m_buffer.erase(pos, m_buffer.next(pos)); This was introduced in 582c3c56b (Do not add trailing newline to non-scrolling fifo buffers, 2024-01-28). The problem seems to be that we call "m_buffer.next()" on a position that is past-end the buffer, so m_lines[coord.line] is out-of-bounds. Fix it. For some reason I have not managed to reproduce the crash, not even with sanitize=address. There might be another problem: m_had_trailing_newline is intentionally uninitialized because it is supposed to be read only on the second read() with a positive return value. Unfortunately I think it's possible that e.g. a NormalIdle hook inserts some text before the first positive read(). Then, this line const bool is_first = pos == BufferCoord{0,0}; if (not m_scroll and (is_first or m_had_trailing_newline)) pos = m_buffer.next(pos); will read uninitialized "m_had_trailing_newline". Fix that too, to be on the safe side. Sadly I don't have a test for this one either so I'm not sure.
2024-02-06Use different hash algorithms for strings and file hashingMaxime Coste
For hash map, using fnv1a is faster as it is a much simpler algorithm we can afford to inline. For files murmur3 should win as it processes bytes 4 by 4.
2024-01-30Do not add trailing newline to non-scrolling fifo buffersJohannes Altmanninger
Internally, all lines have a trailing "\n". Buffers created empty (like fifo buffers) start with a single line. When reading data into fifo buffers, we insert *before* the last line's trailing newline ("last newline"). This enables autoscrolling (enabled with "edit -scroll") as long as the cursor is on the last newline. When autoscrolling is disabled, we have a special case to insert *after* the last newline. This means that a cursor on that newline won't be moved. Then we transplant the newline character from the beginning to the end of the buffer. This special case happens only on the very first fifo read; on subsequent reads, the cursor at position 1.1 will not be moved anway because insertions happen below 1.1. Since we always insert (effectively) before the last newline, fifo buffers have a trailing empty line. For autoscrolling buffers this seems correct; it gives users an obvious way to toggle autoscrolling. For non-scrolling buffers the newline is redundant. Remove it. This requires keeping track of whether the last newline comes from the fifo, or was added by us. The shortest fix I could find is to always append to the buffer if not scrolling, and then delete the added newline character if applicable. m_buffer.insert(m_scroll ? pos : m_buffer.next(pos), StringView(data, data+count)); if (not m_scroll and not m_had_trailing_newline) m_buffer.erase(pos, m_buffer.next(pos)); maybe that's the best fix overall; but erasing at the end seems better than erasing in the middle, so do that whenever possible. Reported in https://lists.sr.ht/~mawww/kakoune/%3CZbTK7qit9nzvrMkx@gmail.com%3E
2023-10-25Clear buffer values on fifo buffer recreationMaxime Coste
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-06-17Revert "Switch undo storage from a tree to a plain list"Maxime Coste
Moving across history moved to <c-j>/<c-k> to keep <a-u>/<a-U> for selection undo/redo This reverts commit e0d33f51b36c9f0be7ae2467dab455d211bbf561.
2023-04-17Switch undo storage from a tree to a plain listOlivier Perret
Whenever a new history node is committed after some undo steps, instead of creating a new branch in the undo graph, we first append the inverse modifications starting from the end of the undo list up to the current position before adding the new node. For example let's assume that the undo history is A-B-C, that a single undo has been done (bringing us to state B) and that a new change D is committed. Instead of creating a new branch starting at B, we add the inverse of C (noted ^C) at the end, and D afterwards. This results in the undo history A-B-C-^C-D. Since C-^C collapses to a null change, this is equivalent to A-B-D but without having lost the C branch of the history. If a new change is committed while no undo has been done, the new history node is simply appended to the list, as was the case previously. This results in a simplification of the user interaction, as two bindings are now sufficient to walk the entire undo history, as opposed to needing extra bindings to switch branches whenever they occur. The <a-u> and <a-U> bindings are now free. It also simplifies the implementation, as the graph traversal and branching code are not needed anymore. The parent and child of a node are now respectively the previous and the next elements in the list, so there is no need to store their ID as part of the node. Only the committing of an undo group is slightly more complex, as inverse history nodes need to be added depending on the current position in the undo list. The following article was the initial motivation for this change: https://github.com/zaboople/klonk/blob/master/TheGURQ.md
2023-02-10Avoid extra indirection for storing FifoWatcherMaxime Coste
By improving the Value interface we can avoid storing a unique_ptr to a FifoWatcher and directly store the FifoWatcher.
2021-05-28Fix File Buffer flag not being correctly appliedMaxime Coste
2021-05-28Support opening files bigger than 2 GiBMaxime Coste
The real technical limit is with lines bigger than 2 GiB and buffers with more than 2 Gi lines, refactor buffer loading to make it possible to load those files. Fix an overflow with the hash_data function at the same time
2021-03-31Parse more data at each fifo buffer readMaxime Coste
2021-03-11Do not select on non-urgent fd when handling only urgent eventsMaxime Coste
This avoids 100% CPU usage when we have pending fifo input while running a shell process, as we will not end-up busy looping in pselect but not reading the available data due to being only processing urgent events.
2020-06-27Refactor how InsetCompletionHide hook parameter is computedMaxime Coste
Keep track of inserted ranges instead of trying to re-derive them. Fixes #3556
2020-05-10Support piping data to client stdinMaxime Coste
Pass the client stdin fd to the server and open a fifo buffer from it. Fixes #3394
2020-03-14Allow reading from fifo in readonly buffersMaxime Coste
readonly is supposed to prevent the user from modifying the buffer and it can be useful to generate a readonly fifo buffer. Fixes #3398
2020-03-02Expand env vars as list of stringsMaxime Coste
This makes it possible to do :select `%val{selections_decs}` and to correctly combine $kak_quoted with those.
2020-01-09Fix compilation on 32bit platformsMaxime Coste
Fixes #3284
2020-01-02Few style changes on history exposition codeMaxime Coste
2020-01-02Merge remote-tracking branch 'eraserhd/history-api'Maxime Coste
2020-01-01Add 'history' and 'uncommitted_modifications' expansionsJason Felice
2019-12-28Refactor fifo buffer reader codeMaxime Coste
2019-11-12Fix display column computationsJason Felice
Closes #3201
2019-11-12Add support for selecting and exporting selections in display columnsMaxime Coste
Fixes #2724
2019-06-11Fix emission of BufReadFifo eventsJason Felice
The hook parameter should not be adjusted for the prevention of scrolling. Also, ensure that the last BufReadFifo is triggered if we encounter an error or EOF after appending some data to the buffer. Closes #2946
2018-11-14Change BufReadFifo hook param to contain the inserted rangeMaxime Coste
the buffer name was not a very interesting information, whereas the buffer range allows a hook to run only on the appended text instead of all the buffer.
2018-10-23Refactor Hook management to have a well defined list of hooksMaxime Coste
Hooks are now an enum class instead of passing strings around.
2018-02-11Refuse modification of ReadOnly buffers and make Debug buffer readonlyMaxime Coste
The debug buffer is a bit special as lots of events might mutate it, permitting it to be modified leads to some buggy behaviour: For example, `pipe` uses a ForwardChangeTracker to track buffer changes, but when applied on a debug buffer with the profile flag on, each shell execution will trigger an additional modification of the buffer while applying the changes, leading to an assertion failing as changes might not be happening in a forward way anymore. Trying to modify a debug buffer will now raise an error immediatly.
2018-02-05Remove the `New` flag from a buffer after reloading itMaxime Coste
If we reload a buffer, it means its underlying file exists, hence the New flag does not make sense anymore. It could be that the file appeared on the filesystem in the meantime.
2017-08-29Do less implicit parse_filename callsMaxime Coste
2017-03-08Add a -debug flag to :edit to set the buffer as debug dataMaxime Coste
As for the *debug* buffer, buffers with the debug flag wont get used for cycling through buffer, or word completion.
2017-01-25Fix fifo reading not handling potential errors from the read callMaxime Coste
Fixes #1153
2016-12-03Change ValueId to just be an enum class, it does not need any operatorsMaxime Coste
2016-12-01Make FDWatcher support Read, Write and Except events, instead of just ReadMaxime Coste
2016-11-28Cleanup include dependencies a bitMaxime Coste
2016-11-14Propagate the hooks disabled state through prompt, menu, and command executionMaxime Coste
Maintain it as well during buffer creation even if the hooks are not executed in client context. Fixes #818
2016-10-23Re-enable undo support on fifo buffers when the fifo closesMaxime Coste
Fixes #881
2016-10-01Rename get_width to codepoint_widthMaxime Coste
2016-10-01Fix get_column function and add some unit tests for fullwidth textMaxime Coste
2016-10-01Support codepoints of variable widthMaxime Coste
Add a ColumnCount type and use it in place of CharCount whenever more appropriate, take column size of codepoints into account for vertical movements and docstring wrapping. Fixes #811
2016-08-30Add a fd_readable(int fd) helper functionMaxime Coste
Use it instead of direct calls to select scatered around the code base.
2016-05-14BufferManager now owns the Buffers instead of registering themMaxime Coste
2016-03-16Use ByteCoords directly for buffer insert/erase/replaceMaxime Coste
2016-03-12Do not include the debug buffer in word completionMaxime Coste
2015-11-27Consolidate writing to fdMaxime Coste
2015-11-19Keep an empty last line in debug buffer to provide auto scrollingMaxime Coste
2015-10-18Fix OSX compilationMaxime Coste
2015-10-17More cleanups in the buffer open/reload codeMaxime Coste
2015-10-17Move line parsing and to Buffer.cc directlyMaxime Coste