Module io

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

Overview

Textadept represents all characters and strings internally as UTF-8. You will not notice any difference for working with files containing ASCII text since UTF-8 is compatible with it. Problems may arise for files with more exotic encodings that may not be detected properly, if at all. When opening a file, the list of encodings tried before throwing a conversion failed error is in core/file_io.lua's try_encodings. Textadept respects the detected encoding when saving the file.

New files are saved as UTF-8 by default.

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('file_opened',
  function(utf8_filename)
    local filename = utf8_filename:iconv(_CHARSET, 'UTF-8')
    local f = io.open(filename, 'rb')
    -- process file
    f:close()
  end)

Events

The following is a list of all File I/O events generated in event_name(arguments) format:

  • file_opened (filename)
    Called when a file has been opened in a new buffer.
    • filename: the filename encoded in UTF-8.
  • file_before_save (filename)
    Called right before a file is saved to disk.
    • filename: the filename encoded in UTF-8.
  • file_saved_as (filename)
    Called when a file is saved under another filename.
    • filename: the other filename encoded in UTF-8.

Functions

close_all () Closes all open buffers.
open_file (utf8_filenames) Opens a list of files.
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 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:

io.open_file(utf8_encoded_filename)
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.
try_encodings
List of encodings to try to decode files as after UTF-8.

Valid XHTML 1.0!