changeset 55802:7bb617df33db

(pp-buffer): New fun created from the code in `pp-to-string' modified to be able to format text with newlines. (pp-to-string): Move the buffer-formatting part of the code to `pp-buffer'. Call `pp-buffer'.
author Juri Linkov <juri@jurta.org>
date Fri, 28 May 2004 21:05:17 +0000
parents 6fe3d9ff80b9
children 9070d5f984ea
files lisp/emacs-lisp/pp.el
diffstat 1 files changed, 31 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/emacs-lisp/pp.el	Fri May 28 21:04:52 2004 +0000
+++ b/lisp/emacs-lisp/pp.el	Fri May 28 21:05:17 2004 +0000
@@ -50,34 +50,40 @@
 	  (let ((print-escape-newlines pp-escape-newlines)
 		(print-quoted t))
 	    (prin1 object (current-buffer)))
-	  (goto-char (point-min))
-	  (while (not (eobp))
-	    ;; (message "%06d" (- (point-max) (point)))
-	    (cond
-	     ((condition-case err-var
-		  (prog1 t (down-list 1))
-		(error nil))
-	      (save-excursion
-		(backward-char 1)
-		(skip-chars-backward "'`#^")
-		(when (and (not (bobp)) (= ?\ (char-before)))
-		  (delete-char -1)
-		  (insert "\n"))))
-	     ((condition-case err-var
-		  (prog1 t (up-list 1))
-		(error nil))
-	      (while (looking-at "\\s)")
-		(forward-char 1))
-	      (delete-region
-	       (point)
-	       (progn (skip-chars-forward " \t") (point)))
-	      (insert ?\n))
-	     (t (goto-char (point-max)))))
-	  (goto-char (point-min))
-	  (indent-sexp)
+          (pp-buffer)
 	  (buffer-string))
       (kill-buffer (current-buffer)))))
 
+(defun pp-buffer ()
+  "Prettify the current buffer with printed representation of a Lisp object."
+  (goto-char (point-min))
+  (while (not (eobp))
+    ;; (message "%06d" (- (point-max) (point)))
+    (cond
+     ((condition-case err-var
+          (prog1 t (down-list 1))
+        (error nil))
+      (save-excursion
+        (backward-char 1)
+        (skip-chars-backward "'`#^")
+        (when (and (not (bobp)) (memq (char-before) '(?\ ?\t ?\n)))
+          (delete-region
+           (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)")
+        (forward-char 1))
+      (delete-region
+       (point)
+       (progn (skip-chars-forward " \t\n") (point)))
+      (insert ?\n))
+     (t (goto-char (point-max)))))
+  (goto-char (point-min))
+  (indent-sexp))
+
 ;;;###autoload
 (defun pp (object &optional stream)
   "Output the pretty-printed representation of OBJECT, any Lisp object.