質問

So far this is all I have in my .emacs:

(when
    (load
     (expand-file-name "~/.emacs.d/elpa/package.el"))
  (package-initialize))

(require 'paredit)

(add-hook 'c++-mode-hook '(lambda () (paredit-mode 1)))

And so with paredit set up, I start typing some code in a new C++ file: (where the [] represents the cursor)

if (someFunc([)]))

Now instead of pressing the right arrow key or something similar, I usually enter in the right paren since it is located right next to the left paren and is a lot more convenient.

However, upon doing that, paredit makes a newline:

if (someFunc ()
             [)]

How do I prevent paredit from doing this?

役に立ちましたか?

解決

Upgrade to a recent version of paredit-mode. From the comment header 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 may be out of date. The latest version is 22, and is available at http://marmalade-repo.org/

Also note that paredit-mode is designed to work with s-exp based languages like lisp or scheme. It might not be the best choice for C++ mode. If you're using paredit mainly to insert matching parentheses rather than the s-exp shortcuts and navigation, you might be better off with electric-pair-mode.

他のヒント

You might also want to try autopair available at http://autopair.googlecode.com/ which works nicely with C/C++, where paredit might not be the best choice.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top