Commit Graph

10310 Commits

Author SHA1 Message Date
Johannes Altmanninger
86d940c225 rc tools git: command for easy recursive blaming
Our ":git blame" annotates each line with the most recent commit.
However often a line has been modified by several commits.

Introduce ":git blame-jump" which shows the commit that added the
line at cursor. Crucially, it works also in Git diff buffers, so it
can be used recursively to find the full history of a line.

To do the recursive blame from a diff, I need to navigate to the
old (deleted) version of a line. Since old and new line are usually
neighbors. Speed up the common scenario of finding the old version
by making ":git blame-jump" jump to the new version. This means the
initial diff view might not include the commit message etc. Compensate
this by showing the commit's date+author+subject in the status line.

Here are some test cases.
- run blame-jump after "git blame"
- create an uncommitted or unsaved line, run "git blame" and
  "blame-jump" on the uncommitted line
- run blame-jump without running "git blame"
- run blame-jump in "git show"
- run blame-jump in "git diff HEAD"
- run blame-jump in "git diff --cached"
- run blame-jump in "git diff" (YMMV if there are cached changes,
  could fix that)

Naming: there are some similar commands in the wild [1];
they are usually called "show-blamed" or similar, but they
don't jump to the corresponding line.  Also our list of git
commands is getting a bit messy (especially the undocumented
show-diff/hide-diff/next-hunk/prev-hunk; subject first naming seems
better).

[1]: f6e78ec4c0/kakrc (L423)

Future work: to go back to the previously-blamed commit we need to
have had the foresight to use "rename-buffer". Perhaps we want to
add some kind of buffer stack (like Magit does for example).
2024-02-05 21:42:02 +11:00
Johannes Altmanninger
36efbf4cbf rc filetype diff: extract diff parsing from diff-jump
Most diff consumers we've written only care about the "final" state
after parsing through a diff. Let's extract the diff parsing part,
for reuse in several new commands.

In future we should try to use this (or better, a diff-parsing library)
for patch-range.pl. We'd add a callback argument that is invoked once
perl hunk (or line). Unfortunately I haven't found that library for
Perl yet.
2024-02-05 21:42:02 +11:00
Johannes Altmanninger
ce7ceb1cf0 rc tools git: detect filetype=git-diff for untracked diff buffers
On untracked diff buffers, it might be useful to make the upcoming
blame features work.

This is experimental, I might drop it.
2024-02-05 21:42:02 +11:00
Johannes Altmanninger
d6b75ac0bb rc tools git: change git diff filetype from diff to git-diff
Diff buffers created by ":git diff" differ from other filetype=diff
buffers in that they use "git rev-parse --show-toplevel" as root
directory for diff-jump. This makes sense because paths printed by
"git diff" are relative to that directory.

Today we handle the above difference by making ":git" override the
diff-jump mapping.  This doesn't work for buffers that were read from
a file.  Fix this by introducing a separate filetype, "git-diff",
which allows to move the mapping in the usual place.

This breaks existing filetype=diff hooks[1] which need to be adapted
to match git-diff (also git-log).

Another motivation for the separate filetype is that a following
patch wants to enable Git blame commands in git-diff buffers but
not in plain diff buffers -- those should keep being blamed like any
other file if tracked by Git.
Perhaps git-* buffers are for Git metadata, not files that are tracked
by Git.

The added hooks awkwardly include their hook parameter to work around
hook ordering issues when switching between filetypes. See also [2].

We could also use filetype=git-log instead of git-diff.
Our highlighting for "git log --graph" would have rare false positives.

Closes #5049

[1]: https://github.com/search?utf8=%E2%9C%93&q=filetype%3Ddiff+language%3Akakounescript+-repo%3Amawww%2Fkakoune+-is%3Afork&type=code
[2]: https://lists.sr.ht/~mawww/kakoune/%3C20240201091907.973508-1-aclopte@gmail.com%3E
2024-02-05 21:42:02 +11:00
Johannes Altmanninger
7a5bf7f649 rc tools git: remove unused dependency on diff from status/show-branch 2024-02-05 21:42:02 +11:00
Johannes Altmanninger
da1adc9b94 rc tools git: blame buffer contents, not on-disk file
When a buffer has unsaved deleted/added lines, then any blame
annotations below those lines may be off. Fix this by feeding the
latest buffer contents to Git.  Unfortunately there is no easy way
to distinguish between "Unsaved" and "Saved but not committed yet"
so let's keep using the umbrella term.
2024-02-05 21:42:02 +11:00
Johannes Altmanninger
c2c978907f rc tools patch: figure out path to patch-range.pl without double-parsing
We double-parse a command definition to figure out the location of
a support script at load time. This feels a bit dangerous and is not
really necessary, so use %val{runtime}/rc/tools/... instead.

