{"thread":{"id":"12156","subject":"[PATCH 2/2] help: add \"man.viewer\" config var to use \"woman\" or \"konqueror\"","startedAt":"2008-02-17T19:52:52Z","lastAt":"2008-02-18T05:08:17Z","messageCount":2,"participants":["Christian Couder","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"69032","messageId":"20080217205252.ff7ea434.chriscool@tuxfamily.org","threadId":"12156","inReplyTo":null,"subject":"[PATCH 2/2] help: add \"man.viewer\" config var to use \"woman\" or \"konqueror\"","fromName":"Christian Couder","fromEmail":"chriscool@tuxfamily.org","sentAt":"2008-02-17T19:52:52Z","receivedAt":"2008-02-17T19:52:52Z","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 (using 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, but currently\nthe \"emacsclient\" version is not checked.\n\nIt should also perhaps try to use kfmclient to launch konqueror\nin a new tab, like it's done in \"git-web-browse\". \n\nSigned-off-by: Christian Couder <chriscool@tuxfamily.org>\n---\n help.c |   40 +++++++++++++++++++++++++++++++++++-----\n 1 files changed, 35 insertions(+), 5 deletions(-)\n\n\tThis is a first draft to know what you think about the\n\tidea and if you have some suggestions about testing\n\temacsclient version.\n\ndiff --git a/help.c b/help.c\nindex 8143dcd..6b0e599 100644\n--- a/help.c\n+++ b/help.c\n@@ -9,6 +9,7 @@\n #include \"common-cmds.h\"\n \n static const char *help_default_format;\n+static const char *man_viewer;\n \n static enum help_format {\n \tman_format,\n@@ -41,6 +42,8 @@ static int git_help_config(const char *var, const char *value)\n {\n \tif (!strcmp(var, \"help.format\"))\n \t\treturn git_config_string(&help_default_format, var, value);\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@@ -312,11 +315,38 @@ static void setup_man_path(void)\n \tstrbuf_release(&new_path);\n }\n \n+static void exec_woman_emacs(const char *page)\n+{\n+\t/*\n+\t * FIXME: This works only with emacsclient version >= 22.\n+\t */\n+\tstruct strbuf man_page = STRBUF_INIT;\n+\tstrbuf_addf(&man_page, \"(woman \\\"%s\\\")\", page);\n+\texeclp(\"emacsclient\", \"emacsclient\", \"-e\", man_page.buf, 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(\"konqueror\", \"konqueror\", 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@@ -363,6 +393,7 @@ int cmd_version(int argc, const char **argv, const char *prefix)\n int cmd_help(int argc, const char **argv, const char *prefix)\n {\n \tconst char *help_cmd = argv[1];\n+\tint nongit;\n \n \tif (argc < 2) {\n \t\tprintf(\"usage: %s\\n\\n\", git_usage_string);\n@@ -370,6 +401,9 @@ int cmd_help(int argc, const char **argv, const char *prefix)\n \t\texit(0);\n \t}\n \n+\tsetup_git_directory_gently(&nongit);\n+\tgit_config(git_help_config);\n+\n \tif (!strcmp(help_cmd, \"--all\") || !strcmp(help_cmd, \"-a\")) {\n \t\tprintf(\"usage: %s\\n\\n\", git_usage_string);\n \t\tlist_commands();\n@@ -388,10 +422,6 @@ int cmd_help(int argc, const char **argv, const char *prefix)\n \t}\n \n \telse {\n-\t\tint nongit;\n-\n-\t\tsetup_git_directory_gently(&nongit);\n-\t\tgit_config(git_help_config);\n \t\tif (help_default_format)\n \t\t\tparse_help_format(help_default_format);\n \n-- \n1.5.4.1.1384.gdeff\n"},{"id":"69087","messageId":"7vodaeua0u.fsf@gitster.siamese.dyndns.org","threadId":"12156","inReplyTo":"20080217205252.ff7ea434.chriscool@tuxfamily.org","subject":"Re: [PATCH 2/2] help: add \"man.viewer\" config var to use \"woman\" or \"konqueror\"","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2008-02-18T05:08:17Z","receivedAt":"2008-02-18T05:08:17Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Christian Couder <chriscool@tuxfamily.org> writes:\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\nI have to wonder if it makes sense to just define the interface\nto launch an external user-supplied command, and have that\ncommand line determine what actually should happen, e.g. inspect\nDISPLAY and check emacs version etc.\n"}]}