{"thread":{"id":"12557","subject":"[PATCH 1/2 resend] help: add \"man.viewer\" config var to use \"woman\" or \"konqueror\"","startedAt":"2008-03-07T07:46:28Z","lastAt":"2008-03-12T01:00:03Z","messageCount":4,"participants":["Christian Couder","Xavier Maillard"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"71321","messageId":"20080307084628.0b311793.chriscool@tuxfamily.org","threadId":"12557","inReplyTo":null,"subject":"[PATCH 1/2 resend] help: add \"man.viewer\" config var to use \"woman\" or \"konqueror\"","fromName":"Christian Couder","fromEmail":"chriscool@tuxfamily.org","sentAt":"2008-03-07T07:46:28Z","receivedAt":"2008-03-07T07:46:28Z","isPatch":true,"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 |   81 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-\n 1 files changed, 80 insertions(+), 1 deletions(-)\n\n\tNow that the run-command patch has been integrated, this\n\tseems to work as expected for me with emacsclient 21 and 22.\n\n\tThanks.\n\ndiff --git a/help.c b/help.c\nindex e57a50e..2cb152d 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,85 @@ static void setup_man_path(void)\n \tstrbuf_release(&new_path);\n }\n \n+static int check_emacsclient_version(void)\n+{\n+\tstruct strbuf buffer = STRBUF_INIT;\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+\tstrbuf_read(&buffer, ec_process.err, 20);\n+\tclose(ec_process.err);\n+\n+\t/*\n+\t * Don't bother checking return value, because \"emacsclient --version\"\n+\t * seems to always exits with code 1.\n+\t */\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":"71636","messageId":"200803110100.m2B102k9007026@localhost.localdomain","threadId":"12557","inReplyTo":"20080307084628.0b311793.chriscool@tuxfamily.org","subject":"Re: [PATCH 1/2 resend] help: add \"man.viewer\" config var to use \"woman\" or \"konqueror\"","fromName":"Xavier Maillard","fromEmail":"xma@gnu.org","sentAt":"2008-03-11T01:00:02Z","receivedAt":"2008-03-11T01:00:02Z","isPatch":true,"sender":{"key":"xma@gnu.org","avatar":null},"body":"   This patch makes it possible to view man pages using other tools\n   than the \"man\" program. It also implements support for emacs'\n   \"woman\" and konqueror with the man KIO slave to view man pages.\n\n   Note that \"emacsclient\" is used with option \"-e\" to launch \"woman\"\n   on emacs and this works only on versions >= 22.\n\n   Signed-off-by: Christian Couder <chriscool@tuxfamily.org>\n\nAcked-off-by: Xavier Maillard <xma@gnu.org>\n\nThere is something wrong though. git cmd --help should wait for\nthe server to return in my opinion.\n\n\tXavier\n-- \nhttp://www.gnu.org\nhttp://www.april.org\nhttp://www.lolica.org\n"},{"id":"71654","messageId":"200803110648.16117.chriscool@tuxfamily.org","threadId":"12557","inReplyTo":"200803110100.m2B102k9007026@localhost.localdomain","subject":"Re: [PATCH 1/2 resend] help: add \"man.viewer\" config var to use \"woman\" or \"konqueror\"","fromName":"Christian Couder","fromEmail":"chriscool@tuxfamily.org","sentAt":"2008-03-11T05:48:15Z","receivedAt":"2008-03-11T05:48:15Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"Le mardi 11 mars 2008, Xavier Maillard a écrit :\n>    This patch makes it possible to view man pages using other tools\n>    than the \"man\" program. It also implements support for emacs'\n>    \"woman\" and konqueror with the man KIO slave to view man pages.\n>\n>    Note that \"emacsclient\" is used with option \"-e\" to launch \"woman\"\n>    on emacs and this works only on versions >= 22.\n>\n>    Signed-off-by: Christian Couder <chriscool@tuxfamily.org>\n>\n> Acked-off-by: Xavier Maillard <xma@gnu.org>\n\nThanks. (\"Tested-by:\" may be better though.) \n\n> There is something wrong though. git cmd --help should wait for\n> the server to return in my opinion.\n\nWhen I try something like the following on the command line:\n\n$ emacsclient -e '(woman \"fork\")'\n\nemacsclient doesn't wait for the server to return.\n\nSo I don't see how and why we should wait.\n\nThanks,\nChristian.\n"},{"id":"71758","messageId":"200803120100.m2C103RP010488@localhost.localdomain","threadId":"12557","inReplyTo":"200803110648.16117.chriscool@tuxfamily.org","subject":"Re: [PATCH 1/2 resend] help: add \"man.viewer\" config var to use \"woman\" or \"konqueror\"","fromName":"Xavier Maillard","fromEmail":"xma@gnu.org","sentAt":"2008-03-12T01:00:03Z","receivedAt":"2008-03-12T01:00:03Z","isPatch":true,"sender":{"key":"xma@gnu.org","avatar":null},"body":"   > There is something wrong though. git cmd --help should wait for\n   > the server to return in my opinion.\n\n   When I try something like the following on the command line:\n\n   $ emacsclient -e '(woman \"fork\")'\n\n   emacsclient doesn't wait for the server to return.\n\n   So I don't see how and why we should wait.\n\nYou are right. In fact, we can only wait for the server to return\nwhen we edit a file. Sorry for the noise\n\nTested-by: Xavier Maillard <xma@gnu.org>\n\n\tXavier\n-- \nhttp://www.gnu.org\nhttp://www.april.org\nhttp://www.lolica.org\n"}]}