{"thread":{"id":"9436","subject":"[PATCH] patch open-editor-at-top-line","startedAt":"2007-08-08T15:11:45Z","lastAt":"2007-08-08T17:43:46Z","messageCount":2,"participants":["Dmitry Monakhov","David Kastrup"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"50195","messageId":"20070808151145.GA2897@dnb.sw.ru","threadId":"9436","inReplyTo":null,"subject":"[PATCH] patch open-editor-at-top-line","fromName":"Dmitry Monakhov","fromEmail":"dmonakhov@openvz.org","sentAt":"2007-08-08T15:11:45Z","receivedAt":"2007-08-08T15:11:45Z","isPatch":true,"sender":{"key":"dmonakhov@openvz.org","avatar":null},"body":"When i use \"guilt series -e\" for realy long series file\nit is not confortable always search current top patch line.\nIMHO editor have to start at the top patch automaticaly.\nBtw: open_editor_at_line may be useful in other places\n\nSigned-off-by: Dmitry Monakhov <dmonakhov@openvz.org>\n---\n guilt        |   34 ++++++++++++++++++++++++++++++++++\n guilt-series |    5 +++--\n 2 files changed, 37 insertions(+), 2 deletions(-)\n\ndiff --git a/guilt b/guilt\nindex bc51472..66c3078 100755\n--- a/guilt\n+++ b/guilt\n@@ -287,6 +287,18 @@ series_insert_patch()\n \tmv \"$series.tmp\" \"$series\"\n }\n \n+# usage: line=get_series_top_line\n+# return top patch line number in series\n+get_series_top_line()\n+{\n+\tawk -v top=\"`get_top`\" -v new=\"$1\" \\\n+\t\t'BEGIN{if (top == \"\") ; iter=0;}\n+\t\t{\n+\t\t\titer=iter+1;\n+\t\t\tif (top != \"\" && top == $0)  {print iter; exit};\n+\t\t}' \"$series\"\n+}\n+\n # usage: series_remove_patch <patchname>\n series_remove_patch()\n {\n@@ -508,6 +520,28 @@ __refresh_patch()\n \tpush_patch \"$1\"\n }\n \n+# usage: open_editor_at_line <editor> <filename> <line>\n+# try to open editor with \"filename\"\" at \"line\"\n+# different editors use different syntax for start line parameter\n+# so the only thing we can do is just compare with known editiors\n+# and ignore line if editor is unknown.\n+open_editor_at_line()\n+{\n+\teditor_name=$1\n+\tfile_name=$2\n+\tline_pos=$3\n+\tcase \"$editor_name\" in\n+\t\t\"vi\" |\"vim\")\n+\t\t\t$editor_name $file_name +$line_pos;;\n+\t\t\"emacs\")\n+\t\t\t$editor_name $file_mame:$line_pos;;\n+\t\t*)\n+\t\t\t# editor is unknown, line_pos is just ignored\n+\t\t\t$editor_name $file_name;;\n+\tesac\n+\treturn $?\n+}\n+\n # usage: munge_hash_range <hash range>\n #\n # this means:\ndiff --git a/guilt-series b/guilt-series\nindex 9c34a08..5a9ebbc 100755\n--- a/guilt-series\n+++ b/guilt-series\n@@ -21,8 +21,9 @@ do\n \tshift\n done\n \n-if [ ! -z \"$edit\" ]; then \n-\t$editor \"$series\"\n+if [ ! -z \"$edit\" ]; then\n+\ttop_line=`get_series_top_line`\n+\topen_editor_at_line $editor \"$series\" \"$top_line\"\n elif [ ! -z \"$gui\" ]; then\n \t[ -z \"`get_top`\" ] && die \"No patches applied.\"\n \tbottom=`head -1 $applied | cut -d: -f1`\n-- \n1.5.2.2\n"},{"id":"50205","messageId":"85wsw5rkfh.fsf@lola.goethe.zz","threadId":"9436","inReplyTo":"20070808151145.GA2897@dnb.sw.ru","subject":"Re: [PATCH] patch open-editor-at-top-line","fromName":"David Kastrup","fromEmail":"dak@gnu.org","sentAt":"2007-08-08T17:43:46Z","receivedAt":"2007-08-08T17:43:46Z","isPatch":true,"sender":{"key":"dak@gnu.org","avatar":"https://avatars.githubusercontent.com/u/52141349?v=4"},"body":"Dmitry Monakhov <dmonakhov@openvz.org> writes:\n\n> When i use \"guilt series -e\" for realy long series file\n> it is not confortable always search current top patch line.\n> IMHO editor have to start at the top patch automaticaly.\n> Btw: open_editor_at_line may be useful in other places\n>\n> +# usage: open_editor_at_line <editor> <filename> <line>\n> +# try to open editor with \"filename\"\" at \"line\"\n> +# different editors use different syntax for start line parameter\n> +# so the only thing we can do is just compare with known editiors\n> +# and ignore line if editor is unknown.\n> +open_editor_at_line()\n> +{\n> +\teditor_name=$1\n> +\tfile_name=$2\n> +\tline_pos=$3\n> +\tcase \"$editor_name\" in\n> +\t\t\"vi\" |\"vim\")\n> +\t\t\t$editor_name $file_name +$line_pos;;\n> +\t\t\"emacs\")\n> +\t\t\t$editor_name $file_mame:$line_pos;;\n                                     ^^^^^^^^^^^^^^^^^^^^^^\n\nYou have not actually tested this patch.\n\n> +\t\t*)\n> +\t\t\t# editor is unknown, line_pos is just ignored\n> +\t\t\t$editor_name $file_name;;\n> +\tesac\n> +\treturn $?\n> +}\n> +\n\nThis does not make much sense.  Pretty much every editor that can be\nplaced into $EDITOR/$VISUAL will understand the\n\n$EDITOR +line filename\n\nline convention (and if they don't, the damage is small).  Certainly\nEmacs does so.  I don't know the situation under Windows, but in Unix\nthis has been the state for editors for eternity.\n\nIt turns out that I recently patched the git_editor function in\ngit-setup-sh.sh to take multiple arguments, and this should come in\nhandy: just do\n\ngit_editor \"+$line_pos\" \"$filename\"\n\nand this should open the desired editor at the right line number.\n\n-- \nDavid Kastrup, Kriemhildstr. 15, 44793 Bochum\n"}]}