aboutsummaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-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
6 files changed, 55 insertions, 74 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]