Re: [code] How would this work?

From: Robert <rob.g.att.web.de>
Date: Thu, 21 Feb 2013 21:38:46 +0100

On Thu, Feb 21, 2013 at 8:58 AM, Michael Richter <ttmrichter.att.gmail.com> wrote:
> I'd like to support vim modelines (or something similar) in textadept. A
> modeline, for those not in the know, looks something like this, stuck in a
> comment somewhere:
>
> vim: ft=prolog sw=3 ts=6
>
> This modeline, for example, tells vim that the file has a file type of
> "prolog", a shift width of 3 and a tab stop of 6.
>
> If I wanted to make a commensurate feature for textadept, how would I go
> about doing this? Let's say I wanted to look for and parse something like
> this:
>
> textadept: set_lexer=prolog tab_width=4 indent=4 use_tabs=false
>
> It could be anywhere in the file (I'd rather not force it to be the first
> line because then shebang settings could interfere) so ... where would I
> hook things for this kind of functionality? (I can write the actual code
> that parses and sets the exposed values easily.)
>

You'd hook that into the "file_opened" event:

events.connect(events.FILE_OPENED, function()
  -- ...
  end)

It doesn't show up in the "events" documentation, but there are a few
events triggered by fiel opening/saving, that are quite useful.
See core/file_io.lua (http://foicica.com/textadept/api/io.html) for
some examples.

Robert

-- 
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 Thu 21 Feb 2013 - 15:38:46 EST

This archive was generated by hypermail 2.2.0 : Fri 22 Feb 2013 - 06:37:09 EST