aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJuri Linkov2004-05-28 21:05:17 +0000
committerJuri Linkov2004-05-28 21:05:17 +0000
commit575c3bca4c340b8e6f23f11273e19c279bf8c022 (patch)
treea7d6acca80810525bc9f06787a2ca1a70bc05ffa
parenta82456f0809885e74aa827d2e98fba1518d6f0af (diff)
downloademacs-575c3bca4c340b8e6f23f11273e19c279bf8c022.tar.gz
emacs-575c3bca4c340b8e6f23f11273e19c279bf8c022.zip
(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'.
-rw-r--r--lisp/emacs-lisp/pp.el56
1 files changed, 31 insertions, 25 deletions
diff --git a/lisp/emacs-lisp/pp.el b/lisp/emacs-lisp/pp.el
index c93868859f0..61d31921e57 100644
--- a/lisp/emacs-lisp/pp.el
+++ b/lisp/emacs-lisp/pp.el
@@ -50,34 +50,40 @@ to make output that `read' can handle, whenever this is possible."
50 (let ((print-escape-newlines pp-escape-newlines) 50 (let ((print-escape-newlines pp-escape-newlines)
51 (print-quoted t)) 51 (print-quoted t))
52 (prin1 object (current-buffer))) 52 (prin1 object (current-buffer)))
53 (goto-char (point-min)) 53 (pp-buffer)
54 (while (not (eobp))
55 ;; (message "%06d" (- (point-max) (point)))
56 (cond
57 ((condition-case err-var
58 (prog1 t (down-list 1))
59 (error nil))
60 (save-excursion
61 (backward-char 1)
62 (skip-chars-backward "'`#^")
63 (when (and (not (bobp)) (= ?\ (char-before)))
64 (delete-char -1)
65 (insert "\n"))))
66 ((condition-case err-var
67 (prog1 t (up-list 1))
68 (error nil))
69 (while (looking-at "\\s)")
70 (forward-char 1))
71 (delete-region
72 (point)
73 (progn (skip-chars-forward " \t") (point)))
74 (insert ?\n))
75 (t (goto-char (point-max)))))
76 (goto-char (point-min))
77 (indent-sexp)
78 (buffer-string)) 54 (buffer-string))
79 (kill-buffer (current-buffer))))) 55 (kill-buffer (current-buffer)))))
80 56
57(defun pp-buffer ()
58 "Prettify the current buffer with printed representation of a Lisp object."
59 (goto-char (point-min))
60 (while (not (eobp))
61 ;; (message "%06d" (- (point-max) (point)))
62 (cond
63 ((condition-case err-var
64 (prog1 t (down-list 1))
65 (error nil))
66 (save-excursion
67 (backward-char 1)
68 (skip-chars-backward "'`#^")
69 (when (and (not (bobp)) (memq (char-before) '(?\ ?\t ?\n)))
70 (delete-region
71 (point)
72 (progn (skip-chars-backward " \t\n") (point)))
73 (insert "\n"))))
74 ((condition-case err-var
75 (prog1 t (up-list 1))
76 (error nil))
77 (while (looking-at "\\s)")
78 (forward-char 1))
79 (delete-region
80 (point)
81 (progn (skip-chars-forward " \t\n") (point)))
82 (insert ?\n))
83 (t (goto-char (point-max)))))
84 (goto-char (point-min))
85 (indent-sexp))
86
81;;;###autoload 87;;;###autoload
82(defun pp (object &optional stream) 88(defun pp (object &optional stream)
83 "Output the pretty-printed representation of OBJECT, any Lisp object. 89 "Output the pretty-printed representation of OBJECT, any Lisp object.