WML syntax hiliting for TextWrangler

The place to post your WML questions and answers.

Moderator: Forum Moderators

Forum rules
  • Please use [code] BBCode tags in your posts for embedding WML snippets.
  • To keep your code readable so that others can easily help you, make sure to indent it following our conventions.
Post Reply
User avatar
Celtic_Minstrel
Developer
Posts: 1734
Joined: August 3rd, 2012, 11:26 pm
Location: Canada
Contact:

WML syntax hiliting for TextWrangler

Post by Celtic_Minstrel »

For Mac users, I made a TextWrangler/BBCode syntax highlighter (with limited support for the function menu as well). The plist file in the download is generated by a simple Python script so that it hilites full tags rather than just the tag-name (thus preventing tag-names from being hilited in other contexts); the source for that script is also available, which could be useful if someone else wanted to update it for newer tags. It's probable that I've missed a tag or two, and there may be one or two tags in the list that don't exist. Preprocessor commands are also considered identifiers and hilited as such, while still supporting comment hiliting.

Download
Source

I didn't include a license file in the download, but it can be considered to be available under a Simplified BSD license.

If I had the time (and motivation) I would do it properly and write a C++ module to interface with TextWrangler for the syntax hiliting; there's an API provided for that, and it would make a lot of things nicer (eg, ability to hilite inline Lua). Maybe someday I'll do that.
Author of The Black Cross of Aleron campaign and Default++ era.
Maintainer of Steelhive.
User avatar
Celtic_Minstrel
Developer
Posts: 1734
Joined: August 3rd, 2012, 11:26 pm
Location: Canada
Contact:

Re: WML syntax hiliting for TextWrangler

Post by Celtic_Minstrel »

Updated this with a bunch of missing tags, and also added a FAI.plist as a hiliter for FormulaAI (automatically applies to files with a .fai extension). I don't use much FormulaAI, so I'm not sure how good this is.

This version considers #wmllint to be a preprocessor directive. Unfortunately this won't work if there's a space, ie "# wmllint".

The new version overwrites the old, so use the same links in the first post.
Author of The Black Cross of Aleron campaign and Default++ era.
Maintainer of Steelhive.
User avatar
Crow_T
Posts: 851
Joined: February 24th, 2011, 4:20 am

Re: WML syntax hiliting for TextWrangler

Post by Crow_T »

Thanks for coding this up- I'm new to Textwrangler and can't seem to figure how to make this work- can you do a quick write up? Most text editors I've use in the past have a simple pulldown to select the highlight mode.
User avatar
Celtic_Minstrel
Developer
Posts: 1734
Joined: August 3rd, 2012, 11:26 pm
Location: Canada
Contact:

Re: WML syntax hiliting for TextWrangler

Post by Celtic_Minstrel »

There are three pull-downs at the bottom of the window, which from left to right are language, encoding, newline style. You need to put the WML.plist where TextWrangler can find it (which is "~/Application Support/TextWrangler/Language Modules" if I recall correctly), and if it's running you need to restart it.
Author of The Black Cross of Aleron campaign and Default++ era.
Maintainer of Steelhive.
User avatar
Celtic_Minstrel
Developer
Posts: 1734
Joined: August 3rd, 2012, 11:26 pm
Location: Canada
Contact:

Re: WML syntax hiliting for TextWrangler

Post by Celtic_Minstrel »

Helmet wrote: November 15th, 2020, 1:34 pm Side note: Is there a way for me to make macros appear green (or some other color) in the syntax highlighter you made? I have no idea where to start. I'd also like to add [elseif] to the recognized list of tags.
Unless TextWrangler allows you to colour "line comments" and "block comments" in different colours, I don't think you can change the macro colour. The thing is, this is just a set of configuration parameters for TextWrangler's basic syntax highlighter, and I set it up to count macros as comments. There's only a limited amount of customizability in the basic highlighter, so I believe that was the best I could manage.

