Sublime 2 - 4 Pane Grid View

Sublime 2 Power Tools

This is a very advanced technical article.

For years, as a developer, I used the fantastic Textmate software for writing code. I got used to it. It’s a power editor for Mac OS X and has bundle support (think of bundles as extensions or plugins) that enhance the functionality of the software) for just about every technology, from Subversion to Git to a bunch of things I don’t use in a PHP environment like C/C++ mallloc (memory allocation), Python, Ruby, etc. It’s even got a WordPress bundle!

The problem with Textmate, however, is that active development is slow. Like, extremely slow. Like, molasses slow. After five years of using version 1.5x, an alpha version of 2.0 finally emerged last year. It’s still in alpha. Pace of development is still painfully slow, and what is in the 2.0 alpha version is not ground-breaking compared to what is in the current stable version.

Along came Sublime 2. This is, by far, my favorite text editor ever. I’ve been using it for about six months. It emulates virtually everything Textmate does. Textmate does snippets (think of them as macros). Sublime 2 also does snippets and supports the Textmate style. (Hint: If you’re a WordPress developer, my favorite – and still most commonly used – snippet comes from Mark Jaquith who wrote this snippet to create WordPress widgets on the fly. It works in both Textmate and Sublime 2).

The great thing about Sublime 2 is that it is truly a hacker’s paradise. All the config files are JSON objects, so if you can write JSON, you can configure Sublime 2. None of this namby pamby UI/click/select from dropdown bulldookie. Write your code and mean it. Related is that the master configuration file is extremely well documented and you can override everything in it, not by editing this file, but by providing new values in the user configuration file.

Ok, let’s back up and get y’all up to speed on what I do when configuring my Sublime 2 environment.

Config Files

First, I recommend you look at the entire Default configuration file. Read all the settings and comments and understand all the possibilities you have. Your most comfortable environment won’t be mine. For me, I see the following configuration settings that I’m going to want to override. Keep in mind, I never edit the default configuration file. It gets overwritten on upgrade.

To access this file, go to Preferences >  Settings – Default 1.

Note that I have included the related Sublime 2 default comments along with the settings I wish to override.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// While you can edit this file, it's best to put your changes in
// "User/Preferences.sublime-settings", which overrides the settings in here.
//
// Settings may also be placed in file type specific options files, for
// example, in Packages/Python/Python.sublime-settings for python files.
{
// Note that the font_face and font_size are overriden in the platform
// specific settings file, for example, "Preferences (Linux).sublime-settings".
// Because of this, setting them here will have no effect: you must set them
// in your User File Preferences.
"font_size": 10,

// OS X only: When files are opened from finder, or by dragging onto the
// dock icon, this controls if a new window is created or not.
"open_files_in_new_window": true,

// Characters that are considered to separate words
"word_separators": "./\\()\"':,.;-<>~!@#$%^&*|+=[]{}`~?",

// When drag_text is enabled, clicking on selected text will begin a
// drag-drop operation
"drag_text": true,
}

These settings and their related comments may seem self-explanatory, but in case they are not…

font_size: This setting controls the font size in the editor. Derp.

open_files_in_new_window: As a developer on an 11″ MacBook Air, I hate this setting. As the name suggests, everytime you open a file, it’s going to be in a separate window. This may be okay if you have a ton of screen real estate, but if you don’t… well, I like to have windows open up in a new tab of my editor so I can access them quickly and easily without consuming precious real estate.

word_separators: This is a list of characters that serve as word separators. I don’t mean code word separators. We’re talking about in the editor. I want to be able to click a CSS selector that often comes with a dash in the middle, and highlight/select the whole selector. By default, if there’s a hyphen, only the portion of the word clicked will be highlighted.

For instance, if a <div> has a class="foo", and I click on foo, foo will, by default, be selected. But if that div has a class="foo-bar", then clicking on foo will only highlight/select foo (up to the hyphen) and not all of the, more contextually accurate, ‘foo-bar’. In my user configuration file, I’m going to remove the hyphen, and thus remove this annoyance from my life.

drag_text: This is an edge case setting, but it has bitten me a few times. If you’re in a window in Sublime 2, and you have a block of code selected, when this default configuration is in play, you can drag that text into another window. I can see the use for this, but it’s also thrown me for a loop more times than it’s been useful. I override this to prevent that from happening. If I really want text in another window, I’ll jkust do the traditional copy and paste.

Overriding Defaults

Knowing I want to change these settings, I can write my own JSON object into my User configuration (Preferences > Settings – User):

1
2
3
4
5
6
{
"drag_text": false,
"font_size": 15.0,
"open_files_in_new_window": false,
"word_separators": "./\\()\"':,.;<>;~!@#$%^&*|+=[]{}`~?"
}

Easy Peasey!

Installing Packages

Where Textmate had Bundles, Sublime 2 has Packages. Packages are extremely powerful.

NOTE: Install this first 2. Trust me. And get familiar with this.

There are a million and one different packages out there, depending on what your needs are. Installing a package is as simple as going to Preferences > Package Manager > Install Package. Note that you can also add new external repositories of external packages that Sublime 2 can also search.

Sublime 2 - 4 Pane Grid View
Sublime 2 – 4 Pane Grid View

Summary

Sublime 2, of course, has hundreds of different setups. It kinda just depends on your taste and not being afraid to try things. Because everything is based on text file configurations and settings, everything can be reversed. Don’t be afraid to break things. You can always back out. You can even set it up so that you have multiple files open in the same tab. Set it up the way you want it and go be more productive!

