Idiomdrottning’s homepage

A paredit pro tip

I realized a while 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. V wraps the next two sexps, and Z wraps the next million sexps (which is great since it only wraps sexps within the containing sexp or body, so it means “wrap all the way to the end of what I’m in”).

Mnemonics: M for Make pair, W for Wrap, a V has two edges, Z is the ultimate last letter. 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 hope you come up with something cool for your uppercase paredit stuff.♥︎

I work by wrapping and raising and with these, it’s so easy to just wrap something and type what I need in front of it. If I wanna type something after, I have that bound to “.” (yeah, I have to C-q . when working with dotted pairs).

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

(define-paredit-wrap "m" 0 "round")
(define-paredit-wrap "w" 1 "round")
(define-paredit-wrap "v" 2 "round")
(define-paredit-wrap "z" 1000000 "round")
(define-paredit-wrap "f" 0 "curly")
(define-paredit-wrap "c" 1 "curly")
(define-paredit-wrap "r" 2 "curly")
(define-paredit-wrap "l" 1000000 "curly")
(define-paredit-wrap "h" 0 "square")
(define-paredit-wrap "t" 1 "square")
(define-paredit-wrap "n" 2 "square")
(define-paredit-wrap "s" 1000000 "square")

(defun paredit-insert-after ()
  (interactive)
  (when (and (or (char-equal ?\) (following-char))
                 (char-equal ?\n (following-char)))
             (char-equal ?\s (preceding-char)))
    (paredit-backward-delete))
  (paredit-forward)
  (when (char-equal ?\s (following-char)) (forward-char))
  (unless (char-equal ?\s (preceding-char)) (insert " "))
  (incarnate))

(defun unincarnate ()
  (interactive)
  (incarnate-mode -1)
  (god-mode))

(defun incarnate ()
  (interactive)
  (when (bound-and-true-p god-local-mode)
    (god-mode)
    (incarnate-mode)))

(define-minor-mode incarnate-mode
  "As normal but toggle to God mode on RET"
  :lighter " God-Inc"
  :keymap '(("\r" . unincarnate)))