Emacs在关闭括号后放置换行符

时间:2012-01-27 23:03:13

标签: emacs paredit

到目前为止,这是我在.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([)]))

现在我不是按右箭头键或类似的东西,而是进入正确的paren,因为它位于左侧的旁边,更方便。

但是,在这样做时,paredit会换行:

if (someFunc ()
             [)]

如何防止paredit这样做?

2 个答案:

答案 0 :(得分:2)

升级到最新版本的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可能会更好。

答案 1 :(得分:1)

您可能还想尝试在http://autopair.googlecode.com/上使用的autopair,它可以很好地与C / C ++一起使用,其中paredit可能不是最佳选择。

相关问题