All of lore.kernel.org
 help / color / mirror / Atom feed
* [GIT GUI PATCH 0/2] teach git gui to open the configured editor
@ 2012-03-23 17:30 Heiko Voigt
  2012-03-23 17:30 ` [GIT GUI PATCH 1/2] git-gui: teach _which procedure to work with absolute paths Heiko Voigt
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Heiko Voigt @ 2012-03-23 17:30 UTC (permalink / raw)
  To: Pat Thoyts; +Cc: git

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(+)

-- 
1.7.10.rc1.29.gf035d

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [GIT GUI PATCH 1/2] git-gui: teach _which procedure to work with absolute paths
  2012-03-23 17:30 [GIT GUI PATCH 0/2] teach git gui to open the configured editor Heiko Voigt
@ 2012-03-23 17:30 ` Heiko Voigt
  2012-03-23 19:31   ` Junio C Hamano
  2012-03-23 17:30 ` [GIT GUI PATCH 2/2] git-gui: add "open in editor" diff context menu entry Heiko Voigt
  2012-03-23 18:43 ` [GIT GUI PATCH 0/2] teach git gui to open the configured editor Bert Wesarg
  2 siblings, 1 reply; 8+ messages in thread
From: Heiko Voigt @ 2012-03-23 17:30 UTC (permalink / raw)
  To: Pat Thoyts; +Cc: git

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

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

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

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [GIT GUI PATCH 2/2] git-gui: add "open in editor" diff context menu entry
  2012-03-23 17:30 [GIT GUI PATCH 0/2] teach git gui to open the configured editor Heiko Voigt
  2012-03-23 17:30 ` [GIT GUI PATCH 1/2] git-gui: teach _which procedure to work with absolute paths Heiko Voigt
@ 2012-03-23 17:30 ` Heiko Voigt
  2012-03-23 18:43 ` [GIT GUI PATCH 0/2] teach git gui to open the configured editor Bert Wesarg
  2 siblings, 0 replies; 8+ messages in thread
From: Heiko Voigt @ 2012-03-23 17:30 UTC (permalink / raw)
  To: Pat Thoyts; +Cc: git

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@mahr.de>
---
 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

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [GIT GUI PATCH 0/2] teach git gui to open the configured editor
  2012-03-23 17:30 [GIT GUI PATCH 0/2] teach git gui to open the configured editor Heiko Voigt
  2012-03-23 17:30 ` [GIT GUI PATCH 1/2] git-gui: teach _which procedure to work with absolute paths Heiko Voigt
  2012-03-23 17:30 ` [GIT GUI PATCH 2/2] git-gui: add "open in editor" diff context menu entry Heiko Voigt
@ 2012-03-23 18:43 ` Bert Wesarg
  2012-03-25 17:02   ` Heiko Voigt
  2 siblings, 1 reply; 8+ messages in thread
From: Bert Wesarg @ 2012-03-23 18:43 UTC (permalink / raw)
  To: Heiko Voigt; +Cc: Pat Thoyts, git

Hi,

On Fri, Mar 23, 2012 at 18:30, Heiko Voigt <hvoigt@hvoigt.net> wrote:
> 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:

<1289770869-11665-1-git-send-email-bert.wesarg@googlemail.com>

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

>
> 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(+)
>
> --
> 1.7.10.rc1.29.gf035d
>
> --
> To unsubscribe from this list: send the line "unsubscribe git" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [GIT GUI PATCH 1/2] git-gui: teach _which procedure to work with absolute paths
  2012-03-23 17:30 ` [GIT GUI PATCH 1/2] git-gui: teach _which procedure to work with absolute paths Heiko Voigt
@ 2012-03-23 19:31   ` Junio C Hamano
  2012-03-25 17:09     ` Heiko Voigt
  0 siblings, 1 reply; 8+ messages in thread
From: Junio C Hamano @ 2012-03-23 19:31 UTC (permalink / raw)
  To: Heiko Voigt; +Cc: Pat Thoyts, git

Heiko Voigt <hvoigt@hvoigt.net> writes:

> _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.
>
> Signed-off-by: Heiko Voigt <heiko.voigt@mahr.de>
> ---
>  git-gui/git-gui.sh |    4 ++++
>  1 file changed, 4 insertions(+)
>
> diff --git a/git-gui/git-gui.sh b/git-gui/git-gui.sh
> index ba4e5c1..35cdee8 100755
> --- a/git-gui/git-gui.sh
> +++ b/git-gui/git-gui.sh
> @@ -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?

>  	if {$_search_path eq {}} {
>  		if {[is_Cygwin] && [regexp {^(/|\.:)} $env(PATH)]} {
>  			set _search_path [split [exec cygpath \

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [GIT GUI PATCH 0/2] teach git gui to open the configured editor
  2012-03-23 18:43 ` [GIT GUI PATCH 0/2] teach git gui to open the configured editor Bert Wesarg
@ 2012-03-25 17:02   ` Heiko Voigt
  2012-03-25 19:33     ` Bert Wesarg
  0 siblings, 1 reply; 8+ messages in thread
From: Heiko Voigt @ 2012-03-25 17:02 UTC (permalink / raw)
  To: Bert Wesarg; +Cc: Pat Thoyts, git

Hi,

On Fri, Mar 23, 2012 at 07:43:32PM +0100, Bert Wesarg wrote:
> On Fri, Mar 23, 2012 at 18:30, Heiko Voigt <hvoigt@hvoigt.net> wrote:
> > 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:
> 
> <1289770869-11665-1-git-send-email-bert.wesarg@googlemail.com>
> 
> 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').

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

> 
> Regards,
> Bert
> 
> [1] http://repo.or.cz/w/git-gui/bertw.git

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [GIT GUI PATCH 1/2] git-gui: teach _which procedure to work with absolute paths
  2012-03-23 19:31   ` Junio C Hamano
@ 2012-03-25 17:09     ` Heiko Voigt
  0 siblings, 0 replies; 8+ messages in thread
From: Heiko Voigt @ 2012-03-25 17:09 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Pat Thoyts, git

Hi,

On Fri, Mar 23, 2012 at 12:31:03PM -0700, Junio C Hamano wrote:
> Heiko Voigt <hvoigt@hvoigt.net> writes:
> >  git-gui/git-gui.sh |    4 ++++
> >  1 file changed, 4 insertions(+)
> >
> > diff --git a/git-gui/git-gui.sh b/git-gui/git-gui.sh
> > index ba4e5c1..35cdee8 100755
> > --- a/git-gui/git-gui.sh
> > +++ b/git-gui/git-gui.sh
> > @@ -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?

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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [GIT GUI PATCH 0/2] teach git gui to open the configured editor
  2012-03-25 17:02   ` Heiko Voigt
@ 2012-03-25 19:33     ` Bert Wesarg
  0 siblings, 0 replies; 8+ messages in thread
From: Bert Wesarg @ 2012-03-25 19:33 UTC (permalink / raw)
  To: Heiko Voigt; +Cc: Pat Thoyts, git

On Sun, Mar 25, 2012 at 19:02, Heiko Voigt <hvoigt@hvoigt.net> wrote:
> Hi,
>
> On Fri, Mar 23, 2012 at 07:43:32PM +0100, Bert Wesarg wrote:
>> On Fri, Mar 23, 2012 at 18:30, Heiko Voigt <hvoigt@hvoigt.net> wrote:
>> > 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:
>>
>> <1289770869-11665-1-git-send-email-bert.wesarg@googlemail.com>
>>
>> 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').
>
> 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

>
> Cheers Heiko
>

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2012-03-25 19:33 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-03-23 17:30 [GIT GUI PATCH 0/2] teach git gui to open the configured editor Heiko Voigt
2012-03-23 17:30 ` [GIT GUI PATCH 1/2] git-gui: teach _which procedure to work with absolute paths Heiko Voigt
2012-03-23 19:31   ` Junio C Hamano
2012-03-25 17:09     ` Heiko Voigt
2012-03-23 17:30 ` [GIT GUI PATCH 2/2] git-gui: add "open in editor" diff context menu entry Heiko Voigt
2012-03-23 18:43 ` [GIT GUI PATCH 0/2] teach git gui to open the configured editor Bert Wesarg
2012-03-25 17:02   ` Heiko Voigt
2012-03-25 19:33     ` Bert Wesarg

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.