Re: [code] [textadept] Language specific settings

From: Rob Kendrick <rjek+foicica.com.att.rjek.com>
Date: Fri, 21 Feb 2014 16:51:37 +0000

On Tue, Jan 28, 2014 at 02:05:44PM -0500, Mitchell wrote:
> >In such a thing, I believe it might be desirable to allow the
> >configuration of indentation rules not just based on lexer in use, but
> >path, as not all projects follow the same.
>
> I cannot imagine what a framework for this would look like... ideas?

I had a spare ten minutes this afternoon, and I hacked together the
following. In ~/.textadept/properties.lua I have:

do
    local rules = { }

    local function add_keyword(word)
        return function(param)
            return function(opts)
                rules[#rules + 1] = {
                    rule = { [word] = param }, opts = opts
                }
            end
        end
    end

    local conf = os.getenv("HOME") .. "/.textadept/format-rules.lua"
    local format_config = loadfile(conf, "t", {
        Language = add_keyword "Language",
        Filename = add_keyword "Filename",
    })

    if format_config then
        format_config()
    end
    
    local function apply_rule(buffer, rule)
        for i, v in pairs(rule) do
            buffer[i] = v
        end
    end
    
    for _, r in ipairs(rules) do
        if r.rule.file and (buffer.filename or ""):match(r.rule.file) then
            apply_rule(buffer, r.opts)
            break
        end
        if r.rule.lang == lang then
            apply_rule(buffer, r.opts)
            break
        end
    end
end

Then, in ~/.textadept/format-rules.lua I have something like this:

Language "lua" {
        use_tabs = false,
        tab_width = 4
}

Language "c" {
        use_tabs = true,
        tab_width = 8
}

Filename "%.yaml$" {
        use_tabs = false,
        tab_width = 4
}

And so on. Comments and improvements welcome, this is a first-cut hack!

B.

-- 
You are subscribed to code.att.foicica.com.
To change subscription settings, send an e-mail to code+help.att.foicica.com.
To unsubscribe, send an e-mail to code+unsubscribe.att.foicica.com.
Received on Fri 21 Feb 2014 - 11:51:37 EST

This archive was generated by hypermail 2.2.0 : Sat 22 Feb 2014 - 06:34:48 EST