【发布时间】:2014-06-27 14:29:27
【问题描述】:
是否可以在 emacs 中添加自己的字符类以便在正则表达式中使用它们?
假设,我想添加一个类[[:consonant:]],它匹配所有不是元音的字母,以避免一直写[b-df-hj-np-tv-z](是的,我知道我的快捷方式几乎与我想避免的术语,把它作为我的问题的简化)。
这可能吗,还是我必须分别使用format 或concat?如果可以的话,我该怎么做?
MWE 可能是这样的:
(defun myfun ()
"Finds clusters of three or more consonants"
(interactive)
(if (search-forward-regexp "[b-df-hj-np-tv-z]\\{3,\\}")
(message "Yepp, here is a consonant cluster.")
))
(defun myfun-1 ()
"Should also find clusters of three or more consonants."
(interactive)
(if (search-forward-regexp "[[:consonant:]]\\{3,\\}")
(message "Yepp, here is a consonant cluster.")
))
myfun 和 myfun-1 两个函数应该做同样的事情。
更进一步,我想知道是否可以将整个表达式放在这样的“快捷方式”中,例如
[[:ending:]] ==> "\\(?:en\\|st\\|t\\|e\\)"
【问题讨论】: