How to use English string in Emacs

I am wondering what people use to use English strings correctly, since "capizeize" will not do the job:

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

Although writing this function is trivial, I wonder if there is a preferred built-in way to do this.

+6
string emacs elisp
source share
4 answers

Perhaps if you temporarily add ' to the current syntax table of the component words:

 (modify-syntax-entry ?' "w") (capitalize "can't") => "Can't" 
+8
source share

I have a Mc associated with a headword, and it works for proper use can't .

+5
source share

Current answers are good, but if you work with strings in your code, you can use the s string manipulation library. s-capitalize capitalization of the first word in a sentence.

 ELISP> (s-capitalize "can't win the war on drugs in a prison, where the hell you gonna win it?") "Can't win the war on drugs in a prison, where the hell you gonna win it?" ELISP> (s-join " " (-map 's-capitalize (s-split " " "can't win the war on drugs in a prison, where the hell you gonna win it?"))) "Can't Win The War On Drugs In A Prison, Where The Hell You Gonna Win It?" 

s-titleize capital letters of each word in the string, but it is a simple wrapper around the built-in capitalize , so Karl Voigtland is used .

 ELISP> (s-titleize "Girl, you can't even think of calling this shit a war.") "Girl, You Can'T Even Think Of Calling This Shit A War." ELISP> (progn (modify-syntax-entry ?' "w") (s-titleize "Girl, you can't even think of calling this shit a war.")) "Girl, You Can't Even Think Of Calling This Shit A War." 
+1
source share

The behavior depends, of course, on the syntax table used, i.e. Depends on the main mode. If the character ' has the syntax "wp" , it should work correctly. This happens in text mode, but not in most programming modes.

+1
source share

All Articles