3

到目前为止,这就是我的 .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 这样做?

4

2 回答 2

2

升级到最新版本的paredit-mode. 从这里的评论标题:

;;; 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.

于 2012-01-27T23:24:59.483 回答
1

您可能还想尝试http://autopair.googlecode.com/上提供的自动配对,它与 C/C++ 很好地配合使用,其中 paredit 可能不是最佳选择。

于 2012-01-30T12:25:53.887 回答