{"thread":{"id":"12325","subject":"help: add \"man.viewer\" config var to use \"woman\" or \"konqueror\"","startedAt":"2008-02-26T06:06:48Z","lastAt":"2008-02-29T02:00:06Z","messageCount":4,"participants":["Christian Couder","Xavier Maillard"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"69961","messageId":"20080226070648.5d799056.chriscool@tuxfamily.org","threadId":"12325","inReplyTo":null,"subject":"help: add \"man.viewer\" config var to use \"woman\" or \"konqueror\"","fromName":"Christian Couder","fromEmail":"chriscool@tuxfamily.org","sentAt":"2008-02-26T06:06:48Z","receivedAt":"2008-02-26T06:06:48Z","isPatch":false,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"This patch makes it possible to view man pages using other tools\nthan the \"man\" program. It also implements support for emacs'\n\"woman\" and konqueror with the man KIO slave to view man pages.\n\nNote that \"emacsclient\" is used with option \"-e\" to launch \"woman\"\non emacs and this works only on versions >= 22.\n\nSigned-off-by: Christian Couder <chriscool@tuxfamily.org>\n---\n help.c |   80 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-\n 1 files changed, 79 insertions(+), 1 deletions(-)\n\n\tJunio wrote:\n\t> I have to wonder if it makes sense to just define the interface\n\t> to launch an external user-supplied command, and have that\n\t> command line determine what actually should happen, e.g. inspect\n\t> DISPLAY and check emacs version etc.\n\n\tThere is some work on git-mergetool to do this. When it's integrated\n\tI will see if I can do something like that for git-help too.   \n\ndiff --git a/help.c b/help.c\nindex e57a50e..d700681 100644\n--- a/help.c\n+++ b/help.c\n@@ -8,6 +8,9 @@\n #include \"exec_cmd.h\"\n #include \"common-cmds.h\"\n #include \"parse-options.h\"\n+#include \"run-command.h\"\n+\n+static const char *man_viewer;\n \n enum help_format {\n \tHELP_FORMAT_MAN,\n@@ -50,6 +53,8 @@ static int git_help_config(const char *var, const char *value)\n \t\thelp_format = parse_help_format(value);\n \t\treturn 0;\n \t}\n+\tif (!strcmp(var, \"man.viewer\"))\n+\t\treturn git_config_string(&man_viewer, var, value);\n \treturn git_default_config(var, value);\n }\n \n@@ -345,11 +350,84 @@ static void setup_man_path(void)\n \tstrbuf_release(&new_path);\n }\n \n+static int check_emacsclient_version()\n+{\n+\tstruct strbuf buffer = STRBUF_INIT;\n+\tssize_t size;\n+\tstruct child_process ec_process;\n+\tconst char *argv_ec[] = { \"emacsclient\", \"--version\", NULL };\n+\tint version;\n+\n+\t/* emacsclient prints its version number on stderr */\n+\tmemset(&ec_process, 0, sizeof(ec_process));\n+\tec_process.argv = argv_ec;\n+\tec_process.err = -1;\n+\tec_process.stdout_to_stderr = 1;\n+\tif (start_command(&ec_process)) {\n+\t\tfprintf(stderr, \"Failed to start emacsclient.\\n\");\n+\t\treturn -1;\n+\t}\n+\tsize = strbuf_read(&buffer, ec_process.err, 20);\n+\tclose(ec_process.err);\n+\n+\t/* Don't bother checking return value, because \"emacsclient --version\"\n+\t * seems to always exits with code 1. */\n+\tfinish_command(&ec_process);\n+\n+\tif (prefixcmp(buffer.buf, \"emacsclient\")) {\n+\t\tfprintf(stderr, \"Failed to parse emacsclient version.\\n\");\n+\t\tstrbuf_release(&buffer);\n+\t\treturn -1;\n+\t}\n+\n+\tstrbuf_remove(&buffer, 0, strlen(\"emacsclient\"));\n+\tversion = atoi(buffer.buf);\n+\n+\tif (version < 22) {\n+\t\tfprintf(stderr,\n+\t\t\t\"emacsclient version '%d' too old (< 22).\\n\",\n+\t\t\tversion);\n+\t\tstrbuf_release(&buffer);\n+\t\treturn -1;\n+\t}\n+\n+\tstrbuf_release(&buffer);\n+\treturn 0;\n+}\n+\n+static void exec_woman_emacs(const char *page)\n+{\n+\tif (!check_emacsclient_version()) {\n+\t\t/* This works only with emacsclient version >= 22. */\n+\t\tstruct strbuf man_page = STRBUF_INIT;\n+\t\tstrbuf_addf(&man_page, \"(woman \\\"%s\\\")\", page);\n+\t\texeclp(\"emacsclient\", \"emacsclient\", \"-e\", man_page.buf, NULL);\n+\t} else\n+\t\texeclp(\"man\", \"man\", page, NULL);\n+}\n+\n+static void exec_man_konqueror(const char *page)\n+{\n+\tconst char *display = getenv(\"DISPLAY\");\n+\tif (display && *display) {\n+\t\tstruct strbuf man_page = STRBUF_INIT;\n+\t\tstrbuf_addf(&man_page, \"man:%s(1)\", page);\n+\t\texeclp(\"kfmclient\", \"kfmclient\", \"newTab\", man_page.buf, NULL);\n+\t} else\n+\t\texeclp(\"man\", \"man\", page, NULL);\n+}\n+\n static void show_man_page(const char *git_cmd)\n {\n \tconst char *page = cmd_to_page(git_cmd);\n \tsetup_man_path();\n-\texeclp(\"man\", \"man\", page, NULL);\n+\tif (!man_viewer || !strcmp(man_viewer, \"man\"))\n+\t\texeclp(\"man\", \"man\", page, NULL);\n+\tif (!strcmp(man_viewer, \"woman\"))\n+\t\texec_woman_emacs(page);\n+\tif (!strcmp(man_viewer, \"konqueror\"))\n+\t\texec_man_konqueror(page);\n+\tdie(\"'%s': unsupported man viewer.\", man_viewer);\n }\n \n static void show_info_page(const char *git_cmd)\n-- \n1.5.4.3.328.gcaed.dirty\n"},{"id":"70198","messageId":"200802280200.m1S207i0006525@localhost.localdomain","threadId":"12325","inReplyTo":"20080226070648.5d799056.chriscool@tuxfamily.org","subject":"Re: help: add \"man.viewer\" config var to use \"woman\" or \"konqueror\"","fromName":"Xavier Maillard","fromEmail":"xma@gnu.org","sentAt":"2008-02-28T02:00:07Z","receivedAt":"2008-02-28T02:00:07Z","isPatch":false,"sender":{"key":"xma@gnu.org","avatar":null},"body":"   Note that \"emacsclient\" is used with option \"-e\" to launch \"woman\"\n   on emacs and this works only on versions >= 22.\n\nAlthough reading the code, I find it nicely done, it wouldn't\napply on my current git repository without modifications.\n\nDid you rebase your work before your patch submission ?\n\n\tXavier\n-- \nhttp://www.gnu.org\nhttp://www.april.org\nhttp://www.lolica.org\n"},{"id":"70205","messageId":"200802280453.11446.chriscool@tuxfamily.org","threadId":"12325","inReplyTo":"200802280200.m1S207i0006525@localhost.localdomain","subject":"Re: help: add \"man.viewer\" config var to use \"woman\" or \"konqueror\"","fromName":"Christian Couder","fromEmail":"chriscool@tuxfamily.org","sentAt":"2008-02-28T03:53:11Z","receivedAt":"2008-02-28T03:53:11Z","isPatch":false,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"Le jeudi 28 février 2008, Xavier Maillard a écrit :\n>    Note that \"emacsclient\" is used with option \"-e\" to launch \"woman\"\n>    on emacs and this works only on versions >= 22.\n>\n> Although reading the code, I find it nicely done, it wouldn't\n> apply on my current git repository without modifications.\n>\n> Did you rebase your work before your patch submission ?\n\nYes, it was rebased on the 'next' branch.\n\nI will send an updated patch based on 'next' soon.\n\nThanks,\nChristian.\n"},{"id":"70355","messageId":"200802290200.m1T206t0018000@localhost.localdomain","threadId":"12325","inReplyTo":"200802280453.11446.chriscool@tuxfamily.org","subject":"Re: help: add \"man.viewer\" config var to use \"woman\" or \"konqueror\"","fromName":"Xavier Maillard","fromEmail":"xma@gnu.org","sentAt":"2008-02-29T02:00:06Z","receivedAt":"2008-02-29T02:00:06Z","isPatch":false,"sender":{"key":"xma@gnu.org","avatar":null},"body":"\n   Le jeudi 28 février 2008, Xavier Maillard a écrit :\n   >    Note that \"emacsclient\" is used with option \"-e\" to launch \"woman\"\n   >    on emacs and this works only on versions >= 22.\n   >\n   > Although reading the code, I find it nicely done, it wouldn't\n   > apply on my current git repository without modifications.\n   >\n   > Did you rebase your work before your patch submission ?\n\n   Yes, it was rebased on the 'next' branch.\n\nOk that explains why I could not apply it here :) I have switched\nto the 'net' branch and it effectively applied.\n\n\tXavier\n-- \nhttp://www.gnu.org\nhttp://www.april.org\nhttp://www.lolica.org\n"}]}