ParEdit (paredit.el) is a minor mode for performing structured editing of S-expression data. The typical example of this would be Lisp or Scheme source code. ParEdit helps **keep parentheses balanced** and adds many keys for moving S-expressions and moving around in S-expressions. Its behavior can be jarring for those who may want transient periods of unbalanced parentheses, such as when typing parentheses directly or commenting out code line by line. Skeleton like matching paren insertion is a small part of ParEdit’s functionality, its true genius won’t be obvious until you code in some list oriented language. The latest stable version is available at paredit.el. See also the Reference Table, the Release Notes and the Paredit Reference Card (modeled on the older PareditCheatsheet). There is an EmacsRocks episode about ParEdit: http://emacsrocks.com/e14.html A spinoff of ParEdit (by the same author) is also now available in the current CVS version of EdWin, MIT Scheme’s Emacs clone. Type M-x paredit-mode RET to enable it, or add the following code to your .edwin file to enable it automatically in the Scheme mode: SLIME’s REPL has the very annoying habit of grabbing DEL which interferes with paredit’s normal operation. To alleviate this problem use the following code: If RETURN is pressed when the cursor is before a closing paren, the following code will add an extra newline. The extra newlines are re-gathered by paredit-close-round, which ParEdit binds to “)” by default. Here’s a short video demonstration of ParEdit working with ElDoc and Show-Paren minor modes along with the electric RETURN function defined above. There are times when I’m in a list like (a b| c d e f g), and I know that want to barf out everything following point from the current form. Since C-} doesn’t take a prefix argument, there’s really no quick way to do this with the standard paredit.el mode. To solve this problem I’ve written some extreme barfage and slurpage commands, so that C-M-} will do what I described and yield (a b) c d e f g. Evaluate the following after paredit is loaded: It’s currently possible to use delete-indentation (aka join-lines) to pull code up from one line and stick it into the end-of-line comment of another line, invalidating the code. The following replacement for delete-indentation ought to prevent that from happening by always making sure the comment is replaced at the end of the line. I downloaded ParEdit a long time ago, but I did not succeed in using it daily. I have two questions here: On the surface it looks like both ParEdit and skeleton are inserting matching parenthesis. However, a skeleton insertion is the end of the story. Think of a ParEdit insertion is just an indicator to show you the context. You can move past “)” to use it or just completely pretend it’s not there. The insertion is just a side-effect of ParEdit’s true purpose – clarify context while coding. – LeWang 2. How do you delete a parenthesis? I often end up with unbalanced parentheses when coding something (without paredit), and activating ParEdit prevents me from deleting the leading parenthesis. 3. I’m working on a mode for a syntax where m#foo is a legal symbol but otherwise, # comments out the line (like in shell scripts). For some reason, putting (paredit-mode 1) in a run-hook for this mode, or in sh-mode-hook, makes it complain on a line like (foo m#bar) with condition-case: Unmatched bracket or quote. But, if I turn on paredit-mode after doing M-x sh-mode, it works fine, and I can edit around parens just as if they said (foo bar). Anyone know why this happens? 4. I’ll bite. Can anyone tell me what’s going on in the “Short video demonstration” video above? I turn on ParEdit and I don’t get newlines after my parens and I don’t get it showing me what comes next after typing “defun”. If these are other major/minor modes then the caption should be replaced with “Here’s a demonstration of ParEdit playing nice with secret-mode.el and fun-minor-mode-that-were-keeping-secret-from-dale.el. It is implicit by the context, the two features you are seeing are “eldoc” and “electric RET” which has a snippet of code just under the video link for you to try it ? – GlauberPrado 5. Older version of Paredit managed newlines differently to the current beta version. I would like to suggest newline insertion context-based. It should add a newline after, for example, of close the right parenthesis of a last of arguments in defun. Many examples can be thought. I am aware it could be instrusive and some paredit users reject this feature. Although it could be an optional feature. What do you think? Source.