Module textredux.fs
textredux.fs provides a text based file browser and file system related functions for Textadept.
It features traditional directory browsing, snapopen functionality, completely keyboard driven interaction, and provides powerful narrow to search functionality.
Some tips on using the file browser
Switching between traditional browsing and snapopen
As said above the file browser allows both traditional browsing as well as
snapopen functionality. But it also allows you to seamlessly switch between
the two modes (by default, Ctrl + S
is assigned for this).
Quickly moving up one directory level
In traditional browsing mode, you can always select ..
to move up one
directory level. But a quicker way of doing the same is to press <backspace>
when you have an empty search. This also works when in snapopen mode.
Opening a sub directory in snapopen mode
In contrast with Textadept snapopen, you will in snapopen mode also see sub directories in the listing. This is by design - you can select a sub directory to snapopen that directory.
Changing the styles used for different file types
If you don't like the default styles (colors, etc.) used by the file browser,
you can easily change these by customizing any of the reduxstyle_<foo>
entries
using the Textredux style module. As an example, to make directory entries
underlined you would do something like the following:
textredux.core.style.fs_directory = {underlined = true}
Please see the documentation for the Textredux style module for instructions on how to define styles.
Functions
select_file (on_selection, start_directory, filter, depth, max_files) | Opens a file browser and lets the user choose a file. |
save_buffer_as () | Saves the current buffer under a new name. |
save_buffer () | Saves the current buffer. |
open_file (start_directory) | Opens the specified directory for browsing. |
snapopen (directory, filter, exclude_FILTER, depth) | Opens a list of files in the specified directory, according to the given parameters. |
Fields
reduxstyle.fs_directory | The style used for directory entries. |
reduxstyle.fs_file | The style used for ordinary file entries. |
reduxstyle.fs_link | The style used for link entries. |
reduxstyle.fs_socket | The style used for socket entries. |
reduxstyle.fs_pipe | The style used for pipe entries. |
reduxstyle.fs_device | The style used for pipe entries. |
Functions
- select_file (on_selection, start_directory, filter, depth, max_files)
-
Opens a file browser and lets the user choose a file.
Parameters:
- on_selection
The function to invoke when the user has choosen a file.
The function will be called with following parameters:
path
: The full path of the choosen file (UTF-8 encoded).exists
: A boolean indicating whether the file exists or not.list
: A reference to the Textredux list used by browser.
The list will not be closed automatically, so close it explicitly using
list:close()
if desired. - start_directory The initial directory to open, in UTF-8 encoding. If nil, the initial directory is determined automatically (preferred choice is to open the directory containing the current file).
- filter The filter to apply, if any. The structure and semantics are the same as for Textadept's snapopen.
- depth The number of directory levels to display in the list. Defaults to 1 if not specified, which results in a "normal" directory listing.
- max_files The maximum number of files to scan and display in the list. Defaults to 10000 if not specified.
- on_selection
The function to invoke when the user has choosen a file.
The function will be called with following parameters:
- save_buffer_as ()
- Saves the current buffer under a new name. Open a browser and lets the user select a name.
- save_buffer ()
- Saves the current buffer. Prompts the users for a filename if it's a new, previously unsaved buffer.
- open_file (start_directory)
-
Opens the specified directory for browsing.
Parameters:
- start_directory The directory to open, in UTF-8 encoding
- snapopen (directory, filter, exclude_FILTER, depth)
-
Opens a list of files in the specified directory, according to the given parameters. This works similarily to Textadept snapopen. The main differences are:
it does not support opening multiple paths at once
filter can contain functions as well as patterns (and can be a function as well). Functions will be passed a file object which is the same as the return from lfs.attributes, with the following additions:
rel_path
: The path of the file relative to the currently displayed directory.hidden
: Whether the path denotes a hidden file.
Parameters:
- directory The directory to open, in UTF-8 encoding.
- filter The filter to apply. The format and semantics are the same as for Textadept.
- exclude_FILTER Same as for Textadept: unless if not true then snapopen.FILTER will be automatically added to the filter. to snapopen.FILTER if not specified.
- depth The number of directory levels to scan. Defaults to DEFAULT_DEPTH if not specified.
Fields
- reduxstyle.fs_directory
- The style used for directory entries.
- reduxstyle.fs_file
- The style used for ordinary file entries.
- reduxstyle.fs_link
- The style used for link entries.
- reduxstyle.fs_socket
- The style used for socket entries.
- reduxstyle.fs_pipe
- The style used for pipe entries.
- reduxstyle.fs_device
- The style used for pipe entries.