Re: [code] Silly little templating snippets system

From: <>
Date: Sat, 09 Jan 2016 14:29:49 -0500

Hey Michael,

Pretty darn cool! I wrote something similar a while back for my
snippets. Though instead of being inside a *_TEMPLATE* directory, I kind
of kept it inside a module you add. going to integrate your work on mine
too. :P Great stuff!

Here’s mine, which I ended up calling ta-extend[1], if you want to
take a look.

On Sat, Jan 9, 2016, at 11:08 AM, Michael Richter wrote:

> I've come up with a really stupid little templating-based snippets
> system for Textadept.  It works like this:
> * Put all the templates into _USERHOME .. '/templates/'
> * The files should be named according to this pattern:
> "<language>.<snippets key>".  So for example if you want
> "mod<tab>": to expand into a full Rexx module, you'd put the code
> for the Rexx module into the file "rexx.mod".  The boilerplate for
> a Prolog predicate might be found in "prolog.pred" to let
> "pred<tab>" expand into the stuff you want at the head of all your
> predicates.
> * Inside those files you put in exactly the same stuff you'd put into
> the snippets string you'd otherwise have put into your init.lua (or
> whatever) file.
> * Inside init.lua add the following code:
>> local templates_dir = _USERHOME .. '/templates/' local function
>> load_snippets(language)  for template in lfs.dir(templates_dir) do
>> b, _, key = string.find(template, '^' .. language .. '%.(.+)

>> if b then      file =, 'r')      snippet =
>> file:read('a')      file:close()      snippets[language] =
>> snippets[language] or {}      snippets[language][key] = snippet
>> end  end end events.connect(events.LEXER_LOADED, load_snippets)
> (As an alternative you could just call load_snippets inside your
> existing LEXER_LOADED event should you have one, which is in fact
> what I do.)
> Now any snippets you want to add to any language can be easily
> maintained in a separate snippets database.
> Motivation:
> * I like Textadept's snippets a lot (simple, yet powerful), but I
> really don't like constantly fiddling with the Lua code in
> init.lua.  Too many chances for totally screwing up my
> configuration.
> * Some of my "snippets" are pretty damned big.  My Rexx module
> "snippet",
for example, is 204 lines of error handling boilerplate.  When this was
in my init.lua it was a bear to navigate and find the specific snippets
I was looking for.
> * It's easier to share snippets that aren't married to your
> idiosyncratic init.lua organization. In case anybody else finds
> matching or overlapping motivations for this feature, I thought I'd
> share it.
> Tested on Textadept 8.5.
> --
> "Perhaps people don't believe this, but throughout all of the
> discussions of entering China our focus has really been what's best
> for the Chinese people. It's not been about our revenue or profit or
> whatnot." --Sergey Brin, demonstrating the emptiness of the "don't be
> evil" mantra.



You are subscribed to
To change subscription settings, send an e-mail to
To unsubscribe, send an e-mail to
Received on Sat 09 Jan 2016 - 14:29:49 EST

This archive was generated by hypermail 2.2.0 : Sun 10 Jan 2016 - 06:34:58 EST