summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 88f66e2)
raw | patch | inline | side by side (parent: 88f66e2)
author | Jonas Fonseca <fonseca@diku.dk> | |
Sat, 18 Aug 2007 15:45:49 +0000 (17:45 +0200) | ||
committer | Jonas Fonseca <fonseca@diku.dk> | |
Sat, 18 Aug 2007 15:53:38 +0000 (17:53 +0200) |
tig.c | patch | blob | history |
index 83b3d18d6a962c0ec684bcebbf339f5965e074ce..95cad92630cbc823f7aa0dcad41d5ce9b7168f09 100644 (file)
--- a/tig.c
+++ b/tig.c
REQ_(STOP_LOADING, "Stop all loading views"), \
REQ_(TOGGLE_LINENO, "Toggle line numbers"), \
REQ_(TOGGLE_REV_GRAPH, "Toggle revision graph visualization"), \
- REQ_(STATUS_UPDATE, "Update file status") \
+ REQ_(STATUS_UPDATE, "Update file status"), \
+ REQ_(EDIT, "Open in editor")
/* User action requests. */
static char opt_search[SIZEOF_STR] = "";
static char opt_cdup[SIZEOF_STR] = "";
static char opt_git_dir[SIZEOF_STR] = "";
+static char opt_editor[SIZEOF_STR] = "";
enum option_type {
OPT_NONE,
{ 'g', REQ_TOGGLE_REV_GRAPH },
{ ':', REQ_PROMPT },
{ 'u', REQ_STATUS_UPDATE },
+ { 'e', REQ_EDIT },
/* Using the ncurses SIGWINCH handler. */
{ KEY_RESIZE, REQ_SCREEN_RESIZE },
update_view_title(view);
}
+static void
+open_editor(struct view *view, char *file)
+{
+ char cmd[SIZEOF_STR];
+ char file_sq[SIZEOF_STR];
+ char *editor;
+
+ editor = getenv("GIT_EDITOR");
+ if (!editor && *opt_editor)
+ editor = opt_editor;
+ if (!editor)
+ editor = getenv("VISUAL");
+ if (!editor)
+ editor = getenv("EDITOR");
+ if (!editor)
+ editor = "vi";
+
+ if (sq_quote(file_sq, 0, file) < sizeof(file_sq) &&
+ string_format(cmd, "%s %s", editor, file_sq)) {
+ def_prog_mode(); /* save current tty modes */
+ endwin(); /* restore original tty modes */
+ system(cmd);
+ reset_prog_mode();
+ redraw_display();
+ }
+}
/*
* User request switch noodle
redraw_display();
break;
+ case REQ_EDIT:
+ report("Nothing to edit");
case REQ_NONE:
doupdate();
static enum request
status_request(struct view *view, enum request request, struct line *line)
{
+ struct status *status = line->data;
+
switch (request) {
case REQ_STATUS_UPDATE:
status_update(view);
break;
+ case REQ_EDIT:
+ if (!status)
+ return request;
+
+ open_editor(view, status->name);
+ break;
+
case REQ_ENTER:
status_enter(view, line);
break;
@@ -4202,6 +4242,9 @@ read_repo_config_option(char *name, size_t namelen, char *value, size_t valuelen
if (!strcmp(name, "i18n.commitencoding"))
string_ncopy(opt_encoding, value, valuelen);
+ if (!strcmp(name, "core.editor"))
+ string_ncopy(opt_editor, value, valuelen);
+
return OK;
}