Mercurial > emacs
annotate lisp/emacs-lisp/pp.el @ 95392:838b2bca5a6f
*** empty log message ***
author | Juanma Barranquero <lekktu@gmail.com> |
---|---|
date | Thu, 29 May 2008 20:05:36 +0000 |
parents | 90a2847062be |
children | a9dc0e7c3f2b |
rev | line source |
---|---|
13337 | 1 ;;; pp.el --- pretty printer for Emacs Lisp |
14169 | 2 |
64751
5b1a238fcbb4
Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
64085
diff
changeset
|
3 ;; Copyright (C) 1989, 1993, 2001, 2002, 2003, 2004, |
79704 | 4 ;; 2005, 2006, 2007, 2008 Free Software Foundation, Inc. |
8544 | 5 |
14224 | 6 ;; Author: Randal Schwartz <merlyn@stonehenge.com> |
39117 | 7 ;; Keywords: lisp |
8544 | 8 |
9 ;; This file is part of GNU Emacs. | |
10 | |
94655
90a2847062be
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
94354
diff
changeset
|
11 ;; GNU Emacs is free software: you can redistribute it and/or modify |
8544 | 12 ;; it under the terms of the GNU General Public License as published by |
94655
90a2847062be
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
94354
diff
changeset
|
13 ;; the Free Software Foundation, either version 3 of the License, or |
90a2847062be
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
94354
diff
changeset
|
14 ;; (at your option) any later version. |
8544 | 15 |
16 ;; GNU Emacs is distributed in the hope that it will be useful, | |
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 ;; GNU General Public License for more details. | |
20 | |
21 ;; You should have received a copy of the GNU General Public License | |
94655
90a2847062be
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
94354
diff
changeset
|
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
8544 | 23 |
38436
b174db545cfd
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
23244
diff
changeset
|
24 ;;; Commentary: |
b174db545cfd
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
23244
diff
changeset
|
25 |
8544 | 26 ;;; Code: |
38436
b174db545cfd
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
23244
diff
changeset
|
27 |
65193
228d206af8c8
(font-lock-verbose): Add defvar.
Juanma Barranquero <lekktu@gmail.com>
parents:
64751
diff
changeset
|
28 (defvar font-lock-verbose) |
228d206af8c8
(font-lock-verbose): Add defvar.
Juanma Barranquero <lekktu@gmail.com>
parents:
64751
diff
changeset
|
29 |
21365 | 30 (defgroup pp nil |
31 "Pretty printer for Emacs Lisp." | |
32 :prefix "pp-" | |
33 :group 'lisp) | |
8544 | 34 |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
43295
diff
changeset
|
35 (defcustom pp-escape-newlines t |
21365 | 36 "*Value of `print-escape-newlines' used by pp-* functions." |
37 :type 'boolean | |
38 :group 'pp) | |
8544 | 39 |
43295
ce2590f06ba0
2002-02-14 Per Abrahamsen <abraham@dina.kvl.dk>
Per Abrahamsen <abraham@dina.kvl.dk>
parents:
39117
diff
changeset
|
40 ;;;###autoload |
8544 | 41 (defun pp-to-string (object) |
23244 | 42 "Return a string containing the pretty-printed representation of OBJECT. |
43 OBJECT can be any Lisp object. Quoting characters are used as needed | |
44 to make output that `read' can handle, whenever this is possible." | |
8544 | 45 (save-excursion |
46 (set-buffer (generate-new-buffer " pp-to-string")) | |
47 (unwind-protect | |
48 (progn | |
19147
ec57f19bc39c
(pp-to-string): Use emacs-lisp-mode-sytax-table.
Richard M. Stallman <rms@gnu.org>
parents:
16171
diff
changeset
|
49 (lisp-mode-variables nil) |
ec57f19bc39c
(pp-to-string): Use emacs-lisp-mode-sytax-table.
Richard M. Stallman <rms@gnu.org>
parents:
16171
diff
changeset
|
50 (set-syntax-table emacs-lisp-mode-syntax-table) |
20598
a61e2395961f
(pp-to-string): Greatly simplify by letting the
Andreas Schwab <schwab@suse.de>
parents:
19147
diff
changeset
|
51 (let ((print-escape-newlines pp-escape-newlines) |
a61e2395961f
(pp-to-string): Greatly simplify by letting the
Andreas Schwab <schwab@suse.de>
parents:
19147
diff
changeset
|
52 (print-quoted t)) |
8544 | 53 (prin1 object (current-buffer))) |
55802
7bb617df33db
(pp-buffer): New fun created from the code in
Juri Linkov <juri@jurta.org>
parents:
54502
diff
changeset
|
54 (pp-buffer) |
8544 | 55 (buffer-string)) |
56 (kill-buffer (current-buffer))))) | |
57 | |
56274 | 58 ;;;###autoload |
55802
7bb617df33db
(pp-buffer): New fun created from the code in
Juri Linkov <juri@jurta.org>
parents:
54502
diff
changeset
|
59 (defun pp-buffer () |
7bb617df33db
(pp-buffer): New fun created from the code in
Juri Linkov <juri@jurta.org>
parents:
54502
diff
changeset
|
60 "Prettify the current buffer with printed representation of a Lisp object." |
7bb617df33db
(pp-buffer): New fun created from the code in
Juri Linkov <juri@jurta.org>
parents:
54502
diff
changeset
|
61 (goto-char (point-min)) |
7bb617df33db
(pp-buffer): New fun created from the code in
Juri Linkov <juri@jurta.org>
parents:
54502
diff
changeset
|
62 (while (not (eobp)) |
7bb617df33db
(pp-buffer): New fun created from the code in
Juri Linkov <juri@jurta.org>
parents:
54502
diff
changeset
|
63 ;; (message "%06d" (- (point-max) (point))) |
7bb617df33db
(pp-buffer): New fun created from the code in
Juri Linkov <juri@jurta.org>
parents:
54502
diff
changeset
|
64 (cond |
7bb617df33db
(pp-buffer): New fun created from the code in
Juri Linkov <juri@jurta.org>
parents:
54502
diff
changeset
|
65 ((condition-case err-var |
7bb617df33db
(pp-buffer): New fun created from the code in
Juri Linkov <juri@jurta.org>
parents:
54502
diff
changeset
|
66 (prog1 t (down-list 1)) |
7bb617df33db
(pp-buffer): New fun created from the code in
Juri Linkov <juri@jurta.org>
parents:
54502
diff
changeset
|
67 (error nil)) |
7bb617df33db
(pp-buffer): New fun created from the code in
Juri Linkov <juri@jurta.org>
parents:
54502
diff
changeset
|
68 (save-excursion |
7bb617df33db
(pp-buffer): New fun created from the code in
Juri Linkov <juri@jurta.org>
parents:
54502
diff
changeset
|
69 (backward-char 1) |
7bb617df33db
(pp-buffer): New fun created from the code in
Juri Linkov <juri@jurta.org>
parents:
54502
diff
changeset
|
70 (skip-chars-backward "'`#^") |
63852
dd7fb3231397
(pp-buffer): Change space constants followed by a sexp to "?\s ".
Juanma Barranquero <lekktu@gmail.com>
parents:
56274
diff
changeset
|
71 (when (and (not (bobp)) (memq (char-before) '(?\s ?\t ?\n))) |
55802
7bb617df33db
(pp-buffer): New fun created from the code in
Juri Linkov <juri@jurta.org>
parents:
54502
diff
changeset
|
72 (delete-region |
7bb617df33db
(pp-buffer): New fun created from the code in
Juri Linkov <juri@jurta.org>
parents:
54502
diff
changeset
|
73 (point) |
7bb617df33db
(pp-buffer): New fun created from the code in
Juri Linkov <juri@jurta.org>
parents:
54502
diff
changeset
|
74 (progn (skip-chars-backward " \t\n") (point))) |
7bb617df33db
(pp-buffer): New fun created from the code in
Juri Linkov <juri@jurta.org>
parents:
54502
diff
changeset
|
75 (insert "\n")))) |
7bb617df33db
(pp-buffer): New fun created from the code in
Juri Linkov <juri@jurta.org>
parents:
54502
diff
changeset
|
76 ((condition-case err-var |
7bb617df33db
(pp-buffer): New fun created from the code in
Juri Linkov <juri@jurta.org>
parents:
54502
diff
changeset
|
77 (prog1 t (up-list 1)) |
7bb617df33db
(pp-buffer): New fun created from the code in
Juri Linkov <juri@jurta.org>
parents:
54502
diff
changeset
|
78 (error nil)) |
7bb617df33db
(pp-buffer): New fun created from the code in
Juri Linkov <juri@jurta.org>
parents:
54502
diff
changeset
|
79 (while (looking-at "\\s)") |
7bb617df33db
(pp-buffer): New fun created from the code in
Juri Linkov <juri@jurta.org>
parents:
54502
diff
changeset
|
80 (forward-char 1)) |
7bb617df33db
(pp-buffer): New fun created from the code in
Juri Linkov <juri@jurta.org>
parents:
54502
diff
changeset
|
81 (delete-region |
7bb617df33db
(pp-buffer): New fun created from the code in
Juri Linkov <juri@jurta.org>
parents:
54502
diff
changeset
|
82 (point) |
7bb617df33db
(pp-buffer): New fun created from the code in
Juri Linkov <juri@jurta.org>
parents:
54502
diff
changeset
|
83 (progn (skip-chars-forward " \t\n") (point))) |
7bb617df33db
(pp-buffer): New fun created from the code in
Juri Linkov <juri@jurta.org>
parents:
54502
diff
changeset
|
84 (insert ?\n)) |
7bb617df33db
(pp-buffer): New fun created from the code in
Juri Linkov <juri@jurta.org>
parents:
54502
diff
changeset
|
85 (t (goto-char (point-max))))) |
7bb617df33db
(pp-buffer): New fun created from the code in
Juri Linkov <juri@jurta.org>
parents:
54502
diff
changeset
|
86 (goto-char (point-min)) |
7bb617df33db
(pp-buffer): New fun created from the code in
Juri Linkov <juri@jurta.org>
parents:
54502
diff
changeset
|
87 (indent-sexp)) |
7bb617df33db
(pp-buffer): New fun created from the code in
Juri Linkov <juri@jurta.org>
parents:
54502
diff
changeset
|
88 |
10329 | 89 ;;;###autoload |
8544 | 90 (defun pp (object &optional stream) |
91 "Output the pretty-printed representation of OBJECT, any Lisp object. | |
23244 | 92 Quoting characters are printed as needed to make output that `read' |
8544 | 93 can handle, whenever this is possible. |
94 Output stream is STREAM, or value of `standard-output' (which see)." | |
95 (princ (pp-to-string object) (or stream standard-output))) | |
96 | |
94354
26ba760c38d0
Johannes Weiner <hannes at saeurebad.de>
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
97 (defun pp-display-expression (expression out-buffer-name) |
26ba760c38d0
Johannes Weiner <hannes at saeurebad.de>
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
98 "Prettify and display EXPRESSION in an appropriate way, depending on length. |
26ba760c38d0
Johannes Weiner <hannes at saeurebad.de>
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
99 If a temporary buffer is needed for representation, it will be named |
26ba760c38d0
Johannes Weiner <hannes at saeurebad.de>
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
100 after OUT-BUFFER-NAME." |
11730
084c36d46615
(pp-eval-expression): Update use of temp-buffer-show-function.
Richard M. Stallman <rms@gnu.org>
parents:
10732
diff
changeset
|
101 (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
|
102 ;; 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
|
103 ;; 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
|
104 ;; 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
|
105 (temp-buffer-show-function |
8544 | 106 (function |
107 (lambda (buf) | |
108 (save-excursion | |
109 (set-buffer buf) | |
110 (goto-char (point-min)) | |
111 (end-of-line 1) | |
112 (if (or (< (1+ (point)) (point-max)) | |
14225
ec298b8bee29
(pp-eval-expression): Use `frame-width' instead of `screen-width'.
Erik Naggum <erik@naggum.no>
parents:
14224
diff
changeset
|
113 (>= (- (point) (point-min)) (frame-width))) |
11730
084c36d46615
(pp-eval-expression): Update use of temp-buffer-show-function.
Richard M. Stallman <rms@gnu.org>
parents:
10732
diff
changeset
|
114 (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
|
115 (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
|
116 (window (display-buffer buf))) |
8544 | 117 (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
|
118 (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
|
119 (unwind-protect |
084c36d46615
(pp-eval-expression): Update use of temp-buffer-show-function.
Richard M. Stallman <rms@gnu.org>
parents:
10732
diff
changeset
|
120 (progn |
084c36d46615
(pp-eval-expression): Update use of temp-buffer-show-function.
Richard M. Stallman <rms@gnu.org>
parents:
10732
diff
changeset
|
121 (select-window window) |
084c36d46615
(pp-eval-expression): Update use of temp-buffer-show-function.
Richard M. Stallman <rms@gnu.org>
parents:
10732
diff
changeset
|
122 (run-hooks 'temp-buffer-show-hook)) |
87649 | 123 (select-window old-selected) |
94354
26ba760c38d0
Johannes Weiner <hannes at saeurebad.de>
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
124 (message "See buffer %s." out-buffer-name))) |
8544 | 125 (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
|
126 )))))) |
94354
26ba760c38d0
Johannes Weiner <hannes at saeurebad.de>
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
127 (with-output-to-temp-buffer out-buffer-name |
26ba760c38d0
Johannes Weiner <hannes at saeurebad.de>
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
128 (pp expression) |
54502
a8550ca246eb
(pp-eval-expression): Simplify.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
52401
diff
changeset
|
129 (with-current-buffer standard-output |
a8550ca246eb
(pp-eval-expression): Simplify.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
52401
diff
changeset
|
130 (emacs-lisp-mode) |
87649 | 131 (setq buffer-read-only nil) |
54502
a8550ca246eb
(pp-eval-expression): Simplify.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
52401
diff
changeset
|
132 (set (make-local-variable 'font-lock-verbose) nil))))) |
8544 | 133 |
10329 | 134 ;;;###autoload |
94354
26ba760c38d0
Johannes Weiner <hannes at saeurebad.de>
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
135 (defun pp-eval-expression (expression) |
26ba760c38d0
Johannes Weiner <hannes at saeurebad.de>
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
136 "Evaluate EXPRESSION and pretty-print its value. |
26ba760c38d0
Johannes Weiner <hannes at saeurebad.de>
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
137 Also add the value to the front of the list in the variable `values'." |
26ba760c38d0
Johannes Weiner <hannes at saeurebad.de>
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
138 (interactive |
26ba760c38d0
Johannes Weiner <hannes at saeurebad.de>
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
139 (list (read-from-minibuffer "Eval: " nil read-expression-map t |
26ba760c38d0
Johannes Weiner <hannes at saeurebad.de>
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
140 'read-expression-history))) |
26ba760c38d0
Johannes Weiner <hannes at saeurebad.de>
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
141 (message "Evaluating...") |
26ba760c38d0
Johannes Weiner <hannes at saeurebad.de>
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
142 (setq values (cons (eval expression) values)) |
26ba760c38d0
Johannes Weiner <hannes at saeurebad.de>
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
143 (pp-display-expression (car values) "*Pp Eval Output*")) |
26ba760c38d0
Johannes Weiner <hannes at saeurebad.de>
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
144 |
26ba760c38d0
Johannes Weiner <hannes at saeurebad.de>
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
145 ;;;###autoload |
26ba760c38d0
Johannes Weiner <hannes at saeurebad.de>
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
146 (defun pp-macroexpand-expression (expression) |
26ba760c38d0
Johannes Weiner <hannes at saeurebad.de>
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
147 "Macroexpand EXPRESSION and pretty-print its value." |
26ba760c38d0
Johannes Weiner <hannes at saeurebad.de>
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
148 (interactive |
26ba760c38d0
Johannes Weiner <hannes at saeurebad.de>
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
149 (list (read-from-minibuffer "Macroexpand: " nil read-expression-map t |
26ba760c38d0
Johannes Weiner <hannes at saeurebad.de>
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
150 'read-expression-history))) |
26ba760c38d0
Johannes Weiner <hannes at saeurebad.de>
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
151 (pp-display-expression (macroexpand expression) "*Pp Macroexpand Output*")) |
26ba760c38d0
Johannes Weiner <hannes at saeurebad.de>
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
152 |
26ba760c38d0
Johannes Weiner <hannes at saeurebad.de>
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
153 (defun pp-last-sexp () |
26ba760c38d0
Johannes Weiner <hannes at saeurebad.de>
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
154 "Read sexp before point. Ignores leading comment characters." |
8544 | 155 (let ((stab (syntax-table)) (pt (point)) start exp) |
156 (set-syntax-table emacs-lisp-mode-syntax-table) | |
157 (save-excursion | |
158 (forward-sexp -1) | |
159 ;; If first line is commented, ignore all leading comments: | |
160 (if (save-excursion (beginning-of-line) (looking-at "[ \t]*;")) | |
161 (progn | |
162 (setq exp (buffer-substring (point) pt)) | |
163 (while (string-match "\n[ \t]*;+" exp start) | |
164 (setq start (1+ (match-beginning 0)) | |
165 exp (concat (substring exp 0 start) | |
166 (substring exp (match-end 0))))) | |
167 (setq exp (read exp))) | |
168 (setq exp (read (current-buffer))))) | |
169 (set-syntax-table stab) | |
94354
26ba760c38d0
Johannes Weiner <hannes at saeurebad.de>
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
170 exp)) |
26ba760c38d0
Johannes Weiner <hannes at saeurebad.de>
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
171 |
26ba760c38d0
Johannes Weiner <hannes at saeurebad.de>
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
172 ;;;###autoload |
26ba760c38d0
Johannes Weiner <hannes at saeurebad.de>
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
173 (defun pp-eval-last-sexp (arg) |
26ba760c38d0
Johannes Weiner <hannes at saeurebad.de>
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
174 "Run `pp-eval-expression' on sexp before point. |
26ba760c38d0
Johannes Weiner <hannes at saeurebad.de>
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
175 With argument, pretty-print output into current buffer. |
26ba760c38d0
Johannes Weiner <hannes at saeurebad.de>
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
176 Ignores leading comment characters." |
26ba760c38d0
Johannes Weiner <hannes at saeurebad.de>
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
177 (interactive "P") |
26ba760c38d0
Johannes Weiner <hannes at saeurebad.de>
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
178 (if arg |
26ba760c38d0
Johannes Weiner <hannes at saeurebad.de>
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
179 (insert (pp-to-string (eval (pp-last-sexp)))) |
26ba760c38d0
Johannes Weiner <hannes at saeurebad.de>
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
180 (pp-eval-expression (pp-last-sexp)))) |
26ba760c38d0
Johannes Weiner <hannes at saeurebad.de>
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
181 |
26ba760c38d0
Johannes Weiner <hannes at saeurebad.de>
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
182 ;;;###autoload |
26ba760c38d0
Johannes Weiner <hannes at saeurebad.de>
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
183 (defun pp-macroexpand-last-sexp (arg) |
26ba760c38d0
Johannes Weiner <hannes at saeurebad.de>
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
184 "Run `pp-macroexpand-expression' on sexp before point. |
26ba760c38d0
Johannes Weiner <hannes at saeurebad.de>
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
185 With argument, pretty-print output into current buffer. |
26ba760c38d0
Johannes Weiner <hannes at saeurebad.de>
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
186 Ignores leading comment characters." |
26ba760c38d0
Johannes Weiner <hannes at saeurebad.de>
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
187 (interactive "P") |
26ba760c38d0
Johannes Weiner <hannes at saeurebad.de>
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
188 (if arg |
26ba760c38d0
Johannes Weiner <hannes at saeurebad.de>
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
189 (insert (pp-to-string (macroexpand (pp-last-sexp)))) |
26ba760c38d0
Johannes Weiner <hannes at saeurebad.de>
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
190 (pp-macroexpand-expression (pp-last-sexp)))) |
8544 | 191 |
192 ;;; Test cases for quote | |
193 ;; (pp-eval-expression ''(quote quote)) | |
194 ;; (pp-eval-expression ''((quote a) (quote b))) | |
195 ;; (pp-eval-expression ''('a 'b)) ; same as above | |
196 ;; (pp-eval-expression ''((quote (quote quote)) (quote quote))) | |
197 ;; These do not satisfy the quote test. | |
198 ;; (pp-eval-expression ''quote) | |
199 ;; (pp-eval-expression ''(quote)) | |
200 ;; (pp-eval-expression ''(quote . quote)) | |
201 ;; (pp-eval-expression ''(quote a b)) | |
202 ;; (pp-eval-expression ''(quotefoo)) | |
203 ;; (pp-eval-expression ''(a b)) | |
204 | |
205 (provide 'pp) ; so (require 'pp) works | |
206 | |
93975
1e3a407766b9
Fix up comment convention on the arch-tag lines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87649
diff
changeset
|
207 ;; arch-tag: b0f7c65b-02c7-42bb-9ee3-508a59b8fbb9 |
38436
b174db545cfd
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
23244
diff
changeset
|
208 ;;; pp.el ends here |