Try this:
1. Open a file F1 with extension .pm, Perl mode is correctly active.
2. Open a second file F2 with extension .pm, Perl mode is correctly active.
3. Change F2's mode to C mode.
4. Switch back to F1's tab and you'll see it's now in C mode!
Is that a bug?
-- fxn
Just in case you are wondering where does this convoluted experiment comes from: I am working in a Perl module that has some part written in C:
http://search.cpan.org/~fxn/Algorithm-Combinatorics/
There's a file ending in .pm that is strictly a Perl module, but that actually is mostly C except for a few lines, since it uses Inline::C. I need C mode there to work normally.
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:
LaTeX stuff LaTeX stuff LaTeX stuff
<<some string>>= C++ stuff C++ stuff C++ stuff @
LaTeX stuff LaTeX stuff LaTeX stuff
<<some other string>>= C++ stuff C++ stuff C++ stuff @
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.
-- Greg Humphreys, Assistant Professor Department of Computer Science, University of Virginia http://www.cs.virginia.edu/~humper/
On Nov 6, 2005, at 9:33 AM, Xavier Noria wrote:
Try this:
1. Open a file F1 with extension .pm, Perl mode is correctly
active.
2. Open a second file F2 with extension .pm, Perl mode is
correctly active.
3. Change F2's mode to C mode. 4. Switch back to F1's tab and you'll see it's now in C mode!
Is that a bug?
-- fxn
Just in case you are wondering where does this convoluted experiment comes from: I am working in a Perl module that has some part written in C:
http://search.cpan.org/~fxn/Algorithm-Combinatorics/
There's a file ending in .pm that is strictly a Perl module, but that actually is mostly C except for a few lines, since it uses Inline::C. I need C mode there to work normally.
For new threads USE THIS: textmate@lists.macromates.com (threading gets destroyed and the universe will collapse if you don't) http://lists.macromates.com/mailman/listinfo/textmate
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
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@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@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/
On 06/11/2005, at 15.33, Xavier Noria wrote:
Try this: 1. Open a file F1 with extension .pm, Perl mode is correctly active. 2. Open a second file F2 with extension .pm, Perl mode is correctly active. 3. Change F2's mode to C mode. 4. Switch back to F1's tab and you'll see it's now in C mode! Is that a bug?
Not really -- when switching language, TextMate learns that the switched-to language should be used for the current extension. And when switching buffer, it re-initializes language + settings. The latter, one could argue, it does a little too often ATM (synch settings) -- but TM is definitely not designed to have the same extension mean two different languages, although it can be worked around by having the grammar specify a “firstLineMatch”, like is done for the .plist/.dict files, which can be both old-style ASCII and XML.
[...] There's a file ending in .pm that is strictly a Perl module, but that actually is mostly C except for a few lines, since it uses Inline::C. I need C mode there to work normally.
If this is official syntax, I can add a rule to the Perl language grammar to support it.
On Nov 7, 2005, at 5:06, Allan Odgaard wrote:
[...] There's a file ending in .pm that is strictly a Perl module, but that actually is mostly C except for a few lines, since it uses Inline::C. I need C mode there to work normally.
If this is official syntax, I can add a rule to the Perl language grammar to support it.
Hmmm, maybe it is not necessary, I see a modeline like this already works (I think I tried this before without luck, maybe I didn't leave a space after the colon)
# -*- Mode: C -*-
and is per file according to my trials. That's fine!
-- fxn