### Highlight Guide Configuration Source: https://orbitalquark.github.io/textadept/api.html Configure highlighting for indentation guides. ```APIDOC ## `view.highlight_guide` ### Description The indentation guide column number to also highlight when highlighting matching braces, or `0` to stop indentation guide highlighting. ``` -------------------------------- ### Migrated Lexer Example Source: https://orbitalquark.github.io/textadept/api.html The migrated version of the legacy lexer example, showcasing the updated API for tokenization, word matching, and styling. ```lua local lexer = lexer local P, S = lpeg.P, lpeg.S local lex = lexer.new(...) lex:add_rule('keyword', lex:tag(lexer.KEYWORD, lex:word_match(lexer.KEYWORD))) lex:add_rule('custom', lex:tag('custom', 'quux')) lex:add_rule('identifier', lex:tag(lexer.IDENTIFIER, lexer.word)) lex:add_rule('string', lex:tag(lexer.STRING, lexer.range('"'))) lex:add_rule('comment', lex:tag(lexer.COMMENT, lexer.to_eol('#'))) lex:add_rule('number', lex:tag(lexer.NUMBER, lexer.number)) lex:add_rule('operator', lex:tag(lexer.OPERATOR, S('+-*/%^=<>,.()[]{}'))) lex:add_fold_point(lexer.OPERATOR, '{', '}') lex:set_word_list(lexer.KEYWORD, {'foo', 'bar', 'baz'}) return lex ``` -------------------------------- ### Example Legacy Lexer Source: https://orbitalquark.github.io/textadept/api.html A concrete example of a legacy lexer demonstrating various token types like keywords, strings, comments, and operators. ```lua local lexer = require('lexer') local token, word_match = lexer.token, lexer.word_match local P, S = lpeg.P, lpeg.S local lex = lexer.new('legacy') lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1)) lex:add_rule('keyword', token(lexer.KEYWORD, word_match('foo bar baz'))) lex:add_rule('custom', token('custom', 'quux')) lex:add_style('custom', lexer.styles.keyword .. {bold = true}) lex:add_rule('identifier', token(lexer.IDENTIFIER, lexer.word)) lex:add_rule('string', token(lexer.STRING, lexer.range('"'))) lex:add_rule('comment', token(lexer.COMMENT, lexer.to_eol('#'))) lex:add_rule('number', token(lexer.NUMBER, lexer.number)) lex:add_rule('operator', token(lexer.OPERATOR, S('+-*/%^=<>,.()[]{}'))) lex:add_fold_point(lexer.OPERATOR, '{', '}') return lex ``` -------------------------------- ### Indentation Guides Configuration Source: https://orbitalquark.github.io/textadept/api.html Configure the display of indentation guides within the editor. ```APIDOC ## `view.indentation_guides` ### Description Draw indentation guides. Indentation guides are dotted vertical lines that appear within indentation whitespace at each level of indentation. ### Options * `view.IV_NONE`: Do not draw any guides. * `view.IV_REAL`: Draw guides only within indentation whitespace. * `view.IV_LOOKFORWARD`: Draw guides beyond the current line up to the next non-empty line’s indentation level, but with an additional level if the previous non-empty line is a fold point. * `view.IV_LOOKBOTH`: Draw guides beyond the current line up to either the indentation level of the previous or next non-empty line, whichever is greater. ### Default Values The default value is `view.IV_LOOKBOTH` in the GUI version, and `view.IV_NONE` in the terminal version. ``` -------------------------------- ### Configure Textadept via init.lua Source: https://orbitalquark.github.io/textadept/manual.html Example configuration for themes, indentation, key bindings, and language-specific settings in the user initialization file. ```lua -- Adjust the default theme's font and size. if not CURSES then view:set_theme('light', {font = 'Monospace', size = 12}) end -- Always use spaces for indentation. io.detect_indentation = false buffer.use_tabs = false buffer.tab_width = 2 -- Always strip trailing spaces on save, automatically highlight the current -- word, and use C89-style block comments in C code. textadept.editing.strip_trailing_spaces = true textadept.editing.highlight_words = textadept.editing.HIGHLIGHT_CURRENT textadept.editing.comment_string.c = '/*|*/' -- Create a key binding to the "Edit > Preferences" menu item. if not OSX and not CURSES then keys['ctrl+,'] = textadept.menu.menubar['Edit/Preferences'][2] end -- Load an external module and bind a key to it. local lsp = require('lsp') keys['ctrl+f12'] = lsp.goto_declaration -- Recognize .luadoc files as Lua code. lexer.detect_extensions.luadoc = 'lua' -- Change the run commands for Lua and Python textadept.run.run_commands.lua = 'lua5.1 "%f"' textadept.run.run_commands.python = 'python3 "%f"' -- Always use PEP-8 indentation style for Python files, and spaces for YAML files. events.connect(events.LEXER_LOADED, function(name) if name == 'python' or name == 'yaml' then buffer.use_tabs = false buffer.tab_width = 4 end end) ``` -------------------------------- ### Match at Start of Line Source: https://orbitalquark.github.io/textadept/api.html Creates a pattern that matches only at the beginning of a line, optionally allowing for indentation. ```lua local preproc = lex:tag(lexer.PREPROCESSOR, lexer.starts_line(lexer.to_eol('#'))) ``` -------------------------------- ### Open Files and Projects from Command Line Source: https://orbitalquark.github.io/textadept/manual.html Examples of how to open files and projects using Textadept from the command line. Textadept assumes file paths are relative to the current working directory unless an absolute path is provided. ```bash textadept /path/to/file1 ../relative/path/to/file2 ``` ```bash textadept /path/to/project/ relative/path/to/file1 relative/file2 ``` -------------------------------- ### Register Command Line Argument Example Source: https://orbitalquark.github.io/textadept/api.html Illustrates the basic syntax for registering a command-line option with its short and long forms, argument count, callback function, and description. ```lua args.register('-r', '--read-only', 0, function() ... end, 'Read-only mode') ``` -------------------------------- ### Define Custom Build, Test, and Project Run Commands Source: https://orbitalquark.github.io/textadept/manual.html Configure `textadept.run.build_commands`, `textadept.run.test_commands`, and `textadept.run.run_project_commands` for specific project directories. This example sets a 'make' command for building, a 'lua' command for testing, and a function for running project commands. ```lua textadept.run.build_commands['/path/to/project'] = 'make -C src -j4' textadept.run.test_commands['/path/to/project'] = 'lua tests.lua' textadept.run.run_project_commands['/path/to/project'] = function() ... end ``` -------------------------------- ### Run Command Entry Source: https://orbitalquark.github.io/textadept/api.html Opens the command entry with a specified label and callback function. The second example demonstrates spawning a shell process. ```lua ui.command_entry.run('echo:', ui.print) ui.command_entry.run('$', os.spawn, 'bash', 'env', ui.print) -- spawn a process ``` -------------------------------- ### Implement a Vi-like Command Mode Source: https://orbitalquark.github.io/textadept/api.html This example demonstrates creating a key mode named 'command_mode' with vi-like navigation keys and an 'i' key to switch to insert mode. It also includes an event handler to update the status bar and sets the default mode to 'command_mode'. Ensure a mechanism to exit modes is defined to avoid restarting Textadept. ```lua keys.command_mode = { ['h'] = buffer.char_left, ['j'] = buffer.line_up, ['k'] = buffer.line_down, ['l'] = buffer.char_right, ['i'] = function() keys.mode = nil ui.statusbar_text = 'INSERT MODE' end } keys['esc'] = function() keys.mode = 'command_mode' end events.connect(events.UPDATE_UI, function() if keys.mode == 'command_mode' then return end ui.statusbar_text = 'INSERT MODE' end) keys.mode = 'command_mode' -- default mode ``` -------------------------------- ### Compile Textadept with CMake Source: https://orbitalquark.github.io/textadept Standard sequence of commands to configure, build, and install Textadept. Requires CMake 3.22+ and appropriate UI toolkit development libraries. ```bash cmake -S . -B build_dir -D CMAKE_BUILD_TYPE=RelWithDebInfo \ -D CMAKE_INSTALL_PREFIX=build_dir/install cmake --build build_dir -j # compiled binaries are in build_dir/ cmake --install build_dir # self-contained installation is in build_dir/install/ ``` -------------------------------- ### Register Custom Command Line Arguments Source: https://orbitalquark.github.io/textadept/api.html Register custom command-line options to modify Textadept's behavior on startup. This example sets buffers to read-only and hides the menubar. ```lua args.register('-r', '--read-only', 0, function() events.connect(events.FILE_OPENED, function() buffer.read_only = true -- make all opened buffers read-only end) textadept.menu.menubar = nil -- hide the menubar end, "Read-only mode") ``` -------------------------------- ### Find Word Start Position Source: https://orbitalquark.github.io/textadept/api.html Calculates the start position of a word based on the current buffer text and word character definitions. ```lua -- Consider the buffer text "word....word" buffer:word_start_position(3, true) --> 1 buffer:word_start_position(7, true) --> 7 buffer:word_start_position(7, false) --> 5 buffer:word_start_position(9, false) --> 5 buffer:word_start_position(9, true) --> 9 ``` -------------------------------- ### LFS File Filtering Patterns Source: https://orbitalquark.github.io/textadept/api.html Examples of shell-style glob patterns used for filtering files and directories in lfs.walk(). ```lua '*.lua' -- match all Lua files in the top-level directory '**/*.lua' -- match all Lua files in any directory {'**/*.{c,h}', '!build'} -- match all C source files except in the top-level build/ directory {'include/*', 'src/*'} -- match all immediate children of the 'include/' and 'src/' dirs {'include/**', 'src/**'} -- match everything in 'include/' and 'src/', including subdirectories ``` -------------------------------- ### Legacy Lexer Structure Source: https://orbitalquark.github.io/textadept/api.html This is an example of a legacy lexer structure before migration. It includes rules for whitespace, keywords, custom tokens, and fold points. ```lua local lexer = require('lexer') local token, word_match = lexer.token, lexer.word_match local P, S = lpeg.P, lpeg.S local lex = lexer.new('?') -- Whitespace. lex:add_rule('whitespace', token(lexer.WHITESPACE, lexer.space^1)) -- Keywords. lex:add_rule('keyword', token(lexer.KEYWORD, word_match{ --[[...]] })) --[[... other rule definitions ...]] -- Custom. lex:add_rule('custom_rule', token('custom_token', ...)) lex:add_style('custom_token', lexer.styles.keyword .. {bold = true}) -- Fold points. lex:add_fold_point(lexer.OPERATOR, '{', '}') return lex ``` -------------------------------- ### Define Custom Compile and Run Commands Source: https://orbitalquark.github.io/textadept/manual.html Modify `textadept.run.compile_commands` and `textadept.run.run_commands` to set custom commands for compiling and running files. The example shows how to define a command for a file named 'foo' and an executable named './"%e"'. ```lua textadept.run.compile_commands.foo = 'foo "%f"' textadept.run.run_commands.foo = './"%e"' ``` -------------------------------- ### Define Global and Language-Specific Key Bindings Source: https://orbitalquark.github.io/textadept/api.html Assign commands to key sequences globally or for specific lexers. Language-specific bindings take priority. The example shows binding 'ctrl+n' to `buffer.new`, 'ctrl+z' to `buffer.undo`, and a custom function for 'shift+ ' in 'c' lexer. ```lua keys['ctrl+n'] = buffer.new keys['ctrl+z'] = buffer.undo keys.c['shift+ '] = function() -- language-specific key buffer:line_end() buffer:add_text(';') buffer:new_line() end keys['0x1234'] = function() ... end -- key code not in keys.KEYSYMS ``` -------------------------------- ### Register RGBA Image for Autocompletion Source: https://orbitalquark.github.io/textadept/api.html This example shows how to register an RGBA image for autocompletion lists. It requires defining the image dimensions and scale beforehand using view.rgba_image_width, view.rgba_image_height, and view.rgba_image_scale. The pixel data should be a sequence of 4-byte values (R, G, B, A) per pixel. ```lua view:register_rgba_image(type, pixels) ``` -------------------------------- ### Get Call Tip Start Position Source: https://orbitalquark.github.io/textadept/api.html Returns the display position of the active call tip. This function does not take any parameters. ```lua view:call_tip_pos_start() ``` -------------------------------- ### Define PHP Start and End Rules for Child Source: https://orbitalquark.github.io/textadept/api.html Define LPeg patterns for the start and end of PHP code blocks within HTML. The start rule uses `lexer.space` to consume whitespace after ''. ```lua local php_start_rule = lex:tag('php_tag', '') ``` -------------------------------- ### Require and Configure LSP Module Source: https://orbitalquark.github.io/textadept/manual.html Load the 'lsp' module and configure a C++ language server command. Place this in your ~/.textadept/init.lua. ```lua local lsp = require('lsp') lsp.server_commands.cpp = 'clangd' ``` -------------------------------- ### Apply Tag to CSS Start Rule Source: https://orbitalquark.github.io/textadept/api.html Append the `tag` rule to the CSS start pattern to ensure the 'style' tag itself is correctly identified as an HTML tag before switching to the CSS lexer. ```lua local css_start_rule = #css_tag * tag ``` -------------------------------- ### Define CSS Start Rule for HTML Parent Source: https://orbitalquark.github.io/textadept/api.html Define an LPeg pattern to identify the start of a CSS block within HTML, specifically looking for a '