ess-mode
是“Emacs speaks statistics”的缩写。这个模式适用于编辑R或Splus(两个不同的统计软件包)的程序。
当我在我的缓冲区中键入_
时,字符将被替换为<-
,这非常令人沮丧。是否有一个emacs lisp语句可以关闭这种行为?
emacs: 22.1.1 ess-mode版本(未知)
来自 ESS 手册(查看“5.2.0 中的更改/新功能”):
ESS[S]: 按下下划线 ("_") 一次会插入 " <- "(与以前相同);按下两次会插入一个下划线。要停止此智能行为,请在加载 ess-site 后将 "(ess-toggle-underscore nil)" 添加到您的 .emacs 文件中。
(require 'ess-site)
应该在 (ess-toggle-underscore nil)
之前。 - jthetzel由于这个功能很实用,你可以将它分配给在R中不经常使用的其他按键,它会自动从下划线中解除分配。我个人将其分配给";"
,只需在.emacs文件中添加以下行。
(setq ess-smart-S-assign-key ";")
我的emacs版本是由Vincent Goulet提供的24.3全套安装文件(安装在Windows 7上)。
希望这可以帮到您。
编辑 在emacs 25.2以上版本中不起作用,而是需要在.emacs文件中添加以下内容。
(setq ess-smart-S-assign-key ";")
(ess-toggle-S-assign nil)
(ess-toggle-S-assign nil)
*-smart-*
变量/函数已被弃用/删除,现在有ess-insert-S-assign
和可选的ess-cycle-assignment
。 - r2evans将 ":" 赋值为 "<-",并停止将下划线(underbar)"_"分配给"<-",请在 .emacs 中输入以下内容(是的,重复的行是正确的):
来自 http://www.r-bloggers.com/a-small-customization-of-ess/ 和 How to change smart assign key ("_" to "<-") binding in ESS
(setq ess-smart-S-assign-key ":")
(ess-toggle-S-assign nil)
(ess-toggle-S-assign nil)
(ess-toggle-underscore nil) ; leave underscore key alone!
一个相对较新的版本,对我来说似乎有效,并且更简洁(您基本上保留普通下划线,但可以设置自己的键以获得这种智能行为!):
(global-set-key (kbd "C-;") (lambda () (interactive) (insert " <- ")))
(ess-toggle-underscore nil)
请用您选择的快捷键替换C-;
。
像 Michał Marczyk 和 这个 R 邮件列表主题 建议的那样,在 ~/.emacs
中添加这行代码:
(ess-toggle-underscore nil)
然后使用 M-x load-file
命令重新加载它,并输入 ~/.emacs
。
但是,如果您再次加载文件,例如添加其他自定义设置,它会切换回原始状态。因此需要切换两次,第一次将其强制恢复到默认状态:
(ess-toggle-underscore t)
(ess-toggle-underscore nil)
话虽如此,我更喜欢Drummermean的解决方案,但是如果您将其添加到~/.emacs
并加载两次,则它也会恢复为默认值。因此,在之前强制切换回默认值:
(ess-toggle-underscore t)
(global-set-key (kbd "M--") (lambda () (interactive) (insert " <- ")))
(ess-toggle-underscore nil)
我将智能分配绑定到Opt-[minus]
,就像在Mac上的RStudio
一样。
.emacs
文件中。(ess-toggle-underscore t)
(ess-toggle-underscore nil)
(define-key ess-mode-map (kbd "M--") (lambda () (interactive) (just-one-space 1) (insert "<-") (just-one-space 1)))
(define-key inferior-ess-mode-map (kbd "M--") (lambda () (interactive) (just-one-space 1) (insert "<-") (just-one-space 1)))
underscore_case
)(参见https://journal.r-project.org/archive/2012/RJ-2012-018/RJ-2012-018.pdf),那将会相当令人烦恼。 - Dave X