annotate lisp/emacs-lisp/pp.el @ 105813:df4934f25eef

* textmodes/two-column.el (2C-split): * textmodes/texnfo-upd.el (texinfo-multi-file-included-list): * textmodes/tex-mode.el (tex-set-buffer-directory): * textmodes/spell.el (spell-region, spell-string): * textmodes/reftex.el (reftex-erase-buffer): (reftex-get-file-buffer-force, reftex-kill-temporary-buffers): * textmodes/reftex-toc.el (reftex-toc-promote-action): * textmodes/reftex-sel.el (reftex-get-offset, reftex-insert-docstruct) (reftex-select-item): * textmodes/reftex-ref.el (reftex-label-info-update) (reftex-offer-label-menu): * textmodes/reftex-index.el (reftex-index-change-entry) (reftex-index-phrases-info): * textmodes/reftex-global.el (reftex-create-tags-file) (reftex-save-all-document-buffers, reftex-ensure-write-access): * textmodes/reftex-dcr.el (reftex-echo-ref, reftex-echo-cite) (reftex-view-crossref-from-bibtex): * textmodes/reftex-cite.el (reftex-bibtex-selection-callback) (reftex-extract-bib-entries-from-thebibliography) (reftex-all-used-citation-keys, reftex-create-bibtex-file): * textmodes/refbib.el (r2b-capitalize-title): (r2b-convert-buffer, r2b-help): * textmodes/page-ext.el (pages-directory) (pages-directory-goto-with-mouse): * textmodes/bibtex.el (bibtex-validate-globally): * textmodes/bib-mode.el (bib-capitalize-title): * textmodes/artist.el (artist-clear-buffer, artist-system): * progmodes/xscheme.el (global-set-scheme-interaction-buffer): (local-set-scheme-interaction-buffer, xscheme-process-filter) (verify-xscheme-buffer, xscheme-enter-interaction-mode) (xscheme-enter-debugger-mode, xscheme-debugger-mode-p) (xscheme-send-control-g-interrupt, xscheme-start-process) (xscheme-process-sentinel, xscheme-cd): * progmodes/verilog-mode.el (verilog-read-always-signals) (verilog-set-define, verilog-getopt-file) (verilog-module-inside-filename-p): * progmodes/sh-script.el: * progmodes/python.el (python-pdbtrack-get-source-buffer) (python-pdbtrack-grub-for-buffer, python-execute-file): * progmodes/octave-inf.el (inferior-octave): * progmodes/idlwave.el (idlwave-scan-user-lib-files) (idlwave-shell-compile-helper-routines, idlwave-set-local) (idlwave-display-completion-list-xemacs, idlwave-list-abbrevs) (idlwave-display-completion-list-emacs, idlwave-list-load-path-shadows) (idlwave-completion-fontify-classes, idlwave-display-calling-sequence): * progmodes/idlw-shell.el (idlwave-shell-examine-display-clear) (idlwave-shell-filter, idlwave-shell-examine-highlight) (idlwave-shell-sentinel, idlwave-shell-filter-directory) (idlwave-shell-display-line, idlwave-shell-set-bp-in-module) (idlwave-shell-examine-display, idlwave-shell-run-region) (idlwave-shell-filter-bp, idlwave-shell-save-and-action) (idlwave-shell-sources-filter, idlwave-shell-goto-next-error): * progmodes/idlw-help.el (idlwave-help-get-special-help) (idlwave-help-get-help-buffer): * progmodes/gud.el (gud-basic-call, gud-find-class) (gud-tooltip-activate-mouse-motions-if-enabled): * progmodes/gdb-mi.el (gdb-mouse-toggle-breakpoint-fringe): * progmodes/ebrowse.el (ebrowse-member-table, ebrowse-save-tree-as) (ebrowse-view-exit-fn, ebrowse-tags-list-members-in-file) (ebrowse-tags-next-file): * progmodes/ebnf2ps.el (ebnf-generate-eps, ebnf-generate-eps) (ebnf-eps-production-list, ebnf-begin-file, ebnf-log) (ebnf-eps-finish-and-write): * progmodes/cpp.el (cpp-edit-save): * progmodes/cperl-mode.el (cperl-pod-to-manpage): * progmodes/cc-defs.el (c-emacs-features): * progmodes/antlr-mode.el (antlr-invalidate-context-cache) (antlr-directory-dependencies): * progmodes/ada-xref.el (ada-gnat-parse-gpr, ada-get-ali-file-name) (ada-run-application, ada-find-in-src-path, ada-goto-parent) (ada-find-any-references, ada-make-filename-from-adaname) (ada-make-body-gnatstub): * obsolete/rnews.el (news-list-news-groups): * obsolete/resume.el (resume-suspend-hook,resume-write-buffer-to-file): * obsolete/iso-acc.el (iso-acc-minibuf-setup): * net/rcirc.el (rcirc-debug): * net/newst-treeview.el (newsticker--treeview-list-add-item) (newsticker--treeview-list-clear, newsticker-treeview-browse-url) (newsticker--treeview-list-update-faces, newsticker-treeview-save) (newsticker--treeview-item-show-text, newsticker--treeview-item-show) (newsticker--treeview-tree-update-tag,newsticker--treeview-buffer-init) (newsticker-treeview-show-item, newsticker--treeview-unfold-node) (newsticker--treeview-list-clear-highlight) (newsticker--treeview-list-update-highlight) (newsticker--treeview-list-highlight-start) (newsticker--treeview-tree-update-highlight) (newsticker--treeview-get-selected-item) (newsticker-treeview-mark-list-items-old) (newsticker--treeview-set-current-node): * net/newst-plainview.el (newsticker--buffer-set-uptodate): * net/newst-backend.el (newsticker--get-news-by-funcall) (newsticker--get-news-by-wget, newsticker--image-get) (newsticker--image-sentinel): * net/mairix.el (mairix-rmail-fetch-field, mairix-gnus-fetch-field): * net/eudcb-ph.el (eudc-ph-do-request, eudc-ph-open-session): (eudc-ph-close-session): * net/eudc.el (eudc-save-options): * language/thai-word.el (thai-update-word-table): * language/japan-util.el (japanese-string-conversion): * international/titdic-cnv.el (tsang-quick-converter) (ziranma-converter, ctlau-converter): * international/mule-cmds.el (describe-language-environment): * international/ja-dic-cnv.el (skkdic-convert-okuri-ari) (skkdic-convert-postfix, skkdic-convert-prefix): (skkdic-convert-okuri-nasi, skkdic-convert): * emacs-lisp/re-builder.el (reb-update-overlays): * emacs-lisp/pp.el (pp-to-string, pp-display-expression): * emacs-lisp/gulp.el (gulp-send-requests): * emacs-lisp/find-gc.el (trace-call-tree): * emacs-lisp/eieio-opt.el (eieio-browse, eieio-describe-class) (eieio-describe-generic): * emacs-lisp/eieio-base.el (eieio-persistent-read): * emacs-lisp/edebug.el (edebug-outside-excursion): * emacs-lisp/debug.el (debugger-make-xrefs): * emacs-lisp/cust-print.el (custom-prin1-to-string): * emacs-lisp/chart.el (chart-new-buffer): * emacs-lisp/authors.el (authors-scan-el, authors-scan-change-log): Use with-current-buffer. * textmodes/artist.el (artist-system): Don't call copy-sequence on a fresh string. * progmodes/idlw-shell.el (easymenu setup): Use dolist.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Sat, 31 Oct 2009 02:38:34 +0000
parents cce8d50c4566
children 1d1d5d9bd884
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
13337
84acc3adcd63 Comment change.
Richard M. Stallman <rms@gnu.org>
parents: 11730
diff changeset
1 ;;; pp.el --- pretty printer for Emacs Lisp
14169
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 13337
diff changeset
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,
100908
a9dc0e7c3f2b Add 2009 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 94655
diff changeset
4 ;; 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
8544
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
5
14224
e47d5fcad4be Comment change.
Erik Naggum <erik@naggum.no>
parents: 14169
diff changeset
6 ;; Author: Randal Schwartz <merlyn@stonehenge.com>
39117
abd085bfec0c Add Keywords header.
Gerd Moellmann <gerd@gnu.org>
parents: 38436
diff changeset
7 ;; Keywords: lisp
8544
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
8
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
9 ;; This file is part of GNU Emacs.
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
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
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
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
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
15
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
16 ;; GNU Emacs is distributed in the hope that it will be useful,
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
19 ;; GNU General Public License for more details.
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
20
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
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
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
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
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
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
db005054f15d Customized.
Stephen Eglen <stephen@gnu.org>
parents: 20598
diff changeset
30 (defgroup pp nil
db005054f15d Customized.
Stephen Eglen <stephen@gnu.org>
parents: 20598
diff changeset
31 "Pretty printer for Emacs Lisp."
db005054f15d Customized.
Stephen Eglen <stephen@gnu.org>
parents: 20598
diff changeset
32 :prefix "pp-"
db005054f15d Customized.
Stephen Eglen <stephen@gnu.org>
parents: 20598
diff changeset
33 :group 'lisp)
8544
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
34
49598
0d8b17d428b5 Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 43295
diff changeset
35 (defcustom pp-escape-newlines t
104024
cce8d50c4566 Remove leading * from defcustom docs.
Glenn Morris <rgm@gnu.org>
parents: 100908
diff changeset
36 "Value of `print-escape-newlines' used by pp-* functions."
21365
db005054f15d Customized.
Stephen Eglen <stephen@gnu.org>
parents: 20598
diff changeset
37 :type 'boolean
db005054f15d Customized.
Stephen Eglen <stephen@gnu.org>
parents: 20598
diff changeset
38 :group 'pp)
8544
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
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
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
41 (defun pp-to-string (object)
23244
67e80974136e Doc fixes.
Karl Heuer <kwzh@gnu.org>
parents: 21365
diff changeset
42 "Return a string containing the pretty-printed representation of OBJECT.
67e80974136e Doc fixes.
Karl Heuer <kwzh@gnu.org>
parents: 21365
diff changeset
43 OBJECT can be any Lisp object. Quoting characters are used as needed
67e80974136e Doc fixes.
Karl Heuer <kwzh@gnu.org>
parents: 21365
diff changeset
44 to make output that `read' can handle, whenever this is possible."
105813
df4934f25eef * textmodes/two-column.el (2C-split):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 104024
diff changeset
45 (with-current-buffer (generate-new-buffer " pp-to-string")
8544
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
46 (unwind-protect
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
47 (progn
19147
ec57f19bc39c (pp-to-string): Use emacs-lisp-mode-sytax-table.
Richard M. Stallman <rms@gnu.org>
parents: 16171
diff changeset
48 (lisp-mode-variables nil)
ec57f19bc39c (pp-to-string): Use emacs-lisp-mode-sytax-table.
Richard M. Stallman <rms@gnu.org>
parents: 16171
diff changeset
49 (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
50 (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
51 (print-quoted t))
8544
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
52 (prin1 object (current-buffer)))
55802
7bb617df33db (pp-buffer): New fun created from the code in
Juri Linkov <juri@jurta.org>
parents: 54502
diff changeset
53 (pp-buffer)
8544
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
54 (buffer-string))
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
55 (kill-buffer (current-buffer)))))
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
56
56274
25c3950468a9 (pp-buffer): Add autoload.
Juri Linkov <juri@jurta.org>
parents: 55802
diff changeset
57 ;;;###autoload
55802
7bb617df33db (pp-buffer): New fun created from the code in
Juri Linkov <juri@jurta.org>
parents: 54502
diff changeset
58 (defun pp-buffer ()
7bb617df33db (pp-buffer): New fun created from the code in
Juri Linkov <juri@jurta.org>
parents: 54502
diff changeset
59 "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
60 (goto-char (point-min))
7bb617df33db (pp-buffer): New fun created from the code in
Juri Linkov <juri@jurta.org>
parents: 54502
diff changeset
61 (while (not (eobp))
7bb617df33db (pp-buffer): New fun created from the code in
Juri Linkov <juri@jurta.org>
parents: 54502
diff changeset
62 ;; (message "%06d" (- (point-max) (point)))
7bb617df33db (pp-buffer): New fun created from the code in
Juri Linkov <juri@jurta.org>
parents: 54502
diff changeset
63 (cond
7bb617df33db (pp-buffer): New fun created from the code in
Juri Linkov <juri@jurta.org>
parents: 54502
diff changeset
64 ((condition-case err-var
7bb617df33db (pp-buffer): New fun created from the code in
Juri Linkov <juri@jurta.org>
parents: 54502
diff changeset
65 (prog1 t (down-list 1))
7bb617df33db (pp-buffer): New fun created from the code in
Juri Linkov <juri@jurta.org>
parents: 54502
diff changeset
66 (error nil))
7bb617df33db (pp-buffer): New fun created from the code in
Juri Linkov <juri@jurta.org>
parents: 54502
diff changeset
67 (save-excursion
7bb617df33db (pp-buffer): New fun created from the code in
Juri Linkov <juri@jurta.org>
parents: 54502
diff changeset
68 (backward-char 1)
7bb617df33db (pp-buffer): New fun created from the code in
Juri Linkov <juri@jurta.org>
parents: 54502
diff changeset
69 (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
70 (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
71 (delete-region
7bb617df33db (pp-buffer): New fun created from the code in
Juri Linkov <juri@jurta.org>
parents: 54502
diff changeset
72 (point)
7bb617df33db (pp-buffer): New fun created from the code in
Juri Linkov <juri@jurta.org>
parents: 54502
diff changeset
73 (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
74 (insert "\n"))))
7bb617df33db (pp-buffer): New fun created from the code in
Juri Linkov <juri@jurta.org>
parents: 54502
diff changeset
75 ((condition-case err-var
7bb617df33db (pp-buffer): New fun created from the code in
Juri Linkov <juri@jurta.org>
parents: 54502
diff changeset
76 (prog1 t (up-list 1))
7bb617df33db (pp-buffer): New fun created from the code in
Juri Linkov <juri@jurta.org>
parents: 54502
diff changeset
77 (error nil))
7bb617df33db (pp-buffer): New fun created from the code in
Juri Linkov <juri@jurta.org>
parents: 54502
diff changeset
78 (while (looking-at "\\s)")
7bb617df33db (pp-buffer): New fun created from the code in
Juri Linkov <juri@jurta.org>
parents: 54502
diff changeset
79 (forward-char 1))
7bb617df33db (pp-buffer): New fun created from the code in
Juri Linkov <juri@jurta.org>
parents: 54502
diff changeset
80 (delete-region
7bb617df33db (pp-buffer): New fun created from the code in
Juri Linkov <juri@jurta.org>
parents: 54502
diff changeset
81 (point)
7bb617df33db (pp-buffer): New fun created from the code in
Juri Linkov <juri@jurta.org>
parents: 54502
diff changeset
82 (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
83 (insert ?\n))
7bb617df33db (pp-buffer): New fun created from the code in
Juri Linkov <juri@jurta.org>
parents: 54502
diff changeset
84 (t (goto-char (point-max)))))
7bb617df33db (pp-buffer): New fun created from the code in
Juri Linkov <juri@jurta.org>
parents: 54502
diff changeset
85 (goto-char (point-min))
7bb617df33db (pp-buffer): New fun created from the code in
Juri Linkov <juri@jurta.org>
parents: 54502
diff changeset
86 (indent-sexp))
7bb617df33db (pp-buffer): New fun created from the code in
Juri Linkov <juri@jurta.org>
parents: 54502
diff changeset
87
10329
aa393c4b380c Add autoload cookies.
Noah Friedman <friedman@splode.com>
parents: 8544
diff changeset
88 ;;;###autoload
8544
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
89 (defun pp (object &optional stream)
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
90 "Output the pretty-printed representation of OBJECT, any Lisp object.
23244
67e80974136e Doc fixes.
Karl Heuer <kwzh@gnu.org>
parents: 21365
diff changeset
91 Quoting characters are printed as needed to make output that `read'
8544
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
92 can handle, whenever this is possible.
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
93 Output stream is STREAM, or value of `standard-output' (which see)."
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
94 (princ (pp-to-string object) (or stream standard-output)))
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
95
94354
26ba760c38d0 Johannes Weiner <hannes at saeurebad.de>
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
96 (defun pp-display-expression (expression out-buffer-name)
26ba760c38d0 Johannes Weiner <hannes at saeurebad.de>
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
97 "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
98 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
99 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
100 (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
101 ;; 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
102 ;; 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
103 ;; 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
104 (temp-buffer-show-function
8544
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
105 (function
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
106 (lambda (buf)
105813
df4934f25eef * textmodes/two-column.el (2C-split):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 104024
diff changeset
107 (with-current-buffer buf
8544
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
108 (goto-char (point-min))
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
109 (end-of-line 1)
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
110 (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
111 (>= (- (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
112 (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
113 (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
114 (window (display-buffer buf)))
8544
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
115 (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
116 (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
117 (unwind-protect
084c36d46615 (pp-eval-expression): Update use of temp-buffer-show-function.
Richard M. Stallman <rms@gnu.org>
parents: 10732
diff changeset
118 (progn
084c36d46615 (pp-eval-expression): Update use of temp-buffer-show-function.
Richard M. Stallman <rms@gnu.org>
parents: 10732
diff changeset
119 (select-window window)
084c36d46615 (pp-eval-expression): Update use of temp-buffer-show-function.
Richard M. Stallman <rms@gnu.org>
parents: 10732
diff changeset
120 (run-hooks 'temp-buffer-show-hook))
87649
107ccd98fa12 Merge from emacs--rel--22
Miles Bader <miles@gnu.org>
parents: 79704
diff changeset
121 (select-window old-selected)
94354
26ba760c38d0 Johannes Weiner <hannes at saeurebad.de>
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
122 (message "See buffer %s." out-buffer-name)))
8544
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
123 (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
124 ))))))
94354
26ba760c38d0 Johannes Weiner <hannes at saeurebad.de>
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
125 (with-output-to-temp-buffer out-buffer-name
26ba760c38d0 Johannes Weiner <hannes at saeurebad.de>
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
126 (pp expression)
54502
a8550ca246eb (pp-eval-expression): Simplify.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52401
diff changeset
127 (with-current-buffer standard-output
a8550ca246eb (pp-eval-expression): Simplify.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52401
diff changeset
128 (emacs-lisp-mode)
87649
107ccd98fa12 Merge from emacs--rel--22
Miles Bader <miles@gnu.org>
parents: 79704
diff changeset
129 (setq buffer-read-only nil)
54502
a8550ca246eb (pp-eval-expression): Simplify.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 52401
diff changeset
130 (set (make-local-variable 'font-lock-verbose) nil)))))
8544
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
131
10329
aa393c4b380c Add autoload cookies.
Noah Friedman <friedman@splode.com>
parents: 8544
diff changeset
132 ;;;###autoload
94354
26ba760c38d0 Johannes Weiner <hannes at saeurebad.de>
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
133 (defun pp-eval-expression (expression)
26ba760c38d0 Johannes Weiner <hannes at saeurebad.de>
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
134 "Evaluate EXPRESSION and pretty-print its value.
26ba760c38d0 Johannes Weiner <hannes at saeurebad.de>
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
135 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
136 (interactive
26ba760c38d0 Johannes Weiner <hannes at saeurebad.de>
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
137 (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
138 'read-expression-history)))
26ba760c38d0 Johannes Weiner <hannes at saeurebad.de>
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
139 (message "Evaluating...")
26ba760c38d0 Johannes Weiner <hannes at saeurebad.de>
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
140 (setq values (cons (eval expression) values))
26ba760c38d0 Johannes Weiner <hannes at saeurebad.de>
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
141 (pp-display-expression (car values) "*Pp Eval Output*"))
26ba760c38d0 Johannes Weiner <hannes at saeurebad.de>
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
142
26ba760c38d0 Johannes Weiner <hannes at saeurebad.de>
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
143 ;;;###autoload
26ba760c38d0 Johannes Weiner <hannes at saeurebad.de>
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
144 (defun pp-macroexpand-expression (expression)
26ba760c38d0 Johannes Weiner <hannes at saeurebad.de>
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
145 "Macroexpand EXPRESSION and pretty-print its value."
26ba760c38d0 Johannes Weiner <hannes at saeurebad.de>
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
146 (interactive
26ba760c38d0 Johannes Weiner <hannes at saeurebad.de>
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
147 (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
148 'read-expression-history)))
26ba760c38d0 Johannes Weiner <hannes at saeurebad.de>
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
149 (pp-display-expression (macroexpand expression) "*Pp Macroexpand Output*"))
26ba760c38d0 Johannes Weiner <hannes at saeurebad.de>
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
150
26ba760c38d0 Johannes Weiner <hannes at saeurebad.de>
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
151 (defun pp-last-sexp ()
26ba760c38d0 Johannes Weiner <hannes at saeurebad.de>
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
152 "Read sexp before point. Ignores leading comment characters."
8544
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
153 (let ((stab (syntax-table)) (pt (point)) start exp)
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
154 (set-syntax-table emacs-lisp-mode-syntax-table)
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
155 (save-excursion
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
156 (forward-sexp -1)
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
157 ;; If first line is commented, ignore all leading comments:
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
158 (if (save-excursion (beginning-of-line) (looking-at "[ \t]*;"))
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
159 (progn
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
160 (setq exp (buffer-substring (point) pt))
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
161 (while (string-match "\n[ \t]*;+" exp start)
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
162 (setq start (1+ (match-beginning 0))
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
163 exp (concat (substring exp 0 start)
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
164 (substring exp (match-end 0)))))
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
165 (setq exp (read exp)))
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
166 (setq exp (read (current-buffer)))))
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
167 (set-syntax-table stab)
94354
26ba760c38d0 Johannes Weiner <hannes at saeurebad.de>
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
168 exp))
26ba760c38d0 Johannes Weiner <hannes at saeurebad.de>
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
169
26ba760c38d0 Johannes Weiner <hannes at saeurebad.de>
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
170 ;;;###autoload
26ba760c38d0 Johannes Weiner <hannes at saeurebad.de>
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
171 (defun pp-eval-last-sexp (arg)
26ba760c38d0 Johannes Weiner <hannes at saeurebad.de>
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
172 "Run `pp-eval-expression' on sexp before point.
26ba760c38d0 Johannes Weiner <hannes at saeurebad.de>
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
173 With argument, pretty-print output into current buffer.
26ba760c38d0 Johannes Weiner <hannes at saeurebad.de>
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
174 Ignores leading comment characters."
26ba760c38d0 Johannes Weiner <hannes at saeurebad.de>
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
175 (interactive "P")
26ba760c38d0 Johannes Weiner <hannes at saeurebad.de>
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
176 (if arg
26ba760c38d0 Johannes Weiner <hannes at saeurebad.de>
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
177 (insert (pp-to-string (eval (pp-last-sexp))))
26ba760c38d0 Johannes Weiner <hannes at saeurebad.de>
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
178 (pp-eval-expression (pp-last-sexp))))
26ba760c38d0 Johannes Weiner <hannes at saeurebad.de>
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
179
26ba760c38d0 Johannes Weiner <hannes at saeurebad.de>
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
180 ;;;###autoload
26ba760c38d0 Johannes Weiner <hannes at saeurebad.de>
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
181 (defun pp-macroexpand-last-sexp (arg)
26ba760c38d0 Johannes Weiner <hannes at saeurebad.de>
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
182 "Run `pp-macroexpand-expression' on sexp before point.
26ba760c38d0 Johannes Weiner <hannes at saeurebad.de>
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
183 With argument, pretty-print output into current buffer.
26ba760c38d0 Johannes Weiner <hannes at saeurebad.de>
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
184 Ignores leading comment characters."
26ba760c38d0 Johannes Weiner <hannes at saeurebad.de>
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
185 (interactive "P")
26ba760c38d0 Johannes Weiner <hannes at saeurebad.de>
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
186 (if arg
26ba760c38d0 Johannes Weiner <hannes at saeurebad.de>
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
187 (insert (pp-to-string (macroexpand (pp-last-sexp))))
26ba760c38d0 Johannes Weiner <hannes at saeurebad.de>
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
188 (pp-macroexpand-expression (pp-last-sexp))))
8544
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
189
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
190 ;;; Test cases for quote
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
191 ;; (pp-eval-expression ''(quote quote))
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
192 ;; (pp-eval-expression ''((quote a) (quote b)))
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
193 ;; (pp-eval-expression ''('a 'b)) ; same as above
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
194 ;; (pp-eval-expression ''((quote (quote quote)) (quote quote)))
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
195 ;; These do not satisfy the quote test.
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
196 ;; (pp-eval-expression ''quote)
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
197 ;; (pp-eval-expression ''(quote))
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
198 ;; (pp-eval-expression ''(quote . quote))
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
199 ;; (pp-eval-expression ''(quote a b))
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
200 ;; (pp-eval-expression ''(quotefoo))
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
201 ;; (pp-eval-expression ''(a b))
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
202
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
203 (provide 'pp) ; so (require 'pp) works
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
204
93975
1e3a407766b9 Fix up comment convention on the arch-tag lines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
205 ;; 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
206 ;;; pp.el ends here