diff options
author | 2010-11-10 21:39:29 -0500 | |
---|---|---|
committer | 2010-11-10 21:39:29 -0500 | |
commit | 13d1c0b4fd435bea1c2a137ec32075827fda5019 (patch) | |
tree | d1886d0a88a810e90885ae4524f73cf36e397891 /modules/lua/commands.lua | |
parent | d5b81d4eb35f65d6fb8779afbbc553677f47eefe (diff) | |
download | textadept-13d1c0b4fd435bea1c2a137ec32075827fda5019.tar.gz textadept-13d1c0b4fd435bea1c2a137ec32075827fda5019.zip |
Changes to Lua module.
Added syntax checking for file saving.
Changed autocomplete of 'end' to take advantage of key propagation; Pressing
Shift+Return is no longer necessary; Return is used.
Diffstat (limited to 'modules/lua/commands.lua')
-rw-r--r-- | modules/lua/commands.lua | 41 |
1 files changed, 30 insertions, 11 deletions
diff --git a/modules/lua/commands.lua b/modules/lua/commands.lua index c6a65bcb..be33337b 100644 --- a/modules/lua/commands.lua +++ b/modules/lua/commands.lua @@ -92,23 +92,23 @@ local control_structure_patterns = { -- @see control_structure_patterns function try_to_autocomplete_end() local buffer = buffer - buffer:begin_undo_action() - buffer:line_end() - buffer:new_line() local line_num = buffer:line_from_position(buffer.current_pos) - local line = buffer:get_line(line_num - 1) + local line = buffer:get_line(line_num) for _, patt in ipairs(control_structure_patterns) do if line:find(patt) then - local indent = buffer.line_indentation[line_num - 1] - buffer:add_text(patt:find('repeat') and '\nuntil' or '\nend') - buffer.line_indentation[line_num + 1] = indent - buffer.line_indentation[line_num] = indent + buffer.indent + local indent = buffer.line_indentation[line_num] + buffer:begin_undo_action() + buffer:new_line() + buffer:new_line() + buffer:add_text(patt:find('repeat') and 'until' or 'end') + buffer.line_indentation[line_num + 1] = indent + buffer.indent buffer:line_up() buffer:line_end() - break + buffer:end_undo_action() + return true end end - buffer:end_undo_action() + return false end --- @@ -135,6 +135,25 @@ function goto_required() end end +events.connect('file_before_save', + function() -- show syntax errors as annotations + if buffer:get_lexer() == 'lua' then + buffer:annotation_clear_all() + local text = buffer:get_text() + local _, err = loadstring(text) + if err then + local line, msg = err:match('^.-:(%d+):%s*(.+)$') + line = tonumber(line) + if line then + buffer.annotation_visible = 2 + buffer:annotation_set_text(line - 1, msg) + buffer.annotation_style[line - 1] = 8 -- error style number + buffer:goto_line(line - 1) + end + end + end + end) + --- -- LuaDoc to load API from. -- Keys are Lua table names with LuaDoc file values. @@ -247,7 +266,7 @@ if type(keys) == 'table' then (_HOME..'/modules/lua/init.lua'):iconv('UTF-8', _CHARSET) }, g = { goto_required }, }, - ['s\n'] = { try_to_autocomplete_end }, + ['\n'] = { try_to_autocomplete_end }, [not OSX and 'c\n' or 'esc'] = { function() -- complete API local part = prev_word('[%w_]', buffer.current_pos) local pos = buffer.current_pos - #part - 1 |