teach git gui to open the configured editor
cover teach git gui to open the configured editor
This patch series adds a new right click menuitem which allows the user to open the configured editor with the currently viewed file. For some popular editors it is also able to move the cursor close to the watched line.
Please have a look at the parsing of the configured editor commandline. I tested it for most situations. Maybe someone has an idea for a more elegant way to split up between arguments and command.
Currently I substitute all ' with " and then abuse the lindex command for trimming and splitting.
Cheers Heiko
Heiko Voigt (2):
git-gui: teach _which procedure to work with absolute paths
git-gui: add "open in editor" diff context menu entry
git-gui/git-gui.sh | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+)
Signature · 1 line
1.7.10.rc1.29.gf035d
Hi,
Quoted 4 lines · Heiko Voigt
This patch series adds a new right click menuitem which allows the user to open the configured editor with the currently viewed file. For some popular editors it is also able to move the cursor close to the watched line.
I once mentioned this in a patch I send ages ago:
Look for the '[1]' reference.
I have done, what was discussed in this thread, but never send something to the list (maybe a private mail to Pat?), but you can have a look at my git-gui repo at [1]. The patch which implements this is bw/master~5 (a648f3a06 'git-gui: open file with GIT_EDITOR').
Regards,
Bert
[1] http://repo.or.cz/w/git-gui/bertw.git
Quoted 24 lines
Please have a look at the parsing of the configured editor commandline. I tested it for most situations. Maybe someone has an idea for a more elegant way to split up between arguments and command.
Currently I substitute all ' with " and then abuse the lindex command for trimming and splitting.
Cheers Heiko
Heiko Voigt (2):
git-gui: teach_whichprocedure to work with absolute paths
git-gui: add "open in editor" diff context menu entrygit-gui/git-gui.sh | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 55 insertions(+)--
1.7.10.rc1.29.gf035d--
To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH 1/2 git-gui: teach _which procedure to work with absolute paths
In reply to Heiko Voigt_which is useful to check whether a certain command can be called. Previously when given an absolute path it would not recognize it as an existing program. Lets change that so it transparently handles such cases.
--- git-gui/git-gui.sh | 4 ++++ 1 file changed, 4 insertions(+)
git-gui/git-gui.sh +4 -0
@@ -429,6 +429,10 @@ proc _git_cmd {name} { proc _which {what args} { global env _search_exe _search_path + if {[file exists $what]} { + return [file normalize $what] + } + if {$_search_path eq {}} { if {[is_Cygwin] && [regexp {^(/|\.:)} $env(PATH)]} { set _search_path [split [exec cygpath \
Signature · 1 line
1.7.10.rc1.29.gf035d
Re: [GIT GUI PATCH 1/2] git-gui: teach _which procedure to work with absolute paths
Quoted 15 lines · Heiko Voigt
_whichis useful to check whether a certain command can be called. Previously when given an absolute path it would not recognize it as an existing program. Lets change that so it transparently handles such cases.Signed-off-by Heiko Voigt <[email protected]>--- git-gui/git-gui.sh | 4 ++++ 1 file changed, 4 insertions(+)git-gui/git-gui.sh +0
-0
git-gui/git-gui.sh proc _git_cmd {name} { · line 434
Quoted 6 lines
git-gui/git-gui.sh +3
-0@@ -429,6 +429,10 @@ proc _git_cmd {name} { proc _which {what args} { global env _search_exe _search_path + if {[file exists $what]} { + return [file normalize $what] + }
Has $what been verified that it is either an absolute path, or contains a directory separator, at this point in the code?
Otherwise, "_which Makefile" would say "Yeah, that is the one I will launch" in a directory that has a "Makefile" even when the user does not have "." in his $PATH, no?
Quoted 3 lines
git-gui/git-gui.sh +0
-0if {$_search_path eq {}} { if {[is_Cygwin] && [regexp {^(/|\.:)} $env(PATH)]} { set _search_path [split [exec cygpath \
PATCH 2/2 git-gui: add "open in editor" diff context menu entry
In reply to Heiko VoigtWhen cleaning up changes it is helpful to start an editor on the file viewed. Since we roughly know the line number it is also possible to feed the editor with that. An example implementation for some popular editors is contained in this patch.
--- git-gui/git-gui.sh | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+)
git-gui/git-gui.sh +51 -0
@@ -2237,6 +2237,49 @@ proc do_explore {} { eval exec $explorer [list [file nativename $_gitworktree]] & } +proc do_editor {file x y} { + global repo_config ui_diff + + set filearg "$file" + set _e [string map {' \"} $repo_config(core.editor)] + set editor [lindex $_e 0] + lappend exe [_which $editor] + if {[llength $_e] > 1} { + lappend args [lrange $_e 1 end] + } + + set line_no {} + catch { + set s_lno [lindex [split [$ui_diff index @$x,$y] .] 0] + set s_lno [$ui_diff search -backwards -regexp ^@@ $s_lno.0 0.0] + set hunk_header [$ui_diff get $s_lno "$s_lno lineend"] + + regexp {^@@@? -([0-9]+),[0-9]+} $hunk_header -> line_no + } + + if {$line_no ne {}} { + switch -glob -- $editor { + *notepad++* { + lappend args -n$line_no + } + *textpad* { + set filearg "$filearg\($line_no,0\)" + } + *emacs* - + *vim* { + lappend args +$line_no + } + } + } + lappend args $filearg + + if {[lindex $exe 0] eq {}} { + error_popup [mc "Couldn't find %s in PATH" $repo_config(core.editor)] + } else { + eval exec $exe $args & + } +} + set is_quitting 0 set ret_code 1
@@ -3516,6 +3559,14 @@ $ctxm add command \ -label [mc "Show More Context"] \ -command show_more_context lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state] +set editor "" +catch {set editor $repo_config(core.editor)} +if {$editor ne {}} { + $ctxm add command \ + -label [mc "Open in Editor"] \ + -command {do_editor $current_diff_path $cursorX $cursorY} + lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state] +} $ctxm add separator create_common_diff_popup $ctxm
Signature · 1 line
1.7.10.rc1.29.gf035d
Hi,
Quoted 8 lines · Bert Wesarg
Quoted 4 lines · Heiko Voigt
This patch series adds a new right click menuitem which allows the user to open the configured editor with the currently viewed file. For some popular editors it is also able to move the cursor close to the watched line.
I once mentioned this in a patch I send ages ago:
Quoted 8 lines
Look for the '[1]' reference.
I have done, what was discussed in this thread, but never send something to the list (maybe a private mail to Pat?), but you can have a look at my git-gui repo at [1]. The patch which implements this is bw/master~5 (
a648f3a06'git-gui: open file withGIT_EDITOR').
Interesting, I will give it a try once I find some time. So do you think it is now ready for inclusion? I saw that you actually did a lot more than me.
Cheers Heiko
Quoted 5 lines
Regards,
Bert
Quoted 15 lines · Heiko Voigt
Hi,
Quoted 12 lines · Bert Wesarg
Quoted 4 lines · Heiko Voigt
This patch series adds a new right click menuitem which allows the user to open the configured editor with the currently viewed file. For some popular editors it is also able to move the cursor close to the watched line.
I once mentioned this in a patch I send ages ago:
Look for the '[1]' reference.
Quoted 8 lines
Quoted 4 lines
I have done, what was discussed in this thread, but never send something to the list (maybe a private mail to Pat?), but you can have a look at my git-gui repo at [1]. The patch which implements this is bw/master~5 (
a648f3a06'git-gui: open file withGIT_EDITOR').Interesting, I will give it a try once I find some time. So do you think it is now ready for inclusion? I saw that you actually did a lot more than me.
You're right, in this commit is more than it should, I split it up. Thanks. I had the action also only on mouse button 2 (ie. middle one) but I added it now to the menus too. You have missed yourself a menu, that what is used for a merge conflict. And I added a menu to the file lists too, so they have a 'Open in Editor' entry now too.
Bert
Quoted 3 lines
Cheers Heiko
Re: [GIT GUI PATCH 1/2] git-gui: teach _which procedure to work with absolute paths
In reply to Junio C HamanoHi,
Quoted 19 lines · Junio C Hamano
Quoted 8 lines · Heiko Voigt
git-gui/git-gui.sh | 4 ++++ 1 file changed, 4 insertions(+)git-gui/git-gui.sh +0
-0git-gui/git-gui.sh proc _git_cmd {name} { · line 434
Quoted 6 lines
git-gui/git-gui.sh +3
-0@@ -429,6 +429,10 @@ proc _git_cmd {name} { proc _which {what args} { global env _search_exe _search_path + if {[file exists $what]} { + return [file normalize $what] + }Has $what been verified that it is either an absolute path, or contains a directory separator, at this point in the code?
Quoted 3 lines
Otherwise, "
_whichMakefile" would say "Yeah, that is the one I will launch" in a directory that has a "Makefile" even when the user does not have "." in his $PATH, no?
Thats a good point. Will add something for that if we have another iteration which depends on Berts patch which seems to try to achieve the same goal as this series.
Cheers Heiko