Contents

io

Extends Lua’s io library with Textadept functions for working with files.

Working with UTF-8

If your filesystem does not use UTF-8-encoded filenames (e.g. Windows), 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 automatically, but if you need to do them manually, use string.iconv() along with _CHARSET, your filesystem’s detected encoding. An example is

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)

Fields


SNAPOPEN_MAX (number)

The maximum number of files to list in the snapopen dialog. The default value is 1000.


_G.events.FILE_AFTER_SAVE (string)

Emitted right after saving a file to disk. Emitted by buffer:save(). Arguments:


_G.events.FILE_BEFORE_SAVE (string)

Emitted right before saving a file to disk. Emitted by buffer:save(). Arguments:


_G.events.FILE_OPENED (string)

Emitted when opening a file in a new buffer. Emitted by open_file(). Arguments:


_G.events.FILE_SAVED_AS (string)

Emitted after saving a file under a different filename. Emitted by buffer:save_as(). Arguments:


Functions


close_all()

Closes all open buffers, prompting the user to continue with unsaved buffers, and returning true if the user did not cancel. No buffers are saved automatically. They must be saved manually.

Return:

See also:


open_file(utf8_filenames)

Opens utf8_filenames, a “\n” delimited string of UTF-8-encoded filenames, or user-selected files. Emits a FILE_OPENED event.

Parameters:

See also:


open_recent_file()

Prompts the user to open a recently opened file.

See also:


save_all()

Saves all unsaved buffers to their respective files.

See also:


snapopen(utf8_paths, filter, exclude_FILTER, …)

Quickly open files from utf8_paths, a “\n” delimited string of UTF-8-encoded directory paths, using a filtered list dialog. Files shown in the dialog do not match any pattern in string or table filter, and, unless exclude_FILTER is true, lfs.FILTER as well. A filter table contains Lua patterns that match filenames to exclude, with patterns matching folders to exclude listed in a folders sub-table. Patterns starting with ‘!’ exclude files and folders that do not match the pattern that follows. Use a table of raw file extensions assigned to an extensions key for fast filtering by extension. All strings must be encoded in _G._CHARSET, not UTF-8. The number of files in the list is capped at SNAPOPEN_MAX.

Parameters:

Usage:

See also:


Tables


boms

List of byte-order marks (BOMs) for identifying unicode file types.


encodings

List of encodings to try to decode files as. You should add to this list if you get a “Conversion failed” error when trying to open a file whose encoding is not recognized. Valid encodings are GNU iconv’s encodings and include:

Usage:


recent_files

List of recently opened files, the most recent being towards the top.