Module io

Extends Lua's io package to provide file input/output routines for Textadept.

Converting Filenames to and from UTF-8

If your filesystem does not use UTF-8 encoded filenames, conversions to and from that encoding will be necessary. When opening and saving files through dialogs, Textadept takes care of these conversions for you, 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.
open_file (utf8_filenames) Opens a list of files.
open_recent_file () Prompts the user to open a recently opened file.
save_all () Saves all dirty buffers to their respective files.

Tables

boms List of byte-order marks (BOMs).
recent_files List of recently opened files.
try_encodings List of encodings to try to decode files as after 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 value:

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. If `nil`, 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.
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.

Valid XHTML 1.0!