From 488a60c8ef78872f38bbb3439a75cb2cda985a12 Mon Sep 17 00:00:00 2001 From: Pierre Habouzit Date: Sun, 11 Mar 2007 22:44:09 +0100 Subject: [PATCH] Now deal with EDITOR from lua as well. Signed-off-by: Pierre Habouzit --- attach.c | 2 +- compose.c | 9 ++++----- editmsg.c | 2 +- globals.h | 1 - headers.c | 7 +++---- init.c | 8 -------- init.h | 7 ------- lib-lua/lua-token.sh | 1 + lib-lua/madmutt.c | 19 ++++++++++++++++++- lib-ui/curs_lib.c | 5 +++-- lib-ui/curses.h | 2 +- protos.h | 2 +- send.c | 9 ++++----- 13 files changed, 37 insertions(+), 37 deletions(-) diff --git a/attach.c b/attach.c index 1dbc76e..648d6db 100644 --- a/attach.c +++ b/attach.c @@ -228,7 +228,7 @@ int mutt_edit_attachment (BODY * a) } else if (a->type == TYPETEXT) { /* On text, default to editor */ - mutt_edit_file (NONULL (Editor), a->filename); + mutt_edit_file(a->filename); } else { rfc1524_entry_delete(&entry); mutt_error (_("No mailcap edit entry for %s"), type); diff --git a/compose.c b/compose.c index c695f3b..9d37626 100644 --- a/compose.c +++ b/compose.c @@ -647,8 +647,8 @@ int mutt_compose_menu (HEADER * msg, /* structure for new message */ mutt_message_hook (NULL, msg, M_SEND2HOOK); break; case OP_COMPOSE_EDIT_MESSAGE: - if (Editor && !option (OPTEDITHDRS)) { - mutt_edit_file (Editor, msg->content->filename); + if (!option (OPTEDITHDRS)) { + mutt_edit_file(msg->content->filename); mutt_update_encoding (msg->content); menu->redraw = REDRAW_CURRENT | REDRAW_STATUS; mutt_message_hook (NULL, msg, M_SEND2HOOK); @@ -662,8 +662,7 @@ int mutt_compose_menu (HEADER * msg, /* structure for new message */ char *err = NULL; mutt_env_to_local (msg->env); - mutt_edit_headers (NONULL (Editor), msg->content->filename, msg, - fcc, fcclen); + mutt_edit_headers(msg->content->filename, msg, fcc, fcclen); if (mutt_env_to_idna (msg->env, &tag, &err)) { mutt_error (_("Bad IDN in \"%s\": '%s'"), tag, err); p_delete(&err); @@ -1023,7 +1022,7 @@ int mutt_compose_menu (HEADER * msg, /* structure for new message */ case OP_COMPOSE_EDIT_FILE: CHECK_COUNT; - mutt_edit_file (NONULL (Editor), idx[menu->current]->content->filename); + mutt_edit_file(idx[menu->current]->content->filename); mutt_update_encoding (idx[menu->current]->content); menu->redraw = REDRAW_CURRENT | REDRAW_STATUS; mutt_message_hook (NULL, msg, M_SEND2HOOK); diff --git a/editmsg.c b/editmsg.c index 6d848e3..c66f5ee 100644 --- a/editmsg.c +++ b/editmsg.c @@ -92,7 +92,7 @@ static int edit_one_message (CONTEXT * ctx, HEADER * cur) goto bail; } - mutt_edit_file (NONULL (Editor), tmp); + mutt_edit_file(tmp); if ((rc = stat (tmp, &sb)) == -1) { mutt_error (_("Can't stat %s: %s"), tmp, strerror (errno)); diff --git a/globals.h b/globals.h index 7430db3..82633db 100644 --- a/globals.h +++ b/globals.h @@ -36,7 +36,6 @@ WHERE char *DateFmt; WHERE char *DisplayFilter; WHERE char *DsnNotify; WHERE char *DsnReturn; -WHERE char *Editor; WHERE char *EditorHeaders; WHERE char *FileCharset; WHERE char *FolderFormat; diff --git a/headers.c b/headers.c index e9775d5..bd4f77e 100644 --- a/headers.c +++ b/headers.c @@ -15,9 +15,8 @@ #include #include "mutt_idna.h" -void mutt_edit_headers (const char *editor, - const char *body, - HEADER * msg, char *fcc, ssize_t fcclen) +void mutt_edit_headers(const char *body, + HEADER * msg, char *fcc, ssize_t fcclen) { char path[_POSIX_PATH_MAX]; /* tempfile used to edit headers + body */ char buffer[LONG_STRING]; @@ -57,7 +56,7 @@ void mutt_edit_headers (const char *editor, mtime = m_decrease_mtime(path, &st); - mutt_edit_file (editor, path); + mutt_edit_file(path); stat (path, &st); if (mtime == st.st_mtime) { /* the file has not changed! */ diff --git a/init.c b/init.c index 93daf2d..163ad04 100644 --- a/init.c +++ b/init.c @@ -2293,14 +2293,6 @@ void mutt_init (int skip_sys_rc, string_list_t * commands) Tempdir = m_strdup((p = getenv ("TMPDIR")) ? p : "/tmp"); - p = getenv ("VISUAL"); - if (!p) { - p = getenv ("EDITOR"); - if (!p) - p = "vi"; - } - Editor = m_strdup(p); - if ((p = getenv ("REPLYTO")) != NULL) { BUFFER buf, token; diff --git a/init.h b/init.h index a2b4c3d..e9c0f85 100644 --- a/init.h +++ b/init.h @@ -603,13 +603,6 @@ struct option_t MuttVars[] = { ** Note: if $$edit_headers had to be turned on by force because ** $$strict_mailto is \fIunset\fP, this option has no effect. */ - {"editor", DT_PATH, R_NONE, UL &Editor, "" }, - /* - ** .pp - ** This variable specifies which editor is used by Madmutt. - ** It defaults to the value of the \fT$$$VISUAL\fP, or \fT$$$EDITOR\fP, environment - ** variable, or to the string "\fTvi\fP" if neither of those are set. - */ {"encode_from", DT_BOOL, R_NONE, OPTENCODEFROM, "no" }, /* ** .pp diff --git a/lib-lua/lua-token.sh b/lib-lua/lua-token.sh index 654ff54..4a73f32 100644 --- a/lib-lua/lua-token.sh +++ b/lib-lua/lua-token.sh @@ -105,6 +105,7 @@ exit 0 ############ Put tokens here ############ ## dotlock +## editor ## sendmail ## shell ## tmpdir diff --git a/lib-lua/madmutt.c b/lib-lua/madmutt.c index 4bb0095..3bd3428 100644 --- a/lib-lua/madmutt.c +++ b/lib-lua/madmutt.c @@ -75,7 +75,11 @@ static int madmutt_assign(lua_State *L) case LTK_SENDMAIL: case LTK_SHELL: _mutt_expand_path(buf, sizeof(buf), val, 0); - mlua_regsets(tk, buf); + val = buf; + /* FALLTHROUGH */ + + case LTK_EDITOR: + mlua_regsets(tk, val); return 0; } } @@ -196,6 +200,12 @@ static const struct { /* {{{ madmutt magic properties */ +static void madmutt_init_editor(char *buf, ssize_t len) +{ + m_strcpy(buf, len, getenv("VISUAL") ?: getenv("EDITOR") ?: "vi"); + fprintf("%s\n", buf); +} + static void madmutt_init_shell(char *buf, ssize_t len) { struct passwd *pw = getpwuid(getuid()); @@ -219,6 +229,13 @@ static const struct { ** Contains the path of the \fTmadmutt_dotlock(1)\fP binary to be used by ** Madmutt. */ + {"editor", madmutt_init_editor, NULL }, + /* + ** .pp + ** This variable specifies which editor is used by Madmutt. + ** It defaults to the value of the \fT$$$VISUAL\fP, or \fT$$$EDITOR\fP, environment + ** variable, or to the string "\fTvi\fP" if neither of those are set. + */ { "sendmail", NULL, SENDMAIL " -oem -oi" }, /* ** .pp diff --git a/lib-ui/curs_lib.c b/lib-ui/curs_lib.c index c99a635..81edf2e 100644 --- a/lib-ui/curs_lib.c +++ b/lib-ui/curs_lib.c @@ -18,6 +18,7 @@ #include #endif +#include #include #include @@ -138,12 +139,12 @@ void mutt_clear_error (void) CLEARLINE (LINES - 1); } -void mutt_edit_file (const char *editor, const char *data) +void mutt_edit_file(const char *data) { char cmd[LONG_STRING]; mutt_endwin (NULL); - m_quotefile_fmt(cmd, sizeof (cmd), editor, data); + m_quotefile_fmt(cmd, sizeof (cmd), mlua_reggets(LTK_EDITOR), data); if (mutt_system (cmd) == -1) mutt_error (_("Error running \"%s\"!"), cmd); keypad (stdscr, TRUE); diff --git a/lib-ui/curses.h b/lib-ui/curses.h index 4cedb6c..4304363 100644 --- a/lib-ui/curses.h +++ b/lib-ui/curses.h @@ -147,7 +147,7 @@ typedef struct { void mutt_progress_bar (progress_t* progress, long pos); void mutt_clear_error (void); -void mutt_edit_file (const char *, const char *); +void mutt_edit_file (const char *); void mutt_curses_error (const char *, ...) __attribute__((format(printf, 1, 2))); void mutt_curses_message (const char *, ...) diff --git a/protos.h b/protos.h index 6a2ab8c..16121c3 100644 --- a/protos.h +++ b/protos.h @@ -57,7 +57,7 @@ void mutt_check_rescore (CONTEXT *); void mutt_default_save (char *, ssize_t, HEADER *); void mutt_display_address (ENVELOPE *); void mutt_edit_content_type (HEADER *, BODY *, FILE *); -void mutt_edit_headers (const char *, const char *, HEADER *, char *, ssize_t); +void mutt_edit_headers(const char *, HEADER *, char *, ssize_t); void mutt_enter_command (void); void mutt_fix_reply_recipients (ENVELOPE * env); void mutt_folder_hook (char *); diff --git a/send.c b/send.c index acb01af..2143f19 100644 --- a/send.c +++ b/send.c @@ -1291,7 +1291,7 @@ int ci_send_message (int flags, /* send mode */ process_user_header (msg->env); - if (option (OPTSIGONTOP) && (!(flags & SENDKEY) && Editor)) + if (option (OPTSIGONTOP) && (!(flags & SENDKEY))) append_signature (tempfp); /* include replies/forwarded messages, unless we are given a template */ @@ -1299,7 +1299,7 @@ int ci_send_message (int flags, /* send mode */ && generate_body (tempfp, msg, flags, ctx, cur) == -1) goto cleanup; - if (!option (OPTSIGONTOP) && (!(flags & SENDKEY) && Editor)) + if (!option (OPTSIGONTOP) && (!(flags & SENDKEY))) append_signature (tempfp); /* @@ -1405,12 +1405,11 @@ int ci_send_message (int flags, /* send mode */ goto cleanup; } else if (option (OPTEDITHDRS)) { mutt_env_to_local (msg->env); - mutt_edit_headers (Editor, msg->content->filename, msg, fcc, - sizeof (fcc)); + mutt_edit_headers(msg->content->filename, msg, fcc, sizeof (fcc)); mutt_env_to_idna (msg->env, NULL, NULL); } else { - mutt_edit_file (Editor, msg->content->filename); + mutt_edit_file(msg->content->filename); if (stat (msg->content->filename, &st) == 0) { if (mtime != st.st_mtime) -- 2.20.1