views:

156

answers:

2

I'm wondering what's people using to correctly capitalize english strings since ''capitalize'' won't do the job:

(capitalize "can't")
=> "Can'T"

Although writing this function is trivial, I'm wondering if there's a preferred built-in way to do it.

+7  A: 

Maybe if you temporarily add ' to the current word constituent syntax table:

(modify-syntax-entry ?' "w")

(capitalize "can't")
=> "Can't"
Karl Voigtland
+1, one caution with this however: (capitalize "this is a 'test'") "This Is A 'test'"
cobbal
+4  A: 

I have M-c bound to capitalize-word, and it works to capitalize can't correctly.

Cheeso
capitalize-word works because it sees "can't" as two words, can and t. This is why originally said strings instead of words. With capitalize-word I'd have to loop over all the words in the string and it'd end up capitilizng the "t"s.
Federico Builes
Nope, that's not right. capitalize-word sees can't as a single word. It does not capitalize the t. But it is an interactive function that capitalizes the following word (or N awords) in the current buffer. It is not a function that applies to the passed string. So it wouldn't work for you, anyway.
Cheeso
I thought the same thing but if you run `M-2 M-x capitalize-word` on "can't" you'll get "Can'T". So, it does see "can't" as two words.
seth
just did this twice. In a text file, it works as I described, treating can't as a single word. When the word "can't" appears in a comment inside a C-Sharp file, it works as *you* described, treating can't as 2 words.
Cheeso