Numbered lists in plain text files

From: Brian Schott <briancsch....at.gmail.com>
Date: Sat, 9 Jul 2011 13:11:28 -0700

I'm going to try something new, starting this weekend. Every Saturday
I'll try to post a short function that you can drop in to your
init.lua file. We'll see how long I can keep this up.

This week is a function that continues a basic numbered list in plain
text files. It should be useful for taking quick notes, documentation,
whatever. It can be made to work with other languages by changing the
line that uses buffer:get_lexer()

-- Continues numbering of a simple numbered list in plain text files
events.connect(events.CHAR_ADDED, function(ch)
        if buffer:get_lexer() == "container" and ch == 10 then
                local lineNumber = buffer:line_from_position(buffer.current_pos) - 1
                local line = buffer:get_line(lineNumber)
                local n, after = line:match("^%s*(%d+)(%.[\t ]+)")
                if n ~= nil then
                        buffer:add_text(string.format("%d%s", n + 1, after))
                        return true
                end
        end
end)
Received on Sat 09 Jul 2011 - 16:11:28 EDT

This archive was generated by hypermail 2.2.0 : Thu 08 Mar 2012 - 12:13:22 EST