Adding additional tags to the recognized list is easy, though. If you open the plist file in an appropriate editor (you can even open it in TextWrangler itself if there are no better editors installed), you can find the list of recognized keywords and add whatever you want. There's probably a lot more missing than just [elseif].
Author of The Black Cross of Aleron campaign and Default++ era.
Maintainer of Steelhive.
User avatar
Helmet
Posts: 200
Joined: December 19th, 2006, 5:28 pm
Location: Florida, USA

Re: WML syntax hiliting for TextWrangler

Post by Helmet »

Celtic_Minstrel wrote: November 16th, 2020, 1:00 am Unless TextWrangler allows you to colour "line comments" and "block comments" in different colours, I don't think you can change the macro colour. The thing is, this is just a set of configuration parameters for TextWrangler's basic syntax highlighter, and I set it up to count macros as comments. There's only a limited amount of customizability in the basic highlighter, so I believe that was the best I could manage.
In TextWrangler's Preferences section is a tab for "colors." I clicked it and saw a list of codes, which included General, HTML, Markdown, etc, and under each code was a list of elements and their colors. It seems to me that if WML were in that list, changing colors of a macro would be possible. I don't know how hard that would be, though. All this stuff may as well be atomic science as far as my comprehension is concerned. Or magnets. But maybe...you could...add..........................it?

Oh! Would it be possible to color macros differently if macros were categorized as something else beside a comment block? Such as predefined symbols? Or even something inaccurate, like XML Processing Instructions or even Misspelled Words? I don't know, but maybe there's a quick workaround.
Celtic_Minstrel wrote: November 16th, 2020, 1:00 am Adding additional tags to the recognized list is easy, though. If you open the plist file in an appropriate editor (you can even open it in TextWrangler itself if there are no better editors installed), you can find the list of recognized keywords and add whatever you want. There's probably a lot more missing than just [elseif].
I shocked myself. I added [elseif] to the syntax highlighter and it works. Yay.
User avatar
Celtic_Minstrel
Developer
Posts: 1734
Joined: August 3rd, 2012, 11:26 pm
Location: Canada
Contact:

Re: WML syntax hiliting for TextWrangler

Post by Celtic_Minstrel »

Helmet wrote: November 16th, 2020, 3:46 am In TextWrangler's Preferences section is a tab for "colors." I clicked it and saw a list of codes, which included General, HTML, Markdown, etc, and under each code was a list of elements and their colors. It seems to me that if WML were in that list, changing colors of a macro would be possible. I don't know how hard that would be, though. All this stuff may as well be atomic science as far as my comprehension is concerned. Or magnets. But maybe...you could...add..........................it?
I have no control over that screen where you set the colours. The only colours available for the basic syntax highlighter are the ones you see in the Source Code section (and not even all of those, I think).
Helmet wrote: November 16th, 2020, 3:46 am Oh! Would it be possible to color macros differently if macros were categorized as something else beside a comment block? Such as predefined symbols? Or even something inaccurate, like XML Processing Instructions or even Misspelled Words? I don't know, but maybe there's a quick workaround.
It's possible to set them as XML Processing Instructions, but not when using a plist file. It would require writing C/C++ code to implement the syntax highlighting… I did give it a try awhile back but it's pretty buggy and I don't even think the plugin I built would work on a newer Mac. Since I don't use TextWrangler for WML anymore, I don't have much motivation to fix it.
Author of The Black Cross of Aleron campaign and Default++ era.
Maintainer of Steelhive.
User avatar
Helmet
Posts: 200
Joined: December 19th, 2006, 5:28 pm
Location: Florida, USA

Re: WML syntax hiliting for TextWrangler

Post by Helmet »

Celtic_Minstrel wrote: November 16th, 2020, 6:27 am ...I don't have much motivation to fix it.
I understand. I have a custom sprite in my campaign that could be better, but it works and I have other sprites that I need to work on instead. The syntax highlighter is still very useful for writing WML, so thanks for making it.
Post Reply