X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=blobdiff_plain;f=lib-lua%2Fmadmutt.c;h=6fe2b4d629bc8f179270680e9ddb2bd07b797c29;hp=4bb0095d8780ca7b8f75a37426675c4eef2d3c7d;hb=a83b73d30397ee8e5c33668bcc0f1712ac74ff29;hpb=6f1bd3d49f9bb02c57e2c7a1ba8e5507edb28ad5 diff --git a/lib-lua/madmutt.c b/lib-lua/madmutt.c index 4bb0095..6fe2b4d 100644 --- a/lib-lua/madmutt.c +++ b/lib-lua/madmutt.c @@ -58,6 +58,19 @@ static int madmutt_folder_name(lua_State *L) return 1; } +static quadopt_t quadopt_parse(const char *s) +{ + if (!m_strcasecmp("yes", s)) + return M_YES; + if (!m_strcasecmp("no", s)) + return M_NO; + if (!m_strcasecmp("ask-yes", s)) + return M_ASKYES; + if (!m_strcasecmp("ask-no", s)) + return M_ASKNO; + return -1; +} + static int madmutt_assign(lua_State *L) { const char *idx = luaL_checkstring(L, 2); @@ -66,39 +79,73 @@ static int madmutt_assign(lua_State *L) switch ((tk = lua_which_token(idx, -1))) { char buf[STRING]; - - default: - luaL_error(L, "read-only or inexistant property '%s'", idx, tk); - return 0; + int i; case LTK_DOTLOCK: case LTK_SENDMAIL: case LTK_SHELL: + case LTK_EDITOR: _mutt_expand_path(buf, sizeof(buf), val, 0); - mlua_regsets(tk, buf); + val = buf; + /* FALLTHROUGH */ + + mlua_regsets(tk, val); + return 0; + + case LTK_QUIT: + i = quadopt_parse(val); + if (i < 0) + return luaL_error(L, "invalid quad option value: '%s'", val); + mlua_regseti(tk, i); return 0; + + case LTK_UNKNOWN: + case LTK_count: + break; } + + return luaL_error(L, "read-only or inexistant property '%s'", idx, tk); } static int madmutt_get(lua_State *L) { const char *idx = luaL_checkstring(L, 2); - int tk; - - switch ((tk = lua_which_token(idx, -1))) { - default: - lua_getmetatable(L, 1); - lua_replace(L, 1); - lua_rawget(L, 1); - return 1; + enum lua_token tk = lua_which_token(idx, -1); + switch (tk) { case LTK_DOTLOCK: case LTK_SENDMAIL: case LTK_SHELL: + case LTK_EDITOR: lua_pushstring(L, mlua_reggets(tk)); + return 1; + + case LTK_QUIT: + switch (mlua_reggeti(tk)) { + case M_YES: + lua_pushstring(L, "yes"); + return 1; + case M_NO: + lua_pushstring(L, "no"); + return 1; + case M_ASKNO: + lua_pushstring(L, "ask-no"); + return 1; + case M_ASKYES: + lua_pushstring(L, "ask-yes"); + return 1; + default: + return 0; + } + + case LTK_UNKNOWN: + case LTK_count: break; } + lua_getmetatable(L, 1); + lua_replace(L, 1); + lua_rawget(L, 1); return 1; } @@ -196,6 +243,11 @@ 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"); +} + static void madmutt_init_shell(char *buf, ssize_t len) { struct passwd *pw = getpwuid(getuid()); @@ -219,6 +271,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 @@ -232,6 +291,14 @@ static const struct { ** Command to use when spawning a subshell. By default, the user's login ** shell from \fT/etc/passwd\fP is used. */ + { "quit", NULL, "yes" }, + /* + ** .pp + ** This variable controls whether ``quit'' and ``exit'' actually quit + ** from Madmutt. If it set to \fIyes\fP, they do quit, if it is set to \fIno\fP, they + ** have no effect, and if it is set to \fIask-yes\fP or \fIask-no\fP, you are + ** prompted for confirmation when you try to quit. + */ }; /* }}} */