Interact with the User Interface using the `ui` module
defaultui module provides utilities for interacting with Textadept's user interface, including managing views, windows, menus, and output buffers.repository·default·Indexed 21 days ago
https://github.com/orbitalquark/textadeptA fast, minimalist, and highly extensible cross-platform text editor for programmers built with C, C++, and Lua. The documentation covers installation across Windows, macOS, and Linux, the use of optional modules like LSP and spellcheck, and a comprehensive Lua API for managing buffers, views, key bindings, and custom command line arguments.
ui module provides utilities for interacting with Textadept's user interface, including managing views, windows, menus, and output buffers.Textadept does not have an explicit "Open Project" command. Instead, a project is defined as a parent directory containing a recognized version control directory (Git, Mercurial, SVN, Bazaar, or Fossil).
Textadept determines the current project context by:
You can set a default project by passing a directory as a command-line argument when starting Textadept, or by changing the working directory within the editor using the Lua command lfs.chdir('/path/to/folder').
Textadept is an event-driven application where nearly all features (syntax highlighting, file I/O, search/replace) are implemented in Lua. It includes an internal copy of Lua 5.4.
Ctrl+O triggers the io.open_file() function via the events.KEYPRESS event.~/.textadept/init.lua file is the primary location for custom scripting. Use it to define custom key bindings, menu items, and event handlers.buffer contents or extend the textadept.menu.menubar.events.FILE_SAVED to trigger asynchronous processes (e.g., linters via os.spawn) or events.BUFFER_BEFORE_SWITCH to implement auto-save.ui.find or add items to the right-click context menu by appending to textadept.menu.context_menu.args.register().The view.selection_layer property determines how selections are rendered relative to the text.
Available modes:
view.LAYER_BASE: Selections are drawn opaquely on the background.view.LAYER_UNDER_TEXT: Selections are drawn translucently under the text.view.LAYER_OVER_TEXT: Selections are drawn translucently over the text.Default value is view.LAYER_BASE.
Textadept uses a target range—a user-defined region of text—to allow certain functions to operate without altering the current selection or scrolling the view.
buffer:set_target_range(start_pos, end_pos): Manually defines the target range.buffer:target_from_selection(): Sets the target range to be the current main selection.buffer:replace_target(text): Replaces the text in the target range with the provided string. This returns the length of the replacement text. Calling this with an empty string deletes the target range.buffer:replace_sel(text): Replaces the current selection and scrolls the caret into view.Note: buffer:replace_target is preferred when you want to modify text without affecting the user's current selection or view position.
Textadept identifies programming languages to apply syntax highlighting using a three-step fallback mechanism:
lexer.detect_patterns.lexer.detect_extensions.You can manually change a buffer's lexer using Ctrl+Alt+L (Windows/Linux/BSD), ^⌘L (macOS), or M-L (terminal).
Placeholder transforms allow you to modify the text of a mirrored or captured placeholder using regex. The syntax is ${n/*regex*/*format*/*options*}.
Supported Format Tokens:
$m or ${m}: The content of the m-th capture (0 is the whole match).${m:/upcase}, ${m:/downcase}, ${m:/capitalize}: Built-in text transformations.${m:?*if*:*else*}: Inserts if if capture m is non-empty, otherwise else.${m:+*if*}: Inserts if if capture m is non-empty, otherwise nothing.${m:*default*}: Inserts default if capture m is empty, otherwise mirrors the content.${m:-*default*}: Inserts default if capture m is empty, otherwise mirrors the content.Options:
g: Global replacement (replace all matches, not just the first).-- Example: Creating an attribute with a getter and setter
-- Uses /./ to match any character and /upcase to transform it
snippets.attr = [[
${1:int} ${2:name};
${1} get${2/./${0:/upcase}/}() { return $2; }
void set${2/./${0:/upcase}/}(${1} ${3:value}) { $2 = $3; }
]]When running Textadept in a terminal, certain GUI features are unavailable due to terminal constraints. Users should be aware of the following limitations:
Shift+Arrow) are recognized, and caret styles (period, line style, width) are unavailable.INDIC_ROUNDBOX and INDIC_STRAIGHTBOX are supported, but they lack translucency and rounded corners.Textadept provides global variables to detect the current environment. This is useful for writing platform-specific or UI-specific logic.
OS: Returns the operating system as one of: 'windows', 'macos', 'linux', or 'bsd'.UI: Returns the user interface type as one of: 'qt', 'gtk', or 'terminal'.if OS == 'windows' then ... end
if UI == 'terminal' then ... endTextadept splits the Scintilla editing component's API into two distinct parts: buffers and views.
view.field or view:function() are often equivalent to buffer.field or buffer:function(). However, a view operation is only equivalent to a buffer operation if the buffer is the one currently contained by that view (buffer == view.buffer).buf:replace_sel('') on a buffer that is not the current one will still modify that buffer's text, even if it isn't visible in the current view.buffer:select_all() on a non-current buffer will modify the selection data in that buffer, but it will not result in a visible selection in the current view.Placeholders allow you to create templates that you can navigate using the Tab key.
$n or ${n}. When the snippet is inserted, the caret starts at $1. Tab moves to $2, and so on.$0 if it exists, otherwise to the end of the snippet.${n:default} to provide a value that can be overwritten.$1) in multiple places. Typing in one will automatically update all others with that index.${n|option1,option2|} to provide a list of selectable items.-- A snippet with tab stops and default values
snippets.lua.fori = [[
for ${1:i} = ${2:1}, $3 do
$0
end]]
-- A snippet with mirrors (HTML tags)
snippets.tag = '<${1:div}>$0</$1>'
-- A snippet with multiple choice
snippets.choice = '${1|foo,bar,baz|}'Key sequences are strings combining modifiers and the character/key.
Modifiers:
'ctrl', 'alt', 'shift'.'ctrl', 'alt' (Option), 'cmd' (Command), 'shift'.'meta'.Key Values:
ctrl+shift+\t for Ctrl+Shift+Tab).keys.KEYSYMS lookup table (e.g., ctrl+right).