0
0
mirror of https://github.com/vim/vim.git synced 2025-09-25 03:54:15 -04:00

Whitespace cleanup.

This commit is contained in:
Bram Moolenaar
2010-07-17 23:52:29 +02:00
parent bd5e15fd5c
commit 55d5c0348c
10 changed files with 1246 additions and 1115 deletions

View File

@@ -1089,17 +1089,12 @@ Before (beta) release 7.3:
- Add fixes for 7.2 to version7.txt - Add fixes for 7.2 to version7.txt
- Add hg history to version7.txt - Add hg history to version7.txt
- Remove UF_VERSION_CRYPT_PREV and UF_VERSION_PREV. - Remove UF_VERSION_CRYPT_PREV and UF_VERSION_PREV.
- Documentation for Python 3 support.
- Build the MS-Windows version with Python 2.6.5 and 3.1.2? - Build the MS-Windows version with Python 2.6.5 and 3.1.2?
Before release 7.3: Before release 7.3:
- Rename vim73 branch to default (hints: Xavier de Gaye, 2010 May 23) - Rename vim73 branch to default (hints: Xavier de Gaye, 2010 May 23)
Vim 7.3:
Needs some work:
- Have a look at patch to enable screen access from Python. (Marko Mahnic,
2010 Apr 12)
More patches: More patches:
- Another patch for Javascript indenting. (Hari Kumar, 2010 Jul 11) - Another patch for Javascript indenting. (Hari Kumar, 2010 Jul 11)
Needs a few tests. Needs a few tests.

View File

