Mercurial > emacs
annotate lisp/emacs-lisp/pp.el @ 38588:08a4c6c00af0
(init_from_display_pos): If POS is in an overlay string,
deal with the first overlay string having an image `display'
property.
(try_window_reusing_current_matrix, compute_line_metrics): Fix
computation of row's visible height for the case that part of the
row is invisible above and part of the row is at the same time
invisible below the window.
author | Gerd Moellmann <gerd@gnu.org> |
---|---|
date | Fri, 27 Jul 2001 15:29:16 +0000 |
parents | b174db545cfd |
children | abd085bfec0c |
rev | line source |
---|---|
13337 | 1 ;;; pp.el --- pretty printer for Emacs Lisp |
14169 | 2 |
8544 | 3 ;; Copyright (C) 1989, 1993 Free Software Foundation, Inc. |
4 | |
14224 | 5 ;; Author: Randal Schwartz <merlyn@stonehenge.com> |
8544 | 6 |
7 ;; This file is part of GNU Emacs. | |
8 | |
9 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
10 ;; it under the terms of the GNU General Public License as published by | |
11 ;; the Free Software Foundation; either version 2, or (at your option) | |
12 ;; any later version. | |
13 | |
14 ;; GNU Emacs is distributed in the hope that it will be useful, | |
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 ;; GNU General Public License for more details. | |
18 | |
19 ;; You should have received a copy of the GNU General Public License | |
14169 | 20 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
22 ;; Boston, MA 02111-1307, USA. | |
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 |
21365 | 28 (defgroup pp nil |
29 "Pretty printer for Emacs Lisp." | |
30 :prefix "pp-" | |
31 :group 'lisp) | |
8544 | 32 |
21365 | 33 (defcustom pp-escape-newlines t |
34 "*Value of `print-escape-newlines' used by pp-* functions." | |
35 :type 'boolean | |
36 :group 'pp) | |
8544 | 37 |
38 (defun pp-to-string (object) | |
23244 | 39 "Return a string containing the pretty-printed representation of OBJECT. |
40 OBJECT can be any Lisp object. Quoting characters are used as needed | |
41 to make output that `read' can handle, whenever this is possible." | |
8544 | 42 (save-excursion |
43 (set-buffer (generate-new-buffer " pp-to-string")) | |
44 (unwind-protect | |
45 (progn | |
19147
ec57f19bc39c
(pp-to-string): Use emacs-lisp-mode-sytax-table.
Richard M. Stallman <rms@gnu.org>
parents:
16171
diff
changeset
|
46 (lisp-mode-variables nil) |
ec57f19bc39c
(pp-to-string): Use emacs-lisp-mode-sytax-table.
Richard M. Stallman <rms@gnu.org>
parents:
16171
diff
changeset
|
47 (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
|
48 (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
|
49 (print-quoted t)) |
8544 | 50 (prin1 object (current-buffer))) |
51 (goto-char (point-min)) | |
52 (while (not (eobp)) | |
53 ;; (message "%06d" (- (point-max) (point))) | |
54 (cond | |
55 ((condition-case err-var | |
56 (prog1 t (down-list 1)) | |
57 (error nil)) | |
20598
a61e2395961f
(pp-to-string): Greatly simplify by letting the
Andreas Schwab <schwab@suse.de>
parents:
19147
diff
changeset
|
58 (save-excursion |
a61e2395961f
(pp-to-string): Greatly simplify by letting the
Andreas Schwab <schwab@suse.de>
parents:
19147
diff
changeset
|
59 (backward-char 1) |
a61e2395961f
(pp-to-string): Greatly simplify by letting the
Andreas Schwab <schwab@suse.de>
parents:
19147
diff
changeset
|
60 (skip-chars-backward "'`#^") |
a61e2395961f
(pp-to-string): Greatly simplify by letting the
Andreas Schwab <schwab@suse.de>
parents:
19147
diff
changeset
|
61 (when (and (not (bobp)) (= ?\ (char-before))) |
a61e2395961f
(pp-to-string): Greatly simplify by letting the
Andreas Schwab <schwab@suse.de>
parents:
19147
diff
changeset
|
62 (delete-char -1) |
a61e2395961f
(pp-to-string): Greatly simplify by letting the
Andreas Schwab <schwab@suse.de>
parents:
19147
diff
changeset
|
63 (insert "\n")))) |
8544 | 64 ((condition-case err-var |
65 (prog1 t (up-list 1)) | |
66 (error nil)) | |
67 (while (looking-at "\\s)") | |
68 (forward-char 1)) | |
69 (delete-region | |
70 (point) | |
71 (progn (skip-chars-forward " \t") (point))) | |
20598
a61e2395961f
(pp-to-string): Greatly simplify by letting the
Andreas Schwab <schwab@suse.de>
parents:
19147
diff
changeset
|
72 (insert ?\n)) |
8544 | 73 (t (goto-char (point-max))))) |
74 (goto-char (point-min)) | |
75 (indent-sexp) | |
76 (buffer-string)) | |
77 (kill-buffer (current-buffer))))) | |
78 | |
10329 | 79 ;;;###autoload |
8544 | 80 (defun pp (object &optional stream) |
81 "Output the pretty-printed representation of OBJECT, any Lisp object. | |
23244 | 82 Quoting characters are printed as needed to make output that `read' |
8544 | 83 can handle, whenever this is possible. |
84 Output stream is STREAM, or value of `standard-output' (which see)." | |
85 (princ (pp-to-string object) (or stream standard-output))) | |
86 | |
10329 | 87 ;;;###autoload |
8544 | 88 (defun pp-eval-expression (expression) |
89 "Evaluate EXPRESSION and pretty-print value into a new display buffer. | |
90 If the pretty-printed value fits on one line, the message line is used | |
23244 | 91 instead. The value is also consed onto the front of the list |
92 in the variable `values'." | |
8544 | 93 (interactive "xPp-eval: ") |
94 (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
|
95 (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
|
96 ;; 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
|
97 ;; 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
|
98 ;; 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
|
99 (temp-buffer-show-function |
8544 | 100 (function |
101 (lambda (buf) | |
102 (save-excursion | |
103 (set-buffer buf) | |
104 (goto-char (point-min)) | |
105 (end-of-line 1) | |
106 (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
|
107 (>= (- (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
|
108 (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
|
109 (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
|
110 (window (display-buffer buf))) |
8544 | 111 (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
|
112 (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
|
113 (unwind-protect |
084c36d46615
(pp-eval-expression): Update use of temp-buffer-show-function.
Richard M. Stallman <rms@gnu.org>
parents:
10732
diff
changeset
|
114 (progn |
084c36d46615
(pp-eval-expression): Update use of temp-buffer-show-function.
Richard M. Stallman <rms@gnu.org>
parents:
10732
diff
changeset
|
115 (select-window window) |
084c36d46615
(pp-eval-expression): Update use of temp-buffer-show-function.
Richard M. Stallman <rms@gnu.org>
parents:
10732
diff
changeset
|
116 (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
|
117 (select-window old-selected))) |
8544 | 118 (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
|
119 )))))) |
8544 | 120 (with-output-to-temp-buffer "*Pp Eval Output*" |
121 (pp (car values))) | |
122 (save-excursion | |
123 (set-buffer "*Pp Eval Output*") | |
16171
919ed1778c0b
(pp-eval-expression): Set font-lock-default locally to nil.
Richard M. Stallman <rms@gnu.org>
parents:
15446
diff
changeset
|
124 (emacs-lisp-mode) |
919ed1778c0b
(pp-eval-expression): Set font-lock-default locally to nil.
Richard M. Stallman <rms@gnu.org>
parents:
15446
diff
changeset
|
125 (make-local-variable 'font-lock-verbose) |
919ed1778c0b
(pp-eval-expression): Set font-lock-default locally to nil.
Richard M. Stallman <rms@gnu.org>
parents:
15446
diff
changeset
|
126 (setq font-lock-verbose nil)))) |
8544 | 127 |
10329 | 128 ;;;###autoload |
8544 | 129 (defun pp-eval-last-sexp (arg) |
130 "Run `pp-eval-expression' on sexp before point (which see). | |
131 With argument, pretty-print output into current buffer. | |
132 Ignores leading comment characters." | |
133 (interactive "P") | |
134 (let ((stab (syntax-table)) (pt (point)) start exp) | |
135 (set-syntax-table emacs-lisp-mode-syntax-table) | |
136 (save-excursion | |
137 (forward-sexp -1) | |
138 ;; If first line is commented, ignore all leading comments: | |
139 (if (save-excursion (beginning-of-line) (looking-at "[ \t]*;")) | |
140 (progn | |
141 (setq exp (buffer-substring (point) pt)) | |
142 (while (string-match "\n[ \t]*;+" exp start) | |
143 (setq start (1+ (match-beginning 0)) | |
144 exp (concat (substring exp 0 start) | |
145 (substring exp (match-end 0))))) | |
146 (setq exp (read exp))) | |
147 (setq exp (read (current-buffer))))) | |
148 (set-syntax-table stab) | |
149 (if arg | |
150 (insert (pp-to-string (eval exp))) | |
151 (pp-eval-expression exp)))) | |
152 | |
153 ;;; Test cases for quote | |
154 ;; (pp-eval-expression ''(quote quote)) | |
155 ;; (pp-eval-expression ''((quote a) (quote b))) | |
156 ;; (pp-eval-expression ''('a 'b)) ; same as above | |
157 ;; (pp-eval-expression ''((quote (quote quote)) (quote quote))) | |
158 ;; These do not satisfy the quote test. | |
159 ;; (pp-eval-expression ''quote) | |
160 ;; (pp-eval-expression ''(quote)) | |
161 ;; (pp-eval-expression ''(quote . quote)) | |
162 ;; (pp-eval-expression ''(quote a b)) | |
163 ;; (pp-eval-expression ''(quotefoo)) | |
164 ;; (pp-eval-expression ''(a b)) | |
165 | |
166 (provide 'pp) ; so (require 'pp) works | |
167 | |
38436
b174db545cfd
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
23244
diff
changeset
|
168 ;;; pp.el ends here |