到目前为止,这是我的 .emacs 中的所有内容:
(when
(load
(expand-file-name "~/.emacs.d/elpa/package.el"))
(package-initialize))
(require 'paredit)
(add-hook 'c++-mode-hook '(lambda () (paredit-mode 1)))
因此,随着 paredit 的设置,我开始在新的 C++ 文件中键入一些代码:(其中 [] 代表光标)
if (someFunc([)]))
现在我不用按右箭头键或类似的键,而是输入右括号,因为它紧挨着左括号,方便多了。
但是,在这样做时,paredit 会换行:
if (someFunc ()
[)]
如何防止 paredit 执行此操作?
最佳答案
升级到最新版本的paredit-mode
。来自评论头here :
;;; The key bindings are designed so that when typing new code in
;;; Paredit Mode, you can generally use exactly the same keystrokes as
;;; you would have used without Paredit Mode. Earlier versions of
;;; paredit.el did not conform to this, because Paredit Mode bound `)'
;;; to a command that would insert a newline. Now `)' is bound to a
;;; command that does not insert a newline, and `M-)' is bound to the
;;; command that inserts a newline.
ELPA 可能已过时。最新版本为 22,可在 http://marmalade-repo.org/ 获取。
另请注意,paredit-mode
旨在与基于 s-exp 的语言(如 lisp 或 scheme)一起使用。它可能不是 C++ 模式的最佳选择。如果您使用 paredit 主要是为了插入匹配的括号而不是 s-exp 快捷方式和导航,您最好使用 electric-pair-mode
。
关于Emacs 在右括号后换行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9041230/