Textadept Scripts

Textadept is easily my favorite text editor (replacing the old favorite, SciTE) Here I've collected some scripts that should make life easier for people using it for programming.

All of these scripts are released under the MIT license.

Comments

Download

Functions for continuing comments over several lines, similar to the way an IDE such as eclipse might do it. This was written so that it can be used by any language. (Right now this is used in my Lua, C/C++, D, Python, DOT, and Java modules.)

Example usage (C++, vertical bar is carat position): Start a comment


// This is a|
Press enter and this will result:

// This is a
// |
Pressing enter again will delete the empty comment on the second line, while typing more text and then pressing enter will cause Textadept to continue to begin the line with comment characters.

Example usage (C, vertical bar is carat position): Start a comment


/*|
Press enter and this will result:

/*
 * |
 */
Continuing to type text and pressing enter will cause lines to be prefixed with a "*" automatically.

/*
 * One-line statement about the function
 * Params:
 *     x = the x-coordinate
 * |
 */

Here's an example section of commands.lua for using this to continue Python's "#" comments:


['\n'] = {
    function()
        buffer:begin_undo_action()
        buffer:new_line()
        continue_block_comment("^%s*#", "^%s*#%s*\n",
            "#")
        end
        buffer:end_undo_action()
    end
},
				

Here's a sample demonstrating C's "/*" "*/" comments:


['\n'] = {
    function()
        buffer:begin_undo_action()
        buffer:new_line()
        continue_stream_comment("^%s*/%*", "^%s*%*", "%*/\n", "*", "*/")
        end
        buffer:end_undo_action()
    end
},
				

C-Style

Download

Module for helping to write code in C-style languages, such as C, C++, C#, D, Java, etc. Contains a function for matching the indentation level of closing braces automatically, identing blocks of code following opening braces, and use of the comments code above. This depends on the comments code. Be sure to remove the curly braces from char_matches in textadept/modules/textadept/editing.lua

Here's an example of how to use it for D source code:


local textadept = _G.textadept

---
-- Commands for the d module.
module('_m.dmd.commands', package.seeall)

require 'common.cstyle'

-- D-specific key commands.
local keys = _G.keys
if type(keys) == 'table' then
    keys.dmd = {
        al = {
            m = { textadept.io.open,
                textadept.iconv(_HOME..'/modules/dmd/init.lua',
                                'UTF-8', _CHARSET) },
        },
        ['a\n'] = {newline},
        ['s\n'] = {newline_semicolon},
        ['c;'] = {endline_semicolon},
        ['s}'] = {match_brace_indent},
        ['\n'] = {enter_key_pressed}
    }
end
				

Graphviz Dot

Download

Contains a lexer for the dot file format used by Graphviz. Be sure to add the line 'dot dot' to textadept/core/ext/mime_types.conf

D

Download

Module for dealing with D code. This contains a fix for a bug in Textadept's default handling of D code that causes keybindings to not work. Depends on the C-Style module. Change textadept/core/ext/mime_types.conf to say


%D
d dmd
di dmd
				
instead of

%D
d d
				

Python

Download

My Python module. Doesn't really do anything special other than indenting after a colon automatically. (But I consider that a useful enough feature to post it here)