This patch makes it possible to view man pages using other tools than the "man" program. It also implements support for emacs' "woman" and konqueror (using the man KIO slave) to view man pages. Note that "emacsclient" is used with option "-e" to launch "woman" on emacs and this works only on versions >= 22, but currently the "emacsclient" version is not checked. It should also perhaps try to use kfmclient to launch konqueror in a new tab, like it's done in "git-web-browse". Signed-off-by: Christian Couder <chriscool@xxxxxxxxxxxxx> --- help.c | 40 +++++++++++++++++++++++++++++++++++----- 1 files changed, 35 insertions(+), 5 deletions(-) This is a first draft to know what you think about the idea and if you have some suggestions about testing emacsclient version. diff --git a/help.c b/help.c index 8143dcd..6b0e599 100644 --- a/help.c +++ b/help.c @@ -9,6 +9,7 @@ #include "common-cmds.h" static const char *help_default_format; +static const char *man_viewer; static enum help_format { man_format, @@ -41,6 +42,8 @@ static int git_help_config(const char *var, const char *value) { if (!strcmp(var, "help.format")) return git_config_string(&help_default_format, var, value); + if (!strcmp(var, "man.viewer")) + return git_config_string(&man_viewer, var, value); return git_default_config(var, value); } @@ -312,11 +315,38 @@ static void setup_man_path(void) strbuf_release(&new_path); } +static void exec_woman_emacs(const char *page) +{ + /* + * FIXME: This works only with emacsclient version >= 22. + */ + struct strbuf man_page = STRBUF_INIT; + strbuf_addf(&man_page, "(woman \"%s\")", page); + execlp("emacsclient", "emacsclient", "-e", man_page.buf, NULL); +} + +static void exec_man_konqueror(const char *page) +{ + const char *display = getenv("DISPLAY"); + if (display && *display) { + struct strbuf man_page = STRBUF_INIT; + strbuf_addf(&man_page, "man:%s(1)", page); + execlp("konqueror", "konqueror", man_page.buf, NULL); + } else + execlp("man", "man", page, NULL); +} + static void show_man_page(const char *git_cmd) { const char *page = cmd_to_page(git_cmd); setup_man_path(); - execlp("man", "man", page, NULL); + if (!man_viewer || !strcmp(man_viewer, "man")) + execlp("man", "man", page, NULL); + if (!strcmp(man_viewer, "woman")) + exec_woman_emacs(page); + if (!strcmp(man_viewer, "konqueror")) + exec_man_konqueror(page); + die("'%s': unsupported man viewer.", man_viewer); } static void show_info_page(const char *git_cmd) @@ -363,6 +393,7 @@ int cmd_version(int argc, const char **argv, const char *prefix) int cmd_help(int argc, const char **argv, const char *prefix) { const char *help_cmd = argv[1]; + int nongit; if (argc < 2) { printf("usage: %s\n\n", git_usage_string); @@ -370,6 +401,9 @@ int cmd_help(int argc, const char **argv, const char *prefix) exit(0); } + setup_git_directory_gently(&nongit); + git_config(git_help_config); + if (!strcmp(help_cmd, "--all") || !strcmp(help_cmd, "-a")) { printf("usage: %s\n\n", git_usage_string); list_commands(); @@ -388,10 +422,6 @@ int cmd_help(int argc, const char **argv, const char *prefix) } else { - int nongit; - - setup_git_directory_gently(&nongit); - git_config(git_help_config); if (help_default_format) parse_help_format(help_default_format); -- 1.5.4.1.1384.gdeff - To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html