Corn planting, Jasper County, Iowa—1940 by Vachon, John, 1914-1975, photographer

Beef up your text editor on Mac OS X

by | Mar 6, 2014 | Developer Blog | 0 comments

This is a gentle reminder that you are not forced to limit yourself to any app’s built-in features when you work on Mac OS X thanks to Services with an assist from Automator. I recently utilized Automator’s Run Shell Script action to create a needed function in Xcode’s text editor.

My problem is that I follow a style guide that limits line length to 80 characters. I usually don’t have trouble with this. Xcode will show a gutter line to help prompt me to break my lines around the limit. But when editing multi-line comments it becomes a pain to reflow the new text. Other editors can do this without my help.

The hockey assist in this story goes to Emacs which has an intelligent function for reflowing text. I knew of this, but I didn’t know that as of a recent Emacs release I could finally tie that function to Xcodes’s editor. Emacs can run elisp scripts on launch, meaning that I can pass it some text, Emacs processes it, and with the Run Script action I get the results back in my editor window.

Software screen captureHere’s the shell script which invokes Emacs and calls its fill-region function. Props to the StackOverflow answer here.

Save that script and make it executable, then create an Automator action to launch that script and check the options to replace selected text. Save it as a Service, and that’s it. Assign it a key command sequence for even more convenience. It’s that simple to make any text editor a beast.

+ more

Accurate Timing

Accurate Timing

In many tasks we need to do something at given intervals of time. The most obvious ways may not give you the best results. Time? Meh. The most basic tasks that don't have what you might call CPU-scale time requirements can be handled with the usual language and...

read more