emacs - 如何在 Emacs 中将一个函数重新映射到另一个函数?

标签 emacs coffeescript elisp evil-mode

coffee-mode RET绑定(bind)到 coffee-newline-and-indent效果很好。

我也用 evil-mode有 Vim 仿真。 evil-mode使用标准 newline-and-indent所以缩进对于一些vim命令是不正确的,比如oO .

重新绑定(bind)newline-and-indent 的最佳方法是什么?至coffee-newline-and-indent ?

我仍然是 ELisp 的新手,并尝试了下面的行,但它不起作用。

(add-hook 'coffee-mode-hook
          (lambda () 
            (setq newline-and-indent '(funcall coffee-newline-and-indent))))

最佳答案

这是我的尝试。它应该工作,但我真的不喜欢它。

(add-hook
 'coffee-mode-hook 
 (lambda ()
   (defalias 
       'newline-and-indent 
       (lambda()
         (interactive)
         (if (eq major-mode 'coffee-mode)
             (coffee-newline-and-indent)
           (delete-horizontal-space t)
           (newline)
           (indent-according-to-mode))))))

我希望我可以使用比复制源代码更优雅的东西
newline-and-indent , 但是 make-variable-buffer-local不适用于这种情况,
我无法获得 symbol-function 的深拷贝任何一个。
我很高兴看到更好的方法。

关于emacs - 如何在 Emacs 中将一个函数重新映射到另一个函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18313914/

相关文章:

ruby-on-rails-3 - 如何不封装 Coffeescript

emacs - 评估 .emacs 时未启用词法绑定(bind)

Emacs:在自定义部分之外设置变量时出现问题

javascript - 创建热图时 highcharts 错误 17

emacs - 我怎样才能改进这个 Emacs lisp 功能?

logging - Emacs 口齿不清 : How to use ad-get-arg and ad-get-args?

emacs - 在 Elisp 中调试 "Error setting nil"

javascript - 如何将此 JS 转换为 CoffeeScript?

emacs - eval/从文件加载时如何使emacs默认切换到*scheme*?

Emacs 框架背景颜色和默认面部背景设置相同,但看起来不同 #010101