annotate lisp/emacs-lisp/pp.el @ 12495:664012a3216e

(LIB_MOTIF, VFORK_RETURN_TYPE): Define these.
author Richard M. Stallman <rms@gnu.org>
date Fri, 07 Jul 1995 13:36:40 +0000
parents 084c36d46615
children 84acc3adcd63
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8544
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1 ;; pp.el --- pretty printer for Emacs Lisp
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2 ;; Copyright (C) 1989, 1993 Free Software Foundation, Inc.
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
4 ;; Author: Randal Schwartz <merlyn@ora.com>
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
5
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
6 ;; This file is part of GNU Emacs.
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
7
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
8 ;; GNU Emacs is free software; you can redistribute it and/or modify
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
9 ;; it under the terms of the GNU General Public License as published by
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
10 ;; the Free Software Foundation; either version 2, or (at your option)
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
11 ;; any later version.
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
12
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
13 ;; GNU Emacs is distributed in the hope that it will be useful,
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
16 ;; GNU General Public License for more details.
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
17
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
18 ;; You should have received a copy of the GNU General Public License
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
19 ;; along with GNU Emacs; see the file COPYING. If not, write to
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
20 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
21
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
22 ;;; Code:
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
23
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
24 (defvar pp-escape-newlines t
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
25 "*Value of print-escape-newlines used by pp-* functions.")
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
26
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
27 (defun pp-to-string (object)
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
28 "Return a string containing the pretty-printed representation of OBJECT,
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
29 any Lisp object. Quoting characters are used when needed to make output
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
30 that `read' can handle, whenever this is possible."
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
31 (save-excursion
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
32 (set-buffer (generate-new-buffer " pp-to-string"))
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
33 (unwind-protect
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
34 (progn
10732
bd193969988d (pp-to-string): Fix previous change.
Richard M. Stallman <rms@gnu.org>
parents: 10724
diff changeset
35 (lisp-mode-variables t)
8544
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
36 (let ((print-escape-newlines pp-escape-newlines))
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
37 (prin1 object (current-buffer)))
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
38 (goto-char (point-min))
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
39 (while (not (eobp))
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
40 ;; (message "%06d" (- (point-max) (point)))
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
41 (cond
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
42 ((looking-at "\\s\(")
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
43 (while (looking-at "\\s(")
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
44 (forward-char 1)))
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
45 ((and (looking-at "\\(quote[ \t]+\\)\\([^.)]\\)")
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
46 (> (match-beginning 1) 1)
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
47 (= ?\( (char-after (1- (match-beginning 1))))
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
48 ;; Make sure this is a two-element list.
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
49 (save-excursion
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
50 (goto-char (match-beginning 2))
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
51 (forward-sexp)
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
52 ;; (looking-at "[ \t]*\)")
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
53 ;; Avoid mucking with match-data; does this test work?
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
54 (char-equal ?\) (char-after (point)))))
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
55 ;; -1 gets the paren preceding the quote as well.
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
56 (delete-region (1- (match-beginning 1)) (match-end 1))
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
57 (insert "'")
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
58 (forward-sexp 1)
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
59 (if (looking-at "[ \t]*\)")
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
60 (delete-region (match-beginning 0) (match-end 0))
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
61 (error "Malformed quote"))
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
62 (backward-sexp 1))
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
63 ((condition-case err-var
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
64 (prog1 t (down-list 1))
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
65 (error nil))
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
66 (backward-char 1)
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
67 (skip-chars-backward " \t")
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
68 (delete-region
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
69 (point)
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
70 (progn (skip-chars-forward " \t") (point)))
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
71 (if (not (char-equal ?' (char-after (1- (point)))))
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
72 (insert ?\n)))
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
73 ((condition-case err-var
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
74 (prog1 t (up-list 1))
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
75 (error nil))
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
76 (while (looking-at "\\s)")
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
77 (forward-char 1))
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
78 (skip-chars-backward " \t")
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
79 (delete-region
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
80 (point)
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
81 (progn (skip-chars-forward " \t") (point)))
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
82 (if (not (char-equal ?' (char-after (1- (point)))))
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
83 (insert ?\n)))
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
84 (t (goto-char (point-max)))))
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
85 (goto-char (point-min))
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
86 (indent-sexp)
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
87 (buffer-string))
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
88 (kill-buffer (current-buffer)))))
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
89
10329
aa393c4b380c Add autoload cookies.
Noah Friedman <friedman@splode.com>
parents: 8544
diff changeset
90 ;;;###autoload
8544
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
91 (defun pp (object &optional stream)
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
92 "Output the pretty-printed representation of OBJECT, any Lisp object.
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
93 Quoting characters are printed when needed to make output that `read'
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
94 can handle, whenever this is possible.
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
95 Output stream is STREAM, or value of `standard-output' (which see)."
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
96 (princ (pp-to-string object) (or stream standard-output)))
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
97
10329
aa393c4b380c Add autoload cookies.
Noah Friedman <friedman@splode.com>
parents: 8544
diff changeset
98 ;;;###autoload
8544
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
99 (defun pp-eval-expression (expression)
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
100 "Evaluate EXPRESSION and pretty-print value into a new display buffer.
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
101 If the pretty-printed value fits on one line, the message line is used
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
102 instead. Value is also consed on to front of variable values 's
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
103 value."
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
104 (interactive "xPp-eval: ")
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
105 (setq values (cons (eval expression) values))
11730
084c36d46615 (pp-eval-expression): Update use of temp-buffer-show-function.
Richard M. Stallman <rms@gnu.org>
parents: 10732
diff changeset
106 (let* ((old-show-function temp-buffer-show-function)
084c36d46615 (pp-eval-expression): Update use of temp-buffer-show-function.
Richard M. Stallman <rms@gnu.org>
parents: 10732
diff changeset
107 ;; Use this function to display the buffer.
084c36d46615 (pp-eval-expression): Update use of temp-buffer-show-function.
Richard M. Stallman <rms@gnu.org>
parents: 10732
diff changeset
108 ;; This function either decides not to display it at all
084c36d46615 (pp-eval-expression): Update use of temp-buffer-show-function.
Richard M. Stallman <rms@gnu.org>
parents: 10732
diff changeset
109 ;; or displays it in the usual way.
084c36d46615 (pp-eval-expression): Update use of temp-buffer-show-function.
Richard M. Stallman <rms@gnu.org>
parents: 10732
diff changeset
110 (temp-buffer-show-function
8544
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
111 (function
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
112 (lambda (buf)
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
113 (save-excursion
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
114 (set-buffer buf)
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
115 (goto-char (point-min))
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
116 (end-of-line 1)
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
117 (if (or (< (1+ (point)) (point-max))
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
118 (>= (- (point) (point-min)) (screen-width)))
11730
084c36d46615 (pp-eval-expression): Update use of temp-buffer-show-function.
Richard M. Stallman <rms@gnu.org>
parents: 10732
diff changeset
119 (let ((temp-buffer-show-function old-show-function)
084c36d46615 (pp-eval-expression): Update use of temp-buffer-show-function.
Richard M. Stallman <rms@gnu.org>
parents: 10732
diff changeset
120 (old-selected (selected-window))
084c36d46615 (pp-eval-expression): Update use of temp-buffer-show-function.
Richard M. Stallman <rms@gnu.org>
parents: 10732
diff changeset
121 (window (display-buffer buf)))
8544
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
122 (goto-char (point-min)) ; expected by some hooks ...
11730
084c36d46615 (pp-eval-expression): Update use of temp-buffer-show-function.
Richard M. Stallman <rms@gnu.org>
parents: 10732
diff changeset
123 (make-frame-visible (window-frame window))
084c36d46615 (pp-eval-expression): Update use of temp-buffer-show-function.
Richard M. Stallman <rms@gnu.org>
parents: 10732
diff changeset
124 (unwind-protect
084c36d46615 (pp-eval-expression): Update use of temp-buffer-show-function.
Richard M. Stallman <rms@gnu.org>
parents: 10732
diff changeset
125 (progn
084c36d46615 (pp-eval-expression): Update use of temp-buffer-show-function.
Richard M. Stallman <rms@gnu.org>
parents: 10732
diff changeset
126 (select-window window)
084c36d46615 (pp-eval-expression): Update use of temp-buffer-show-function.
Richard M. Stallman <rms@gnu.org>
parents: 10732
diff changeset
127 (run-hooks 'temp-buffer-show-hook))
084c36d46615 (pp-eval-expression): Update use of temp-buffer-show-function.
Richard M. Stallman <rms@gnu.org>
parents: 10732
diff changeset
128 (select-window old-selected)))
8544
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
129 (message "%s" (buffer-substring (point-min) (point)))
11730
084c36d46615 (pp-eval-expression): Update use of temp-buffer-show-function.
Richard M. Stallman <rms@gnu.org>
parents: 10732
diff changeset
130 ))))))
8544
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
131 (with-output-to-temp-buffer "*Pp Eval Output*"
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
132 (pp (car values)))
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
133 (save-excursion
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
134 (set-buffer "*Pp Eval Output*")
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
135 (emacs-lisp-mode))))
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
136
10329
aa393c4b380c Add autoload cookies.
Noah Friedman <friedman@splode.com>
parents: 8544
diff changeset
137 ;;;###autoload
8544
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
138 (defun pp-eval-last-sexp (arg)
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
139 "Run `pp-eval-expression' on sexp before point (which see).
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
140 With argument, pretty-print output into current buffer.
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
141 Ignores leading comment characters."
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
142 (interactive "P")
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
143 (let ((stab (syntax-table)) (pt (point)) start exp)
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
144 (set-syntax-table emacs-lisp-mode-syntax-table)
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
145 (save-excursion
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
146 (forward-sexp -1)
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
147 ;; If first line is commented, ignore all leading comments:
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
148 (if (save-excursion (beginning-of-line) (looking-at "[ \t]*;"))
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
149 (progn
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
150 (setq exp (buffer-substring (point) pt))
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
151 (while (string-match "\n[ \t]*;+" exp start)
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
152 (setq start (1+ (match-beginning 0))
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
153 exp (concat (substring exp 0 start)
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
154 (substring exp (match-end 0)))))
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
155 (setq exp (read exp)))
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
156 (setq exp (read (current-buffer)))))
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
157 (set-syntax-table stab)
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
158 (if arg
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
159 (insert (pp-to-string (eval exp)))
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
160 (pp-eval-expression exp))))
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
161
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
162 ;;; Test cases for quote
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
163 ;; (pp-eval-expression ''(quote quote))
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
164 ;; (pp-eval-expression ''((quote a) (quote b)))
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
165 ;; (pp-eval-expression ''('a 'b)) ; same as above
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
166 ;; (pp-eval-expression ''((quote (quote quote)) (quote quote)))
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
167 ;; These do not satisfy the quote test.
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
168 ;; (pp-eval-expression ''quote)
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
169 ;; (pp-eval-expression ''(quote))
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
170 ;; (pp-eval-expression ''(quote . quote))
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
171 ;; (pp-eval-expression ''(quote a b))
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
172 ;; (pp-eval-expression ''(quotefoo))
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
173 ;; (pp-eval-expression ''(a b))
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
174
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
175 (provide 'pp) ; so (require 'pp) works
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
176
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
177 ;;; pp.el ends here.