Emacs Paredit Notes for OSX

Some notes on Emacs’ Paredit mode. More so I can stop fighting with Paredit and do some Clojure programming than show any expertise – see Mudphone’s Paredit Preso for the real deal, as well as hagelb’s Paredit screencast notes and the Paredit Cheat Sheet.

  • M-(  wrap parens around something. Also for { [ “
  • M-s  remove parens from something
  • M-S-s  split sexpr into two
  • M-S-j  join sexprs
  • C-q ♦  just do what I say, dammit! force insert of paren or bracket ♦
  • C-u DEL  force delete paren or bracket

“Barfage and slurpage” ie moving parens left and right.  I had some trouble getting this going on OSX, as the terminal doesn’t seem to map control key sequences correctly. After modifying emacs (see below), I got these going:

  • C-<right>, C-<left>  move right paren right or left
  • ESC C-<right>, ESC C-<left> move left paren right or left

I wrote this elisp for my ~/.emacs.d/sonia.el (I’m using Technomancy’s Emacs Starter Kit):

(when (eq system-type 'darwin)
  (eval-after-load 'paredit
    '(progn
       ;; C-left
       (define-key paredit-mode-map (kbd "M-[ 5 d")
                   'paredit-forward-barf-sexp)
       ;; C-right
       (define-key paredit-mode-map (kbd "M-[ 5 c")
                   'paredit-forward-slurp-sexp)
       ;; ESC-C-left
       (define-key paredit-mode-map (kbd "ESC M-[ 5 d")
                   'paredit-backward-slurp-sexp)
       ;; ESC-C-right
       (define-key paredit-mode-map (kbd "ESC M-[ 5 c")
                   'paredit-backward-barf-sexp)
     )))

Lisp Parens

Tags: ,


Share This


 


7 Responses to Emacs Paredit Notes for OSX

  1. nice,
    on my system I needed to take the global assignments of c-> c-< out the system/preferences/keyboard….
    funny I am reading exactly the same lisp /clojure books at approximately the same time…..

    • You’re welcome! Clojure/Lisp is great once you get your head around it; many book to go… Are you doing the 4clojure or Euler problems? A good way to practice.

      • I will be doing some 4clojure tomorrow. we are tying to start a clojure group in my town and tomorrow we are having a coding dojo where we intend to pick some 4clojure problems and try to solve them…

        • Cool, nice. The only way I ever learn a language is by writing code in it; I love the idea of “Code Katas” as they usually give a graduated approach to learning the language.

  2. […] their it was just a matter of balancing parentheses (thanks paredit) by breaking up the problem into stages, starting with calculating the GCD of two […]

  3. Hi – just stumbled on this trying to figure out why half of my paredit keysequences were not working! Thanks for your help!

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>