git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] patch open-editor-at-top-line
@ 2007-08-08 15:11 Dmitry Monakhov
  2007-08-08 17:43 ` David Kastrup
  0 siblings, 1 reply; 2+ messages in thread
From: Dmitry Monakhov @ 2007-08-08 15:11 UTC (permalink / raw)
  Cc: git

When i use "guilt series -e" for realy long series file
it is not confortable always search current top patch line.
IMHO editor have to start at the top patch automaticaly.
Btw: open_editor_at_line may be useful in other places

Signed-off-by: Dmitry Monakhov <dmonakhov@openvz.org>
---
 guilt        |   34 ++++++++++++++++++++++++++++++++++
 guilt-series |    5 +++--
 2 files changed, 37 insertions(+), 2 deletions(-)

diff --git a/guilt b/guilt
index bc51472..66c3078 100755
--- a/guilt
+++ b/guilt
@@ -287,6 +287,18 @@ series_insert_patch()
 	mv "$series.tmp" "$series"
 }
 
+# usage: line=get_series_top_line
+# return top patch line number in series
+get_series_top_line()
+{
+	awk -v top="`get_top`" -v new="$1" \
+		'BEGIN{if (top == "") ; iter=0;}
+		{
+			iter=iter+1;
+			if (top != "" && top == $0)  {print iter; exit};
+		}' "$series"
+}
+
 # usage: series_remove_patch <patchname>
 series_remove_patch()
 {
@@ -508,6 +520,28 @@ __refresh_patch()
 	push_patch "$1"
 }
 
+# usage: open_editor_at_line <editor> <filename> <line>
+# try to open editor with "filename"" at "line"
+# different editors use different syntax for start line parameter
+# so the only thing we can do is just compare with known editiors
+# and ignore line if editor is unknown.
+open_editor_at_line()
+{
+	editor_name=$1
+	file_name=$2
+	line_pos=$3
+	case "$editor_name" in
+		"vi" |"vim")
+			$editor_name $file_name +$line_pos;;
+		"emacs")
+			$editor_name $file_mame:$line_pos;;
+		*)
+			# editor is unknown, line_pos is just ignored
+			$editor_name $file_name;;
+	esac
+	return $?
+}
+
 # usage: munge_hash_range <hash range>
 #
 # this means:
diff --git a/guilt-series b/guilt-series
index 9c34a08..5a9ebbc 100755
--- a/guilt-series
+++ b/guilt-series
@@ -21,8 +21,9 @@ do
 	shift
 done
 
-if [ ! -z "$edit" ]; then 
-	$editor "$series"
+if [ ! -z "$edit" ]; then
+	top_line=`get_series_top_line`
+	open_editor_at_line $editor "$series" "$top_line"
 elif [ ! -z "$gui" ]; then
 	[ -z "`get_top`" ] && die "No patches applied."
 	bottom=`head -1 $applied | cut -d: -f1`
-- 
1.5.2.2

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

* Re: [PATCH] patch open-editor-at-top-line
  2007-08-08 15:11 [PATCH] patch open-editor-at-top-line Dmitry Monakhov
@ 2007-08-08 17:43 ` David Kastrup
  0 siblings, 0 replies; 2+ messages in thread
From: David Kastrup @ 2007-08-08 17:43 UTC (permalink / raw)
  To: Dmitry Monakhov; +Cc: git

Dmitry Monakhov <dmonakhov@openvz.org> writes:

> When i use "guilt series -e" for realy long series file
> it is not confortable always search current top patch line.
> IMHO editor have to start at the top patch automaticaly.
> Btw: open_editor_at_line may be useful in other places
>
> +# usage: open_editor_at_line <editor> <filename> <line>
> +# try to open editor with "filename"" at "line"
> +# different editors use different syntax for start line parameter
> +# so the only thing we can do is just compare with known editiors
> +# and ignore line if editor is unknown.
> +open_editor_at_line()
> +{
> +	editor_name=$1
> +	file_name=$2
> +	line_pos=$3
> +	case "$editor_name" in
> +		"vi" |"vim")
> +			$editor_name $file_name +$line_pos;;
> +		"emacs")
> +			$editor_name $file_mame:$line_pos;;
                                     ^^^^^^^^^^^^^^^^^^^^^^

You have not actually tested this patch.

> +		*)
> +			# editor is unknown, line_pos is just ignored
> +			$editor_name $file_name;;
> +	esac
> +	return $?
> +}
> +

This does not make much sense.  Pretty much every editor that can be
placed into $EDITOR/$VISUAL will understand the

$EDITOR +line filename

line convention (and if they don't, the damage is small).  Certainly
Emacs does so.  I don't know the situation under Windows, but in Unix
this has been the state for editors for eternity.

It turns out that I recently patched the git_editor function in
git-setup-sh.sh to take multiple arguments, and this should come in
handy: just do

git_editor "+$line_pos" "$filename"

and this should open the desired editor at the right line number.

-- 
David Kastrup, Kriemhildstr. 15, 44793 Bochum

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

end of thread, other threads:[~2007-08-08 17:43 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-08-08 15:11 [PATCH] patch open-editor-at-top-line Dmitry Monakhov
2007-08-08 17:43 ` David Kastrup

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).