如何阻止 emacs 在 ess 模式下用 <- 替换下划线

发布于 2024-08-27 05:09:04 字数 212 浏览 7 评论 0 原文

ess-mode 是“Emacs 讲统计”。此模式对于编辑 R 或 Splus(两个独立的统计包)程序非常有用。

在我的缓冲区中,每当我输入 _ 时,字符就会被 <- 替换,这非常令人沮丧。是否有 emacs lisp 语句可以关闭此行为?

emacs:22.1.1 ess 模式发布(未知)

ess-mode is "Emacs speaks statistics." This mode is useful for editing programs for R or Splus (two separate statistics packages).

In my buffer, when ever I type _ the character is replaced with <-, which is very frustrating. Is there an emacs lisp statement to turn off this behavior?

emacs: 22.1.1
ess-mode release (unknown)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

空袭的梦i 2024-09-03 05:09:04

来自 ESS 手册(查看“5.2.0 中的更改/新功能”) :

ESS[S]:按下划线(“_”)一次插入“ <- ”(如前);按下划线两次会插入文字下划线。要停止这种智能行为,请在加载 ess-site 后将“(ess-toggle-underscore nil)”添加到您的 .emacs

From ESS's manual (look under "Changes/New Features in 5.2.0"):

ESS[S]: Pressing underscore ("_") once inserts " <- " (as before); pressing underscore twice inserts a literal underscore. To stop this smart behaviour, add "(ess-toggle-underscore nil)" to your .emacs after ess-site has been loaded

海风掠过北极光 2024-09-03 05:09:04

因为这个功能很有用。您可以将其分配给您在 R 中较少使用的其他键,它会自动从下划线中取消分配它。我个人通过在 .emacs 文件中添加以下行将其分配给 ";"

(setq ess-smart-S-assign-key ";")

我的 emacs 版本是 24.3 Vincent Goulet 的一体化安装文件。(安装在 Windows 7 上)

希望这有助于

编辑
在 emacs 25.2 上面不起作用,而是在 .emacs 文件中添加以下内容

(setq ess-smart-S-assign-key ";")
(ess-toggle-S-assign nil)
(ess-toggle-S-assign nil)

Since the feature is useful. You can assign it to other key which is less used by you in R it will automatically unassign it from underscore. I personally assign it to ";" by adding following line in .emacs file.

(setq ess-smart-S-assign-key ";")

My version of emacs is 24.3 All-in-one installation file by Vincent Goulet.(Installed on windows 7)

hope this helps

Edit
In emacs 25.2 above do not work instead add following in the .emacs file

(setq ess-smart-S-assign-key ";")
(ess-toggle-S-assign nil)
(ess-toggle-S-assign nil)
鸠书 2024-09-03 05:09:04

一个更新的版本似乎对我有用,并且不那么冗长(您基本上保留正常的下划线,但可以为这种智能行为设置自己的密钥!):

(global-set-key (kbd "C-;")  (lambda () (interactive) (insert " <- ")))
(ess-toggle-underscore nil)

插入您的快捷键选择而不是 C-;< /代码>。

A more recent version which seemed to work for me, and is a lot less verbose (you essentially keep normal underscores, but can set your own key for this smart behaviour!):

(global-set-key (kbd "C-;")  (lambda () (interactive) (insert " <- ")))
(ess-toggle-underscore nil)

Insert your shortkey choice instead of C-;.

心不设防 2024-09-03 05:09:04

来自 http://www.r-bloggers.com/a- Small-customization-of-ess/
如何将智能分配键(“_”更改为“ <-") ESS 中的绑定

要将“:”分配给“<-”并停止将下划线“_”分配给“<-”,请将以下内容放入 .emacs 中(是) ,重复的行是正确的)

(setq ess-smart-S-assign-key ":")
(ess-toggle-S-assign nil)
(ess-toggle-S-assign nil)
(ess-toggle-underscore nil) ; leave underscore key alone!

From http://www.r-bloggers.com/a-small-customization-of-ess/ and
How to change smart assign key ("_" to "<-") binding in ESS

To assign ":" to "<-" and to stop the assignment of underscore (underbar) "_" to "<-" put the following in .emacs (yes, the repeated line is correct)

(setq ess-smart-S-assign-key ":")
(ess-toggle-S-assign nil)
(ess-toggle-S-assign nil)
(ess-toggle-underscore nil) ; leave underscore key alone!
相权↑美人 2024-09-03 05:09:04

就像 Michał Marczyk 和这个 R 邮件列表线程 建议,将此行添加到 ~/.emacs

(ess-toggle-underscore nil)

然后使用 Mx 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],就像 RStudio(在 Mac 上)一样。

Like Michał Marczyk and this R mailing list thread suggested, add this line to ~/.emacs:

(ess-toggle-underscore nil)

Then reload it with M-x load-file and type ~/.emacs.

But if you load the file again, e.g. if you add another customization, then it toggles it back to the original state. So toggle it twice, the first one forcing it to the default:

(ess-toggle-underscore t)
(ess-toggle-underscore nil)

That being said, I like Drummermean's solution better, but it also reverts back to default if you add it to ~/.emacs and load it twice. So force a toggle to the default before:

(ess-toggle-underscore t)
(global-set-key (kbd "M--")  (lambda () (interactive) (insert " <- ")))
(ess-toggle-underscore nil)

I bound the smart assignment to Opt-[minus] like RStudio (on a Mac).

沉溺在你眼里的海 2024-09-03 05:09:04

作为 @mmorin 答案的后续。要以与 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)))

As a follow-up on @mmorin answer. To set keybinding for the assignment operator the same way as in Rstudio add the following in your .emacs file

(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)))

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文