简体   繁体   English

如何在Emacs中大写英文字符串

[英]How to capitalize english string in Emacs

I'm wondering what's people using to correctly capitalize english strings since ''capitalize'' won't do the job: 我想知道人们使用什么来正确地大写英文字符串,因为“ capitalize”将无法完成工作:

(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. 尽管编写此函数很简单,但我想知道是否存在一种首选的内置方法来实现。

Maybe if you temporarily add ' to the current word constituent syntax table: 也许如果您暂时将'添加到当前单词构成语法表中:

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

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

我有Mc一定要大写单词,并且它can't正确地大写。

Current answers are fine, but if you work with strings in code, you can use s string manipulation library. 当前的答案很好,但是如果您在代码中使用字符串,则可以使用s字符串操作库。 s-capitalize capitalizes the first word in a sentence. s-capitalize将句子中的第一个单词大写。

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 capitalizes every word in a string, but it's a simple wrapper around built-in capitalize , therefore Karl Voigtland's workaround applies. s-titleize将字符串中的每个单词s-titleize大写,但这是对内置capitalize的简单包装,因此适用了Karl Voigtland的变通方法

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."

The behavior depends of course on the syntax-table in use, ie depends on the major-mode. 该行为当然取决于所使用的语法表,即取决于主模式。 If the ' character has the "wp" syntax, then it should work correctly. 如果'字符具有"wp"语法,则它应该可以正常工作。 This is the case in text-mode, but not in most programming modes. 在文本模式下就是这种情况,但在大多数编程模式下并非如此。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM