How to understand patterns defined in TextMate? - textmate

I am learning TextMate in order to define customized keyword for highlighting in a Orion editor(A browser based editor who is using TextMate grammar). I read this link http://manual.macromates.com/en/language_grammars.html#language_rules. And I don't understand how to define a pattern to match a keyword.
Below is an example I tried to define database as a keyword. But it doesn't get recognized by the editor.
{ name = 'keyword.control.db';
match = '\b(database)\b';
}
what is the correct way to do this?

Related

Sublime Text 2 highlighting : how to differenciate variable declaration and variable use?

Is there a way to differenciate variable declaration and variable use by using two different colors with Sublime Text 2 syntax highlighting ?
Here is an example of what I'm trying to do : (screenshot from jsFiddle)
I didn't find anything helpful in any of the Sublime Text 2 color schemes xml files and on the web either. Is what I'm trying to do even possible ?
This is only possible if the syntax definition scopes the variable declarations differently to the uses. The JavaScript syntax that ships with ST doesn't do so.
Therefore, unless you alter the syntax definition, there is no way to change the color scheme to achieve what you want.
If you upgrade to ST3, you could update the syntax so that after it scopes the var keyword, it could push into another context where it would expect an identifier, and scope that uniquely. See the sublime-syntax documentation for details.

Sublime Text - Exclude comments in search

Every time I search for a function inside of hundreds of files, I see so many matches for comments which have no effect in the code.
Can someone limit Sublime Text's search scope to real code, and exclude comments?
I use Sublime Text 3 for developing a C++ program.
I created a Plugin that search for a given string inside a given scope.
The default scope selector is -comment effectively searching outside of comments. The text to search for is taken from the current selection. The results are presented in the drop-down menu
Basically I combined two API methods:
view.find_all(pattern) that searches for a pattern in the given view.
view.match_selector(position, scope_selecor) that check if the given position is inside the given scope.
You could use regex to find patters matching the regex you give.
Design the regex according to match your.
You can give regex by turning on the 'Regular Expression' flag
Example
You can have this regex to match your case if you want to match alone in single line comments.
^(?!\/\/)([^\/\n]*)YOUR_SEARCH_TERM
If you want to match also in multi line comments use this.
^(?!(\/\/|(\/\*(.|\n)*([^\*])(?=\/))))YOUR_SEARCH_TERM

Syntax Highlighting in Sublime Text 2

So I have been trying to figure out how to add syntax highlighting for the name of typedef's in c++ files, in sublime text.
For example, if I have typedef long long integer; I want integer to be highlighted (preferably the same color as the other types: int, bool, etc.). I went looked at the C.tmLanuage file, and tried to add the following regex code ^typedef.*?\s(\w+)\s*; to storage.type.c (line 49), but it didn't work. If I add the word string, it will highlight all instances of the word string. I tried going in the C++.tmLanguage file, and adding the regex code to storage.type.c++, but it still did not work.
Does anybody know how to get typedef's highlighted in sublime text?
Also, is there a way to get syntax highlighting for class name? Let's say I declare a string or vector, I would like either string or vector to be highlighted.
That regex would work (I believe) if you had something along the lines of typedef foo; To get the behavior you want, you will have to create a slightly more complex pattern entry in the tmLanguage file. As the language file is based on TextMates, you will want to have this as a reference (http://manual.macromates.com/en/language_grammars#language_grammars). I would also recommend using PlistJsonConverter (working in JSON is easier for me than working in XML). You will probably need to define begin and end patterns (begin will probably be typedef end will probably be ;). You can then apply whatever patterns you want to that group.
As for the class name highlighting, I would look to see what, if any scopes are being applied. If none are, you will have to come up with a regex to apply the scope to those. You can then add a color entry, or use a defined one from the color scheme.
Edit:
Actually they don't appear to be JSON. I see () rather than []. JSON is pretty simple to understand. You can look for something more in depth, but wikipedia is a good place to start. What you would probably be interested in are the things under the "Rule Keys" section. I did some searching (because I knew there were some better examples out there), and came across http://docs.sublimetext.info/en/latest/extensibility/syntaxdefs.html . It goes over syntax definitions from scratch, but the most relevant section is probably http://docs.sublimetext.info/en/latest/extensibility/syntaxdefs.html#analyzing-patterns. I don't have a regex to find class names, so you would have to come up with one yourself. If you haven't already though, you may want to search around to see if someone else has implemented a language file in a way that works for you.
You will want to start with the built in tmLanguage file and convert that from a Plist to json. You can then edit that file and move it back.

Autocomplete already defined variables in TextMate

Taking a tutorial on basic programming. I'm using TextMate as the text editor and can't seem to get it to pull in previously defined variables when using them later in the file.
For example, if I write:
var str = "Hello" + "World";
and then write:
alert(st
I noticed in the tutorial, the teachers editor completes it with str. I've been looking all over to see if TextMate supports this functionality, but can't seem to find it. Is this possible or do I need another editor?
This answer seems to imply that it should complete if using terms used in the same file:
Autocomplete Class methods in textmate?
But it doesn't happen that way when I'm writing. Thanks.
You can use the escape key to autocomplete.

What other markup syntax is closest to MediaWiki?

GeShi is a syntax highlighting tool used by projects and vendors like MediaWiki and pastebin.com, respectively.
However, GeShi does not natively support MediaWiki markup syntax. What would be the closest "look alike" that I could use to highlight a MediaWiki template?
I doubt there is any. MediaWiki's syntax is a bit unique. It's more than just markup language for creating single text documents, it's for creating whole sites. The difference is relations between documents: linking, redirections and embedding one into another (templates).
BTW creating good syntax highlight for MediaWiki syntax is not possible, and all this because of templates. For example:
{{{!}}
! a !! b
{{!}}}
Above would be completely valid table on the English Wikipedia because {{!}} resolves to |, so exclamation marks in second line should be highlighted as in table, but you can't tell that if you're not able to resolve templates. (However not-that-good highlight could be found in Vim).

Resources