Hacker News new | past | comments | ask | show | jobs | submit login
The Animated Guide to Emacs Paredit (danmidwood.com)
142 points by 3rd3 on Nov 26, 2014 | hide | past | favorite | 21 comments

I think paredit is one of the best arguments for simple sexp style syntax. It allows you to build easily comprehensible tools that manipulate code on syntactic rather than textual level. Its definitely possible to build the same kind of tools for more complex syntaxes, but its harder for users to understand and use those tools.

You'd also have to rebuild the tools for every new syntax, whereas paredit basically "just works" for every lisp.

It's quite surprising to see something I wrote turn up here.

When I first started with Paredit I struggled to absorb the functions and key bindings from the manual and cheat sheets well enough so that I could use them while writing code. I know that seeing them in action would have helped me a lot, so I made this and put it out there, I really hope that it can help other people to start using more of Paredit.

I'd love to see something like this for smartparens and slime.

Those of you on Mac laptop keyboards may find the following elisp helpful:

    (add-hook 'paredit-mode-hook
              (lambda ()
                (define-key paredit-mode-map (kbd "<prior>") 'paredit-forward-slurp-sexp)
                (define-key paredit-mode-map (kbd "<next>") 'paredit-backward-slurp-sexp)
                (define-key paredit-mode-map (kbd "<home>") 'paredit-backward-barf-sexp)
                (define-key paredit-mode-map (kbd "<end>") 'paredit-forward-barf-sexp)))
This will let your fn key (which if you're clever you've defined as 'hyper', though it doesn't matter here) + arrow keys work for the fundamental paredit commands.

If I had the time and gumption I'd like to make a paredit-game in emacs to help learn/internalize the motions by rote repetition.

If someone else has more time than I do please run with the idea. I'll help test it!

(> smartparens paredit)


I love the animated tutorial, though. Something along those lines would be a great way to augment smartparens' docs.

I've read comparisons between smartparens and paredit, but I haven't found the case for smartparens compelling enough to switch. Are there any features in smartparens that paredit lacks that you feel you can't live with out, or make your life easier?

Good question.

Smartparens is actively maintained, which for me is an attractive "feature" when evaluating any tool that is to find a prominent place in my workflow. Also, its extensible design allows it to be used with languages and data formats other than lisp/scheme dialects, so it has a broader reach than paredit.

As for wrangling sexprs in, say, Clojure, I think paredit and smartparens are one equal footing. I still stand by my original statement inasmuch as I think smartparens is a worthy successor to paredit.

Thanks for the answer. Have you tried paxedit? If so, how does that compare to smartparens?

I have not tried paxedit, but it looks intriguing and I will give it a spin at some point.

Have you tried it? If so, what do you think of it with respect to paredit?

I haven't yet, but I intend to when I get some time. I was hoping to find someone else to give me an opinion on how it compared to paredit and smartparens, before I tried it out :)

Smartparens will work with xml tags and more.

(I still use paredit for lisp languages though, and I can't remember if there was a reason for that or it's just inertia/conservatism).

add lispy.el to the list


time for a new standard ? #927

https://github.com/magnars/expand-region.el is a nice addition, especially for non-sexp languages. It's like Mathematica's "C-."

I've been using paredit with my clojure for a while now and I really love it. But how do I get those multi coloured matched brackets? I've seen them on others screenshots too, but I don't know which mode enables them in my emacs.

Also, I've found with paredit that it keeps the brackets balanced until I paste in a segment of lisp with unmatched brackets. Then it gets in a bind and I need to either disable paredit to manually fix it, or go into overwrite mode to fix it. Is there any graceful way to deal with bad bracket-unmatched code pasting in paredit?

It's called rainbow delimiters and I use it with everything.


As for the unbalanced delimiters, I just M-x paredit-mode, turn it off, make my fixes (which is easy because rainbow delimiters shows me exactly which delimiter is out of place), and then turn it back on again.

An easier way to deal with unbalanced delimiters without toggling paredit-mode is to use C-q, quoted-insert. C-q ) inserts a literal ) where regular ) is bound to paredit-close-round.

Quoted insert is generally useful when you want to enter a specific character that is bound to something other than self-insert, such as a literal newline in a regex pattern.

Yep, C-q is also useful when you need to comment out part of a multiline sexp without doing a block select and C-; Otherwise paredit will helpfully move the comment to a newline to avoid breaking the balance ;)


For the bonus, paredit-convolute-sexp is useful exactly for the case they show, moving a binding/wrapping form some levels up. It saves a lot of keystrokes when you're in that situation.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact