[GIT GUI PATCH 2/2] git-gui: add "open in editor" diff context menu entry

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



When 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.

Signed-off-by: Heiko Voigt <heiko.voigt@xxxxxxx>
---
 git-gui/git-gui.sh |   51 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 51 insertions(+)

diff --git a/git-gui/git-gui.sh b/git-gui/git-gui.sh
index 35cdee8..c80bbff 100755
--- a/git-gui/git-gui.sh
+++ b/git-gui/git-gui.sh
@@ -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
 
-- 
1.7.10.rc1.29.gf035d

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]