aboutsummaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authormitchell <70453897+667e-11@users.noreply.github.com>2014-03-01 12:09:41 -0500
committermitchell <70453897+667e-11@users.noreply.github.com>2014-03-01 12:09:41 -0500
commit9a3685348d1205cbffeb784df296d55216f512aa (patch)
tree7be097113b7aa54dbbc99b651bb2d355dcbcec40 /core
parentb3be88aed1e8196c5b0490a8e22c5839fdd12e18 (diff)
downloadtextadept-9a3685348d1205cbffeb784df296d55216f512aa.tar.gz
textadept-9a3685348d1205cbffeb784df296d55216f512aa.zip
Use `assert(...)` as a shortcut for `if not ... then error() end`.
Diffstat (limited to 'core')
-rw-r--r--core/events.lua2
-rw-r--r--core/file_io.lua10
-rw-r--r--core/locale.lua2
3 files changed, 6 insertions, 8 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*(.+)$')