aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/emacs-lisp/pp.el
diff options
context:
space:
mode:
authorJuri Linkov <[email protected]>2004-05-28 21:05:17 +0000
committerJuri Linkov <[email protected]>2004-05-28 21:05:17 +0000
commit575c3bca4c340b8e6f23f11273e19c279bf8c022 (patch)
treea7d6acca80810525bc9f06787a2ca1a70bc05ffa /lisp/emacs-lisp/pp.el
parenta82456f0809885e74aa827d2e98fba1518d6f0af (diff)
(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'.
Diffstat (limited to 'lisp/emacs-lisp/pp.el')
-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 c93868859f..61d31921e5 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."
(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.