aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormitchell <70453897+667e-11@users.noreply.github.com>2010-06-10 22:54:51 -0400
committermitchell <70453897+667e-11@users.noreply.github.com>2010-06-10 22:54:51 -0400
commit7af3a62b748ab62596b6815ac97c9cf527513a6c (patch)
tree3b9aa55c6fe0b34bd71cbad9aacca2c90c01a07f
parent13dc7390e0ddfe7f2a1b11d5b50265a74448e44f (diff)
downloadtextadept-7af3a62b748ab62596b6815ac97c9cf527513a6c.tar.gz
textadept-7af3a62b748ab62596b6815ac97c9cf527513a6c.zip
Moved textadept.io into Lua's io table.
Renamed textadept.io.open to textadept.io.open_file to prevent conflicts.
-rw-r--r--core/.buffer.lua25
-rw-r--r--core/events.lua14
-rw-r--r--core/ext/find.lua2
-rw-r--r--core/ext/key_commands.lua16
-rw-r--r--core/ext/menu.lua4
-rw-r--r--core/file_io.lua68
-rw-r--r--doc/manual/7_LuaInterface.md2
-rw-r--r--init.lua2
-rw-r--r--modules/cpp/commands.lua2
-rw-r--r--modules/lua/commands.lua4
-rw-r--r--modules/textadept/run.lua2
-rw-r--r--modules/textadept/session.lua9
12 files changed, 66 insertions, 84 deletions
diff --git a/core/.buffer.lua b/core/.buffer.lua
index aa7cbff6..e76edcf7 100644
--- a/core/.buffer.lua
+++ b/core/.buffer.lua
@@ -349,9 +349,9 @@ function buffer:text_range(start_pos, end_pos)
---
-- Deletes the current buffer.
-- The indexed buffer must be the currently focused one. WARNING: this function
--- should NOT be called via scripts. textadept.io provides a close() function
--- for buffers to prompt for confirmation if necessary; this function does not.
--- Activates the 'buffer_deleted' signal.
+-- should NOT be called via scripts. io provides a close() function for buffers
+-- to prompt for confirmation if necessary; this function does not. Activates
+-- the 'buffer_deleted' signal.
function buffer:delete()
--- Adds a new selection from anchor to caret as the main selection. All other
@@ -935,18 +935,23 @@ function buffer:zoom_in()
--- Makes the displayed text smaller by decreasing the font sizes by 1 point.
function buffer:zoom_out()
----
--- @see textadept.io.reload
+--- Reloads the file in a given buffer.
function buffer:reload()
---
--- @see textadept.io.set_encoding
+-- Sets the encoding for the buffer, converting its contents in the process.
+-- @param encoding The encoding to set. Valid encodings are ones that GTK's
+-- g_convert() function accepts (typically GNU iconv's encodings).
+-- @usage buffer:set_encoding('ASCII')
function buffer:set_encoding()
----
--- @see textadept.io.save
+--- Saves the current buffer to a file.
function buffer:save()
---
--- @see textadept.io.save_as
+-- Saves the current buffer to a file different than its filename property.
+-- @param utf8_filename The new filepath to save the buffer to. Must be UTF-8
+-- encoded.
function buffer:save_as()
---
--- @see textadept.io.close
+-- Closes the current buffer.
+-- If the buffer is dirty, the user is prompted to continue. The buffer is not
+-- saved automatically. It must be done manually.
function buffer:close()
diff --git a/core/events.lua b/core/events.lua
index 302e6fda..0ef56b58 100644
--- a/core/events.lua
+++ b/core/events.lua
@@ -307,7 +307,7 @@ add_handler('uri_dropped',
if WIN32 then utf8_uri = utf8_uri:sub(2, -1) end -- ignore leading '/'
local uri = textadept.iconv(utf8_uri, _CHARSET, 'UTF-8')
if lfs.attributes(uri).mode ~= 'directory' then
- textadept.io.open(utf8_uri)
+ io.open_file(utf8_uri)
end
end
end
@@ -339,17 +339,7 @@ add_handler('margin_click',
buffer:toggle_fold(line)
end)
-add_handler('buffer_new',
- function() -- set additional buffer functions
- local buffer = buffer
- buffer.reload = textadept.io.reload
- buffer.set_encoding = textadept.io.set_encoding
- buffer.save = textadept.io.save
- buffer.save_as = textadept.io.save_as
- buffer.close = textadept.io.close
- buffer.encoding = 'UTF-8'
- set_title(buffer)
- end)
+add_handler('buffer_new', function() set_title(buffer) end)
add_handler('buffer_before_switch',
function() -- save buffer properties
diff --git a/core/ext/find.lua b/core/ext/find.lua
index d1686c9b..f8cf27c8 100644
--- a/core/ext/find.lua
+++ b/core/ext/find.lua
@@ -320,7 +320,7 @@ local function goto_file(pos, line_num)
end
end
end
- textadept.io.open(file)
+ io.open_file(file)
buffer:ensure_visible_enforce_policy(file_line_num - 1)
buffer:goto_line(file_line_num - 1)
end
diff --git a/core/ext/key_commands.lua b/core/ext/key_commands.lua
index 05543b4d..e0b9ae3a 100644
--- a/core/ext/key_commands.lua
+++ b/core/ext/key_commands.lua
@@ -136,12 +136,12 @@ if not MAC then
-- File
local m_session = _m.textadept.session
keys.cn = { t.new_buffer }
- keys.co = { t.io.open }
+ keys.co = { io.open_file }
-- TODO: { 'reload', b }
keys.cs = { 'save', b }
keys.cS = { 'save_as', b }
keys.cw = { 'close', b }
- keys.cW = { t.io.close_all }
+ keys.cW = { io.close_all }
-- TODO: { m_session.load } after prompting with open dialog
-- TODO: { m_session.save } after prompting with save dialog
keys.aq = { t.quit }
@@ -258,13 +258,13 @@ if not MAC then
local RECENT_FILES = 1
t.events.add_handler('user_list_selection',
function(type, text)
- if type == RECENT_FILES then t.io.open(text) end
+ if type == RECENT_FILES then io.open_file(text) end
end)
keys.ao = {
function()
local buffer = buffer
local files = {}
- for _, filename in ipairs(t.io.recent_files) do
+ for _, filename in ipairs(io.recent_files) do
table.insert(files, 1, filename)
end
local sep = buffer.auto_c_separator
@@ -293,12 +293,12 @@ else
-- File
local m_session = _m.textadept.session
keys.an = { t.new_buffer }
- keys.ao = { t.io.open }
+ keys.ao = { io.open_file }
-- TODO: { 'reload', b }
keys.as = { 'save', b }
keys.aS = { 'save_as', b }
keys.aw = { 'close', b }
- keys.aW = { t.io.close_all }
+ keys.aW = { io.close_all }
-- TODO: { m_session.load } after prompting with open dialog
-- TODO: { m_session.save } after prompting with save dialog
keys.aq = { t.quit }
@@ -420,13 +420,13 @@ else
local RECENT_FILES = 1
t.events.add_handler('user_list_selection',
function(type, text)
- if type == RECENT_FILES then t.io.open(text) end
+ if type == RECENT_FILES then io.open_file(text) end
end)
keys.co = {
function()
local buffer = buffer
local files = {}
- for _, filename in ipairs(t.io.recent_files) do
+ for _, filename in ipairs(io.recent_files) do
table.insert(files, 1, filename)
end
local sep = buffer.auto_c_separator
diff --git a/core/ext/menu.lua b/core/ext/menu.lua
index 9c71383e..98a2a8c3 100644
--- a/core/ext/menu.lua
+++ b/core/ext/menu.lua
@@ -327,12 +327,12 @@ end
local actions = {
-- File
[ID.NEW] = { t.new_buffer },
- [ID.OPEN] = { t.io.open },
+ [ID.OPEN] = { io.open_file },
[ID.RELOAD] = { 'reload', b },
[ID.SAVE] = { 'save', b },
[ID.SAVEAS] = { 'save_as', b },
[ID.CLOSE] = { 'close', b },
- [ID.CLOSE_ALL] = { t.io.close_all },
+ [ID.CLOSE_ALL] = { io.close_all },
[ID.LOAD_SESSION] = {
function()
local utf8_filename =
diff --git a/core/file_io.lua b/core/file_io.lua
index 60307a06..64160417 100644
--- a/core/file_io.lua
+++ b/core/file_io.lua
@@ -4,8 +4,8 @@ local textadept = _G.textadept
local locale = _G.locale
---
--- Provides file input/output routines for Textadept.
-module('textadept.io', package.seeall)
+-- Extends Lua's io package to provide file input/output routines for Textadept.
+module('io', package.seeall)
-- Markdown:
-- ## Overview
@@ -186,8 +186,8 @@ end
-- @param utf8_filenames A '\n' separated list of filenames to open. If none
-- specified, the user is prompted to open files from a dialog. These paths
-- must be encoded in UTF-8.
--- @usage textadept.io.open(utf8_encoded_filename)
-function open(utf8_filenames)
+-- @usage io.open_file(utf8_encoded_filename)
+function open_file(utf8_filenames)
utf8_filenames =
utf8_filenames or
textadept.dialog('fileselect',
@@ -198,12 +198,8 @@ function open(utf8_filenames)
for filename in utf8_filenames:gmatch('[^\n]+') do open_helper(filename) end
end
----
--- Reloads the file in a given buffer.
--- @param buffer The buffer to reload. This must be the currently focused
--- buffer.
--- @usage buffer:reload()
-function reload(buffer)
+-- LuaDoc is in core/.buffer.lua.
+local function reload(buffer)
textadept.check_focused_buffer(buffer)
if not buffer.filename then return end
local pos = buffer.current_pos
@@ -224,14 +220,8 @@ function reload(buffer)
buffer.modification_time = lfs.attributes(filename).modification
end
----
--- Sets the encoding for the buffer, converting its contents in the process.
--- @param buffer The buffer to set the encoding for. It must be the currently
--- focused buffer.
--- @param encoding The encoding to set. Valid encodings are ones that GTK's
--- g_convert() function accepts (typically GNU iconv's encodings).
--- @usage buffer:set_encoding('ASCII')
-function set_encoding(buffer, encoding)
+-- LuaDoc is in core/.buffer.lua.
+local function set_encoding(buffer, encoding)
textadept.check_focused_buffer(buffer)
if not buffer.encoding then error('Cannot change binary file encoding') end
local iconv = textadept.iconv
@@ -248,12 +238,8 @@ function set_encoding(buffer, encoding)
buffer.encoding, buffer.encoding_bom = encoding, boms[encoding]
end
----
--- Saves the current buffer to a file.
--- @param buffer The buffer to save. Its 'filename' property is used as the
--- path of the file to save to. This must be the currently focused buffer.
--- @usage buffer:save()
-function save(buffer)
+-- LuaDoc is in core/.buffer.lua.
+local function save(buffer)
textadept.check_focused_buffer(buffer)
if not buffer.filename then return save_as(buffer) end
textadept.events.handle('file_before_save', buffer.filename)
@@ -275,13 +261,8 @@ function save(buffer)
if buffer._type then buffer._type = nil end
end
----
--- Saves the current buffer to a file different than its filename property.
--- @param buffer The buffer to save. This must be the currently focused buffer.
--- @param utf8_filename The new filepath to save the buffer to. Must be UTF-8
--- encoded.
--- @usage buffer:save_as(filename)
-function save_as(buffer, utf8_filename)
+-- LuaDoc is in core/.buffer.lua.
+local function save_as(buffer, utf8_filename)
textadept.check_focused_buffer(buffer)
if not utf8_filename then
utf8_filename =
@@ -302,7 +283,7 @@ end
---
-- Saves all dirty buffers to their respective files.
--- @usage textadept.io.save_all()
+-- @usage io.save_all()
function save_all()
local current_buffer = buffer
local current_index
@@ -314,14 +295,8 @@ function save_all()
view:goto_buffer(current_index)
end
----
--- Closes the current buffer.
--- If the buffer is dirty, the user is prompted to continue. The buffer is not
--- saved automatically. It must be done manually.
--- @param buffer The buffer to close. This must be the currently focused
--- buffer.
--- @usage buffer:close()
-function close(buffer)
+-- LuaDoc is in core/.buffer.lua.
+local function close(buffer)
textadept.check_focused_buffer(buffer)
if buffer.dirty and
textadept.dialog('msgbox',
@@ -343,7 +318,7 @@ end
-- Closes all open buffers.
-- If any buffer is dirty, the user is prompted to continue. No buffers are
-- saved automatically. They must be saved manually.
--- @usage textadept.io.close_all()
+-- @usage io.close_all()
-- @return true if user did not cancel.
function close_all()
while #textadept.buffers > 1 do
@@ -379,6 +354,17 @@ end
textadept.events.add_handler('buffer_after_switch', update_modified_file)
textadept.events.add_handler('view_after_switch', update_modified_file)
+textadept.events.add_handler('buffer_new',
+ function() -- set additional buffer functions
+ local buffer = buffer
+ buffer.reload = reload
+ buffer.set_encoding = set_encoding
+ buffer.save = save
+ buffer.save_as = save_as
+ buffer.close = close
+ buffer.encoding = 'UTF-8'
+ end)
+
textadept.events.add_handler('file_opened',
function(utf8_filename) -- close initial 'Untitled' buffer
local b = textadept.buffers[1]
diff --git a/doc/manual/7_LuaInterface.md b/doc/manual/7_LuaInterface.md
index 3756f615..f99691e4 100644
--- a/doc/manual/7_LuaInterface.md
+++ b/doc/manual/7_LuaInterface.md
@@ -29,5 +29,5 @@ Textadept's Lua state:
[package_path]: http://www.lua.org/manual/5.1/manual.html#pdf-package.path
[theme]: 6_Startup.html
-[file_io]: ../modules/textadept.io.html
+[file_io]: ../modules/io.html
[textadept_reset]: ../modules/textadept.html#reset
diff --git a/init.lua b/init.lua
index 8d60b562..18cfb431 100644
--- a/init.lua
+++ b/init.lua
@@ -53,6 +53,6 @@ if not RESETTING then
end
-- open files
- for _, filename in ipairs(arg) do textadept.io.open(filename) end
+ for _, filename in ipairs(arg) do io.open_file(filename) end
end
end
diff --git a/modules/cpp/commands.lua b/modules/cpp/commands.lua
index 263b6819..65f67ff4 100644
--- a/modules/cpp/commands.lua
+++ b/modules/cpp/commands.lua
@@ -26,7 +26,7 @@ local keys = _G.keys
if type(keys) == 'table' then
keys.cpp = {
al = {
- m = { textadept.io.open,
+ m = { io.open_file,
textadept.iconv(_HOME..'/modules/cpp/init.lua',
'UTF-8', _CHARSET) },
},
diff --git a/modules/lua/commands.lua b/modules/lua/commands.lua
index ac68ab84..5f544ae0 100644
--- a/modules/lua/commands.lua
+++ b/modules/lua/commands.lua
@@ -69,7 +69,7 @@ function goto_required()
for path in package.path:gmatch('[^;]+') do
path = path:gsub('?', file)
if lfs.attributes(path) then
- textadept.io.open(textadept.iconv(path, 'UTF-8', _CHARSET))
+ io.open_file(textadept.iconv(path, 'UTF-8', _CHARSET))
break
end
end
@@ -80,7 +80,7 @@ local keys = _G.keys
if type(keys) == 'table' then
keys.lua = {
al = {
- m = { textadept.io.open,
+ m = { io.open_file,
textadept.iconv(_HOME..'/modules/lua/init.lua',
'UTF-8', _CHARSET) },
g = { goto_required },
diff --git a/modules/textadept/run.lua b/modules/textadept/run.lua
index e03665cb..c14e8e2d 100644
--- a/modules/textadept/run.lua
+++ b/modules/textadept/run.lua
@@ -117,7 +117,7 @@ function goto_error(pos, line_num)
local utf8_filename = captures[error_detail.filename]
local filename = textadept.iconv(utf8_filename, _CHARSET, 'UTF-8')
if lfs.attributes(filename) then
- textadept.io.open(utf8_filename)
+ io.open_file(utf8_filename)
_m.textadept.editing.goto_line(captures[error_detail.line])
local msg = captures[error_detail.message]
if msg then buffer:call_tip_show(buffer.current_pos, msg) end
diff --git a/modules/textadept/session.lua b/modules/textadept/session.lua
index 20b0c831..30d9e823 100644
--- a/modules/textadept/session.lua
+++ b/modules/textadept/session.lua
@@ -32,9 +32,9 @@ local lfs = require 'lfs'
-- @usage _m.textadept.session.load(filename)
function load(filename)
local not_found = {}
- local f = io.open(filename or DEFAULT_SESSION, 'rb')
+ local f = io.open_file(filename or DEFAULT_SESSION, 'rb')
if not f then
- if not textadept.io.close_all() then return false end
+ if not io.close_all() then return false end
end
if not f then return false end
local current_view, splits = 1, { [0] = {} }
@@ -44,7 +44,7 @@ function load(filename)
line:match('^buffer: (%d+) (%d+) (%d+) (.+)$')
if not filename:find('^%[.+%]$') then
if lfs.attributes(filename) then
- textadept.io.open(filename)
+ io.open_file(filename)
else
not_found[#not_found + 1] = filename
end
@@ -160,7 +160,8 @@ function save(filename)
local size = textadept.size
session[#session + 1] = ("size: %d %d"):format(size[1], size[2])
-- Write the session.
- local f = io.open(filename or textadept.session_file or DEFAULT_SESSION, 'wb')
+ local f =
+ io.open_file(filename or textadept.session_file or DEFAULT_SESSION, 'wb')
if f then
f:write(table.concat(session, '\n'))
f:close()