annotate lisp/emacs-lisp/pp.el @ 30408:e3e2c9051c5f

Got rid of all byte-compiler warnings on Emacs. Add to the menu when the file is loaded, not in ada-mode-hook. Add -toolbar to the default ddd command Switches moved from ada-prj-default-comp-cmd and ada-prj-default-make-cmd to ada-prj-default-comp-opt (ada-add-ada-menu): Remove the map and name parameters Add the Ada Reference Manual to the menu (ada-check-current): rewritten as a call to ada-compile-current (ada-compile): Removed. (ada-compile-application, ada-compile-current, ada-check-current): Set the compilation-search-path so that compile.el automatically finds the sources in src_dir. Automatic scrollong of the compilation buffer. C-uC-cC-c asks for confirmation before compiling (ada-compile-current): New parameter, prj-field (ada-complete-identifier): Load the .ali file before doing processing (ada-find-ali-file-in-dir): prepend build_dir to obj_dir to conform to gnatmake's behavior. (ada-find-file-in-dir): New function (ada-find-references): Set the environment variables for gnatfind (ada-find-src-file-in-dir): New function. (ada-first-non-nil): Removed (ada-gdb-application): Add support for jdb, the java debugger. (ada-get-ada-file-name): Load the original-file first if not done yet. (ada-get-all-references): Handles the new ali syntax (parent types are found between <>). (ada-initialize-runtime-library): New function (ada-mode-hook): Always load a project file when a file is opened, so that the casing exceptions are correctly read. (ada-operator-re): Add all missing operators ("abs", "rem", "**"). (ada-parse-prj-file): Use find-file-noselect instead of find-file to open the project file, since the latter does not work with speedbar Get default values before loading the prj file, or the default executable file name is wrong. Use the absolute value of src_dir to initialize ada-search-directories and compilation-search-path,... Add the standard runtime library to the search path for find-file. (ada-prj-default-debugger): Was missing an opening '{' (ada-prj-default-bind-opt, ada-prj-default-link-opt): New variables. (ada-prj-default-gnatmake-opt): New variable (ada-prj-find-prj-file): Handles non-file buffers For non-Ada buffers, the project file is the default one Save the windows configuration before displaying the menu. (ada-prj-src-dir, ada-prj-obj-dir, ada-prj-comp-opt,...): Removed (ada-read-identifier): Fix xrefs on operators (for "mod", "and", ...) regexp-quote identifiers names to support operators +, -,... in regexps. (ada-remote): New function. (ada-run-application): Erase the output buffer before starting the run Support remote execution of the application. Use call-process, or the arguments are incorrectly parsed (ada-set-default-project-file): Reread the content of the active project file, not the one from the current buffer When a project file is set as the default project, all directories are automatically associated with it. (ada-set-environment): New function (ada-treat-cmd-string): New special variable ${current} (ada-treat-cmd-string): Revised. The substitution is now done for any ${...} substring (ada-xref-current): If no body was found, compiles the spec instead. Setup ADA_{SOURCE,OBJECTS}_PATH before running the compiler to get rid of command line length limitations. (ada-xref-get-project-field): New function (ada-xref-project-files): New variable (ada-xref-runtime-library-specs-path) (ada-xref-runtime-library-ali-path): New variables (ada-xref-set-default-prj-values): Default run command now does a cd to the build directory. New field: main_unit Provide a default file name even if the current buffer has no prj file.
author Gerd Moellmann <gerd@gnu.org>
date Mon, 24 Jul 2000 11:13:11 +0000
parents 67e80974136e
children b174db545cfd
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
8544
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3 ;; Copyright (C) 1989, 1993 Free Software Foundation, Inc.
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
4
14224
e47d5fcad4be Comment change.
Erik Naggum <erik@naggum.no>
parents: 14169
diff changeset
5 ;; Author: Randal Schwartz <merlyn@stonehenge.com>
8544
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
6
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
7 ;; This file is part of GNU Emacs.
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 ;; GNU Emacs is free software; you can redistribute it and/or modify
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
10 ;; 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
11 ;; the Free Software Foundation; either version 2, or (at your option)
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
12 ;; any later version.
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
13
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
14 ;; GNU Emacs is distributed in the hope that it will be useful,
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
17 ;; GNU General Public License for more details.
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
18
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
19 ;; You should have received a copy of the GNU General Public License
14169
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 13337
diff changeset
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 13337
diff changeset
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 13337
diff changeset
22 ;; Boston, MA 02111-1307, USA.
8544
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 ;;; Code:
21365
db005054f15d Customized.
Stephen Eglen <stephen@gnu.org>
parents: 20598
diff changeset
25 (defgroup pp nil
db005054f15d Customized.
Stephen Eglen <stephen@gnu.org>
parents: 20598
diff changeset
26 "Pretty printer for Emacs Lisp."
db005054f15d Customized.
Stephen Eglen <stephen@gnu.org>
parents: 20598
diff changeset
27 :prefix "pp-"
db005054f15d Customized.
Stephen Eglen <stephen@gnu.org>
parents: 20598
diff changeset
28 :group 'lisp)
8544
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
29
21365
db005054f15d Customized.
Stephen Eglen <stephen@gnu.org>
parents: 20598
diff changeset
30 (defcustom pp-escape-newlines t
db005054f15d Customized.
Stephen Eglen <stephen@gnu.org>
parents: 20598
diff changeset
31 "*Value of `print-escape-newlines' used by pp-* functions."
db005054f15d Customized.
Stephen Eglen <stephen@gnu.org>
parents: 20598
diff changeset
32 :type 'boolean
db005054f15d Customized.
Stephen Eglen <stephen@gnu.org>
parents: 20598
diff changeset
33 :group 'pp)
8544
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
34
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
35 (defun pp-to-string (object)
23244
67e80974136e Doc fixes.
Karl Heuer <kwzh@gnu.org>
parents: 21365
diff changeset
36 "Return a string containing the pretty-printed representation of OBJECT.
67e80974136e Doc fixes.
Karl Heuer <kwzh@gnu.org>
parents: 21365
diff changeset
37 OBJECT can be any Lisp object. Quoting characters are used as needed
67e80974136e Doc fixes.
Karl Heuer <kwzh@gnu.org>
parents: 21365
diff changeset
38 to make output that `read' can handle, whenever this is possible."
8544
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
39 (save-excursion
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
40 (set-buffer (generate-new-buffer " pp-to-string"))
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
41 (unwind-protect
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
42 (progn
19147
ec57f19bc39c (pp-to-string): Use emacs-lisp-mode-sytax-table.
Richard M. Stallman <rms@gnu.org>
parents: 16171
diff changeset
43 (lisp-mode-variables nil)
ec57f19bc39c (pp-to-string): Use emacs-lisp-mode-sytax-table.
Richard M. Stallman <rms@gnu.org>
parents: 16171
diff changeset
44 (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
45 (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
46 (print-quoted t))
8544
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
47 (prin1 object (current-buffer)))
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
48 (goto-char (point-min))
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
49 (while (not (eobp))
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
50 ;; (message "%06d" (- (point-max) (point)))
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
51 (cond
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
52 ((condition-case err-var
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
53 (prog1 t (down-list 1))
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
54 (error nil))
20598
a61e2395961f (pp-to-string): Greatly simplify by letting the
Andreas Schwab <schwab@suse.de>
parents: 19147
diff changeset
55 (save-excursion
a61e2395961f (pp-to-string): Greatly simplify by letting the
Andreas Schwab <schwab@suse.de>
parents: 19147
diff changeset
56 (backward-char 1)
a61e2395961f (pp-to-string): Greatly simplify by letting the
Andreas Schwab <schwab@suse.de>
parents: 19147
diff changeset
57 (skip-chars-backward "'`#^")
a61e2395961f (pp-to-string): Greatly simplify by letting the
Andreas Schwab <schwab@suse.de>
parents: 19147
diff changeset
58 (when (and (not (bobp)) (= ?\ (char-before)))
a61e2395961f (pp-to-string): Greatly simplify by letting the
Andreas Schwab <schwab@suse.de>
parents: 19147
diff changeset
59 (delete-char -1)
a61e2395961f (pp-to-string): Greatly simplify by letting the
Andreas Schwab <schwab@suse.de>
parents: 19147
diff changeset
60 (insert "\n"))))
8544
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
61 ((condition-case err-var
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
62 (prog1 t (up-list 1))
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
63 (error nil))
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
64 (while (looking-at "\\s)")
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
65 (forward-char 1))
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
66 (delete-region
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
67 (point)
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
68 (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
69 (insert ?\n))
8544
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
70 (t (goto-char (point-max)))))
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
71 (goto-char (point-min))
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
72 (indent-sexp)
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
73 (buffer-string))
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
74 (kill-buffer (current-buffer)))))
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
75
10329
aa393c4b380c Add autoload cookies.
Noah Friedman <friedman@splode.com>
parents: 8544
diff changeset
76 ;;;###autoload
8544
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
77 (defun pp (object &optional stream)
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
78 "Output the pretty-printed representation of OBJECT, any Lisp object.
23244
67e80974136e Doc fixes.
Karl Heuer <kwzh@gnu.org>
parents: 21365
diff changeset
79 Quoting characters are printed as needed to make output that `read'
8544
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
80 can handle, whenever this is possible.
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
81 Output stream is STREAM, or value of `standard-output' (which see)."
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
82 (princ (pp-to-string object) (or stream standard-output)))
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
83
10329
aa393c4b380c Add autoload cookies.
Noah Friedman <friedman@splode.com>
parents: 8544
diff changeset
84 ;;;###autoload
8544
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
85 (defun pp-eval-expression (expression)
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
86 "Evaluate EXPRESSION and pretty-print value into a new display buffer.
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
87 If the pretty-printed value fits on one line, the message line is used
23244
67e80974136e Doc fixes.
Karl Heuer <kwzh@gnu.org>
parents: 21365
diff changeset
88 instead. The value is also consed onto the front of the list
67e80974136e Doc fixes.
Karl Heuer <kwzh@gnu.org>
parents: 21365
diff changeset
89 in the variable `values'."
8544
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
90 (interactive "xPp-eval: ")
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
91 (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
92 (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
93 ;; 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
94 ;; 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
95 ;; 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
96 (temp-buffer-show-function
8544
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
97 (function
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
98 (lambda (buf)
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
99 (save-excursion
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
100 (set-buffer buf)
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
101 (goto-char (point-min))
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
102 (end-of-line 1)
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
103 (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
104 (>= (- (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
105 (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
106 (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
107 (window (display-buffer buf)))
8544
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
108 (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
109 (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
110 (unwind-protect
084c36d46615 (pp-eval-expression): Update use of temp-buffer-show-function.
Richard M. Stallman <rms@gnu.org>
parents: 10732
diff changeset
111 (progn
084c36d46615 (pp-eval-expression): Update use of temp-buffer-show-function.
Richard M. Stallman <rms@gnu.org>
parents: 10732
diff changeset
112 (select-window window)
084c36d46615 (pp-eval-expression): Update use of temp-buffer-show-function.
Richard M. Stallman <rms@gnu.org>
parents: 10732
diff changeset
113 (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
114 (select-window old-selected)))
8544
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
115 (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
116 ))))))
8544
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
117 (with-output-to-temp-buffer "*Pp Eval Output*"
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
118 (pp (car values)))
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
119 (save-excursion
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
120 (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
121 (emacs-lisp-mode)
919ed1778c0b (pp-eval-expression): Set font-lock-default locally to nil.
Richard M. Stallman <rms@gnu.org>
parents: 15446
diff changeset
122 (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
123 (setq font-lock-verbose nil))))
8544
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
124
10329
aa393c4b380c Add autoload cookies.
Noah Friedman <friedman@splode.com>
parents: 8544
diff changeset
125 ;;;###autoload
8544
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
126 (defun pp-eval-last-sexp (arg)
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
127 "Run `pp-eval-expression' on sexp before point (which see).
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
128 With argument, pretty-print output into current buffer.
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
129 Ignores leading comment characters."
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
130 (interactive "P")
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
131 (let ((stab (syntax-table)) (pt (point)) start exp)
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
132 (set-syntax-table emacs-lisp-mode-syntax-table)
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 (forward-sexp -1)
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
135 ;; If first line is commented, ignore all leading comments:
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
136 (if (save-excursion (beginning-of-line) (looking-at "[ \t]*;"))
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
137 (progn
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
138 (setq exp (buffer-substring (point) pt))
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
139 (while (string-match "\n[ \t]*;+" exp start)
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
140 (setq start (1+ (match-beginning 0))
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
141 exp (concat (substring exp 0 start)
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
142 (substring exp (match-end 0)))))
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
143 (setq exp (read exp)))
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
144 (setq exp (read (current-buffer)))))
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
145 (set-syntax-table stab)
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
146 (if arg
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
147 (insert (pp-to-string (eval exp)))
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
148 (pp-eval-expression exp))))
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
149
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
150 ;;; Test cases for quote
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
151 ;; (pp-eval-expression ''(quote quote))
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
152 ;; (pp-eval-expression ''((quote a) (quote b)))
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
153 ;; (pp-eval-expression ''('a 'b)) ; same as above
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
154 ;; (pp-eval-expression ''((quote (quote quote)) (quote quote)))
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
155 ;; These do not satisfy the quote test.
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
156 ;; (pp-eval-expression ''quote)
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
157 ;; (pp-eval-expression ''(quote))
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
158 ;; (pp-eval-expression ''(quote . quote))
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
159 ;; (pp-eval-expression ''(quote a b))
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
160 ;; (pp-eval-expression ''(quotefoo))
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
161 ;; (pp-eval-expression ''(a b))
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
162
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
163 (provide 'pp) ; so (require 'pp) works
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
164
dc4a53a05b98 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
165 ;;; pp.el ends here.