Bob Glickstein在“编写GNU Emacs扩展”的第3章中描述了一种建议滚动功能的方法。(他建议使它们可逆,因此我们必须在滚动之前保存状态。)
例如,对于scroll-up-command,该建议如下所示
(defadvice scroll-up-command (before reversibilate activate compile)
"If it wants to be reversible, it must save the former state."
(save-before-scroll))井。当然,我必须对所有的scroll命令执行此操作。所以我想对它们做一个序列,并一起给出建议。
(setq reversible-scroll-commands
[scroll-up-command
scroll-down-command
scroll-left-command
scroll-right-command])(我使用一个向量来保存5个引用。)
但现在我被卡住了。
(mapcar
(lambda (fun-name)
(defadvice fun-name (before reversibilate activate compile)
"If it wants to be reversible, it must save the former state."
(save-before-scroll)))
reversible-scroll-commands)将建议(不存在的)函数fun-name四次,因为是一个宏,并且不会计算fun-name。
有什么办法可以做到吗?
(我使用的是Emacs 24)
发布于 2012-07-05 17:03:33
未经测试:
(mapcar
(lambda (fun-name)
(eval `(defadvice ,fun-name (before reversibilate activate compile)
"If it wants to be reversible, it must save the former state."
(save-before-scroll))))
reversible-scroll-commands)请参阅elisp手册中的section about backquotes。
https://stackoverflow.com/questions/11341000
复制相似问题