问题描述
我找到了此邮件列表消息关于多词缩写,但是仍然无法扩展工作.
I found this mailing list message about multi-word abbreviations, butstill can't get expansion to work.
我定义了以下两个缩写:
I have these two abbreviations defined:
"agw" 0 "a great whale"
"a g w" 0 "a great whale"
在"agw"起作用后按空格,而不是"a g w".但是如果我打电话(缩写扩展"a g w")
,然后返回正确的扩展.
pressing space after "agw" works, but not "a g w". However if I call(abbrev-expansion "a g w")
, then the correct expansion is returned.
问题是如何使Emacs向后搜索超出一个单词边界?
The question is how to get Emacs to search beyond one word boundary backwards?
是的,yasnippet存在,我可以使用它,但是缩写更加无缝(例如,按"1/2"后的空格将其变成unicode的一半).我也不想改变语法表.
Yes, yasnippet exists and I use it, but abbrev is more seamless (e.g. pressspace after "1/2" turns it into unicode half). I also don't want to changethe syntax table.
推荐答案
如安德里亚斯(Andreas)所述,它不起作用,因为默认情况下,缩写仅在由单词构成"和"组成的字符组成的情况下才起作用单词组成.您可以为给定的表更改此规则,例如使用(abbrev-table-put< table>:regexp< regexp>)
之类的正则表达式,例如"\\< \\(\\ w +:?\\)\\ W *"
几乎可以重现默认行为.
As explained by Andreas, it does not work because by default abbrevs only work if they are made up of chars that are "word constituent" and " " is not a word constituent. You can change this rule, tho, for a given table, with something like (abbrev-table-put <table> :regexp <regexp>)
where a regexp like "\\<\\(\\w+:?\\)\\W*"
would pretty much reproduce the default behavior.
现在就您的情况而言,您需要一个正则表达式,该正则表达式将匹配"agw"和"agw",但请注意,它不应该与"dawg"的"agw"匹配,也不应该与"ag agw"匹配,这使得有点棘手.一种方法是将正则表达式定义为(concat"\\<"(regexp-opt'("agw""agw"))"\\ W *")
,即这样做很简单,但缺点是,每次添加缩写时都需要更改正则表达式.
Now for your case, you want a regexp that will match "a g w" and "agw" but note that it shouldn't match the "agw" of "dawg" and neither should it match "a g agw", which makes it a bit tricky. One way to do that is to define your regexp as (concat "\\<" (regexp-opt '("agw" "a g w")) "\\W*")
, which is fairly simple to do but has the downside that it requires changing the regexp any time you add an abbrev.
这篇关于多词缩写扩展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!