Comments (3)
To improve even more the experience, I think that doing while on a hash (a short hash such as when doing :git log --oneline or a long hash in regular :git log) could do a :git show <the_selected_hash>. This way, one could really rapidly navigate the history to check a previous change with :git log and .
One problem with overloading <ret>
with two different behaviors (well,
three, we already map it to blame-jump
while blame annotations are
shown) is that we have to second-guess the user in edge cases where
it's not clear whether we are in a diff / whether the thing at cursor
is an object ID.
It's probably still worth adding. Here's a rough attempt:
diff --git a/rc/tools/git.kak b/rc/tools/git.kak
index 1a1e8d81e..594e54a4a 100644
--- a/rc/tools/git.kak
+++ b/rc/tools/git.kak
@@ -41,10 +41,10 @@ hook -group git-diff-highlight global WinSetOption filetype=(git-diff|git-log) %
}
}
-hook global WinSetOption filetype=(?:git-diff|git-log) %{
- map buffer normal <ret> %exp{:git-diff-goto-source # %val{hook_param}<ret>} -docstring 'Jump to source from git diff'
+hook global WinSetOption filetype=git-(?:commit|diff|log|notes|rebase) %{
+ map buffer normal <ret> %exp{:git-jump # %val{hook_param}<ret>} -docstring 'Jump to source from git diff'
hook -once -always window WinSetOption filetype=.* %exp{
- unmap buffer normal <ret> %%{:git-diff-goto-source # %val{hook_param}<ret>}
+ unmap buffer normal <ret> %%{:git-jump # %val{hook_param}<ret>}
}
}
@@ -776,3 +776,30 @@ define-command git-diff-goto-source \
fi
}
}
+
+define-command git-jump -docstring %{
+ If inside a diff, run git-diff-goto-source,
+ Else show the Git object at cursor.
+} %{ evaluate-commands -save-regs c %{
+ try %{
+ execute-keys -draft l[px<a-k>^diff<ret>
+ set-register c git-diff-goto-source
+ } catch %{
+ evaluate-commands -draft %{
+ try %{
+ execute-keys <a-i>w # TODO this should include characters like -.@# etc
+ } catch %{
+ fail git-jump: no word at cursor
+ }
+ try %{
+ evaluate-commands %sh{
+ [ "$(git rev-parse --revs-only "$kak_selection")" ] || echo fail
+ }
+ } catch %{
+ fail "git-jump: bad revision '%val{selection}'"
+ }
+ set-register c git show %val{selection} --
+ }
+ }
+ %reg{c}
+}}
Of course, if :git show is called while within :git log, it means that the user won't be able to go back to the log while seeing the patch, as they are using the same scratch buffer git. This could be mitigated if another scratch buffer is used so that the user could use ^O to jump back. But maybe it is not worth it to go that far.
I keep a stack of all git buffers - look for git-stack
here
from kakoune.
Yeah. I use this, mapped to a different key than <ret>
though.
define-command -override my-git-enter %{ evaluate-commands -save-regs c %{
try %{
evaluate-commands -draft %{
execute-keys s\S+<ret>
try %{
evaluate-commands %sh{
[ "$(git rev-parse --revs-only "$kak_selection")" ] || echo fail
}
} catch %{
try %{ execute-keys <a-i>w }
evaluate-commands %sh{
[ "$(git rev-parse --revs-only "$kak_selection")" ] || echo fail
}
}
set-register c %val{selection}
}
git show %reg{c} --
} catch %{
git-diff-goto-source
}
}}
from kakoune.
Nice, thank you for sharing.
According to you, would it be worth it to integrate this behavior directly to rc/tools/git.kak
?
from kakoune.
Related Issues (20)
- [REQUEST] Rotate values from registers when pasting HOT 6
- [REQUEST] Incremental buffer synchronisation with coprocess (unidirectional)
- [QUESTION]: `:new` command gives an error `'terminal': no such command` when using Kakoune with Alacritty HOT 12
- [QUESTION]: hook gives different results when the same keystrokes are splitted to two `execute-keys`. Why? HOT 2
- [QUESTION] Cursor position independent way to select word under the cursor HOT 1
- [REQUEST] make <c-c> capturable with RawKey hook HOT 4
- [BUG] Garbage instead of Cyrillic text when connecting to Kakoune server launched as a daemon using `launchd` HOT 4
- goto and view keybindings don't work properly when there is a wrap highlighter [BUG] HOT 2
- [BUG] Python filetype does not allow paragraphs in block comments.
- [REQUEST] add more details to `:debug mappings` and/or provide an additional command that shows all bindings HOT 5
- [REQUEST] Creating undo groups in Normal mode HOT 3
- [REQUEST] Add "right hand side" mapping to `:debug mappings` HOT 4
- [BUG] Backspace occasionally behaves like Delete HOT 24
- [QUESTION] Remote Events aync ?
- [BUG][CRASH] ctags-search crashes kakoune after trying to browse autocomplete options. HOT 2
- [BUG] %val{buflist} does not produce quoted output by default HOT 1
- [BUG] :w write paste wl-clipboard contents HOT 4
- [BUG] mv operation should not interfere with HOT 3
- [QUESTION] Text file busy make: *** [Makefile:181: install] Error 1 HOT 1
- [QUESTION] Cursor up/down navigation in soft-wrapped text (gj/gk in Vim) HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from kakoune.