Notes:

  1. Sublime 2 works on Mac OS X, Windows and Linux. All options will be similar, if not identical, to what I’m providing here from an OS X perspective. If you can’t find what I’m referring to, think about where logically it might be in your menus.
  2. Specific installation instructions can be found here.
117048243_7cc6bb0b87_b

Impending Legal Precedent for GPL Licensing?

If you pay attention to the WordPress world, you might be aware that a landmark lawsuit is likely to be filed. I say landmark expecting that both sides will litigate and not settle – something that is desperately needed in the United States to validate and uphold the scope of the GPL license.

WordPress is a free software that is licensed under GPLv2 – a license that was created in 1991 to protect the ability of developers and users to gain access to software, create derivative works and distribute the copyrighted code in its entirety under the same protective license.

One of the tenants of the GPL that is argued prolifically is that derivative works are works that “link” into other works via APIs and dependencies (such as library dependencies). According to the argument, software that is considered a derivative work must retain the same licensing as the GPL’d work that it links into.

There are many legal (and non-legal) minds who would like to interpret this license in a variety of ways. There have been notable legal cases around the GPL in the United States, but all (to the best of my knowledge) have settled prior to litigation. One of these cases, Progress Software v MySQL AB, revolved around a product called Nusphere that was bundled with MySQL but was proprietary and incompatible with the GPL. The judge refused to grant summary judgement and eventually MySQL simply did not bundle the proprietary software.

Another case avoided judicial decision – and thus avoided judicial precedence. That case, Free Software Foundation v. Cisco, was settled out of court with a donation from Cisco and a pledge of commitment to the GPL.

Today, a major incident happened that has been brewing for years now. Due to an unfortunate incident which involved source code for the popular Thesis theme for WordPress (from DIYThemes) becoming compromised by a hacker, tempers started boiling over. Matt Mullenweg, founder of WordPress and the public face of )Automattic, the largest company behind the WordPress project, ended up on a live interview alongside Chris Pearson of DIYThemes.

Matt suggests (I think accurately) that a theme that is provided for WordPress (it does not work without WordPress) is a derivative work and requires GPL compatibility. He also suggests (accurately, I think) that GPL compliance would only enhance DIYTheme’s business as evidenced by countless other proprietary software providers who have gone open source.

Not to mention that a license does insinuate adherence to legal requirements provided by the license. If you don’t agree to the terms of the license, you’re not permitted to use the software. Makes sense.

Chris’ defense is that Thesis is completely independent of WordPress (which I question the rationality of since the software cannot exist absent of WordPress). He believes he has a business and economic right to maintain a license that is at odds with WordPress’ GPL license.

So my editorial question is… compliance with the WordPress GPL license is optional but compliance with the Thesis license is not? Hmmm.

Matt, in so many words, has already indicated that there will be a lawsuit that comes out of this. This could be landmark as, if the suit were not settled, it could define the parameters of open source software creation, usage and distribution reaching into every aspect of our life. Who uses Firefox? Yeah… depending on the outcome, that could be affected.

In a perfect world, the two sides reach an amicable solution. Thesis is popular, but it is not the only game in town. However, the second best solution is a legal precedent governing GPL software.

So we stand by and wait.

Image by Joe Gratz

4407979507_82e0e427de_b

I’m Pro Choice. I’m Android.

We in the tech world are a fickle bunch. On one side of our brain, we scream about openness and freedoms. We verbally disparage anyone who would dare mess with our precious Internet freedoms. Many of us, especially in my WordPress community, swear allegiance to licensing that ensures data and code exchanges on open standards.

Yet one thing stands out to me as an anomaly on this, the opening day of pre-orders for the iPhone 4.


Photo by laihiu on Flickr

Ah yes. The iPhone. The gadget that makes grown men quake in their shoes. The thing that causes adults to behave as if they left their brains at the door. At one point in time, I called this behavior “an applegasm” and identified the Apple store as the place where intelligent people go to die.

And it’s not only the iPhone. It’s the iPad too (I bought one 3 weeks after release and only because I needed it for some client work). In fact, it’s any Apple device. Apple has a way of turning people into automatons controlled by the Borg in Cupertino.

Don’t get me wrong. I love Apple and I love Apple products. However, there is a degree of hypocrisy (or shall we call it “situational morality”) that comes into play here. There is nothing “open” about Apple products. Sure, Steve Jobs famously points out that Apple encourages the use of open web standards like HTML5, CSS3 and Javascript, but the devices are nowhere near open.

In fact, the devices are so closed and guarded that strange things like lost stolen iPhone prototypes make huge news. There is only one device. There is only one operating system. There is only one permitted way of designing apps. There is only one carrier (in the United States).

And the open standards, web-free, maniacal tech world that is ready to take off the heads of closed entities like Microsoft, Facebook and Palm, whistle silently and look the other way when it comes to Apple.

In another few weeks, I am going to be eligible for an upgrade with Verizon Wireless. As a longtime BlackBerry user (I refuse to give money to AT&T ever), I will be investing in a new Android-based phone. I won’t be doing this with any kind of religious conviction about open source. There is a legitimate place for closed source in this world. I’m doing this because the culture of openness (which supersedes the execution of openness, in my mind), allows for more innovation and creativity.

In the Android world (which is quickly catching up to the iPhone world), apps are being created without the artificial restrictions placed by a single gatekeeper. There are more choices in phones. Don’t like this one? Try that one. There is a greater anticipation around what can be done.

Apple had to have its arm twisted to enable multitasking in it’s latest operating system. It had to have its arm twisted to allow cut and paste. It still hasn’t provided a decent camera, despite consumers begging for one. In the Android world, if Motorola doesn’t provide it, maybe HTC does. You have choice. Choice is good.

I’m pro choice.