Showing posts with label technology. Show all posts
Showing posts with label technology. Show all posts

Sunday, March 15, 2009

Creating a TextMate Bundle

I spend a fair amount of time dealing with code written in SQR. Since this isn't a very popular language there isn't a good editor with syntax highlighting for it. I use TextMate a good deal and so it seemed natural to write a bundle for SQR. Step one is to open TextMate and click Bundle then Bundle Editor and then Show Bundle Editor. Once there click the plus at the bottom of the screen and add new bundle.


Now name the bundle something appropriate, in my case SQR. Now you need to add a new language to your bundle, the language is what controls syntax highlighting.



This will generate the following code.

{ scopeName = 'source.untitled';
fileTypes = ( );
foldingStartMarker = '/\*\*|\{\s*$';
foldingStopMarker = '\*\*/|^\s*\}';
patterns = (
{ name = 'keyword.control.untitled';
match = '\b(if|while|for|return)\b';
},
{ name = 'string.quoted.double.untitled';
begin = '"';
end = '"';
patterns = (
{ name = 'constant.character.escape.untitled';
match = '\\.';
},
);
},
);
}

Lets go through this in detail.
  • scopeName (line 1) — this should be a unique name for the language. The convention is for these to be dot separated where the left most piece is the most specific. In my case I used source.SQR. (TextMate 1)
  • fileTypes (line 2) — this is an array of file type extensions that the language should (by default) be used with. This is referenced when TextMate does not know what grammar to use for a file the user opens. If however the user selects a grammar from the language pop-up in the status bar, TextMate will remember that choice. (TextMate 1)
  • foldingStartMarker / foldingStopMarker (line 3-4) — these are regular expressions that lines (in the document) are matched against. If a line matches one of the patterns (but not both), it becomes a folding marker. The means you will get the arrow in the left margin that will allow you to expand and collapse large sections of code (TextMate 1)
  • patterns (line 5-18) — this is an array with the actual rules used to parse the document. In this example there are two rules (line 6-8 and 9-17). (TextMate 1)


For example this is the beginning of my definition for the SQR language.


{ scopeName = 'source.SQR';
fileTypes = ( 'sqr', 'sqc', 'SQR', 'SQC' );
foldingStartMarker = '(?i)^\s*+(Begin-Procedure|If|Begin-Report|Begin-Heading|begin-select|begin-sql|#ifdef).*';
foldingStopMarker = '(?i)^\s*+(End-Procedure|End-If|End-Report|End-Heading|end-select|end-sql|#end-if).*';
patterns = (
{ name = 'comment.line.double-slash.SQR';
match = '!.*\n';
},
...
);
}
The name for the scope is source.SQR and it operates by default on files with the following extensions sqr, sqc, SQR, and SQC. Lets look at just one of the folding markers, Begin-Procedure/End-Procedure. The regex match I set up does a case insensitive match looking for a line that starts with any number of spaces then Begin-Procedure and basically the same for End-Procedure. The result:


Yeah for little arrow thingys!

So the other you might note is the lines with '!' are grayed out, this is because they are set to be comments by our pattern. The name of the pattern is a special name that matches a TextMate property, for a full list see here under 12.4 Naming Conventions. In this case I choose one that is for comments, "comment.line.double-slash" then added ".SQR" for the right scope. The second part of the pattern is the match in this case "!.*\n." This will watch and '!' and any characters after it.

You can go on to add more patterns for reserved words, variables, strings, etc. In not too long you can have syntax highlighting all set. Then you can go on to add snippets and other commands, but we while have to save that for another time.

You can download what I have so far here.

(TextMate 1, http://manual.macromates.com/en/language_grammars#naming_conventions.html)

Sunday, August 10, 2008

When to reinvent the wheel

One of the cardinal rules of software development is to never reinvent the wheel. I have in my ten years of software development strictly adhered to this rule, primarily because programmers are lazy. For the most part it is in your best interest to used tested code the is already written, however sometimes it can be a detriment.

Recently I was working on a project where I wanted to do an auto suggest drop down for a text box. I started off, as usual, slogging through the net looking for something that work. Without too much work I was able to find about three contenders. I downloaded, installed and tested each. None of the three was really what I wanted so I adventured back to the Internet in search of the perfect auto suggest JavaScript and before I knew it I had spent a whole work day (8 hours) just scouring the internet.

I took a step back and wrote:

function suggest() {
var searchBox = document.getElementById('search-form-query');
var suggestions = document.getElementById('suggestions');

var url = 'searchData.cfm';
var pars = 'field=' + searchBox.value;

var ajax = new Ajax.Updater(
{success: 'suggestions'},
url,
{method: 'get', parameters: pars, onFailure: reportError});

suggestions.style.display = 'inline'
}

function hideSuggestions() {
var suggestions = document.getElementById('suggestions');
suggestions.style.display = 'none'
}

With a tiny bit of HTML to help:

<div id="suggestions" style="overflow: auto; position: absolute; background-color: white; width: 150px; height: 250px; display: none;" onclick="hideSuggestions()">This is where the auto suggestions will go</div>

This code took me maybe ten minutes to write and test and it was exactly what I wanted in the end. In the end it was far more efficient for me just to write the code and move on. It's important for programmers to strike a good balance between writing their own stuff and using packages from the Internet.

Friday, April 13, 2007

My new work machine


My new work machine
Originally uploaded by Drizzt51.
I was doing to much so they gave me a new machine. Of course little do they know that giving me a mac, even an ancient one, will allow me to be much more productive

Friday, March 23, 2007

Rsync Rocks

I have used this for backup and file mirroring ... it works great!
 powered by clipmarksblog it

Tuesday, March 20, 2007

FIRST Robotics

When I was at clarkson I was on the FIRST team ... cool stuff.
clipped from gizmodo.com

FIRST Robotics Competition: Like Battlebots with Fewer Saws

This weekend was the FIRST robotics competition at the Javits Center here in NYC, an event where groups of students compete to see who built the best robot in the six-week competition window. How it works:

The core of the high school–level FIRST Robotics Competition (FRC) is the design and building of a robotic competitor. Each year in early January, FIRST unveils the competition or "game" at an annual kick-off event that is beamed by NASA satellite to auditoriums all over the world. This is the first glimpse students get of the game they will have to design their robot to play.

Working in teams, students have just six weeks to create their robot. They get the opportunity to work with programmable radio controls, pneumatics, motors, electrical circuits, mechanics, machining, web design, computer animation, computer assisted design, and other technologies—just like professional engineers and technologists do.

 powered by clipmarks

Friday, March 2, 2007

Windows Hosed my Computer (svchost.exe application error)

Stupid automatic update was killing my network connectivity. Grrrrr. The following solution bailed me out

1.Go 2 the start menu
2.Right click "my computer"
3.Click "properties" then the "automatic updates"
tab
4.Choose "turn off automatic updates"
5.Reboot your computer
6.Go back to start menu and in all programs go to "windows update" you have to be connected to the internet.
7.Manually update windows.
8.Turn your automatic updates back on.

powered by clipmarks