Sublime Forum

Smarter Title Case

#1

During my switchover from TextMate to ST2 I noticed a difference in the way Title Case is handled.

In TextMate, Text > Convert > To Titlecase changes:
this is an example of title case
to
This Is an Example of Title Case

In Sublime Text 2, Edit > Convert Case > Title Case changes:
this is an example of title case
to:
This Is An Example Of Title Case

This is an instance where TextMate yields better results. Per the Chicago Manual of Style, for example, the rule for titles all words to be capitalized except “articles (a, an, the), coordinating conjunctions (and, but, or, for, nor), and prepositions, regardless of length, are lowercased unless they are the first or last word of the title.” (source)

My request is for ST2’s title_case command to do this instead of indiscriminately capitalizing every word. A frequent scenario for us is when we’re handed content with headings in ALL CAPS. Converting them is currently a 2-step operation in ST2 – converting to Title Case, then editing the exceptions (above) by hand.

Thanks!

0 Likes

#2

I’d also love smarter case convert, so a vote from me as well!

In addition I would love something that Notepad++'s TextFX plugin has, which is called Proper Case (said plugin also has UPPER CASE, lower case, Sentence case and iNVERT cASE to a name few).

In Notepad++ TextFX > TextFX Characters > Proper Case changes:
this is an example of title case,
with multi-line conversion,
and some of the strangeness it creates.

to:
This Is An Example Of Title Case,
With Multi-Line Conversion,
And Some Of The Strangeness It Creates.

In Sublime Text 2, Edit > Convert Case > Title Case changes it to:
This Is An Example Of Title Case,
with Multi-line Conversion,
and Some Of The Strangeness It Creates.

Combination of smart case conversion and the way Notepad++ does Proper Case conversion would be ideal to me, seems like something the previous poster would also like.
BTW, I’ve no idea why the first letter of the second line (and after) is lower cased or where this would be a desired result, but that seems just wrong to me.

0 Likes

#3

Apparently this has already been added to the UserEcho as sublimetext.userecho.com/topic/1 … itle-case/

0 Likes

#4

Though not built in, this is very doable through plugins. Though I didn’t really test it much, I posted what I did on github (github.com/skuroda/ChangeCase). There is a command available to convert to title case through the command palatte (“ChangeCase: Title Case”). Ignored words can be found in the settings file.

0 Likes

#5

I was just looking into writing a plugin when I noticed this.
Tried to fiddle with it, but didn’t get it to work at all. After installing (ZIP rename, copy into Installed Packages, restart ST2) the only thing I noticed was Package Settings in Preferences and it’s empty submenus.

Tried to add it to Edit -> Convert Case submenu, but after looking into the code I wonder if this is supposed to change the way Title Case behaves instead of adding a new menuitem? It didn’t change Title Case behaviour either tho.

None the less, thanks for looking into this.

0 Likes

#6

[quote=“Shrikester”]

I was just looking into writing a plugin when I noticed this.
Tried to fiddle with it, but didn’t get it to work at all. After installing (ZIP rename, copy into Installed Packages, restart ST2) the only thing I noticed was Package Settings in Preferences and it’s empty submenus.

Tried to add it to Edit -> Convert Case submenu, but after looking into the code I wonder if this is supposed to change the way Title Case behaves instead of adding a new menuitem? It didn’t change Title Case behaviour either tho.

None the less, thanks for looking into this.[/quote]

It doesn’t modify the built in title case command. The command you want to specify is “change_case_title_case”. I wasn’t sure what would happen if I named it the same, and was lazy so didn’t test it out. That being said, I did add a command to the command palette “ChangeCase: Title Case”. In any case, I’d be happy to help you get it working if you would like. I’ll try to check back here every so often, but it may be easier to create an issue on the github page since I will get notifications for those.

0 Likes

#7

Sounds great, I’ll use the github page and post you some information next week.

BTW, I’m on Linux (Ubuntu 12.04 64-bit) just FYI.

0 Likes

#8

I can confirm it works, if you redefined an existing command, the last definition is used (at least for command that are defined in a python file in Default folder).
But take care that the packages are read in alphabetical order (Default is not read first and User last, like for settings and keybindings (bug ?)).

0 Likes

#9

I was looking for something like this too and created a simple wrapper for Stuart Colville’s Python implementation of John Gruber’s Title Case script:

github.com/mattstevens/sublime-titlecase

Tweaked to add support for ST3 and available through Package Control as “Smart Title Case”.

1 Like