Emacs,更改默认的 reftex 引用
我想在使用 reftex 时修改 emacs 的行为,以便在按“抄送 [”并选择引用格式后,出现的默认正则表达式将为我提供上次使用的引用(正常行为是默认到光标之前的单词,这很少有任何用处)。我经常连续多次引用相同的来源,特别是在一张纸上做笔记时,所以这将是节省几次击键的好方法,这就是我们使用 emacs 的目的,对吧:)
我知道有点口齿不清,所以我希望最终我自己能找到一种方法来做到这一点,但我认为值得四处询问,看看是否有人先做到了,没有必要重新发明轮子。 (如果您确实想要此功能,但也不知道如何实现它,请告诉我,我完成后会给您发送电子邮件。)
谢谢
I'd like to modify emacs' behaviour when using reftex, so that after pressing 'C-c [' and choosing a citation format the default regex that comes up is one that will give me the citation I used last (the normal behaviour is to default to the word before the cursor, which is rarely of any use). I often cite the same source many times in a row, particularly when making notes on a single paper, so this would be a nice way to save a few keystrokes, and that's what we're all using emacs for, right :)
I know a little lisp, so I expect I'll end up working out a way to do this myself eventually, but I thought it'd be worth asking around to see if anyone else has done it first, no point re-inventing the wheel. (If you do want this feature, but also don't know how to achieve it, let me know and I'll drop you an email when I've done it.)
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
加载 reftex 后(例如在 AUCTeX 模式挂钩中)重新定义 reftex-get-bibkey-default 应该可以做到。最简单的是:
但是,这将破坏默认行为,并且如果您的历史记录为空,则不会返回任何内容,为了在这种情况下保留 reftex 中的“前一个单词”行为,然后使用历史记录,您可以重新定义是这样的:
redifining
reftex-get-bibkey-default
after you have loaded reftex (e.g. in your AUCTeX mode hook) should do it. The simplest would thus be:However, this will destroy the default behaviour and wouldn't return anything if your history is empty, to keep the "previous word at point" behaviour from reftex in that case and then use the history, you can redefine it this way:
(警告:这是我写的第一个 elisp 代码,长度超过 3 行,它可能是糟糕的代码。但它似乎有效。但是任何关于风格或最佳实践的评论将不胜感激。)
我'我已经解决了!只需将以下代码添加到 .emacs 中,它的行为就完全符合我的希望。如果您之前没有引用过任何内容,那么它会表现正常,否则默认引用是最后使用的。
感谢莫蒂默的帮助,没有你的起点我永远不会到达这里!
(只是想知道,您的解决方案是否有任何原因不使用
defadvice
?正如我上面暗示的那样,elisp 对我来说都是非常新的,所以了解最好的方法会很有用事物。)(WARNING: This is the first elisp code I've ever written which is more than 3 lines long, it could be terrible code. But it seems to work. But any comments on style or best practices would be most appreciated.)
I've worked it out! Just add the following code to .emacs it behaves exactly as I'd hoped. If you've not cited anything before then it behaves as normal, otherwise the default citation is the last used.
Thanks for the help Mortimer, without your starting point I'd never had got here!
(Just wondering, is there any reason why your solution didn't use
defadvice
? As I implied above, elisp is all very new to me, so it'd be useful to know the best way of doing things.)