@@ -229,33 +229,44 @@ static const luaV_Reg luaV_dll[] = {
static HINSTANCE hinstLua = 0; static HINSTANCE hinstLua = 0;
static void end_dynamic_lua (void) { static void
if (hinstLua) { end_dynamic_lua(void)
{
if (hinstLua)
{
FreeLibrary(hinstLua); FreeLibrary(hinstLua);
hinstLua = 0; hinstLua = 0;
} }
} }
static int lua_link_init (char *libname, int verbose) { static int
lua_link_init(char *libname, int verbose)
{
const luaV_Reg *reg; const luaV_Reg *reg;
if (hinstLua) return OK; if (hinstLua) return OK;
hinstLua = LoadLibrary(libname); hinstLua = LoadLibrary(libname);
if (!hinstLua) { if (!hinstLua)
if (verbose) EMSG2(_(e_loadlib), libname); {
if (verbose)
EMSG2(_(e_loadlib), libname);
return FAIL; return FAIL;
} }
for (reg = luaV_dll; reg->func; reg++) { for (reg = luaV_dll; reg->func; reg++)
{
if ((*reg->func = GetProcAddress(hinstLua, reg->name)) == NULL) { if ((*reg->func = GetProcAddress(hinstLua, reg->name)) == NULL) {
FreeLibrary(hinstLua); FreeLibrary(hinstLua);
hinstLua = 0; hinstLua = 0;
if (verbose) EMSG2(_(e_loadfunc), reg->name); if (verbose)
EMSG2(_(e_loadfunc), reg->name);
return FAIL; return FAIL;
} }
} }
return OK; return OK;
} }
int lua_enabled (int verbose) { int
lua_enabled(int verbose)
{
return lua_link_init(DYNAMIC_LUA_DLL, verbose) == OK; return lua_link_init(DYNAMIC_LUA_DLL, verbose) == OK;
} }
@@ -264,19 +275,27 @@ int lua_enabled (int verbose) {
/* ======= Internal ======= */ /* ======= Internal ======= */
static void luaV_newmetatable (lua_State *L, const char *tname) { static void
luaV_newmetatable(lua_State *L, const char *tname)
{
lua_newtable(L); lua_newtable(L);
lua_pushlightuserdata(L, (void *) tname); lua_pushlightuserdata(L, (void *) tname);
lua_pushvalue(L, -2); lua_pushvalue(L, -2);
lua_rawset(L, LUA_REGISTRYINDEX); lua_rawset(L, LUA_REGISTRYINDEX);
} }
static void *luaV_toudata (lua_State *L, int ud, const char *tname) { static void *
luaV_toudata(lua_State *L, int ud, const char *tname)
{
void *p = lua_touserdata(L, ud); void *p = lua_touserdata(L, ud);
if (p != NULL) { /* value is userdata? */
if (lua_getmetatable(L, ud)) { /* does it have a metatable? */ if (p != NULL) /* value is userdata? */
{
if (lua_getmetatable(L, ud)) /* does it have a metatable? */
{
luaV_getfield(L, tname); /* get metatable */ luaV_getfield(L, tname); /* get metatable */
if (lua_rawequal(L, -1, -2)) { /* MTs match? */ if (lua_rawequal(L, -1, -2)) /* MTs match? */
{
lua_pop(L, 2); /* MTs */ lua_pop(L, 2); /* MTs */
return p; return p;
} }
@@ -285,15 +304,20 @@ static void *luaV_toudata (lua_State *L, int ud, const char *tname) {
return NULL; return NULL;
} }
static void *luaV_checkudata (lua_State *L, int ud, const char *tname) { static void *
luaV_checkudata(lua_State *L, int ud, const char *tname)
{
void *p = luaV_toudata(L, ud, tname); void *p = luaV_toudata(L, ud, tname);
if (p == NULL) luaL_typerror(L, ud, tname); if (p == NULL) luaL_typerror(L, ud, tname);
return p; return p;
} }
static void luaV_pushtypval (lua_State *L, typval_T *tv) { static void
luaV_pushtypval(lua_State *L, typval_T *tv)
{
if (tv == NULL) luaL_error(L, "null type"); if (tv == NULL) luaL_error(L, "null type");
switch (tv->v_type) { switch (tv->v_type)
{
case VAR_STRING: case VAR_STRING:
lua_pushstring(L, (char *) tv->vval.v_string); lua_pushstring(L, (char *) tv->vval.v_string);
break; break;
@@ -307,11 +331,14 @@ static void luaV_pushtypval (lua_State *L, typval_T *tv) {
#endif #endif
case VAR_LIST: { case VAR_LIST: {
list_T *l = tv->vval.v_list; list_T *l = tv->vval.v_list;
if (l != NULL) {
if (l != NULL)
{
/* check cache */ /* check cache */
lua_pushlightuserdata(L, (void *) l); lua_pushlightuserdata(L, (void *) l);
lua_rawget(L, LUA_ENVIRONINDEX); lua_rawget(L, LUA_ENVIRONINDEX);
if (lua_isnil(L, -1)) { /* not interned? */ if (lua_isnil(L, -1)) /* not interned? */
{
listitem_T *li; listitem_T *li;
int n = 0; int n = 0;
lua_pop(L, 1); /* nil */ lua_pop(L, 1); /* nil */
@@ -319,7 +346,8 @@ static void luaV_pushtypval (lua_State *L, typval_T *tv) {
lua_pushlightuserdata(L, (void *) l); lua_pushlightuserdata(L, (void *) l);
lua_pushvalue(L, -2); lua_pushvalue(L, -2);
lua_rawset(L, LUA_ENVIRONINDEX); lua_rawset(L, LUA_ENVIRONINDEX);
for (li = l->lv_first; li != NULL; li = li->li_next) { for (li = l->lv_first; li != NULL; li = li->li_next)
{
luaV_pushtypval(L, &li->li_tv); luaV_pushtypval(L, &li->li_tv);
lua_rawseti(L, -2, ++n); lua_rawseti(L, -2, ++n);
} }
@@ -330,7 +358,9 @@ static void luaV_pushtypval (lua_State *L, typval_T *tv) {
} }
case VAR_DICT: { case VAR_DICT: {
dict_T *d = tv->vval.v_dict; dict_T *d = tv->vval.v_dict;
if (d != NULL) {
if (d != NULL)
{
/* check cache */ /* check cache */
lua_pushlightuserdata(L, (void *) d); lua_pushlightuserdata(L, (void *) d);
lua_rawget(L, LUA_ENVIRONINDEX); lua_rawget(L, LUA_ENVIRONINDEX);
@@ -343,8 +373,10 @@ static void luaV_pushtypval (lua_State *L, typval_T *tv) {
lua_pushlightuserdata(L, (void *) d); lua_pushlightuserdata(L, (void *) d);
lua_pushvalue(L, -2); lua_pushvalue(L, -2);
lua_rawset(L, LUA_ENVIRONINDEX); lua_rawset(L, LUA_ENVIRONINDEX);
for (hi = ht->ht_array; n > 0; hi++) { for (hi = ht->ht_array; n > 0; hi++)
if (!HASHITEM_EMPTY(hi)) { {
if (!HASHITEM_EMPTY(hi))
{
dictitem_T *di = dict_lookup(hi); dictitem_T *di = dict_lookup(hi);
luaV_pushtypval(L, &di->di_tv); luaV_pushtypval(L, &di->di_tv);
lua_setfield(L, -2, (char *) hi->hi_key); lua_setfield(L, -2, (char *) hi->hi_key);
@@ -363,17 +395,24 @@ static void luaV_pushtypval (lua_State *L, typval_T *tv) {
/* similar to luaL_addlstring, but replaces \0 with \n if toline and /* similar to luaL_addlstring, but replaces \0 with \n if toline and
* \n with \0 otherwise */ * \n with \0 otherwise */
static void luaV_addlstring (luaL_Buffer *b, const char *s, size_t l, static void
int toline) { luaV_addlstring(luaL_Buffer *b, const char *s, size_t l, int toline)
while (l--) { {
if (*s == '\0' && toline) luaL_addchar(b, '\n'); while (l--)
else if (*s == '\n' && !toline) luaL_addchar(b, '\0'); {
else luaL_addchar(b, *s); if (*s == '\0' && toline)
luaL_addchar(b, '\n');
else if (*s == '\n' && !toline)
luaL_addchar(b, '\0');
else
luaL_addchar(b, *s);
s++; s++;
} }
} }
static void luaV_pushline (lua_State *L, buf_T *buf, linenr_T n) { static void
luaV_pushline(lua_State *L, buf_T *buf, linenr_T n)
{
const char *s = (const char *) ml_get_buf(buf, n, FALSE); const char *s = (const char *) ml_get_buf(buf, n, FALSE);
luaL_Buffer b; luaL_Buffer b;
luaL_buffinit(L, &b); luaL_buffinit(L, &b);
@@ -381,9 +420,12 @@ static void luaV_pushline (lua_State *L, buf_T *buf, linenr_T n) {
luaL_pushresult(&b); luaL_pushresult(&b);
} }
static char_u *luaV_toline (lua_State *L, int pos) { static char_u *
luaV_toline(lua_State *L, int pos)
{
size_t l; size_t l;
const char *s = lua_tolstring(L, pos, &l); const char *s = lua_tolstring(L, pos, &l);
luaL_Buffer b; luaL_Buffer b;
luaL_buffinit(L, &b); luaL_buffinit(L, &b);
luaV_addlstring(&b, s, l, 1); luaV_addlstring(&b, s, l, 1);
@@ -393,7 +435,9 @@ static char_u *luaV_toline (lua_State *L, int pos) {
/* pops a string s from the top of the stack and calls mf(t) for pieces t of /* pops a string s from the top of the stack and calls mf(t) for pieces t of
* s separated by newlines */ * s separated by newlines */
static void luaV_msgfunc (lua_State *L, msgfunc_T mf) { static void
luaV_msgfunc(lua_State *L, msgfunc_T mf)
{
luaL_Buffer b; luaL_Buffer b;
size_t l; size_t l;
const char *p, *s = lua_tolstring(L, -1, &l); const char *p, *s = lua_tolstring(L, -1, &l);
@@ -402,8 +446,10 @@ static void luaV_msgfunc (lua_State *L, msgfunc_T mf) {
luaL_pushresult(&b); luaL_pushresult(&b);
/* break string */ /* break string */
p = s = lua_tolstring(L, -1, &l); p = s = lua_tolstring(L, -1, &l);
while (l--) { while (l--)
if (*p++ == '\0') { /* break? */ {
if (*p++ == '\0') /* break? */
{
mf((char_u *) s); mf((char_u *) s);
s = p; s = p;
} }
@@ -415,7 +461,9 @@ static void luaV_msgfunc (lua_State *L, msgfunc_T mf) {
/* ======= Buffer type ======= */ /* ======= Buffer type ======= */
static luaV_Buffer *luaV_newbuffer (lua_State *L, buf_T *buf) { static luaV_Buffer *
luaV_newbuffer(lua_State *L, buf_T *buf)
{
luaV_Buffer *b = (luaV_Buffer *) lua_newuserdata(L, sizeof(luaV_Buffer)); luaV_Buffer *b = (luaV_Buffer *) lua_newuserdata(L, sizeof(luaV_Buffer));
*b = buf; *b = buf;
lua_pushlightuserdata(L, (void *) buf); lua_pushlightuserdata(L, (void *) buf);
@@ -431,48 +479,61 @@ static luaV_Buffer *luaV_newbuffer (lua_State *L, buf_T *buf) {
return b; return b;
} }
static luaV_Buffer *luaV_pushbuffer (lua_State *L, buf_T *buf) { static luaV_Buffer *
luaV_pushbuffer (lua_State *L, buf_T *buf)
{
luaV_Buffer *b = NULL; luaV_Buffer *b = NULL;
if (buf == NULL) if (buf == NULL)
lua_pushnil(L); lua_pushnil(L);
else { else {
lua_pushlightuserdata(L, (void *) buf); lua_pushlightuserdata(L, (void *) buf);
lua_rawget(L, LUA_ENVIRONINDEX); lua_rawget(L, LUA_ENVIRONINDEX);
if (lua_isnil(L, -1)) { /* not interned? */ if (lua_isnil(L, -1)) /* not interned? */
{
lua_pop(L, 1); lua_pop(L, 1);
b = luaV_newbuffer(L, buf); b = luaV_newbuffer(L, buf);
} }
else b = (luaV_Buffer *) lua_touserdata(L, -1); else
b = (luaV_Buffer *) lua_touserdata(L, -1);
} }
return b; return b;
} }
/* Buffer metamethods */ /* Buffer metamethods */
static int luaV_buffer_tostring (lua_State *L) { static int
luaV_buffer_tostring(lua_State *L)
{
lua_pushfstring(L, "%s: %p", LUAVIM_BUFFER, lua_touserdata(L, 1)); lua_pushfstring(L, "%s: %p", LUAVIM_BUFFER, lua_touserdata(L, 1));
return 1; return 1;
} }
static int luaV_buffer_len (lua_State *L) { static int
luaV_buffer_len(lua_State *L)
{
luaV_Buffer *b = lua_touserdata(L, 1); luaV_Buffer *b = lua_touserdata(L, 1);
lua_pushinteger(L, (*b)->b_ml.ml_line_count); lua_pushinteger(L, (*b)->b_ml.ml_line_count);
return 1; return 1;
} }
static int luaV_buffer_call (lua_State *L) { static int
luaV_buffer_call(lua_State *L)
{
luaV_Buffer *b = (luaV_Buffer *) lua_touserdata(L, 1); luaV_Buffer *b = (luaV_Buffer *) lua_touserdata(L, 1);
lua_settop(L, 1); lua_settop(L, 1);
set_curbuf(*b, DOBUF_SPLIT); set_curbuf(*b, DOBUF_SPLIT);
return 1; return 1;
} }
static int luaV_buffer_index (lua_State *L) { static int
luaV_buffer_index(lua_State *L)
{
luaV_Buffer *b = (luaV_Buffer *) lua_touserdata(L, 1); luaV_Buffer *b = (luaV_Buffer *) lua_touserdata(L, 1);
linenr_T n = (linenr_T) lua_tointeger(L, 2); linenr_T n = (linenr_T) lua_tointeger(L, 2);
if (n > 0 && n <= (*b)->b_ml.ml_line_count) if (n > 0 && n <= (*b)->b_ml.ml_line_count)
luaV_pushline(L, *b, n); luaV_pushline(L, *b, n);
else if (lua_isstring(L, 2)) { else if (lua_isstring(L, 2))
{
const char *s = lua_tostring(L, 2); const char *s = lua_tostring(L, 2);
if (strncmp(s, "name", 4) == 0) if (strncmp(s, "name", 4) == 0)
lua_pushstring(L, (char *) (*b)->b_sfname); lua_pushstring(L, (char *) (*b)->b_sfname);
@@ -484,17 +545,22 @@ static int luaV_buffer_index (lua_State *L) {
else if (strncmp(s, "insert", 6) == 0 else if (strncmp(s, "insert", 6) == 0
|| strncmp(s, "next", 4) == 0 || strncmp(s, "next", 4) == 0
|| strncmp(s, "previous", 8) == 0 || strncmp(s, "previous", 8) == 0
|| strncmp(s, "isvalid", 7) == 0) { || strncmp(s, "isvalid", 7) == 0)
{
lua_getmetatable(L, 1); lua_getmetatable(L, 1);
lua_getfield(L, -1, s); lua_getfield(L, -1, s);
} }
else lua_pushnil(L); else
lua_pushnil(L);
} }
else lua_pushnil(L); else
lua_pushnil(L);
return 1; return 1;
} }
static int luaV_buffer_newindex (lua_State *L) { static int
luaV_buffer_newindex(lua_State *L)
{
luaV_Buffer *b = (luaV_Buffer *) lua_touserdata(L, 1); luaV_Buffer *b = (luaV_Buffer *) lua_touserdata(L, 1);
linenr_T n = (linenr_T) luaL_checkinteger(L, 2); linenr_T n = (linenr_T) luaL_checkinteger(L, 2);
#ifdef HAVE_SANDBOX #ifdef HAVE_SANDBOX
@@ -502,22 +568,28 @@ static int luaV_buffer_newindex (lua_State *L) {
#endif #endif
if (n < 1 || n > (*b)->b_ml.ml_line_count) if (n < 1 || n > (*b)->b_ml.ml_line_count)
luaL_error(L, "invalid line number"); luaL_error(L, "invalid line number");
if (lua_isnil(L, 3)) { /* delete line */ if (lua_isnil(L, 3)) /* delete line */
{
buf_T *buf = curbuf; buf_T *buf = curbuf;
curbuf = *b; curbuf = *b;
if (u_savedel(n, 1L) == FAIL) { if (u_savedel(n, 1L) == FAIL)
{
curbuf = buf; curbuf = buf;
luaL_error(L, "cannot save undo information"); luaL_error(L, "cannot save undo information");
} }
else if (ml_delete(n, FALSE) == FAIL) { else if (ml_delete(n, FALSE) == FAIL)
{
curbuf = buf; curbuf = buf;
luaL_error(L, "cannot delete line"); luaL_error(L, "cannot delete line");
} }
else { else {
deleted_lines_mark(n, 1L); deleted_lines_mark(n, 1L);
if (*b == curwin->w_buffer) { /* fix cursor in current window? */ if (*b == curwin->w_buffer) /* fix cursor in current window? */
if (curwin->w_cursor.lnum >= n) { {
if (curwin->w_cursor.lnum > n) { if (curwin->w_cursor.lnum >= n)
{
if (curwin->w_cursor.lnum > n)
{
curwin->w_cursor.lnum -= 1; curwin->w_cursor.lnum -= 1;
check_cursor_col(); check_cursor_col();
} }
@@ -529,14 +601,17 @@ static int luaV_buffer_newindex (lua_State *L) {
} }
curbuf = buf; curbuf = buf;
} }
else if (lua_isstring(L, 3)) { /* update line */ else if (lua_isstring(L, 3)) /* update line */
{
buf_T *buf = curbuf; buf_T *buf = curbuf;
curbuf = *b; curbuf = *b;
if (u_savesub(n) == FAIL) { if (u_savesub(n) == FAIL)
{
curbuf = buf; curbuf = buf;
luaL_error(L, "cannot save undo information"); luaL_error(L, "cannot save undo information");
} }
else if (ml_replace(n, luaV_toline(L, 3), TRUE) == FAIL) { else if (ml_replace(n, luaV_toline(L, 3), TRUE) == FAIL)
{
curbuf = buf; curbuf = buf;
luaL_error(L, "cannot replace line"); luaL_error(L, "cannot replace line");
} }
@@ -550,7 +625,9 @@ static int luaV_buffer_newindex (lua_State *L) {
return 0; return 0;
} }
static int luaV_buffer_insert (lua_State *L) { static int
luaV_buffer_insert(lua_State *L)
{
luaV_Buffer *b = luaV_checkudata(L, 1, LUAVIM_BUFFER); luaV_Buffer *b = luaV_checkudata(L, 1, LUAVIM_BUFFER);
linenr_T last = (*b)->b_ml.ml_line_count; linenr_T last = (*b)->b_ml.ml_line_count;
linenr_T n = (linenr_T) luaL_optinteger(L, 3, last); linenr_T n = (linenr_T) luaL_optinteger(L, 3, last);
@@ -565,11 +642,13 @@ static int luaV_buffer_insert (lua_State *L) {
/* insert */ /* insert */
buf = curbuf; buf = curbuf;
curbuf = *b; curbuf = *b;
if (u_save(n, n + 1) == FAIL) { if (u_save(n, n + 1) == FAIL)
{
curbuf = buf; curbuf = buf;
luaL_error(L, "cannot save undo information"); luaL_error(L, "cannot save undo information");
} }
else if (ml_append(n, luaV_toline(L, 2), 0, FALSE) == FAIL) { else if (ml_append(n, luaV_toline(L, 2), 0, FALSE) == FAIL)
{
curbuf = buf; curbuf = buf;
luaL_error(L, "cannot insert line"); luaL_error(L, "cannot insert line");
} }
@@ -580,19 +659,25 @@ static int luaV_buffer_insert (lua_State *L) {
return 0; return 0;
} }
static int luaV_buffer_next (lua_State *L) { static int
luaV_buffer_next(lua_State *L)
{
luaV_Buffer *b = luaV_checkudata(L, 1, LUAVIM_BUFFER); luaV_Buffer *b = luaV_checkudata(L, 1, LUAVIM_BUFFER);
luaV_pushbuffer(L, (*b)->b_next); luaV_pushbuffer(L, (*b)->b_next);
return 1; return 1;
} }
static int luaV_buffer_previous (lua_State *L) { static int
luaV_buffer_previous(lua_State *L)
{
luaV_Buffer *b = luaV_checkudata(L, 1, LUAVIM_BUFFER); luaV_Buffer *b = luaV_checkudata(L, 1, LUAVIM_BUFFER);
luaV_pushbuffer(L, (*b)->b_prev); luaV_pushbuffer(L, (*b)->b_prev);
return 1; return 1;
} }
static int luaV_buffer_isvalid (lua_State *L) { static int
luaV_buffer_isvalid(lua_State *L)
{
luaV_Buffer *b = luaV_checkudata(L, 1, LUAVIM_BUFFER); luaV_Buffer *b = luaV_checkudata(L, 1, LUAVIM_BUFFER);
lua_pushlightuserdata(L, (void *) (*b)); lua_pushlightuserdata(L, (void *) (*b));
lua_rawget(L, LUA_ENVIRONINDEX); lua_rawget(L, LUA_ENVIRONINDEX);
@@ -616,7 +701,9 @@ static const luaL_Reg luaV_Buffer_mt[] = {
/* ======= Window type ======= */ /* ======= Window type ======= */
static luaV_Window *luaV_newwindow (lua_State *L, win_T *win) { static luaV_Window *
luaV_newwindow(lua_State *L, win_T *win)
{
luaV_Window *w = (luaV_Window *) lua_newuserdata(L, sizeof(luaV_Window)); luaV_Window *w = (luaV_Window *) lua_newuserdata(L, sizeof(luaV_Window));
*w = win; *w = win;
lua_pushlightuserdata(L, (void *) win); lua_pushlightuserdata(L, (void *) win);
@@ -632,14 +719,17 @@ static luaV_Window *luaV_newwindow (lua_State *L, win_T *win) {
return w; return w;
} }
static luaV_Window *luaV_pushwindow (lua_State *L, win_T *win) { static luaV_Window *
luaV_pushwindow(lua_State *L, win_T *win)
{
luaV_Window *w = NULL; luaV_Window *w = NULL;
if (win == NULL) if (win == NULL)
lua_pushnil(L); lua_pushnil(L);
else { else {
lua_pushlightuserdata(L, (void *) win); lua_pushlightuserdata(L, (void *) win);
lua_rawget(L, LUA_ENVIRONINDEX); lua_rawget(L, LUA_ENVIRONINDEX);
if (lua_isnil(L, -1)) { /* not interned? */ if (lua_isnil(L, -1)) /* not interned? */
{
lua_pop(L, 1); lua_pop(L, 1);
w = luaV_newwindow(L, win); w = luaV_newwindow(L, win);
} }
@@ -650,19 +740,25 @@ static luaV_Window *luaV_pushwindow (lua_State *L, win_T *win) {
/* Window metamethods */ /* Window metamethods */
static int luaV_window_tostring (lua_State *L) { static int
luaV_window_tostring(lua_State *L)
{
lua_pushfstring(L, "%s: %p", LUAVIM_WINDOW, lua_touserdata(L, 1)); lua_pushfstring(L, "%s: %p", LUAVIM_WINDOW, lua_touserdata(L, 1));
return 1; return 1;
} }
static int luaV_window_call (lua_State *L) { static int
luaV_window_call(lua_State *L)
{
luaV_Window *w = (luaV_Window *) lua_touserdata(L, 1); luaV_Window *w = (luaV_Window *) lua_touserdata(L, 1);
lua_settop(L, 1); lua_settop(L, 1);
win_goto(*w); win_goto(*w);
return 1; return 1;
} }
static int luaV_window_index (lua_State *L) { static int
luaV_window_index(lua_State *L)
{
luaV_Window *w = (luaV_Window *) lua_touserdata(L, 1); luaV_Window *w = (luaV_Window *) lua_touserdata(L, 1);
const char *s = luaL_checkstring(L, 2); const char *s = luaL_checkstring(L, 2);
if (strncmp(s, "buffer", 6) == 0) if (strncmp(s, "buffer", 6) == 0)
@@ -680,7 +776,8 @@ static int luaV_window_index (lua_State *L) {
/* methods */ /* methods */
else if (strncmp(s, "next", 4) == 0 else if (strncmp(s, "next", 4) == 0
|| strncmp(s, "previous", 8) == 0 || strncmp(s, "previous", 8) == 0
|| strncmp(s, "isvalid", 7) == 0) { || strncmp(s, "isvalid", 7) == 0)
{
lua_getmetatable(L, 1); lua_getmetatable(L, 1);
lua_getfield(L, -1, s); lua_getfield(L, -1, s);
} }
@@ -689,11 +786,14 @@ static int luaV_window_index (lua_State *L) {
return 1; return 1;
} }
static int luaV_window_newindex (lua_State *L) { static int
luaV_window_newindex (lua_State *L)
{
luaV_Window *w = (luaV_Window *) lua_touserdata(L, 1); luaV_Window *w = (luaV_Window *) lua_touserdata(L, 1);
const char *s = luaL_checkstring(L, 2); const char *s = luaL_checkstring(L, 2);
int v = luaL_checkinteger(L, 3); int v = luaL_checkinteger(L, 3);
if (strncmp(s, "line", 4) == 0) { if (strncmp(s, "line", 4) == 0)
{
#ifdef HAVE_SANDBOX #ifdef HAVE_SANDBOX
luaV_checksandbox(L); luaV_checksandbox(L);
#endif #endif
@@ -702,7 +802,8 @@ static int luaV_window_newindex (lua_State *L) {
(*w)->w_cursor.lnum = v; (*w)->w_cursor.lnum = v;
update_screen(VALID); update_screen(VALID);
} }
else if (strncmp(s, "col", 3) == 0) { else if (strncmp(s, "col", 3) == 0)
{
#ifdef HAVE_SANDBOX #ifdef HAVE_SANDBOX
luaV_checksandbox(L); luaV_checksandbox(L);
#endif #endif
@@ -710,7 +811,8 @@ static int luaV_window_newindex (lua_State *L) {
update_screen(VALID); update_screen(VALID);
} }
#ifdef FEAT_VERTSPLIT #ifdef FEAT_VERTSPLIT
else if (strncmp(s, "width", 5) == 0) { else if (strncmp(s, "width", 5) == 0)
{
win_T *win = curwin; win_T *win = curwin;
#ifdef FEAT_GUI #ifdef FEAT_GUI
need_mouse_correct = TRUE; need_mouse_correct = TRUE;
@@ -720,7 +822,8 @@ static int luaV_window_newindex (lua_State *L) {
curwin = win; curwin = win;
} }
#endif #endif
else if (strncmp(s, "height", 6) == 0) { else if (strncmp(s, "height", 6) == 0)
{
win_T *win = curwin; win_T *win = curwin;
#ifdef FEAT_GUI #ifdef FEAT_GUI
need_mouse_correct = TRUE; need_mouse_correct = TRUE;
@@ -734,19 +837,25 @@ static int luaV_window_newindex (lua_State *L) {
return 0; return 0;
} }
static int luaV_window_next (lua_State *L) { static int
luaV_window_next(lua_State *L)
{
luaV_Window *w = luaV_checkudata(L, 1, LUAVIM_WINDOW); luaV_Window *w = luaV_checkudata(L, 1, LUAVIM_WINDOW);
luaV_pushwindow(L, (*w)->w_next); luaV_pushwindow(L, (*w)->w_next);
return 1; return 1;
} }
static int luaV_window_previous (lua_State *L) { static int
luaV_window_previous(lua_State *L)
{
luaV_Window *w = luaV_checkudata(L, 1, LUAVIM_WINDOW); luaV_Window *w = luaV_checkudata(L, 1, LUAVIM_WINDOW);
luaV_pushwindow(L, (*w)->w_prev); luaV_pushwindow(L, (*w)->w_prev);
return 1; return 1;
} }
static int luaV_window_isvalid (lua_State *L) { static int
luaV_window_isvalid(lua_State *L)
{
luaV_Window *w = luaV_checkudata(L, 1, LUAVIM_WINDOW); luaV_Window *w = luaV_checkudata(L, 1, LUAVIM_WINDOW);
lua_pushlightuserdata(L, (void *) (*w)); lua_pushlightuserdata(L, (void *) (*w));
lua_rawget(L, LUA_ENVIRONINDEX); lua_rawget(L, LUA_ENVIRONINDEX);
@@ -768,14 +877,17 @@ static const luaL_Reg luaV_Window_mt[] = {
/* ======= Vim module ======= */ /* ======= Vim module ======= */
static int luaV_print (lua_State *L) { static int
luaV_print(lua_State *L)
{
int i, n = lua_gettop(L); /* nargs */ int i, n = lua_gettop(L); /* nargs */
const char *s; const char *s;
size_t l; size_t l;
luaL_Buffer b; luaL_Buffer b;
luaL_buffinit(L, &b); luaL_buffinit(L, &b);
lua_getglobal(L, "tostring"); lua_getglobal(L, "tostring");
for (i = 1; i <= n; i++) { for (i = 1; i <= n; i++)
{
lua_pushvalue(L, -1); /* tostring */ lua_pushvalue(L, -1); /* tostring */
lua_pushvalue(L, i); /* arg */ lua_pushvalue(L, i); /* arg */
lua_call(L, 1, 1); lua_call(L, 1, 1);
@@ -791,33 +903,45 @@ static int luaV_print (lua_State *L) {
return 0; return 0;
} }
static int luaV_command (lua_State *L) { static int
luaV_command(lua_State *L)
{
do_cmdline_cmd((char_u *) luaL_checkstring(L, 1)); do_cmdline_cmd((char_u *) luaL_checkstring(L, 1));
update_screen(VALID); update_screen(VALID);
return 0; return 0;
} }
static int luaV_eval (lua_State *L) { static int
luaV_eval(lua_State *L)
{
typval_T *tv = eval_expr((char_u *) luaL_checkstring(L, 1), NULL); typval_T *tv = eval_expr((char_u *) luaL_checkstring(L, 1), NULL);
if (tv == NULL) luaL_error(L, "invalid expression"); if (tv == NULL) luaL_error(L, "invalid expression");
luaV_pushtypval(L, tv); luaV_pushtypval(L, tv);
return 1; return 1;
} }
static int luaV_beep (lua_State *L) { static int
luaV_beep(lua_State *L)
{
vim_beep(); vim_beep();
return 0; return 0;
} }
static int luaV_line (lua_State *L) { static int
luaV_line(lua_State *L)
{
luaV_pushline(L, curbuf, curwin->w_cursor.lnum); luaV_pushline(L, curbuf, curwin->w_cursor.lnum);
return 1; return 1;
} }
static int luaV_buffer (lua_State *L) { static int
luaV_buffer(lua_State *L)
{
buf_T *buf; buf_T *buf;
if (lua_isstring(L, 1)) { /* get by number or name? */ if (lua_isstring(L, 1)) /* get by number or name? */
if (lua_isnumber(L, 1)) { /* by number? */ {
if (lua_isnumber(L, 1)) /* by number? */
{
int n = lua_tointeger(L, 1); int n = lua_tointeger(L, 1);
for (buf = firstbuf; buf != NULL; buf = buf->b_next) for (buf = firstbuf; buf != NULL; buf = buf->b_next)
if (buf->b_fnum == n) break; if (buf->b_fnum == n) break;
@@ -825,8 +949,10 @@ static int luaV_buffer (lua_State *L) {
else { /* by name */ else { /* by name */
size_t l; size_t l;
const char *s = lua_tolstring(L, 1, &l); const char *s = lua_tolstring(L, 1, &l);
for (buf = firstbuf; buf != NULL; buf = buf->b_next) { for (buf = firstbuf; buf != NULL; buf = buf->b_next)
if (buf->b_ffname == NULL || buf->b_sfname == NULL) { {
if (buf->b_ffname == NULL || buf->b_sfname == NULL)
{
if (l == 0) break; if (l == 0) break;
} }
else if (strncmp(s, buf->b_ffname, l) == 0 else if (strncmp(s, buf->b_ffname, l) == 0
@@ -846,9 +972,12 @@ static int luaV_buffer (lua_State *L) {
return 1; return 1;
} }
static int luaV_window (lua_State *L) { static int
luaV_window(lua_State *L)
{
win_T *win; win_T *win;
if (lua_isnumber(L, 1)) { /* get by number? */ if (lua_isnumber(L, 1)) /* get by number? */
{
int n = lua_tointeger(L, 1); int n = lua_tointeger(L, 1);
for (win = firstwin; win != NULL; win = win->w_next, n--) for (win = firstwin; win != NULL; win = win->w_next, n--)
if (n == 1) break; if (n == 1) break;
@@ -864,7 +993,9 @@ static int luaV_window (lua_State *L) {
return 1; return 1;
} }
static int luaV_open (lua_State *L) { static int
luaV_open(lua_State *L)
{
luaV_Buffer *b; luaV_Buffer *b;
char_u *s = NULL; char_u *s = NULL;
#ifdef HAVE_SANDBOX #ifdef HAVE_SANDBOX
@@ -875,21 +1006,28 @@ static int luaV_open (lua_State *L) {
return 1; return 1;
} }
static int luaV_isbuffer (lua_State *L) { static int
luaV_isbuffer(lua_State *L)
{
lua_pushboolean(L, luaV_toudata(L, 1, LUAVIM_BUFFER) != NULL); lua_pushboolean(L, luaV_toudata(L, 1, LUAVIM_BUFFER) != NULL);
return 1; return 1;
} }
static int luaV_iswindow (lua_State *L) { static int
luaV_iswindow(lua_State *L)
{
lua_pushboolean(L, luaV_toudata(L, 1, LUAVIM_WINDOW) != NULL); lua_pushboolean(L, luaV_toudata(L, 1, LUAVIM_WINDOW) != NULL);
return 1; return 1;
} }
/* for freeing buffer and window objects; lightuserdata as arg */ /* for freeing buffer and window objects; lightuserdata as arg */
static luaV_free (lua_State *L) { static int
luaV_free(lua_State *L)
{
lua_pushvalue(L, 1); /* lightudata */ lua_pushvalue(L, 1); /* lightudata */
lua_rawget(L, LUA_ENVIRONINDEX); lua_rawget(L, LUA_ENVIRONINDEX);
if (!lua_isnil(L, -1)) { if (!lua_isnil(L, -1))
{
lua_pushnil(L); lua_pushnil(L);
lua_rawset(L, LUA_ENVIRONINDEX); /* env[udata] = nil */ lua_rawset(L, LUA_ENVIRONINDEX); /* env[udata] = nil */
lua_pushnil(L); lua_pushnil(L);
@@ -911,7 +1049,9 @@ static const luaL_Reg luaV_module[] = {
{NULL, NULL} {NULL, NULL}
}; };
static int luaopen_vim (lua_State *L) { static int
luaopen_vim(lua_State *L)
{
/* set environment */ /* set environment */
lua_newtable(L); lua_newtable(L);
lua_newtable(L); lua_newtable(L);
@@ -935,7 +1075,9 @@ static int luaopen_vim (lua_State *L) {
return 0; return 0;
} }
static lua_State *luaV_newstate (void) { static lua_State *
luaV_newstate(void)
{
lua_State *L = luaL_newstate(); lua_State *L = luaL_newstate();
const luaL_Reg luaV_core_libs[] = { const luaL_Reg luaV_core_libs[] = {
{"", luaopen_base}, {"", luaopen_base},
@@ -953,7 +1095,8 @@ static lua_State *luaV_newstate (void) {
const luaL_Reg *reg = luaV_core_libs; const luaL_Reg *reg = luaV_core_libs;
const char **s = os_funcs; const char **s = os_funcs;
/* core libs */ /* core libs */
for ( ; reg->func; reg++) { for ( ; reg->func; reg++)
{
lua_pushcfunction(L, reg->func); lua_pushcfunction(L, reg->func);
lua_pushstring(L, reg->name); lua_pushstring(L, reg->name);
lua_call(L, 1, 0); lua_call(L, 1, 0);
@@ -961,7 +1104,8 @@ static lua_State *luaV_newstate (void) {
/* restricted os lib */ /* restricted os lib */
lua_getglobal(L, LUA_OSLIBNAME); lua_getglobal(L, LUA_OSLIBNAME);
lua_newtable(L); lua_newtable(L);
for ( ; *s; s++) { for ( ; *s; s++)
{
lua_getfield(L, -2, *s); lua_getfield(L, -2, *s);
lua_setfield(L, -2, *s); lua_setfield(L, -2, *s);
} }
@@ -973,7 +1117,9 @@ static lua_State *luaV_newstate (void) {
return L; return L;
} }
static void luaV_setrange (lua_State *L, int line1, int line2) { static void
luaV_setrange(lua_State *L, int line1, int line2)
{
lua_getglobal(L, LUAVIM_NAME); lua_getglobal(L, LUAVIM_NAME);
lua_pushinteger(L, line1); lua_pushinteger(L, line1);
lua_setfield(L, -2, "firstline"); lua_setfield(L, -2, "firstline");
@@ -987,10 +1133,14 @@ static void luaV_setrange (lua_State *L, int line1, int line2) {
static lua_State *L = NULL; static lua_State *L = NULL;
static int lua_init (void) { static int
if (L == NULL) { lua_init(void)
{
if (L == NULL)
{
#ifdef DYNAMIC_LUA #ifdef DYNAMIC_LUA
if (!lua_enabled(TRUE)) { if (!lua_enabled(TRUE))
{
EMSG(_("Lua library cannot be loaded.")); EMSG(_("Lua library cannot be loaded."));
return FAIL; return FAIL;
} }
@@ -1000,8 +1150,11 @@ static int lua_init (void) {
return OK; return OK;
} }
void lua_end (void) { void
if (L != NULL) { lua_end(void)
{
if (L != NULL)
{
lua_close(L); lua_close(L);
L = NULL; L = NULL;
#ifdef DYNAMIC_LUA #ifdef DYNAMIC_LUA
@@ -1011,11 +1164,14 @@ void lua_end (void) {
} }
/* ex commands */ /* ex commands */
void ex_lua (exarg_T *eap) { void
ex_lua(exarg_T *eap)
{
char *script; char *script;
if (lua_init() == FAIL) return; if (lua_init() == FAIL) return;
script = (char *) script_get(eap, eap->arg); script = (char *) script_get(eap, eap->arg);
if (!eap->skip) { if (!eap->skip)
{
char *s = (script) ? script : (char *) eap->arg; char *s = (script) ? script : (char *) eap->arg;
luaV_setrange(L, eap->line1, eap->line2); luaV_setrange(L, eap->line1, eap->line2);
if (luaL_loadbuffer(L, s, strlen(s), LUAVIM_CHUNKNAME) if (luaL_loadbuffer(L, s, strlen(s), LUAVIM_CHUNKNAME)
@@ -1025,13 +1181,16 @@ void ex_lua (exarg_T *eap) {
if (script != NULL) vim_free(script); if (script != NULL) vim_free(script);
} }
void ex_luado (exarg_T *eap) { void
ex_luado(exarg_T *eap)
{
linenr_T l; linenr_T l;
const char *s = (const char *) eap->arg; const char *s = (const char *) eap->arg;
luaL_Buffer b; luaL_Buffer b;
size_t len; size_t len;
if (lua_init() == FAIL) return; if (lua_init() == FAIL) return;
if (u_save(eap->line1 - 1, eap->line2 + 1) == FAIL) { if (u_save(eap->line1 - 1, eap->line2 + 1) == FAIL)
{
EMSG(_("cannot save undo information")); EMSG(_("cannot save undo information"));
return; return;
} }
@@ -1042,21 +1201,25 @@ void ex_luado (exarg_T *eap) {
luaL_addlstring(&b, " end", 4); /* footer */ luaL_addlstring(&b, " end", 4); /* footer */
luaL_pushresult(&b); luaL_pushresult(&b);
s = lua_tolstring(L, -1, &len); s = lua_tolstring(L, -1, &len);
if (luaL_loadbuffer(L, s, len, LUAVIM_CHUNKNAME)) { if (luaL_loadbuffer(L, s, len, LUAVIM_CHUNKNAME))
{
luaV_emsg(L); luaV_emsg(L);
lua_pop(L, 1); /* function body */ lua_pop(L, 1); /* function body */
return; return;
} }
lua_call(L, 0, 1); lua_call(L, 0, 1);
lua_replace(L, -2); /* function -> body */ lua_replace(L, -2); /* function -> body */
for (l = eap->line1; l <= eap->line2; l++) { for (l = eap->line1; l <= eap->line2; l++)
{
lua_pushvalue(L, -1); /* function */ lua_pushvalue(L, -1); /* function */
luaV_pushline(L, curbuf, l); /* current line as arg */ luaV_pushline(L, curbuf, l); /* current line as arg */
if (lua_pcall(L, 1, 1, 0)) { if (lua_pcall(L, 1, 1, 0))
{
luaV_emsg(L); luaV_emsg(L);
break; break;
} }
if (lua_isstring(L, -1)) { /* update line? */ if (lua_isstring(L, -1)) /* update line? */
{
#ifdef HAVE_SANDBOX #ifdef HAVE_SANDBOX
luaV_checksandbox(L); luaV_checksandbox(L);
#endif #endif
@@ -1071,9 +1234,13 @@ void ex_luado (exarg_T *eap) {
update_screen(NOT_VALID); update_screen(NOT_VALID);
} }
void ex_luafile (exarg_T *eap) { void
if (lua_init() == FAIL) return; ex_luafile(exarg_T *eap)
if (!eap->skip) { {
if (lua_init() == FAIL)
return;
if (!eap->skip)
{
luaV_setrange(L, eap->line1, eap->line2); luaV_setrange(L, eap->line1, eap->line2);
if (luaL_loadfile(L, (char *) eap->arg) || lua_pcall(L, 0, 0, 0)) if (luaL_loadfile(L, (char *) eap->arg) || lua_pcall(L, 0, 0, 0))
luaV_emsg(L); luaV_emsg(L);
@@ -1081,7 +1248,9 @@ void ex_luafile (exarg_T *eap) {
} }
/* buffer */ /* buffer */
void lua_buffer_free (buf_T *buf) { void
lua_buffer_free(buf_T *buf)
{
if (lua_init() == FAIL) return; if (lua_init() == FAIL) return;
luaV_getfield(L, LUAVIM_FREE); luaV_getfield(L, LUAVIM_FREE);
lua_pushlightuserdata(L, (void *) buf); lua_pushlightuserdata(L, (void *) buf);
@@ -1089,7 +1258,9 @@ void lua_buffer_free (buf_T *buf) {
} }
/* window */ /* window */
void lua_window_free (win_T *win) { void
lua_window_free(win_T *win)
{
if (lua_init() == FAIL) return; if (lua_init() == FAIL) return;
luaV_getfield(L, LUAVIM_FREE); luaV_getfield(L, LUAVIM_FREE);
lua_pushlightuserdata(L, (void *) win); lua_pushlightuserdata(L, (void *) win);

View File

@@ -1627,8 +1627,8 @@ static struct PyMethodDef RangeMethods[] = {
static PySequenceMethods RangeAsSeq = { static PySequenceMethods RangeAsSeq = {
(lenfunc) RangeLength, /* sq_length, len(x) */ (lenfunc) RangeLength, /* sq_length, len(x) */
(binaryfunc) 0, /* RangeConcat, */ /* sq_concat, x+y */ (binaryfunc) 0, /* RangeConcat, sq_concat, x+y */
(ssizeargfunc) 0, /* RangeRepeat, */ /* sq_repeat, x*n */ (ssizeargfunc) 0, /* RangeRepeat, sq_repeat, x*n */
(ssizeargfunc) RangeItem, /* sq_item, x[i] */ (ssizeargfunc) RangeItem, /* sq_item, x[i] */
0, /* was_sq_slice, x[i:j] */ 0, /* was_sq_slice, x[i:j] */
(ssizeobjargproc) RangeAsItem, /* sq_as_item, x[i]=v */ (ssizeobjargproc) RangeAsItem, /* sq_as_item, x[i]=v */
@@ -1849,55 +1849,7 @@ static struct PyMethodDef WindowMethods[] = {
{ NULL, NULL, 0, NULL } { NULL, NULL, 0, NULL }
}; };
static PyTypeObject WindowType = { static PyTypeObject WindowType;
PyVarObject_HEAD_INIT(NULL, 0)
"vim.window", /* tp_name */
sizeof(WindowObject), /* tp_basicsize */
0, /* tp_itemsize */
WindowDestructor, /* tp_dealloc */
0, /* tp_print */
0, /* tp_getattr */
0, /* tp_setattr */
0, /* tp_reserved */
WindowRepr, /* tp_repr */
0, /* tp_as_number */
0, /* tp_as_sequence */
0, /* tp_as_mapping */
0, /* tp_hash */
0, /* tp_call */
0, /* tp_str */
WindowGetattro, /* tp_getattro */
WindowSetattro, /* tp_setattro */
0, /* tp_as_Window */
Py_TPFLAGS_DEFAULT, /* tp_flags */
"vim Window object", /* tp_doc */
0, /*tp_traverse*/
0, /*tp_clear*/
0, /*tp_richcompare*/
0, /*tp_weaklistoffset*/
0, /*tp_iter*/
0, /*tp_iternext*/
WindowMethods, /*tp_methods*/
0, /*tp_members*/
0, /*tp_getset*/
0, /*tp_base*/
0, /*tp_dict*/
0, /*tp_descr_get*/
0, /*tp_descr_set*/
0, /*tp_dictoffset*/
0, /*tp_init*/
call_PyType_GenericAlloc, /*tp_alloc*/
call_PyType_GenericNew, /*tp_new*/
call_PyObject_Free, /*tp_free*/
0, /*tp_is_gc*/
0, /*tp_bases*/
0, /*tp_mro*/
0, /*tp_cache*/
0, /*tp_subclasses*/
0, /*tp_weaklist*/
0, /*tp_del*/
0, /*tp_version_tag*/
};
/* Window object - Implementation /* Window object - Implementation
*/ */
@@ -2721,7 +2673,6 @@ static int VimErrorCheck(void)
return 0; return 0;
} }
static void init_structs(void) static void init_structs(void)
{ {
vim_memset(&OutputType, 0, sizeof(OutputType)); vim_memset(&OutputType, 0, sizeof(OutputType));
@@ -2751,6 +2702,20 @@ static void init_structs(void)
BufferType.tp_new = call_PyType_GenericNew; BufferType.tp_new = call_PyType_GenericNew;
BufferType.tp_free = call_PyObject_Free; BufferType.tp_free = call_PyObject_Free;
vim_memset(&WindowType, 0, sizeof(WindowType));
WindowType.tp_name = "vim.window";
WindowType.tp_basicsize = sizeof(WindowObject);
WindowType.tp_dealloc = WindowDestructor;
WindowType.tp_repr = WindowRepr;
WindowType.tp_getattro = WindowGetattro;
WindowType.tp_setattro = WindowSetattro;
WindowType.tp_flags = Py_TPFLAGS_DEFAULT;
WindowType.tp_doc = "vim Window object";
WindowType.tp_methods = WindowMethods;
WindowType.tp_alloc = call_PyType_GenericAlloc;
WindowType.tp_new = call_PyType_GenericNew;
WindowType.tp_free = call_PyObject_Free;
vim_memset(&BufListType, 0, sizeof(BufListType)); vim_memset(&BufListType, 0, sizeof(BufListType));
BufListType.tp_name = "vim.bufferlist"; BufListType.tp_name = "vim.bufferlist";
BufListType.tp_basicsize = sizeof(BufListObject); BufListType.tp_basicsize = sizeof(BufListObject);