Reference: https://lists.sr.ht/~mawww/kakoune/%3CZbOSCK2JjJvo-RTt@gmail.com%3E
2024-02-01 20:41:01 +11:00
Johannes Altmanninger
582c3c56b2 Do not add trailing newline to non-scrolling fifo buffers
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
2024-01-30 08:24:27 +11:00
Johannes Altmanninger
fdbad4d9b2 Test to demonstrate fifo buffer blank line inconsistency
When "edit -fifo" reads data without a trailing newline, the fifo
buffer will not have a trailing blank line. But if there is a trailing
newline, we will get a trailing blank line. This is weird because the
trailing blank line exists for scrolling, it should not be determined
by the data read.

Add a test case to demonstrates the inconsistency which is fixed by
the next patch.
2024-01-30 08:23:59 +11:00
Maxime Coste
c124c8f517 Support -after switch for flag-lines highlighter 2024-01-30 08:20:13 +11:00
Johannes Altmanninger
2c944f6415 rc patch.kak: fix quoting
I learned that

    $ foo="'1

    2'"
    $ echo $foo
    '1 2'

Quote some variables to avoid this double unescaping.
2024-01-26 10:05:55 +11:00
Johannes Altmanninger
11e7e2964c rc tools patch: skip patch message signature, fixing diff application
Patches as produced by "git format-patch" have a trailing signature
that is separated from the body by a line with "-- " on it.  By default
it contains the Git version.  We erroneously include this signature
in the diff we pipe to patch, which fails to apply as a result.

Add a targeted fix to suppress these signatures.
2024-01-26 09:55:52 +11:00
Johannes Altmanninger
c7eeb0ead5 rc tools git: suggest -3/--3way argument to git apply
Sometimes a patch that fails to apply will apply cleanly after
adding -3.  Also sometimes we do want to apply with conflict markers.
So this is another somewhat common option.
2024-01-26 09:52:01 +11:00
Johannes Altmanninger
6eb3d1baf5 rc tools git: fix regression hiding blame in large files
Sorry I did not test my earlier patch in production.  It passes
blame flags via the environment.  On a 5000 line file this results in
"execve failed: Argument list too long" errors.

Use a different way of checking whether blame info is shown.
2024-01-23 08:16:16 +11:00
Johannes Altmanninger
52bf8d343b README.asciidoc: fix markup for sourcehut builds banner
Fixes the rendering on github.
2024-01-23 08:15:07 +11:00
Maxime Coste
1194aa861e Merge remote-tracking branch 'krobelus/patch-context-only-filediff' 2024-01-22 20:23:52 +11:00
Maxime Coste
a500d27ef1 Merge remote-tracking branch 'krobelus/git-blame-toggle' 2024-01-22 20:23:49 +11:00
Maxime Coste
f535c37aae Build README for Sourcehut 2024-01-22 20:23:45 +11:00
Johannes Altmanninger
1276e67ef7 rc tools patch: skip spurious diff header for files with no changes
Since :patch transforms its inputs into context-only lines, we can
easily get into a state where a file diff has only context lines.
git apply does not accept a "diff" without any hunk, so let's skip
that.
2024-01-22 07:02:31 +01:00
Johannes Altmanninger
462bf9ff6a rc tools git: blame to hide blame if already shown
This simplifies the UI (no need to add multiple mappings) and might
obsolete hide-blame.
2024-01-21 13:01:28 +01:00
Johannes Altmanninger
6b03f4dc4f rc tools git: remove redundant try
These commands must never fail.
2024-01-21 13:01:28 +01:00
Maxime Coste
869e89b3e5 Add builds.sr.ht configurations
Build and test (using both clang and gcc) on Debian stable x86_64,
FreeBSD and Debian unstable arm64.
2024-01-21 16:04:37 +11:00
Maxime Coste
5ea5c99c58 Fix using invalid strings for undo content strings
The code was wrongly using the write_it instead of the read_it to
access the removed lines content.

Fixes #5088
2024-01-21 10:24:08 +11:00
Maxime Coste
0674311945 Remove sorting of tags results
It is not an obviously better result than just displaying results
from each tag file, so remove sorting to take advantage of live
completion updates

