2012-01-27 156 views
2

后,到目前为止,这是我在我的.emacs:的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从这样做呢?

回答

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

+0

啊哈谢谢!我尝试了电子对,但他们不会自动删除一对空的大括号。现在我已经拥有了最新的信任,将光标放在关闭的paren上并按下退格键不再将其移回一个字符。我应该如何恢复到旧功能? – wrongusername 2012-01-28 01:08:53

1

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