;;; pp.el --- pretty printer for Emacs Lisp
-;; Copyright (C) 1989, 1993, 2001-2011 Free Software Foundation, Inc.
+;; Copyright (C) 1989, 1993, 2001-2015 Free Software Foundation, Inc.
;; Author: Randal Schwartz <merlyn@stonehenge.com>
;; Keywords: lisp
"Return a string containing the pretty-printed representation of OBJECT.
OBJECT can be any Lisp object. Quoting characters are used as needed
to make output that `read' can handle, whenever this is possible."
- (with-current-buffer (generate-new-buffer " pp-to-string")
- (unwind-protect
- (progn
- (lisp-mode-variables nil)
- (set-syntax-table emacs-lisp-mode-syntax-table)
- (let ((print-escape-newlines pp-escape-newlines)
- (print-quoted t))
- (prin1 object (current-buffer)))
- (pp-buffer)
- (buffer-string))
- (kill-buffer (current-buffer)))))
+ (with-temp-buffer
+ (lisp-mode-variables nil)
+ (set-syntax-table emacs-lisp-mode-syntax-table)
+ (let ((print-escape-newlines pp-escape-newlines)
+ (print-quoted t))
+ (prin1 object (current-buffer)))
+ (pp-buffer)
+ (buffer-string)))
;;;###autoload
(defun pp-buffer ()
(while (not (eobp))
;; (message "%06d" (- (point-max) (point)))
(cond
- ((condition-case err-var
- (prog1 t (down-list 1))
- (error nil))
+ ((ignore-errors (down-list 1) t)
(save-excursion
(backward-char 1)
(skip-chars-backward "'`#^")
(point)
(progn (skip-chars-backward " \t\n") (point)))
(insert "\n"))))
- ((condition-case err-var
- (prog1 t (up-list 1))
- (error nil))
- (while (looking-at "\\s)")
+ ((ignore-errors (up-list 1) t)
+ (while (looking-at-p "\\s)")
(forward-char 1))
(delete-region
(point)
(progn
(select-window window)
(run-hooks 'temp-buffer-show-hook))
- (select-window old-selected)
+ (when (window-live-p old-selected)
+ (select-window old-selected))
(message "See buffer %s." out-buffer-name)))
(message "%s" (buffer-substring (point-min) (point)))
))))))
"Evaluate EXPRESSION and pretty-print its value.
Also add the value to the front of the list in the variable `values'."
(interactive
- (list (read-from-minibuffer "Eval: " nil read-expression-map t
- 'read-expression-history)))
+ (list (read--expression "Eval: ")))
(message "Evaluating...")
- (setq values (cons (eval expression) values))
+ (setq values (cons (eval expression lexical-binding) values))
(pp-display-expression (car values) "*Pp Eval Output*"))
;;;###autoload
(defun pp-macroexpand-expression (expression)
"Macroexpand EXPRESSION and pretty-print its value."
(interactive
- (list (read-from-minibuffer "Macroexpand: " nil read-expression-map t
- 'read-expression-history)))
- (pp-display-expression (macroexpand expression) "*Pp Macroexpand Output*"))
+ (list (read--expression "Macroexpand: ")))
+ (pp-display-expression (macroexpand-1 expression) "*Pp Macroexpand Output*"))
(defun pp-last-sexp ()
"Read sexp before point. Ignores leading comment characters."
(save-excursion
(forward-sexp -1)
;; If first line is commented, ignore all leading comments:
- (if (save-excursion (beginning-of-line) (looking-at "[ \t]*;"))
+ (if (save-excursion (beginning-of-line) (looking-at-p "[ \t]*;"))
(progn
(setq exp (buffer-substring (point) pt))
(while (string-match "\n[ \t]*;+" exp start)
Ignores leading comment characters."
(interactive "P")
(if arg
- (insert (pp-to-string (eval (pp-last-sexp))))
+ (insert (pp-to-string (eval (pp-last-sexp) lexical-binding)))
(pp-eval-expression (pp-last-sexp))))
;;;###autoload
Ignores leading comment characters."
(interactive "P")
(if arg
- (insert (pp-to-string (macroexpand (pp-last-sexp))))
+ (insert (pp-to-string (macroexpand-1 (pp-last-sexp))))
(pp-macroexpand-expression (pp-last-sexp))))
;;; Test cases for quote