As discussed in #5081
2024-01-17 21:18:22 +11:00
Maxime Coste
b0119b0696 Merge remote-tracking branch 'razetime/master' 2024-01-17 21:01:45 +11:00
Maxime Coste
11aede3493 Merge remote-tracking branch 'c7skasku/ocaml-comment-insert' 2024-01-17 21:01:04 +11:00
Maxime Coste
455cd73a93 Merge remote-tracking branch 'geppettodivacin/protobuf-newline-fix' 2024-01-17 21:00:26 +11:00
Maxime Coste
4bb1f17928 Merge remote-tracking branch 'krobelus/validate-empty-prompt' 2024-01-17 20:59:26 +11:00
Maxime Coste
f9fe191437 Merge remote-tracking branch 'krobelus/show-completions-eagerly' 2024-01-17 20:57:17 +11:00
Maxime Coste
218f7ba0e0 Merge remote-tracking branch 'greenfork/update-pony' 2024-01-17 20:55:46 +11:00
Eric Dilmore
8ff2860851 Fix command name in protobuf newline hook 2024-01-16 14:58:31 -06:00
Johannes Altmanninger
20b0eadfc8 Don't modify prompt history when validating empty input
Fixes #5076
2024-01-15 15:08:10 +01:00
Johannes Altmanninger
9d8c9777a4 Await all UI events after each key press in mouse-during-insert test
This test doesn't care about testing things like "if I send the next
key before we have finished reacting to the previous ones, nothing
bad ever happens".

Hence we can until exhaustion after each input.  This should fix
bespoke flakiness. The handling of "c<esc>" should be atomic.

This reasoning probably applies to most tests; waiting for all events
seems like the safest and easiest approach overall (compared to sleep
or sleep-until). The downside is that the tests need changes when
UI code changes but it rarely does, and if it does we can automate
the updates.

Closes #5073
2024-01-15 15:08:10 +01:00
Cormac Stephenson
3beeda7bcc ocaml.kak: give a name to the hook which inserts comment characters
This lets set-option window disabled_hooks .*-insert work as expected.
2024-01-15 03:15:42 +00:00
Johannes Altmanninger
c9a544413c rc tools ctags/man: rationalize sorting of completion candidates
As of recently, shell script candidate completions are computed in
the background, and displayed incrementally.
Sorting completions means we can't show partial results.

We do this for "ctags-search"; but if there is only one ctags file
there is already a sensible order (which is slightly different than
what GNU sort does). So let's preserve the order in that case.
The number of completions is probably too high for an order to be useful.

Similarly, for "man", sorting is probably not very helpful because
there are so many results.

See https://github.com/mawww/kakoune/pull/5035#discussion_r1413015934
2024-01-13 17:24:03 +01:00
Dmitry Matveyev
2a5a1ab611 Update Pony language support
The last update is from 2017, it's pretty outdated. Current
support was combined from existing languages such as Ruby and
Zig and tweaked to fit the Pony language.
2024-01-11 23:46:14 +03:00
razetime
e9a71d22f3 add prolog highlighter 2024-01-11 10:47:41 +08:00
Johannes Altmanninger
ea930664ad rc tools git: fix off-by-one regression in git blame SHA column
Introduced in f27f6fa2d (rc git: fix "git blame" on macOS with perl
rewrite, 2023-11-12); awk uses 1-based indices but perl uses offsets.
2024-01-07 20:51:20 +01:00
Maxime Coste
9b166e8007 Try to fix regression/0-mouse-during-insert test flakyness 2024-01-05 15:39:30 +11:00
Maxime Coste
9716875ba9 Merge remote-tracking branch 'arachsys/scheme-infnan' 2024-01-05 15:27:25 +11:00
Maxime Coste
12246674f1 Merge remote-tracking branch 'arachsys/groovy-quoting' 2024-01-05 15:26:44 +11:00
Maxime Coste
91d6ac013f Merge remote-tracking branch 'krobelus/fix-with-option' 2024-01-05 15:25:51 +11:00
Maxime Coste
eed3aa24c1 Merge branch 'patch-1' of https://github.com/igor-ramazanov/kakoune 2024-01-05 15:21:57 +11:00
Maxime Coste
c33d7f84d6 Merge branch 'patch-1' of http://github.com/yatesco/kakoune 2024-01-05 15:17:27 +11:00
Igor Ramazanov
1edebb8505
Update scala.kak to support SBT, ScalaCLI and Ammonite files
* https://www.scala-sbt.org/1.x/docs/Directories.html#sbt+build+definition+files
* https://scala-cli.virtuslab.org/docs/getting_started#scripting
* https://ammonite.io/#ScriptFiles
2023-12-30 19:29:32 +00:00
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
Colin Yates
f8ad2e3726
Update TRAMPOLINE
added missing word "...which *does* not store anything written..."
2023-12-20 15:47:28 +00:00