[TxMt] language mode is not per tab/file?

Greg Humphreys humper at gmail.com
Mon Nov 7 04:05:10 UTC 2005


Sweet, I'm blown away.  I guess it's time to start poking around and
seeing how this thing works!

Thanks for the tip.

On 11/6/05, Charilaos Skiadas <cskiadas at uchicago.edu> wrote:
>
> On Nov 6, 2005, at 11:29 AM, Greg Humphreys wrote:
>
> > Along those lines, I have a feature request which I would use
> > frequently, which is that a single file could be multi-mode based
> > on some very simple regular expression matching.
> >
> > For example, I have lots of files that look like this:
> >
> <example snipped>
> > and so on.  I'd like the sections to be syntax highlighted (hilit?)
> > according to their respective styles, and when the cursor is
> > between the <<...>>= and @, I'd like to edit in C++ mode with all
> > the associated macros / tab expanders, and in LaTeX otherwise.
> >
> > I'm mainly just a user of TextMate; I haven't really extended it in
> > any meaningful way; is this something that an experienced end-user
> > could do, or would it require a fundamental change to the core?
> >
> > Allan?  Thoughts about this?  I imagine it would be implemented as
> > a "meta-mode", which is just a mode that tells TM under what
> > circumstances it should interpret blocks as other modes.
>
> Yes, this is already possible. This is a portion of the LaTeX syntax
> file:
>
>          {    name = 'source.python.embedded.latex';
>              comment = 'Put the lstlisting match before the more
> general environment listing. Someday it would be nice to make this
> rule general enough to figure out which language is inside the
> lstlisting environment rather than my own personal use for python. --
> Brad';
>              begin = '(\\begin\{)(lstlisting)(\})(\[(.*)\])?';
>              end = '(\\end\{)(lstlisting)(\})';
>              captures =
>              {    1 = { name = 'support.function.latex'; };
>                  2 = { name = 'variable.parameter.latex'; };
>                  3 = { name = 'support.function.latex'; };
>                  4 = { name = 'support.function.latex'; };
>              };
>              patterns = ( { include = 'source.python'; } );
>          },
>
> As you can see, the part saying include = 'source.python' will make
> it so that when in this mode, you are really editing in python, with
> the full power of the python bundle. So it is just a question of
> adding your own thing in there, by the appropriate begin,end regex's.
> This is actually not as hard as it looks, if you read the "syntax
> highlight" part of the help file, or just look at some example
> language files.
> I would guess something like this would work:
>          {    name = 'source.c++.embedded.latex';
>              begin = '^(<<).+(>>)=';
>              end = '^(@)$';
>              patterns = ( { include = 'source.c++'; } );
>          },
>
> You'll want to add some capture patterns of course, to color things
> properly, and maybe finetune the regexs. But the inside should
> already be colored properly.
>
> Haris
>
>
>
>
> ______________________________________________________________________
> For new threads USE THIS: textmate at lists.macromates.com
> (threading gets destroyed and the universe will collapse if you don't)
> http://lists.macromates.com/mailman/listinfo/textmate
>


--
Greg Humphreys, Assistant Professor
Department of Computer Science, University of Virginia
http://www.cs.virginia.edu/~humper/



More information about the textmate mailing list