diff options
-rw-r--r-- | core/events.lua | 2 | ||||
-rw-r--r-- | core/file_io.lua | 10 | ||||
-rw-r--r-- | core/locale.lua | 2 | ||||
-rw-r--r-- | modules/textadept/command_entry.lua | 2 | ||||
-rw-r--r-- | modules/textadept/file_types.lua | 2 | ||||
-rw-r--r-- | modules/textadept/find.lua | 2 | ||||
-rw-r--r-- | modules/textadept/keys.lua | 4 | ||||
-rw-r--r-- | modules/textadept/menu.lua | 5 |
8 files changed, 13 insertions, 16 deletions
diff --git a/core/events.lua b/core/events.lua index 127f44ed..6e473212 100644 --- a/core/events.lua +++ b/core/events.lua @@ -302,7 +302,7 @@ local error_emitted = false -- @usage events.emit('my_event', 'my message') -- @name emit function M.emit(event, ...) - if not event then error(_L['Undefined event name']) end + assert(event, _L['Undefined event name']) local h = handlers[event] if not h then return end local pcall, table_unpack, type = pcall, table.unpack, type diff --git a/core/file_io.lua b/core/file_io.lua index 257eb5ef..35ca5c03 100644 --- a/core/file_io.lua +++ b/core/file_io.lua @@ -148,7 +148,7 @@ function io.open_file(filenames) local ok, conv = pcall(string.iconv, text, 'UTF-8', io.encodings[i]) if ok then buffer.encoding, text = io.encodings[i], conv break end end - if not buffer.encoding then error(_L['Encoding conversion failed.']) end + assert(buffer.encoding, _L['Encoding conversion failed.']) end buffer.code_page = buffer.encoding and buffer.CP_UTF8 or 0 -- Detect EOL mode. @@ -182,7 +182,7 @@ function io.reload_file() if not buffer.filename then return end local pos, first_visible_line = buffer.current_pos, buffer.first_visible_line local f, err = io.open(buffer.filename, 'rb') - if not f then error(err) end + assert(f, err) local text = f:read('*all') f:close() local encoding, encoding_bom = buffer.encoding, buffer.encoding_bom @@ -203,9 +203,7 @@ end -- @usage io.set_buffer_encoding('ASCII') -- @name set_buffer_encoding function io.set_buffer_encoding(encoding) - if not buffer.encoding then - error(_L['Cannot change binary file encoding']) - end + assert(buffer.encoding, _L['Cannot change binary file encoding']) local pos, first_visible_line = buffer.current_pos, buffer.first_visible_line local text = buffer:get_text() text = text:iconv(buffer.encoding, 'UTF-8') @@ -232,7 +230,7 @@ function io.save_file() text = (buffer.encoding_bom or '')..text:iconv(buffer.encoding, 'UTF-8') end local f, err = io.open(buffer.filename, 'wb') - if not f then error(err) end + assert(f, err) f:write(text) f:close() buffer:set_save_point() diff --git a/core/locale.lua b/core/locale.lua index fb3f0742..51ff68a6 100644 --- a/core/locale.lua +++ b/core/locale.lua @@ -15,7 +15,7 @@ if not f then if lang then f = io.open(_HOME..'/core/locales/locale.'..lang..'.conf') end end if not f then f = io.open(_HOME..'/core/locale.conf', 'rb') end -if not f then error('"core/locale.conf" not found.') end +assert(f, '"core/locale.conf" not found.') for line in f:lines() do if not line:find('^%s*%%') then local id, str = line:match('^(.-)%s*=%s*(.+)$') diff --git a/modules/textadept/command_entry.lua b/modules/textadept/command_entry.lua index 6d2b58dc..0302aa67 100644 --- a/modules/textadept/command_entry.lua +++ b/modules/textadept/command_entry.lua @@ -101,7 +101,7 @@ local env = setmetatable({}, { function M.execute_lua(code) if code:sub(1, 1) == '=' then code = 'return '..code:sub(2) end local f, err = load(code, nil, 'bt', env) - if err then error(err) end + assert(f, err) local result = f() if result ~= nil then ui.print(result) end events.emit(events.UPDATE_UI) diff --git a/modules/textadept/file_types.lua b/modules/textadept/file_types.lua index fe0c8adc..df5918ba 100644 --- a/modules/textadept/file_types.lua +++ b/modules/textadept/file_types.lua @@ -99,7 +99,7 @@ local function set_lexer_functions() buffer.get_lexer, buffer.set_lexer = get_lexer, set_lexer buffer.style_name = setmetatable({}, { __index = function(t, style_num) -- LuaDoc is in core/.buffer.luadoc - if style_num < 0 or style_num > 255 then error('0 <= style_num < 256') end + assert(style_num >= 0 and style_num <= 255, '0 <= style_num < 256') return buffer:private_lexer_call(style_num) end, __newindex = function() error('read-only property') end diff --git a/modules/textadept/find.lua b/modules/textadept/find.lua index 3d82ad1b..be6d767c 100644 --- a/modules/textadept/find.lua +++ b/modules/textadept/find.lua @@ -271,7 +271,7 @@ local function replace(rtext) local ok, rtext = pcall(rtext.gsub, rtext, '%%(%b())', function(code) code = code:gsub('[\a\b\f\n\r\t\v\\]', escapes) local ok, result = pcall(load('return '..code)) - if not ok then error(result) end + assert(ok, result) return result:gsub('\\[abfnrtv\\]', escapes) end) if ok then diff --git a/modules/textadept/keys.lua b/modules/textadept/keys.lua index 7a341977..dcf4ea87 100644 --- a/modules/textadept/keys.lua +++ b/modules/textadept/keys.lua @@ -276,12 +276,12 @@ M.utils = { open_webpage = function(url) if WIN32 then local p = io.popen(string.format('start "" "%s"', url)) - if not p then error(_L['Error loading webpage:']..url) end + assert(p, _L['Error loading webpage:']..url) p:close() else local _, _, code = os.execute(string.format(OSX and 'open "file://%s"' or 'xdg-open "%s" &', url)) - if code ~= 0 then error(_L['Error loading webpage:']..url) end + assert(code == 0, _L['Error loading webpage:']..url) end end, cut_to_eol = function() diff --git a/modules/textadept/menu.lua b/modules/textadept/menu.lua index ea4b9db1..3a0348ab 100644 --- a/modules/textadept/menu.lua +++ b/modules/textadept/menu.lua @@ -379,9 +379,8 @@ end events.connect(events.MENU_CLICKED, function(menu_id) local actions = menu_id < 1000 and menu_actions or contextmenu_actions local action = actions[menu_id < 1000 and menu_id or menu_id - 1000] - if type(action) ~= 'function' and type(action) ~= 'table' then - error(_L['Unknown command:']..' '..tostring(action)) - end + assert(type(action) == 'function' or type(action) == 'table', + _L['Unknown command:']..' '..tostring(action)) keys.run_command(action, type(action)) end) |