Merge from emacs-24; up to 2012-12-19T13:01:16Z!michael.albinus@gmx.de
[bpt/emacs.git] / lisp / emacs-lisp / pp.el
index 2d1b886..b7e5532 100644 (file)
@@ -1,6 +1,6 @@
 ;;; pp.el --- pretty printer for Emacs Lisp
 
-;; Copyright (C) 1989, 1993, 2001-2011 Free Software Foundation, Inc.
+;; Copyright (C) 1989, 1993, 2001-2013 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 ()
@@ -60,9 +57,7 @@ to make output that `read' can handle, whenever this is possible."
   (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 "'`#^")
@@ -71,10 +66,8 @@ to make output that `read' can handle, whenever this is possible."
            (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)
@@ -117,7 +110,8 @@ after OUT-BUFFER-NAME."
                         (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)))
                 ))))))
@@ -154,7 +148,7 @@ Also add the value to the front of the list in the variable `values'."
     (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)