fileio: Move event definitions to the generator script

This commit is contained in:
ZyX 2014-09-20 20:11:19 +04:00
parent 7a6bf3f418
commit 8ed2dbf6e2
5 changed files with 181 additions and 205 deletions

65
scripts/gen_events.lua Normal file
View File

@ -0,0 +1,65 @@
if arg[1] == '--help' then
print('Usage: gen_events.lua src/nvim enum_file event_names_file')
os.exit(0)
end
local nvimsrcdir = arg[1]
local fileio_enum_file = arg[2]
local names_file = arg[3]
package.path = nvimsrcdir .. '/?.lua;' .. package.path
local auevents = require('auevents')
local events = auevents.events
local aliases = auevents.aliases
enum_tgt = io.open(fileio_enum_file, 'w')
names_tgt = io.open(names_file, 'w')
enum_tgt:write('typedef enum auto_event {')
names_tgt:write([[
static const struct event_name {
size_t len;
char *name;
event_T event;
} event_names[] = {]])
for i, event in ipairs(events) do
if i > 1 then
comma = ',\n'
else
comma = '\n'
end
enum_tgt:write(('%s EVENT_%s = %u'):format(comma, event:upper(), i - 1))
names_tgt:write(('%s {%u, "%s", EVENT_%s}'):format(comma, #event, event, event:upper()))
end
for alias, event in pairs(aliases) do
names_tgt:write((',\n {%u, "%s", EVENT_%s}'):format(#alias, alias, event:upper()))
end
names_tgt:write(',\n {0, NULL, (event_T)0}')
enum_tgt:write('\n} event_T;\n')
names_tgt:write('\n};\n')
enum_tgt:write(('\n#define NUM_EVENTS %u\n'):format(#events))
names_tgt:write('\nstatic AutoPat *first_autopat[NUM_EVENTS] = {\n ')
line_len = 1
for i = 1,((#events) - 1) do
line_len = line_len + #(' NULL,')
if line_len > 80 then
names_tgt:write('\n ')
line_len = 1 + #(' NULL,')
end
names_tgt:write(' NULL,')
end
if line_len + #(' NULL') > 80 then
names_tgt:write('\n NULL')
else
names_tgt:write(' NULL')
end
names_tgt:write('\n};\n')
enum_tgt:close()
names_tgt:close()

View File

@ -18,7 +18,11 @@ set(HEADER_GENERATOR ${PROJECT_SOURCE_DIR}/scripts/gendeclarations.lua)
set(GENERATED_INCLUDES_DIR ${PROJECT_BINARY_DIR}/include)
set(GENERATED_EX_CMDS_ENUM ${GENERATED_INCLUDES_DIR}/ex_cmds_enum.generated.h)
set(GENERATED_EX_CMDS_DEFS ${GENERATED_DIR}/ex_cmds_defs.generated.h)
set(GENERATED_EVENTS_ENUM ${GENERATED_INCLUDES_DIR}/auevents_enum.generated.h)
set(GENERATED_EVENTS_NAMES_MAP ${GENERATED_DIR}/auevents_name_map.generated.h)
set(EX_CMDS_GENERATOR ${PROJECT_SOURCE_DIR}/scripts/genex_cmds.lua)
set(EVENTS_GENERATOR ${PROJECT_SOURCE_DIR}/scripts/gen_events.lua)
set(EVENTS_LIST_FILE ${PROJECT_SOURCE_DIR}/src/nvim/auevents.lua)
set(EX_CMDS_DEFS_FILE ${PROJECT_SOURCE_DIR}/src/nvim/ex_cmds.lua)
include_directories(${GENERATED_DIR})
@ -149,6 +153,8 @@ list(APPEND NEOVIM_GENERATED_SOURCES
"${MSGPACK_DISPATCH}"
"${GENERATED_EX_CMDS_ENUM}"
"${GENERATED_EX_CMDS_DEFS}"
"${GENERATED_EVENTS_ENUM}"
"${GENERATED_EVENTS_NAMES_MAP}"
)
add_custom_command(OUTPUT ${GENERATED_EX_CMDS_ENUM} ${GENERATED_EX_CMDS_DEFS}
@ -157,6 +163,12 @@ add_custom_command(OUTPUT ${GENERATED_EX_CMDS_ENUM} ${GENERATED_EX_CMDS_DEFS}
DEPENDS ${EX_CMDS_GENERATOR} ${EX_CMDS_DEFS_FILE}
)
add_custom_command(OUTPUT ${GENERATED_EVENTS_ENUM} ${GENERATED_EVENTS_NAMES_MAP}
COMMAND ${LUA_PRG} ${EVENTS_GENERATOR}
${PROJECT_SOURCE_DIR}/src/nvim ${GENERATED_EVENTS_ENUM} ${GENERATED_EVENTS_NAMES_MAP}
DEPENDS ${EVENTS_GENERATOR} ${EVENTS_LIST_FILE}
)
# Our dependencies come first.
if (LibIntl_FOUND)

98
src/nvim/auevents.lua Normal file
View File

@ -0,0 +1,98 @@
return {
events = {
'BufAdd', -- after adding a buffer to the buffer list
'BufDelete', -- deleting a buffer from the buffer list
'BufEnter', -- after entering a buffer
'BufFilePost', -- after renaming a buffer
'BufFilePre', -- before renaming a buffer
'BufHidden', -- just after buffer becomes hidden
'BufLeave', -- before leaving a buffer
'BufNew', -- after creating any buffer
'BufNewFile', -- when creating a buffer for a new file
'BufReadCmd', -- read buffer using command
'BufReadPost', -- after reading a buffer
'BufReadPre', -- before reading a buffer
'BufUnload', -- just before unloading a buffer
'BufWinEnter', -- after showing a buffer in a window
'BufWinLeave', -- just after buffer removed from window
'BufWipeout', -- just before really deleting a buffer
'BufWriteCmd', -- write buffer using command
'BufWritePost', -- after writing a buffer
'BufWritePre', -- before writing a buffer
'CmdUndefined', -- command undefined
'CmdWinEnter', -- after entering the cmdline window
'CmdWinLeave', -- before leaving the cmdline window
'ColorScheme', -- after loading a colorscheme
'CompleteDone', -- after finishing insert complete
'CursorHold', -- cursor in same position for a while
'CursorHoldI', -- idem, in Insert mode
'CursorMoved', -- cursor was moved
'CursorMovedI', -- cursor was moved in Insert mode
'EncodingChanged', -- after changing the 'encoding' option
'FileAppendCmd', -- append to a file using command
'FileAppendPost', -- after appending to a file
'FileAppendPre', -- before appending to a file
'FileChangedRO', -- before first change to read-only file
'FileChangedShell', -- after shell command that changed file
'FileChangedShellPost', -- after (not) reloading changed file
'FileReadCmd', -- read from a file using command
'FileReadPost', -- after reading a file
'FileReadPre', -- before reading a file
'FileType', -- new file type detected (user defined)
'FileWriteCmd', -- write to a file using command
'FileWritePost', -- after writing a file
'FileWritePre', -- before writing a file
'FilterReadPost', -- after reading from a filter
'FilterReadPre', -- before reading from a filter
'FilterWritePost', -- after writing to a filter
'FilterWritePre', -- before writing to a filter
'FocusGained', -- got the focus
'FocusLost', -- lost the focus to another app
'FuncUndefined', -- if calling a function which doesn't exist
'GUIEnter', -- after starting the GUI
'GUIFailed', -- after starting the GUI failed
'InsertChange', -- when changing Insert/Replace mode
'InsertCharPre', -- before inserting a char
'InsertEnter', -- when entering Insert mode
'InsertLeave', -- when leaving Insert mode
'JobActivity', -- when job sent some data
'MenuPopup', -- just before popup menu is displayed
'QuickFixCmdPost', -- after :make, :grep etc.
'QuickFixCmdPre', -- before :make, :grep etc.
'QuitPre', -- before :quit
'RemoteReply', -- upon string reception from a remote vim
'SessionLoadPost', -- after loading a session file
'ShellCmdPost', -- after ":!cmd"
'ShellFilterPost', -- after ":1,2!cmd", ":w !cmd", ":r !cmd".
'SourceCmd', -- sourcing a Vim script using command
'SourcePre', -- before sourcing a Vim script
'SpellFileMissing', -- spell file missing
'StdinReadPost', -- after reading from stdin
'StdinReadPre', -- before reading from stdin
'SwapExists', -- found existing swap file
'Syntax', -- syntax selected
'TabClosed', -- a tab has closed
'TabEnter', -- after entering a tab page
'TabLeave', -- before leaving a tab page
'TabNew', -- when creating a new tab
'TabNewEntered', -- after entering a new tab
'TermChanged', -- after changing 'term'
'TermResponse', -- after setting "v:termresponse"
'TermOpen', -- after opening a terminal buffer
'TextChanged', -- text was modified
'TextChangedI', -- text was modified in Insert mode
'User', -- user defined autocommand
'VimEnter', -- after starting Vim
'VimLeave', -- before exiting Vim
'VimLeavePre', -- before exiting Vim and writing .viminfo
'VimResized', -- after Vim window was resized
'WinEnter', -- after entering a window
'WinLeave', -- before leaving a window
},
aliases = {
BufCreate = 'BufAdd',
BufRead = 'BufReadPost',
BufWrite = 'BufWritePre',
FileEncoding = 'EncodingChanged',
}
}

View File

@ -5121,116 +5121,9 @@ void forward_slash(char_u *fname)
/*
* Code for automatic commands.
*/
static struct event_name {
char *name; /* event name */
event_T event; /* event number */
} event_names[] =
{
{"BufAdd", EVENT_BUFADD},
{"BufCreate", EVENT_BUFADD},
{"BufDelete", EVENT_BUFDELETE},
{"BufEnter", EVENT_BUFENTER},
{"BufFilePost", EVENT_BUFFILEPOST},
{"BufFilePre", EVENT_BUFFILEPRE},
{"BufHidden", EVENT_BUFHIDDEN},
{"BufLeave", EVENT_BUFLEAVE},
{"BufNew", EVENT_BUFNEW},
{"BufNewFile", EVENT_BUFNEWFILE},
{"BufRead", EVENT_BUFREADPOST},
{"BufReadCmd", EVENT_BUFREADCMD},
{"BufReadPost", EVENT_BUFREADPOST},
{"BufReadPre", EVENT_BUFREADPRE},
{"BufUnload", EVENT_BUFUNLOAD},
{"BufWinEnter", EVENT_BUFWINENTER},
{"BufWinLeave", EVENT_BUFWINLEAVE},
{"BufWipeout", EVENT_BUFWIPEOUT},
{"BufWrite", EVENT_BUFWRITEPRE},
{"BufWritePost", EVENT_BUFWRITEPOST},
{"BufWritePre", EVENT_BUFWRITEPRE},
{"BufWriteCmd", EVENT_BUFWRITECMD},
{"CmdwinEnter", EVENT_CMDWINENTER},
{"CmdwinLeave", EVENT_CMDWINLEAVE},
{"CmdUndefined", EVENT_CMDUNDEFINED},
{"ColorScheme", EVENT_COLORSCHEME},
{"CompleteDone", EVENT_COMPLETEDONE},
{"CursorHold", EVENT_CURSORHOLD},
{"CursorHoldI", EVENT_CURSORHOLDI},
{"CursorMoved", EVENT_CURSORMOVED},
{"CursorMovedI", EVENT_CURSORMOVEDI},
{"EncodingChanged", EVENT_ENCODINGCHANGED},
{"FileEncoding", EVENT_ENCODINGCHANGED},
{"FileAppendPost", EVENT_FILEAPPENDPOST},
{"FileAppendPre", EVENT_FILEAPPENDPRE},
{"FileAppendCmd", EVENT_FILEAPPENDCMD},
{"FileChangedShell",EVENT_FILECHANGEDSHELL},
{"FileChangedShellPost",EVENT_FILECHANGEDSHELLPOST},
{"FileChangedRO", EVENT_FILECHANGEDRO},
{"FileReadPost", EVENT_FILEREADPOST},
{"FileReadPre", EVENT_FILEREADPRE},
{"FileReadCmd", EVENT_FILEREADCMD},
{"FileType", EVENT_FILETYPE},
{"FileWritePost", EVENT_FILEWRITEPOST},
{"FileWritePre", EVENT_FILEWRITEPRE},
{"FileWriteCmd", EVENT_FILEWRITECMD},
{"FilterReadPost", EVENT_FILTERREADPOST},
{"FilterReadPre", EVENT_FILTERREADPRE},
{"FilterWritePost", EVENT_FILTERWRITEPOST},
{"FilterWritePre", EVENT_FILTERWRITEPRE},
{"FocusGained", EVENT_FOCUSGAINED},
{"FocusLost", EVENT_FOCUSLOST},
{"FuncUndefined", EVENT_FUNCUNDEFINED},
{"GUIEnter", EVENT_GUIENTER},
{"GUIFailed", EVENT_GUIFAILED},
{"InsertChange", EVENT_INSERTCHANGE},
{"InsertEnter", EVENT_INSERTENTER},
{"InsertLeave", EVENT_INSERTLEAVE},
{"InsertCharPre", EVENT_INSERTCHARPRE},
{"MenuPopup", EVENT_MENUPOPUP},
{"QuickFixCmdPost", EVENT_QUICKFIXCMDPOST},
{"QuickFixCmdPre", EVENT_QUICKFIXCMDPRE},
{"QuitPre", EVENT_QUITPRE},
{"RemoteReply", EVENT_REMOTEREPLY},
{"SessionLoadPost", EVENT_SESSIONLOADPOST},
{"ShellCmdPost", EVENT_SHELLCMDPOST},
{"ShellFilterPost", EVENT_SHELLFILTERPOST},
{"SourcePre", EVENT_SOURCEPRE},
{"SourceCmd", EVENT_SOURCECMD},
{"SpellFileMissing",EVENT_SPELLFILEMISSING},
{"StdinReadPost", EVENT_STDINREADPOST},
{"StdinReadPre", EVENT_STDINREADPRE},
{"SwapExists", EVENT_SWAPEXISTS},
{"Syntax", EVENT_SYNTAX},
{"TabClosed", EVENT_TABCLOSED},
{"TabEnter", EVENT_TABENTER},
{"TabLeave", EVENT_TABLEAVE},
{"TabNew", EVENT_TABNEW},
{"TabNewEntered", EVENT_TABNEWENTERED},
{"TermChanged", EVENT_TERMCHANGED},
{"TermOpen", EVENT_TERMOPEN},
{"TermResponse", EVENT_TERMRESPONSE},
{"TextChanged", EVENT_TEXTCHANGED},
{"TextChangedI", EVENT_TEXTCHANGEDI},
{"User", EVENT_USER},
{"VimEnter", EVENT_VIMENTER},
{"VimLeave", EVENT_VIMLEAVE},
{"VimLeavePre", EVENT_VIMLEAVEPRE},
{"WinEnter", EVENT_WINENTER},
{"WinLeave", EVENT_WINLEAVE},
{"VimResized", EVENT_VIMRESIZED},
{NULL, (event_T)0}
};
static AutoPat *first_autopat[NUM_EVENTS] =
{
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
};
#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "auevents_name_map.generated.h"
#endif
static AutoPatCmd *active_apc_list = NULL; /* stack of active autocommands */
@ -5526,7 +5419,7 @@ static event_T event_name2nr(char_u *start, char_u **end)
for (p = start; *p && !ascii_iswhite(*p) && *p != ','; ++p)
;
for (i = 0; event_names[i].name != NULL; ++i) {
len = (int)STRLEN(event_names[i].name);
len = (int) event_names[i].len;
if (len == p - start && STRNICMP(event_names[i].name, start, len) == 0)
break;
}

View File

@ -12,100 +12,6 @@
#define READ_DUMMY 0x10 /* reading into a dummy buffer */
#define READ_KEEP_UNDO 0x20 /* keep undo info*/
/*
* Events for autocommands.
*/
typedef enum auto_event {
EVENT_BUFADD = 0, /* after adding a buffer to the buffer list */
EVENT_BUFNEW, /* after creating any buffer */
EVENT_BUFDELETE, /* deleting a buffer from the buffer list */
EVENT_BUFWIPEOUT, /* just before really deleting a buffer */
EVENT_BUFENTER, /* after entering a buffer */
EVENT_BUFFILEPOST, /* after renaming a buffer */
EVENT_BUFFILEPRE, /* before renaming a buffer */
EVENT_BUFLEAVE, /* before leaving a buffer */
EVENT_BUFNEWFILE, /* when creating a buffer for a new file */
EVENT_BUFREADPOST, /* after reading a buffer */
EVENT_BUFREADPRE, /* before reading a buffer */
EVENT_BUFREADCMD, /* read buffer using command */
EVENT_BUFUNLOAD, /* just before unloading a buffer */
EVENT_BUFHIDDEN, /* just after buffer becomes hidden */
EVENT_BUFWINENTER, /* after showing a buffer in a window */
EVENT_BUFWINLEAVE, /* just after buffer removed from window */
EVENT_BUFWRITEPOST, /* after writing a buffer */
EVENT_BUFWRITEPRE, /* before writing a buffer */
EVENT_BUFWRITECMD, /* write buffer using command */
EVENT_CMDWINENTER, /* after entering the cmdline window */
EVENT_CMDWINLEAVE, /* before leaving the cmdline window */
EVENT_COLORSCHEME, /* after loading a colorscheme */
EVENT_COMPLETEDONE, /* after finishing insert complete */
EVENT_FILEAPPENDPOST, /* after appending to a file */
EVENT_FILEAPPENDPRE, /* before appending to a file */
EVENT_FILEAPPENDCMD, /* append to a file using command */
EVENT_FILECHANGEDSHELL, /* after shell command that changed file */
EVENT_FILECHANGEDSHELLPOST, /* after (not) reloading changed file */
EVENT_FILECHANGEDRO, /* before first change to read-only file */
EVENT_FILEREADPOST, /* after reading a file */
EVENT_FILEREADPRE, /* before reading a file */
EVENT_FILEREADCMD, /* read from a file using command */
EVENT_FILETYPE, /* new file type detected (user defined) */
EVENT_FILEWRITEPOST, /* after writing a file */
EVENT_FILEWRITEPRE, /* before writing a file */
EVENT_FILEWRITECMD, /* write to a file using command */
EVENT_FILTERREADPOST, /* after reading from a filter */
EVENT_FILTERREADPRE, /* before reading from a filter */
EVENT_FILTERWRITEPOST, /* after writing to a filter */
EVENT_FILTERWRITEPRE, /* before writing to a filter */
EVENT_FOCUSGAINED, /* got the focus */
EVENT_FOCUSLOST, /* lost the focus to another app */
EVENT_GUIENTER, /* after starting the GUI */
EVENT_GUIFAILED, /* after starting the GUI failed */
EVENT_INSERTCHANGE, /* when changing Insert/Replace mode */
EVENT_INSERTENTER, /* when entering Insert mode */
EVENT_INSERTLEAVE, /* when leaving Insert mode */
EVENT_MENUPOPUP, /* just before popup menu is displayed */
EVENT_QUICKFIXCMDPOST, /* after :make, :grep etc. */
EVENT_QUICKFIXCMDPRE, /* before :make, :grep etc. */
EVENT_QUITPRE, /* before :quit */
EVENT_SESSIONLOADPOST, /* after loading a session file */
EVENT_STDINREADPOST, /* after reading from stdin */
EVENT_STDINREADPRE, /* before reading from stdin */
EVENT_SYNTAX, /* syntax selected */
EVENT_TERMCHANGED, /* after changing 'term' */
EVENT_TERMRESPONSE, /* after setting "v:termresponse" */
EVENT_USER, /* user defined autocommand */
EVENT_VIMENTER, /* after starting Vim */
EVENT_VIMLEAVE, /* before exiting Vim */
EVENT_VIMLEAVEPRE, /* before exiting Vim and writing .viminfo */
EVENT_VIMRESIZED, /* after Vim window was resized */
EVENT_WINENTER, /* after entering a window */
EVENT_WINLEAVE, /* before leaving a window */
EVENT_ENCODINGCHANGED, /* after changing the 'encoding' option */
EVENT_INSERTCHARPRE, /* before inserting a char */
EVENT_CURSORHOLD, /* cursor in same position for a while */
EVENT_CURSORHOLDI, /* idem, in Insert mode */
EVENT_FUNCUNDEFINED, /* if calling a function which doesn't exist */
EVENT_REMOTEREPLY, /* upon string reception from a remote vim */
EVENT_SWAPEXISTS, /* found existing swap file */
EVENT_SOURCEPRE, /* before sourcing a Vim script */
EVENT_SOURCECMD, /* sourcing a Vim script using command */
EVENT_SPELLFILEMISSING, /* spell file missing */
EVENT_CURSORMOVED, /* cursor was moved */
EVENT_CURSORMOVEDI, /* cursor was moved in Insert mode */
EVENT_TABCLOSED, /* a tab has closed */
EVENT_TABLEAVE, /* before leaving a tab page */
EVENT_TABENTER, /* after entering a tab page */
EVENT_TABNEW, /* when creating a new tab */
EVENT_TABNEWENTERED, /* after entering a new tab */
EVENT_SHELLCMDPOST, /* after ":!cmd" */
EVENT_SHELLFILTERPOST, /* after ":1,2!cmd", ":w !cmd", ":r !cmd". */
EVENT_TERMOPEN, // after opening a terminal buffer
EVENT_TEXTCHANGED, /* text was modified */
EVENT_TEXTCHANGEDI, /* text was modified in Insert mode*/
EVENT_CMDUNDEFINED, ///< command undefined
NUM_EVENTS /* MUST be the last one */
} event_T;
/*
* Struct to save values in before executing autocommands for a buffer that is
* not the current buffer.
@ -120,6 +26,8 @@ typedef struct {
} aco_save_T;
#ifdef INCLUDE_GENERATED_DECLARATIONS
// Events for autocommands
# include "auevents_enum.generated.h"
# include "fileio.h.generated.h"
#endif
#endif // NVIM_FILEIO_H