Skip to content

Instantly share code, notes, and snippets.

@nicferrier
Created August 18, 2012 15:06
Show Gist options
  • Save nicferrier/3387334 to your computer and use it in GitHub Desktop.
Save nicferrier/3387334 to your computer and use it in GitHub Desktop.
(defun lisp-reinsert-as-pp ()
"Read sexp at point, delete it and pretty print it back in."
(interactive)
(let* ((buf (current-buffer))
(pp-sexp
(replace-regexp-in-string
"\\(\n\\)$"
""
(with-temp-buffer
(let ((bufname (buffer-name)))
(pp-display-expression
(with-current-buffer buf
(car
(read-from-string
(replace-regexp-in-string
"\\*\\(.*?\\)\\*\\(<[0-9]+>\\)* <[0-9:.]+>"
"\"\\&\""
(save-excursion
(buffer-substring-no-properties
(point)
(progn
(forward-sexp)
(point))))))))
bufname)
(buffer-substring (point-min) (point-max)))))))
(kill-sexp)
(insert pp-sexp)))
@vic
Copy link

vic commented Aug 18, 2012

nice :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment