Textadept
- Home |
- Download |
- Lua API |
- Source |
- Language Modules |
- Stats |
- Wiki |
- Mailing List
Contents
io
Extends Lua’s io package to provide file input/output routines for Textadept.
Working with UTF-8
If your filesystem does not use UTF-8 encoded filenames, conversions to and
from that encoding are necessary since all of Textadept’s internal strings
are UTF-8 encoded. When opening and saving files through dialogs, these
conversions are performed autmatically, but if you need to do them manually,
use string.iconv()
along with _CHARSET
, your filesystem’s detected
encoding.
Example:
events.connect(events.FILE_OPENED, function(utf8_filename)
local filename = utf8_filename:iconv(_CHARSET, 'UTF-8')
local f = io.open(filename, 'rb')
-- process file
f:close()
end)
File Events
_G.events.FILE_OPENED
Called when a file is opened in a new buffer. Arguments:filename
: The filename encoded in UTF-8.
_G.events.FILE_BEFORE_SAVE
Called right before a file is saved to disk. Arguments:filename
: The filename encoded in UTF-8.
_G.events.FILE_AFTER_SAVE
Called right after a file is saved to disk. Arguments:filename
: The filename encoded in UTF-8.
_G.events.FILE_SAVED_AS
Called when a file is saved under a different filename. Arguments:filename
: The filename encoded in UTF-8.
Functions
close_all
()
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:
io.close_all()
Return:
true
if user did not cancel.
open_file
(utf8_filenames)
Opens a list of files.
Parameters:
utf8_filenames
: A\n
separated list of UTF-8-encoded filenames to open. Ifnil
, the user is prompted with a fileselect dialog.
Usage:
io.open_file(utf8_encoded_filename)
open_recent_file
()
Prompts the user to open a recently opened file.
See also:
save_all
()
Saves all dirty buffers to their respective files.
Usage:
io.save_all()
Tables
boms
List of byte-order marks (BOMs).
recent_files
List of recently opened files. The most recent are towards the top.
try_encodings
List of encodings to try to decode files as after UTF-8.