Skip to content

Instantly share code, notes, and snippets.

@valpackett
Created November 7, 2010 14:55
Show Gist options
  • Save valpackett/666161 to your computer and use it in GitHub Desktop.
Save valpackett/666161 to your computer and use it in GitHub Desktop.
Coda-like swapping in Emacs
(defun coda-swap (expr)
(interactive "sExpr: ")
(query-replace-regexp
(replace-regexp-in-string "$[1-2]" "\\\\([0-9a-zA-Z]*\\\\)" expr)
(replace-regexp-in-string "$[1-2]" (lambda (m) (if (equal m "$1") "\\\\2" "\\\\1")) expr)))
;; Example:
; enter
; width="$1" height="$2"
; and it will replace
; width="240" height="320"
; with
; width="320" height="240"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment