Idiomdrottning’s homepage

A paredit pro tip

I realized a few days ago that in Lisp, since most stuff is lower case, you can bind the uppercase letters to stuff, using paredit’s context predicates (like paredit-in-comment-p and paredit-in-string-p) so you can still type normal stuff in comments and strings. So far, I’ve only bound M, W. V and Z (remember that those four are next to each other on Dvorak). It has been so awesome and it’s now the main way I type parens. M when I want to insert a pair, and W when I want to wrap the next sexp. I often enough wanna wrap two or three so that’s V or Z.

Mnemonics: M for Make pair, W for Wrap, a V has two edges, a Z has three. And also the MWVZ 0123 physical location.

If I do need to insert those uppercase characters in a symbol or identifier, I can with C-q.

I was just about to continue the series with PYFGCRL (for Dvorak reasons: it’s also where I have numbers four through zero on Atreus Layer #1) but I realized that that I should hold off on that since I only more rarely wrap that many. (While wrap two is great.)

I hope you come up with something cool for your uppercase paredit stuff.♥

(defmacro define-paredit-wrap (letter number)
  `(defun ,(intern (apply 'concat (list "paredit-wrap-" letter)))
	 (or (paredit-in-string-p) (paredit-in-comment-p))
	 (insert ,(upcase letter))
       (paredit-wrap-round ,number))))

(define-paredit-wrap "m" 0)
(define-paredit-wrap "w" 1)
(define-paredit-wrap "v" 2)
(define-paredit-wrap "z" 3)

(eval-after-load "paredit"
    (define-key paredit-mode-map (kbd "M") 'paredit-wrap-m)
    (define-key paredit-mode-map (kbd "W") 'paredit-wrap-w)
    (define-key paredit-mode-map (kbd "V") 'paredit-wrap-v)
    (define-key paredit-mode-map (kbd "Z") 'paredit-wrap-z)))


First of all, I got so used to it that I was getting annoyed in other modes so I moved my normal open round to layer #1 M. Not quite the same immediacy of shift M but at least the same ballpark.

Second, I bound C-c m to toggle between markdown-mode and scheme-mode, since I often write markdown files that have Scheme code. (It also calls untabify on the whole buffer when I switch. Then I have to markdown-pre-region manually, which I have set to csp on god-mode. I think that’s the default. I usually do this last of all.) Even so, I’m sometimes sloppy and just write a line or two without switching, and I’ve been really rewarded by W, V and Z being so rare in my writing. M on the other hand…

So maybe it should get even better at recognizing context, or I should get better at switching modes or using C-q M, but it’s fine. I’m so much faster at programming now, I’m kinda embarrassing that physically typing parens was holding me back.