* [PATCH 2/2] help: add "man.viewer" config var to use "woman" or "konqueror"
@ 2008-02-17 19:52 Christian Couder
2008-02-18 5:08 ` Junio C Hamano
0 siblings, 1 reply; 2+ messages in thread
From: Christian Couder @ 2008-02-17 19:52 UTC (permalink / raw)
To: git; +Cc: Junio Hamano, Pascal Obry
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@tuxfamily.org>
---
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
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH 2/2] help: add "man.viewer" config var to use "woman" or "konqueror"
2008-02-17 19:52 [PATCH 2/2] help: add "man.viewer" config var to use "woman" or "konqueror" Christian Couder
@ 2008-02-18 5:08 ` Junio C Hamano
0 siblings, 0 replies; 2+ messages in thread
From: Junio C Hamano @ 2008-02-18 5:08 UTC (permalink / raw)
To: Christian Couder; +Cc: git, Pascal Obry
Christian Couder <chriscool@tuxfamily.org> writes:
> 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);
> }
I have to wonder if it makes sense to just define the interface
to launch an external user-supplied command, and have that
command line determine what actually should happen, e.g. inspect
DISPLAY and check emacs version etc.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2008-02-18 5:09 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-02-17 19:52 [PATCH 2/2] help: add "man.viewer" config var to use "woman" or "konqueror" Christian Couder
2008-02-18 5:08 ` Junio C Hamano
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).