annotate lisp/edebug/cl-read.el @ 27:0a3286277d9b

Added tag r19-15b96 for changeset 441bb1e64a06
author cvs
date Mon, 13 Aug 2007 08:51:34 +0200
parents b82b59fe008d
children ec9a17fef872
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 ;; Customizable, Common Lisp like reader for Emacs Lisp.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 ;; Copyright (C) 1993 by Guido Bosch <Guido.Bosch@loria.fr>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
5 ;; This file is part of XEmacs
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
7 ;; XEmacs is free software; you can redistribute it and/or modify it
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
8 ;; under the terms of the GNU General Public License as published by
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
9 ;; the Free Software Foundation; either version 2, or (at your option)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
10 ;; any later version.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
12 ;; XEmacs is distributed in the hope that it will be useful, but
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
13 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
15 ;; General Public License for more details.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 ;; You should have received a copy of the GNU General Public License
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
18 ;; along with XEmacs; see the file COPYING. If not, write to the Free
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
19 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
20 ;; 02111-1307, USA.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
22 ;;; Synched up with: Not in FSF
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
23
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
24 ;;; Commentary:
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
25
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 ;; Please send bugs and comments to the author.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 ;; <DISCLAIMER>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 ;; This program is still under development. Neither the author nor
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 ;; his employer accepts responsibility to anyone for the consequences of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 ;; using it or for whether it serves any particular purpose or works
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 ;; at all.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 ;; Introduction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 ;; ------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 ;; This package replaces the standard Emacs Lisp reader (implemented
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 ;; as a set of built-in Lisp function in C) by a flexible and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 ;; customizable Common Lisp like one (implemented entirely in Emacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 ;; Lisp). During reading of Emacs Lisp source files, it is about 40%
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 ;; slower than the built-in reader, but there is no difference in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 ;; loading byte compiled files - they dont contain any syntactic sugar
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 ;; and are loaded with the built in subroutine `load'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 ;; The user level functions for defining read tables, character and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 ;; dispatch macros are implemented according to the Commom Lisp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 ;; specification by Steel's (2nd edition), but the read macro functions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 ;; themselves are implemented in a slightly different way, because the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 ;; basic character reading is done in an Emacs buffer, and not by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 ;; using the primitive functions `read-char' and `unread-char', as real
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 ;; CL does. To get 100% compatibility with CL, the above functions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 ;; (or their equivalents) must be implemented as subroutines.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 ;; Another difference with real CL reading is that basic tokens (symbols
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 ;; numbers, strings, and a few more) are still read by the original
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 ;; built-in reader. This is necessary to get reasonable performance.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 ;; As a consquence, the read syntax of basic tokens can't be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 ;; customized.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 ;; Most of the built-in reader syntax has been replaced by lisp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 ;; character macros: parentheses and brackets, simple and double
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 ;; quotes, semicolon comments and the dot. In addition to that, the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 ;; following new syntax features are provided:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 ;; Backquote-Comma-Atsign Macro: `(,el ,@list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 ;; (the clumsy Emacs Lisp syntax (` ((, el) (,@ list))) is also
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 ;; supported, but with one restriction: the blank behind the quote
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 ;; characters is mandatory when using the old syntax. The cl reader
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 ;; needs it as a landmark to distinguish between old and new syntax.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 ;; An example:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 ;; With blanks, both readers read the same:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 ;; (` (, (head)) (,@ (tail))) -std-read-> (` (, (head)) (,@ (tail)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 ;; (` (, (head)) (,@ (tail))) -cl-read-> (` (, (head)) (,@ (tail)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 ;; Without blanks, the form is interpreted differently by the two readers:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 ;; (`(,(head)) (,@(tail))) -std-read-> (` (, (head)) (,@ (tail)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 ;; (`(,(head)) (,@(tail))) -cl-read-> ((` ((, ((head)))) ((,@ ((tail)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 ;; Dispatch Character Macro" `#'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 ;; #'<function> function quoting
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 ;; #\<charcter> character syntax
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 ;; #.<form> read time evaluation
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 ;; #p<path>, #P<path> paths
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 ;; #+<feature>, #-<feature> conditional reading
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 ;; #<n>=, #<n># tags for shared structure reading
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 ;; Other read macros can be added easily (see the definition of the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 ;; above ones in this file, using the functions `set-macro-character'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 ;; and `set-dispatch-macro-character')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 ;; The Cl reader is mostly downward compatile, (exception: backquote
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 ;; comma macro, see above). E.g., this file, which is written entirely
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 ;; in the standard Emacs Lisp syntax, can be read and compiled with the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 ;; cl-reader activated (see Examples below).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 ;; This also works with package.el for Common Lisp packages.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 ;; Requirements
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 ;; ------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 ;; The package runs on Emacs 18 and Emacs 19 (FSF and Lucid) It is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 ;; built on top of Dave Gillespie's cl.el package (version 2.02 or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 ;; later). The old one (from Ceazar Quiroz, still shiped with some
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 ;; Emacs 19 disributions) will not do.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 ;; Usage
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 ;; -----
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 ;; The package is implemented as a kind of minor mode to the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 ;; emacs-lisp-mode. As most of the Emacs Lisp files are still written
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 ;; in the standard Emacs Lisp syntax, the cl reader is only activated
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 ;; on elisp files whose property lines contain the following entry:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 ;; -*- Read-Syntax: Common-Lisp -*-
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 ;; Note that both property name ("Read-Syntax") and value
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 ;; ("Common-Lisp") are not case sensitive. There can also be other
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 ;; properties in this line:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 ;; -*- Mode: Emacs-Lisp; Read-Syntax: Common-Lisp -*-
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 ;; Installation
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 ;; ------------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 ;; Save this file in a directory where Emacs will find it, then
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 ;; byte compile it (M-x byte-compile-file).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 ;; A permanent installation of the package can be done in two ways:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 ;; 1.) If you want to have the package always loaded, put this in your
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 ;; .emacs, or in just the files that require it:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 ;; (require 'cl-read)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 ;; 2.) To load the cl-read package automatically when visiting an elisp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 ;; file that needs it, it has to be installed using the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 ;; emacs-lisp-mode-hook. In this case, put the following function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 ;; definition and add-hook form in your .emacs:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 ;; (defun cl-reader-autoinstall-function ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 ;; "Activates the Common Lisp style reader for emacs-lisp-mode buffers,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 ;; if the property line has a local variable setting like this:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 ;; \;\; -*- Read-Syntax: Common-Lisp -*-"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 ;; (or (boundp 'local-variable-hack-done)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 ;; (let (local-variable-hack-done
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 ;; (case-fold-search t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 ;; (hack-local-variables-prop-line 't)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 ;; (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 ;; ((and (boundp 'read-syntax)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 ;; read-syntax
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 ;; (string-match "^common-lisp$" (symbol-name read-syntax)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 ;; (require 'cl-read)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 ;; (make-local-variable 'cl-read-active)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 ;; (setq cl-read-active 't))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 ;; (add-hook 'emacs-lisp-mode-hook 'cl-reader-autoinstall-function)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 ;; The `cl-reader-autoinstall-function' function tests for the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 ;; presence of the correct Read-Syntax property in the first line of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 ;; the file and loads the cl-read package if necessary. cl-read
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 ;; replaces the following standard elisp functions:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 ;; - read
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 ;; - read-from-string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 ;; - eval-current-buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 ;; - eval-buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 ;; - eval-region
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 ;; - eval-expression (to call reader explicitly)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 ;; There may be other built-in functions that need to be replaced
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 ;; (e.g. load). The behavior of the new reader function depends on
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 ;; the value of the buffer local variable `cl-read-active': if it is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 ;; nil, they just call the original functions, otherwise they call the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 ;; cl reader. If the cl reader is active in a buffer, this is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 ;; indicated in the modeline by the string "CL" (minor mode like).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 ;; Examples:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 ;; ---------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 ;; After having installed the package as described above, the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 ;; following forms can be evaluated (M-C-x) with the cl reader being
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 ;; active. (make sure that the mode line displays "(Emacs-Lisp CL)")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 ;; (setq whitespaces '(#\space #\newline #\tab))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 ;; (setq more-whitespaces `(#\page ,@whitespaces #\linefeed))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 ;; (setq whitespace-strings (mapcar #'char-to-string more-whitespaces))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 ;; (setq shared-struct '(#1=[hello world] #1# #1#))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 ;; (progn (setq cirlist '#1=(a b . #1#)) 't)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 ;; This file, though written in standard Emacs Lisp syntax, can also be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 ;; compiled with the cl reader active: Type M-x byte-compile-file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 ;; TO DO List:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 ;; -----------
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 ;; - Provide a replacement for load so that uncompiled cl syntax
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 ;; source file can be loaded, too. For now prohibit loading un-bytecompiled.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 ;; - Do we really need the (require 'cl) dependency? Yes.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 ;; - More read macros: #S for structs, #A for array, #X for hex, #nR for radix
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 ;; - Refine the error signaling mechanism.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 ;; - invalid-cl-read-syntax is now defined. what else?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 ; Change History
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 ;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 ; $Log: cl-read.el,v $
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
211 ; Revision 1.1.1.3 1996/12/18 03:54:28 steve
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
212 ; XEmacs 19.15-b3
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 ;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 ; Revision 1.19 94/03/21 19:59:24 liberte
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 ; Add invalid-cl-read-syntax error symbol.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 ; Add reader::read-sexp and reader::read-sexp-func to allow customization
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 ; based on the results of reading.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 ; Remove more dependencies on cl-package.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 ; Remove reader::eval-current-buffer, eval-buffer, and eval-region,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 ; and use elisp-eval-region package instead.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 ;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 ; Revision 1.18 94/03/04 23:42:24 liberte
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 ; Fix typos in comments.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 ;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 ; Revision 1.17 93/11/24 12:04:09 bosch
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 ; cl-packages dependency removed. `reader::read-constituent' and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 ; corresponding variables moved to cl-packages.el.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 ; Multi-line comment #| ... |# dispatch character read macro added.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 ;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 ; Revision 1.16 1993/11/23 10:21:02 bosch
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 ; Patches from Daniel LaLiberte integrated.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 ;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 ; Revision 1.15 1993/11/18 21:21:10 bosch
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 ; `reader::symbol-regexp1' modified.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 ;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 ; Revision 1.14 1993/11/17 19:06:32 bosch
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 ; More characters added to `reader::symbol-characters'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 ; `reader::read-constituent' modified.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 ; defpackage form added.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 ;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 ; Revision 1.13 1993/11/16 13:06:41 bosch
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 ; - Symbol reading for CL package convention implemented.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 ; Variables `reader::symbol-characters', `reader::symbol-regexp1' and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 ; `reader::symbol-regexp2' and functions `reader::lookup-symbol' and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 ; `reader::read-constituent' added.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 ; - Prefix for internal symbols is now "reader::" (Common Lisp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 ; compatible).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 ; - Dispatch character macro #: for reading uninterned symbols added.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 ;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 ; Revision 1.12 1993/11/07 19:29:07 bosch
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 ; Minor bug fix.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 ;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 ; Revision 1.11 1993/11/07 19:23:59 bosch
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 ; Comment added. Character read macro #\<char> rewritten. Now reads
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 ; e.g. #\meta-control-x. Needs to be checked.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 ; fix in `reader::restore-shared-structure'. `cl-reader-autoinstall-function' improved.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 ;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 ; Revision 1.10 1993/11/06 18:35:35 bosch
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 ; Included Daniel LaLiberte's Patches.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 ; Efficiency of `reader::restore-shared-structure' improved.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 ; Implementation notes for shared structure reading added.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 ;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 ; Revision 1.9 1993/09/08 07:44:54 bosch
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 ; Comment modified.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 ;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 ; Revision 1.8 1993/08/10 13:43:34 bosch
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 ; Hook function `cl-reader-autoinstall-function' for automatic installation added.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 ; Buffer local variable `cl-read-active' added: together with the above
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 ; hook it allows the file specific activation of the cl reader.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 ;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 ; Revision 1.7 1993/08/10 10:35:21 bosch
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 ; Functions `read*' and `read-from-string*' renamed into `reader::read'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 ; and `reader::read-from-string'. Whitespace character skipping after
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 ; recursive reader calls removed (Emacs 19 should not need this).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 ; Functions `cl-reader-install' and `cl-reader-uninstall' updated.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 ; Introduction text and function comments added.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 ;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 ; Revision 1.6 1993/08/09 15:36:05 bosch Function `read*' now nearly
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 ; elisp compatible (no functions as streams, yet -- I don't think I
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 ; will ever implement this, it would be far too slow). Elisp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 ; compatible function `read-from-string*' added. Replacements for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 ; `eval-current-buffer', `eval-buffer' and `eval-region' added.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 ; Renamed feature `cl-dg' in `cl', as Dave Gillespie's cl.el package
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 ; is rather stable now. Function `cl-reader-install' and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 ; `cl-reader-uninstall' modified.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 ;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 ; Revision 1.5 1993/08/09 10:23:35 bosch
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 ; Functions `copy-readtable' and `set-syntax-from-character' added.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289 ; Variable `reader::internal-standard-readtable' added. Standard
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290 ; readtable initialization modified. Whitespace skipping placed back
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 ; inside the read loop.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292 ;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 ; Revision 1.4 1993/05/14 13:00:48 bosch
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294 ; Included patches from Daniel LaLiberte.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 ;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 ; Revision 1.3 1993/05/11 09:57:39 bosch
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297 ; `read*' renamed in `reader::read-from-buffer'. `read*' now can read
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298 ; from strings.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299 ;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300 ; Revision 1.2 1993/05/09 16:30:50 bosch
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301 ; (require 'cl-read) added.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 ; Calling of `{before,after}-read-hook' modified.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 ;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 ; Revision 1.1 1993/03/29 19:37:21 bosch
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305 ; Initial revision
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 ;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 ;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
309 ;;; Code:
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
311 (require 'cl)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
312 ;; Thou shalt evaluate a defadvice only once, or thou shalt surely lose. -sb
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
313 (require 'advise-eval-region)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
314
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
315 ;; load before compiling
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
316 ;; This is ugly, but apparently the only way to do it :-( -sb
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 (provide 'cl-read)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318 (require 'cl-read)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320 ;; bootstrapping with cl-packages
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321 ;; defpackage and in-package are ignored until cl-read is installed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322 '(defpackage reader
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323 (:nicknames "rd")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324 (:use el)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325 (:export
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326 cl-read-active
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327 copy-readtable
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328 set-macro-character
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329 get-macro-character
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330 set-syntax-from-character
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331 make-dispatch-macro-character
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332 set-dispatch-macro-character
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333 get-dispatch-macro-character
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334 before-read-hook
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335 after-read-hook
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336 cl-reader-install
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337 cl-reader-uninstall
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338 read-syntax
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339 cl-reader-autoinstall-function))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341 '(in-package reader)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344 (autoload 'compiled-function-p "bytecomp")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
346 ;; This makes cl-read behave as a kind of minor mode:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
347
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
348 (make-variable-buffer-local 'cl-read-active)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349 (defvar cl-read-active nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
350 "Buffer local variable that enables Common Lisp style syntax reading.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
351 (setq-default cl-read-active nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
352
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
353 (or (assq 'cl-read-active minor-mode-alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
354 (setq minor-mode-alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
355 (cons '(cl-read-active " CL") minor-mode-alist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
356
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
357 ;; Define a new error symbol: invalid-cl-read-syntax
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
358 ;; XEmacs change
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
359 (define-error 'invalid-cl-read-syntax "Invalid CL read syntax"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
360 'invalid-read-syntax)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
361
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
362 (defun reader::error (msg &rest args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
363 (signal 'invalid-cl-read-syntax (list (apply 'format msg args))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
364
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
365
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
366 ;; The readtable
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
367
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
368 (defvar reader::readtable-size 256
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
369 "The size of a readtable."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
370 ;; Actually, the readtable is a vector of size (1+
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
371 ;; reader::readtable-size), because the last element contains the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
372 ;; symbol `readtable', used for defining `readtablep.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
373 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
374
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
375 ;; An entry of the readtable must have one of the following forms:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
376 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
377 ;; 1. A symbol, one of {illegal, constituent, whitespace}. It means
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
378 ;; the character's reader class.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
379 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
380 ;; 2. A function (i.e., a symbol with a function definition, a byte
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
381 ;; compiled function or an uncompiled lambda expression). It means the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
382 ;; character is a macro character.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
383 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
384 ;; 3. A vector of length `reader::readtable-size'. Elements of this vector
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
385 ;; may be `nil' or a function (see 2.). It means the charater is a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
386 ;; dispatch character, and the vector its dispatch fucntion table.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
387
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
388 (defvar *readtable*)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
389 (defvar reader::internal-standard-readtable)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
390
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
391 (defun* copy-readtable
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
392 (&optional (from-readtable *readtable*)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
393 (to-readtable
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
394 (make-vector (1+ reader::readtable-size) 'illegal)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
395 "Return a copy of FROM-READTABLE \(default: *readtable*\). If the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
396 FROM-READTABLE argument is provided as `nil', make a copy of a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
397 standard \(CL-like\) readtable. If TO-READTABLE is provided, modify and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
398 return it, otherwise create a new readtable object."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
399
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
400 (if (null from-readtable)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
401 (setq from-readtable reader::internal-standard-readtable))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
402
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
403 (loop for i to reader::readtable-size
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
404 as from-syntax = (aref from-readtable i)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
405 do (setf (aref to-readtable i)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
406 (if (vectorp from-syntax)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
407 (copy-sequence from-syntax)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
408 from-syntax))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
409 finally return to-readtable))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
410
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
411
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
412 (defmacro reader::get-readtable-entry (char readtable)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
413 (` (aref (, readtable) (, char))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
414
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
415 (defun set-macro-character
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
416 (char function &optional readtable)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
417 "Makes CHAR to be a macro character with FUNCTION as handler.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
418 When CHAR is seen by reader::read-from-buffer, it calls FUNCTION.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
419 Returns always t. Optional argument READTABLE is the readtable to set
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
420 the macro character in (default: *readtable*)."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
421 (or readtable (setq readtable *readtable*))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
422 (or (reader::functionp function)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
423 (reader::error "Not valid character macro function: %s" function))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
424 (setf (reader::get-readtable-entry char readtable) function)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
425 t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
426
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
427
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
428 (put 'set-macro-character 'edebug-form-spec
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
429 '(&define sexp function-form &optional sexp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
430 (put 'set-macro-character 'lisp-indent-function 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
431
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
432 (defun get-macro-character (char &optional readtable)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
433 "Return the function associated with the character CHAR.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
434 Optional READTABLE defaults to *readtable*. If char isn't a macro
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
435 character in READTABLE, return nil."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
436 (or readtable (setq readtable *readtable*))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
437 (let ((entry (reader::get-readtable-entry char readtable)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
438 (if (reader::functionp entry)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
439 entry)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
440
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
441 (defun set-syntax-from-character
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
442 (to-char from-char &optional to-readtable from-readtable)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
443 "Make the syntax of TO-CHAR be the same as the syntax of FROM-CHAR.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
444 Optional TO-READTABLE and FROM-READTABLE are the corresponding tables
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
445 to use. TO-READTABLE defaults to the current readtable
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
446 \(*readtable*\), and FROM-READTABLE to nil, meaning to use the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
447 syntaxes from the standard Lisp Readtable."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
448 (or to-readtable (setq to-readtable *readtable*))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
449 (or from-readtable
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
450 (setq from-readtable reader::internal-standard-readtable))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
451 (let ((from-syntax
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
452 (reader::get-readtable-entry from-char from-readtable)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
453 (if (vectorp from-syntax)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
454 ;; dispatch macro character table
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
455 (setq from-syntax (copy-sequence from-syntax)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
456 (setf (reader::get-readtable-entry to-char to-readtable)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
457 from-syntax))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
458 t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
459
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
460
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
461 ;; Dispatch macro character
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
462 (defun make-dispatch-macro-character (char &optional readtable)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
463 "Let CHAR be a dispatch macro character in READTABLE (default: *readtable*)."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
464 (or readtable (setq readtable *readtable*))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
465 (setf (reader::get-readtable-entry char readtable)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
466 ;; create a dispatch character table
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
467 (make-vector reader::readtable-size nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
468
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
469
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
470 (defun set-dispatch-macro-character
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
471 (disp-char sub-char function &optional readtable)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
472 "Make reading CHAR1 followed by CHAR2 be handled by FUNCTION.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
473 Optional argument READTABLE (default: *readtable*). CHAR1 must first be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
474 made a dispatch char with `make-dispatch-macro-character'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
475 (or readtable (setq readtable *readtable*))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
476 (let ((disp-table (reader::get-readtable-entry disp-char readtable)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
477 ;; check whether disp-char is a valid dispatch character
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
478 (or (vectorp disp-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
479 (reader::error "`%c' not a dispatch macro character." disp-char))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
480 ;; check whether function is a valid function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
481 (or (reader::functionp function)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
482 (reader::error "Not valid dispatch character macro function: %s"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
483 function))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
484 (setf (aref disp-table sub-char) function)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
485
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
486 (put 'set-dispatch-macro-character 'edebug-form-spec
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
487 '(&define sexp sexp function-form &optional sexp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
488 (put 'set-dispatch-macro-character 'lisp-indent-function 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
489
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
490
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
491 (defun get-dispatch-macro-character
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
492 (disp-char sub-char &optional readtable)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
493 "Return the macro character function for SUB-CHAR unser DISP-CHAR.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
494 Optional READTABLE defaults to *readtable*.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
495 Returns nil if there is no such function."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
496 (or readtable (setq readtable *readtable*))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
497 (let ((disp-table (reader::get-readtable-entry disp-char readtable)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
498 (and (vectorp disp-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
499 (reader::functionp (aref disp-table sub-char))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
500 (aref disp-table sub-char))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
501
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
502
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
503 (defun reader::functionp (function)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
504 ;; Check whether FUNCTION is a valid function object to be used
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
505 ;; as (dispatch) macro character function.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
506 (or (and (symbolp function) (fboundp function))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
507 (compiled-function-p function)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
508 (and (consp function) (eq (first function) 'lambda))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
509
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
510
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
511 ;; The basic reader loop
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
512
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
513 ;; shared and circular structure reading
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
514 (defvar reader::shared-structure-references nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
515 (defvar reader::shared-structure-labels nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
516
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
517 (defun reader::read-sexp-func (point func)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
518 ;; This function is called to read a sexp at POINT by calling FUNC.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
519 ;; reader::read-sexp-func is here to be advised, e.g. by Edebug,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
520 ;; to do something before or after reading.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
521 (funcall func))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
522
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
523 (defmacro reader::read-sexp (point &rest body)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
524 ;; Called to return a sexp starting at POINT. BODY creates the sexp result
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
525 ;; and should leave point after the sexp. The body is wrapped in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
526 ;; a lambda expression and passed to reader::read-sexp-func.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
527 (` (reader::read-sexp-func (, point) (function (lambda () (,@ body))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
528
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
529 (put 'reader::read-sexp 'edebug-form-spec '(form body))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
530 (put 'reader::read-sexp 'lisp-indent-function 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
531 (put 'reader::read-sexp 'lisp-indent-hook 1) ;; Emacs 18
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
532
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
533
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
534 (defconst before-read-hook nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
535 (defconst after-read-hook nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
536
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
537 ;; Set the hooks to `read-char' in order to step through the reader. e.g.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
538 ;; (add-hook 'before-read-hook '(lambda () (message "before") (read-char)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
539 ;; (add-hook 'after-read-hook '(lambda () (message "after") (read-char)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
540
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
541 (defmacro reader::encapsulate-recursive-call (reader-call)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
542 ;; Encapsulate READER-CALL, a form that contains a recursive call to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
543 ;; the reader, for usage inside the main reader loop. The macro
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
544 ;; wraps two hooks around READER-CALL: `before-read-hook' and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
545 ;; `after-read-hook'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
546 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
547 ;; If READER-CALL returns normally, the macro exits immediately from
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
548 ;; the surrounding loop with the value of READER-CALL as result. If
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
549 ;; it exits non-locally (with tag `reader-ignore'), it just returns
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
550 ;; the value of READER-CALL, in which case the surrounding reader
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
551 ;; loop continues its execution.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
552 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
553 ;; In both cases, `before-read-hook' and `after-read-hook' are
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
554 ;; called before and after executing READER-CALL.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
555 ;; Are there any other uses for these hooks? Edebug doesn't need them.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
556 (` (prog2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
557 (run-hooks 'before-read-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
558 ;; this catch allows to ignore the return, in the case that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
559 ;; reader::read-from-buffer should continue looping (e.g.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
560 ;; skipping over comments)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
561 (catch 'reader-ignore
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
562 ;; this only works inside a block (e.g., in a loop):
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
563 ;; go outside
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
564 (return
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
565 (prog1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
566 (, reader-call)
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
567 ;; this occurrence of the after hook fires if the
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
568 ;; reader-call returns normally ...
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
569 (run-hooks 'after-read-hook))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
570 ;; ... and that one if it was thrown to the tag 'reader-ignore
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
571 (run-hooks 'after-read-hook))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
572
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
573 (put 'reader::encapsulate-recursive-call 'edebug-form-spec '(form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
574 (put 'reader::encapsulate-recursive-call 'lisp-indent-function 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
575
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
576 (defun reader::read-from-buffer (&optional stream reader::recursive-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
577 (or (bufferp stream)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
578 (reader::error "Sorry, can only read on buffers"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
579 (if (not reader::recursive-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
580 ;; set up environment for shared structure reading
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
581 (let (reader::shared-structure-references
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
582 reader::shared-structure-labels
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
583 tmp-sexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
584 ;; the reader returns an unshared sexpr, possibly containing
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
585 ;; symbolic references
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
586 (setq tmp-sexp (reader::read-from-buffer stream 't))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
587 (if ;; sexpr actually contained shared structures
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
588 reader::shared-structure-references
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
589 (reader::restore-shared-structure tmp-sexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
590 ;; it did not, so don't bother about restoring
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
591 tmp-sexp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
592
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
593 (loop for char = (following-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
594 for entry = (reader::get-readtable-entry char *readtable*)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
595 if (eobp) do (reader::error "End of file during reading")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
596 do
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
597 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
598
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
599 ((eq entry 'illegal)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
600 (reader::error "`%c' has illegal character syntax" char))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
601
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
602 ;; skipping whitespace characters must be done inside this
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
603 ;; loop as character macro subroutines may return without
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
604 ;; leaving the loop using (throw 'reader-ignore ...)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
605 ((eq entry 'whitespace)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
606 (forward-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
607 ;; skip all whitespace
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
608 (while (eq 'whitespace
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
609 (reader::get-readtable-entry
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
610 (following-char) *readtable*))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
611 (forward-char 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
612
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
613 ;; for every token starting with a constituent character
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
614 ;; call the built-in reader (symbols, numbers, strings,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
615 ;; characters with ?<char> syntax)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
616 ((eq entry 'constituent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
617 (reader::encapsulate-recursive-call
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
618 (reader::read-constituent stream)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
619
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
620 ((vectorp entry)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
621 ;; Dispatch macro character. The dispatch macro character
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
622 ;; function is contained in the vector `entry', at the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
623 ;; place indicated by <sub-char>, the first non-digit
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
624 ;; character following the <disp-char>:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
625 ;; <disp-char><digit>*<sub-char>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
626 (reader::encapsulate-recursive-call
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
627 (loop initially do (forward-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
628 for sub-char = (prog1 (following-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
629 (forward-char 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
630 while (memq sub-char
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
631 '(?0 ?1 ?2 ?3 ?4 ?5 ?6 ?7 ?8 ?9))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
632 collect sub-char into digit-args
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
633 finally
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
634 (return
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
635 (funcall
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
636 ;; no test is done here whether a non-nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
637 ;; contents is a correct dispatch character
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
638 ;; function to apply.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
639 (or (aref entry sub-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
640 (reader::error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
641 "Undefined subsequent dispatch character `%c'"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
642 sub-char))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
643 stream
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
644 sub-char
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
645 (string-to-int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
646 (apply 'concat
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
647 (mapcar
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
648 'char-to-string digit-args))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
649
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
650 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
651 ;; must be a macro character. In this case, `entry' is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
652 ;; the function to be called
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
653 (reader::encapsulate-recursive-call
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
654 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
655 (forward-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
656 (funcall entry stream char))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
657
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
658
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
659 ;; Constituent reader fix for Emacs 18
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
660 (if (string-match "^19" emacs-version)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
661 (defun reader::read-constituent (stream)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
662 (reader::read-sexp (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
663 (reader::original-read stream)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
664
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
665 (defun reader::read-constituent (stream)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
666 (reader::read-sexp (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
667 (prog1 (reader::original-read stream)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
668 ;; For Emacs 18, backing up is necessary because the `read' function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
669 ;; reads one character too far after reading a symbol or number.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
670 ;; This doesnt apply to reading chars (e.g. ?n).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
671 ;; This still loses for escaped chars.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
672 (if (not (eq (reader::get-readtable-entry
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
673 (preceding-char) *readtable*) 'constituent))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
674 (forward-char -1))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
675
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
676
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
677 ;; Make the default current CL readtable
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
678
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
679 (defconst *readtable*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
680 (loop with raw-readtable =
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
681 (make-vector (1+ reader::readtable-size) 'illegal)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
682 initially do (setf (aref raw-readtable reader::readtable-size)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
683 'readtable)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
684 for entry in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
685 '((constituent ?! ?@ ?$ ?% ?& ?* ?_ ?- ?+ ?= ?/ ?\\ ?0 ?1 ?2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
686 ?3 ?4 ?5 ?6 ?7 ?8 ?9 ?: ?~ ?> ?< ?a ?b
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
687 ?c ?d ?e ?f ?g ?h ?i ?j ?k ?l ?m ?n ?o ?p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
688 ?q ?r ?s ?t ?u ?v ?w ?x ?y ?z ?A ?B ?C ?D
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
689 ?E ?F ?G ?H ?I ?J ?K ?L ?M ?N ?O ?P ?Q ?R
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
690 ?S ?T ?U ?V ?W ?X ?Y ?Z)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
691 (whitespace ? ?\t ?\n ?\r ?\f)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
692
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
693 ;; The following CL character classes are only useful for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
694 ;; token parsing. We don't need them, as token parsing is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
695 ;; left to the built-in reader.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
696 ;; (single-escape ?\\)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
697 ;; (multiple-escape ?|)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
698 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
699 do
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
700 (loop for char in (rest entry)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
701 do (setf (reader::get-readtable-entry char raw-readtable)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
702 (first entry)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
703 finally return raw-readtable)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
704 "The current readtable.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
705
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
706
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
707 ;; Variables used non-locally in the standard readmacros
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
708 (defvar reader::context)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
709 (defvar reader::stack)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
710 (defvar reader::recursive-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
711
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
712
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
713 ;;;; Read macro character definitions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
714
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
715 ;;; Hint for modifying, testing and debugging new read macros: All the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
716 ;;; read macros and dispatch character macros below are defined in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
717 ;;; the `*readtable*'. Modifications or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
718 ;;; instrumenting with edebug are effective immediately without having to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
719 ;;; copy the internal readtable to the standard *readtable*. However,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
720 ;;; if you wish to modify reader::internal-standard-readtable, then
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
721 ;;; you must recopy *readtable*.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
722
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
723 ;; Chars and strings
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
724
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
725 ;; This is defined to distinguish chars from constituents
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
726 ;; since chars are read by the standard reader without reading too far.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
727 (set-macro-character ?\?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
728 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
729 (lambda (stream char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
730 (forward-char -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
731 (reader::read-sexp (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
732 (reader::original-read stream)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
733
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
734 ;; ?\M-\C-a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
735
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
736 ;; This is defined to distinguish strings from constituents
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
737 ;; since backing up after reading a string is simpler.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
738 (set-macro-character ?\"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
739 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
740 (lambda (stream char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
741 (forward-char -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
742 (reader::read-sexp (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
743 (prog1 (reader::original-read stream)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
744 ;; This is not needed with Emacs 19, but it is OK. See above.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
745 (if (/= (preceding-char) ?\")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
746 (forward-char -1)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
747
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
748 ;; Lists and dotted pairs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
749 (set-macro-character ?\(
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
750 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
751 (lambda (stream char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
752 (reader::read-sexp (1- (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
753 (catch 'read-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
754 (let ((reader::context 'list) reader::stack )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
755 ;; read list elements up to a `.'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
756 (catch 'dotted-pair
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
757 (while t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
758 (setq reader::stack (cons (reader::read-from-buffer stream 't)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
759 reader::stack))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
760 ;; In dotted pair. Read one more element
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
761 (setq reader::stack (cons (reader::read-from-buffer stream 't)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
762 reader::stack)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
763 ;; signal it to the closing paren
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
764 reader::context 'dotted-pair)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
765 ;; Next char *must* be the closing paren that throws read-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
766 (reader::read-from-buffer stream 't)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
767 ;; otherwise an error is signalled
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
768 (reader::error "Illegal dotted pair read syntax")))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
769
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
770 (set-macro-character ?\)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
771 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
772 (lambda (stream char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
773 (cond ((eq reader::context 'list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
774 (throw 'read-list (nreverse reader::stack)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
775 ((eq reader::context 'dotted-pair)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
776 (throw 'read-list (nconc (nreverse (cdr reader::stack))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
777 (car reader::stack))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
778 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
779 (reader::error "`)' doesn't end a list"))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
780
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
781 (set-macro-character ?\.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
782 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
783 (lambda (stream char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
784 (and (eq reader::context 'dotted-pair)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
785 (reader::error "No more than one `.' allowed in list"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
786 (throw 'dotted-pair nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
787
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
788 ;; '(#\a . #\b)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
789 ;; '(a . (b . c))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
790
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
791 ;; Vectors: [a b]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
792 (set-macro-character ?\[
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
793 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
794 (lambda (stream char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
795 (reader::read-sexp (1- (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
796 (let ((reader::context 'vector))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
797 (catch 'read-vector
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
798 (let ((reader::context 'vector)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
799 reader::stack)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
800 (while t (push (reader::read-from-buffer stream 't)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
801 reader::stack)))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
802
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
803 (set-macro-character ?\]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
804 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
805 (lambda (stream char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
806 (if (eq reader::context 'vector)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
807 (throw 'read-vector (apply 'vector (nreverse reader::stack)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
808 (reader::error "`]' doesn't end a vector")))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
809
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
810 ;; Quote and backquote/comma macro
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
811 (set-macro-character ?\'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
812 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
813 (lambda (stream char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
814 (reader::read-sexp (1- (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
815 (list (reader::read-sexp (point) 'quote)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
816 (reader::read-from-buffer stream 't))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
817
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
818 (set-macro-character ?\`
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
819 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
820 (lambda (stream char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
821 (if (= (following-char) ?\ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
822 ;; old backquote syntax. This is ambigous, because
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
823 ;; (`(sexp)) is a valid form in both syntaxes, but
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
824 ;; unfortunately not the same.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
825 ;; old syntax: read -> (` (sexp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
826 ;; new syntax: read -> ((` (sexp)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
827 (reader::read-sexp (1- (point)) '\`)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
828 (reader::read-sexp (1- (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
829 (list (reader::read-sexp (point) '\`)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
830 (reader::read-from-buffer stream 't)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
831
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
832 (set-macro-character ?\,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
833 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
834 (lambda (stream char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
835 (cond ((eq (following-char) ?\ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
836 ;; old syntax
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
837 (reader::read-sexp (point) '\,))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
838 ((eq (following-char) ?\@)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
839 (forward-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
840 (cond ((eq (following-char) ?\ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
841 (reader::read-sexp (point) '\,\@))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
842 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
843 (reader::read-sexp (- (point) 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
844 (list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
845 (reader::read-sexp (point) '\,\@)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
846 (reader::read-from-buffer stream 't))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
847 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
848 (reader::read-sexp (1- (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
849 (list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
850 (reader::read-sexp (1- (point)) '\,)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
851 (reader::read-from-buffer stream 't))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
852
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
853 ;; 'a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
854 ;; '(a b c)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
855 ;; (let ((a 10) (b '(20 30))) `(,a ,@b c))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
856 ;; the old syntax is also supported:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
857 ;; (let ((a 10) (b '(20 30))) (` ((, a) (,@ b) c)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
858
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
859 ;; Single line character comment: ;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
860 (set-macro-character ?\;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
861 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
862 (lambda (stream char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
863 (skip-chars-forward "^\n\r")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
864 (throw 'reader-ignore nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
865
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
866
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
867
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
868 ;; Dispatch character character #
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
869 (make-dispatch-macro-character ?\#)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
870
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
871 (defsubst reader::check-0-infix (n)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
872 (or (= n 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
873 (reader::error "Numeric infix argument not allowed: %d" n)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
874
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
875
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
876 (defalias 'search-forward-regexp 're-search-forward)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
877
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
878 ;; nested multi-line comments #| ... |#
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
879 (set-dispatch-macro-character ?\# ?\|
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
880 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
881 (lambda (stream char n)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
882 (reader::check-0-infix n)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
883 (let ((counter 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
884 (while (search-forward-regexp "#|\\||#" nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
885 (if (string-equal
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
886 (buffer-substring
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
887 (match-beginning 0) (match-end 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
888 "|#")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
889 (cond ((> counter 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
890 (decf counter))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
891 ((= counter 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
892 ;; stop here
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
893 (goto-char (match-end 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
894 (throw 'reader-ignore nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
895 ('t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
896 (reader::error "Unmatching closing multicomment")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
897 (incf counter)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
898 (reader::error "Unmatching opening multicomment")))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
899
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
900 ;; From cl-packages.el
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
901 (defconst reader::symbol-characters "[A-Za-z0-9-_!@$%^&*+=|~{}<>/]")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
902 (defconst reader::symbol-regexp2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
903 (format "\\(%s+\\)" reader::symbol-characters))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
904
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
905 (set-dispatch-macro-character ?\# ?\:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
906 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
907 (lambda (stream char n)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
908 (reader::check-0-infix n)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
909 (or (looking-at reader::symbol-regexp2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
910 (reader::error "Invalid symbol read syntax"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
911 (goto-char (match-end 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
912 (make-symbol
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
913 (buffer-substring (match-beginning 0) (match-end 0))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
914
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
915 ;; Function quoting: #'<function>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
916 (set-dispatch-macro-character ?\# ?\'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
917 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
918 (lambda (stream char n)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
919 (reader::check-0-infix n)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
920 ;; Probably should test if cl is required by current buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
921 ;; Currently, cl will always be a feature because cl-read requires it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
922 (reader::read-sexp (- (point) 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
923 (list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
924 (reader::read-sexp (point) (if (featurep 'cl) 'function* 'function))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
925 (reader::read-from-buffer stream 't))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
926
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
927 ;; Character syntax: #\<char>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
928 ;; Not yet implemented: #\Control-a #\M-C-a etc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
929 ;; This definition is not used - the next one is more general.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
930 '(set-dispatch-macro-character ?# ?\\
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
931 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
932 (lambda (stream char n)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
933 (reader::check-0-infix n)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
934 (let ((next (following-char))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
935 name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
936 (if (not (and (<= ?a next) (<= next ?z)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
937 (progn (forward-char 1) next)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
938 (setq next (reader::read-from-buffer stream t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
939 (cond ((symbolp next) (setq name (symbol-name next)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
940 ((integerp next) (setq name (int-to-string next))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
941 (if (= 1 (length name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
942 (string-to-char name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
943 (case next
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
944 (linefeed ?\n)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
945 (newline ?\r)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
946 (space ?\ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
947 (rubout ?\b)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
948 (page ?\f)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
949 (tab ?\t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
950 (return ?\C-m)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
951 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
952 (reader::error "Unknown character specification `%s'"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
953 next))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
954 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
955
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
956 (defvar reader::special-character-name-table
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
957 '(("linefeed" . ?\n)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
958 ("newline" . ?\r)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
959 ("space" . ?\ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
960 ("rubout" . ?\b)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
961 ("page" . ?\f)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
962 ("tab" . ?\t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
963 ("return" . ?\C-m)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
964
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
965 (set-dispatch-macro-character ?# ?\\
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
966 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
967 (lambda (stream char n)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
968 (reader::check-0-infix n)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
969 (forward-char -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
970 ;; We should read in a special package to avoid creating symbols.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
971 (let ((symbol (reader::read-from-buffer stream t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
972 (case-fold-search t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
973 name modifier character char-base)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
974 (setq name (symbol-name symbol))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
975 (if (string-match "^\\(meta-\\|m-\\|control-\\|c-\\)+" name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
976 (setq modifier (substring name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
977 (match-beginning 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
978 (match-end 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
979 character (substring name (match-end 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
980 (setq character name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
981 (setq char-base
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
982 (cond ((= (length character) 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
983 (string-to-char character))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
984 ('t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
985 (cdr (assoc character
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
986 reader::special-character-name-table)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
987 (or char-base
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
988 (reader::error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
989 "Unknown character specification `%s'" character))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
990
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
991 (and modifier
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
992 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
993 (and (string-match "control-\\|c-" modifier)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
994 (decf char-base 32))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
995 (and (string-match "meta-\\|m-" modifier)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
996 (incf char-base 128))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
997 char-base))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
998
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
999 ;; '(#\meta-space #\tab #\# #\> #\< #\a #\A #\return #\space)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1000 ;; (eq #\m-tab ?\M-\t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1001 ;; (eq #\c-m-x #\m-c-x)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1002 ;; (eq #\Meta-Control-return #\M-C-return)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1003 ;; (eq #\m-m-c-c-x #\m-c-x)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1004 ;; #\C-space #\C-@ ?\C-@
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1005
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1006
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1007
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1008 ;; Read and load time evaluation: #.<form>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1009 ;; Not yet implemented: #,<form>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1010 (set-dispatch-macro-character ?\# ?\.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1011 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1012 (lambda (reader::stream reader::char reader::n)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1013 (reader::check-0-infix reader::n)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1014 ;; This eval will see all internal vars of reader,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1015 ;; e.g. stream, reader::recursive-p. Anything that might be bound.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1016 ;; We must use `read' here rather than read-from-buffer with 'recursive-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1017 ;; because the expression must not have unresolved #n#s in it anyway.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1018 ;; Otherwise the top-level expression must be completely read before
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1019 ;; any embedded evaluation(s) occur(s). CLtL2 does not specify this.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1020 ;; Also, call `read' so that it may be customized, by e.g. Edebug
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1021 (eval (read reader::stream)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1022 ;; '(#.(current-buffer) #.(get-buffer "*scratch*"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1023
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1024 ;; Path names (kind of): #p<string>, #P<string>,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1025 (set-dispatch-macro-character ?\# ?\P
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1026 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1027 (lambda (stream char n)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1028 (reader::check-0-infix n)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1029 (let ((string (reader::read-from-buffer stream 't)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1030 (or (stringp string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1031 (reader::error "Pathname must be a string: %s" string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1032 (expand-file-name string)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1033
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1034 (set-dispatch-macro-character ?\# ?\p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1035 (get-dispatch-macro-character ?\# ?\P))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1036
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1037 ;; #P"~/.emacs"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1038 ;; #p"~root/home"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1039
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1040 ;; Feature reading: #+<feature>, #-<feature>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1041 ;; Not yet implemented: #+<boolean expression>, #-<boolean expression>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1042
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1043
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1044 (defsubst reader::read-feature (stream char n flag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1045 (reader::check-0-infix n)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1046 (let (;; Use the original reader to only read the feature.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1047 ;; This is not exactly correct without *read-suppress*.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1048 ;; Also Emacs 18 read goes one too far,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1049 ;; so we assume there is a space after the feature.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1050 (feature (reader::original-read stream))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1051 (object (reader::read-from-buffer stream 't)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1052 (if (eq (featurep feature) flag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1053 object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1054 ;; Ignore it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1055 (throw 'reader-ignore nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1056
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1057 (set-dispatch-macro-character ?\# ?\+
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1058 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1059 (lambda (stream char n)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1060 (reader::read-feature stream char n t))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1061
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1062 (set-dispatch-macro-character ?\# ?\-
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1063 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1064 (lambda (stream char n)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1065 (reader::read-feature stream char n nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1066
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1067 ;; (#+cl loop #+cl do #-cl while #-cl t (body))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1068
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1069
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1070
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1071
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1072 ;; Shared structure reading: #<n>=, #<n>#
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1073
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1074 ;; Reading of sexpression with shared and circular structure read
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1075 ;; syntax is done in two steps:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1076 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1077 ;; 1. Create an sexpr with unshared structures, just as the ordinary
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1078 ;; read macros do, with two exceptions:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1079 ;; - each label (#<n>=) creates, as a side effect, a symbolic
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1080 ;; reference for the sexpr that follows it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1081 ;; - each reference (#<n>#) is replaced by the corresponding
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1082 ;; symbolic reference.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1083 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1084 ;; 2. This non-cyclic and unshared lisp structure is given to the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1085 ;; function `reader::restore-shared-structure' (see
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1086 ;; `reader::read-from-buffer'), which simply replaces
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1087 ;; destructively all symbolic references by the lisp structures the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1088 ;; references point at.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1089 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1090 ;; A symbolic reference is an uninterned symbol whose name is obtained
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1091 ;; from the label/reference number using the function `int-to-string':
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1092 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1093 ;; There are two non-locally used variables (bound in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1094 ;; `reader::read-from-buffer') which control shared structure reading:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1095 ;; `reader::shared-structure-labels':
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1096 ;; A list of integers that correspond to the label numbers <n> in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1097 ;; the string currently read. This is used to avoid multiple
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1098 ;; definitions of the same label.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1099 ;; `reader::shared-structure-references':
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1100 ;; The list of symbolic references that will be used as temporary
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1101 ;; placeholders for the shared objects introduced by a reference
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1102 ;; with the same number identification.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1103
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1104 (set-dispatch-macro-character ?\# ?\=
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1105 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1106 (lambda (stream char n)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1107 (and (= n 0) (reader::error "0 not allowed as label"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1108 ;; check for multiple definition of the same label
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1109 (if (memq n reader::shared-structure-labels)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1110 (reader::error "Label defined twice")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1111 (push n reader::shared-structure-labels))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1112 ;; create an uninterned symbol as symbolic reference for the label
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1113 (let* ((string (int-to-string n))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1114 (ref (or (find string reader::shared-structure-references
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1115 :test 'string=)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1116 (first
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1117 (push (make-symbol string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1118 reader::shared-structure-references)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1119 ;; the link between the symbolic reference and the lisp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1120 ;; structure it points at is done using the symbol value cell
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1121 ;; of the reference symbol.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1122 (setf (symbol-value ref)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1123 ;; this is also the return value
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1124 (reader::read-from-buffer stream 't))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1125
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1126
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1127 (set-dispatch-macro-character ?\# ?\#
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1128 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1129 (lambda (stream char n)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1130 (and (= n 0) (reader::error "0 not allowed as label"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1131 ;; use the non-local variable `reader::recursive-p' (from the reader
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1132 ;; main loop) to detect labels at the top level of an sexpr.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1133 (if (not reader::recursive-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1134 (reader::error "References at top level not allowed"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1135 (let* ((string (int-to-string n))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1136 (ref (or (find string reader::shared-structure-references
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1137 :test 'string=)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1138 (first
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1139 (push (make-symbol string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1140 reader::shared-structure-references)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1141 ;; the value of reading a #n# form is a reference symbol
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1142 ;; whose symbol value is or will be the shared structure.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1143 ;; `reader::restore-shared-structure' then replaces the symbol by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1144 ;; its value.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1145 ref))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1146
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1147 (defun reader::restore-shared-structure (obj)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1148 ;; traverses recursively OBJ and replaces all symbolic references by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1149 ;; the objects they point at. Remember that a symbolic reference is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1150 ;; an uninterned symbol whose value is the object it points at.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1151 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1152 ((consp obj)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1153 (loop for rest on obj
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1154 as lastcdr = rest
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1155 do
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1156 (if;; substructure is a symbolic reference
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1157 (memq (car rest) reader::shared-structure-references)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1158 ;; replace it by its symbol value, i.e. the associated object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1159 (setf (car rest) (symbol-value (car rest)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1160 (reader::restore-shared-structure (car rest)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1161 finally
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1162 (if (memq (cdr lastcdr) reader::shared-structure-references)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1163 (setf (cdr lastcdr) (symbol-value (cdr lastcdr)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1164 (reader::restore-shared-structure (cdr lastcdr)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1165 ((vectorp obj)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1166 (loop for i below (length obj)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1167 do
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1168 (if;; substructure is a symbolic reference
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1169 (memq (aref obj i) reader::shared-structure-references)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1170 ;; replace it by its symbol value, i.e. the associated object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1171 (setf (aref obj i) (symbol-value (aref obj i)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1172 (reader::restore-shared-structure (aref obj i))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1173 obj)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1174
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1175
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1176 ;; #1=(a b #3=[#2=c])
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1177 ;; (#1=[#\return #\a] #1# #1#)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1178 ;; (#1=[a b c] #1# #1#)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1179 ;; #1=(a b . #1#)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1180
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1181 ;; Creation and initialization of an internal standard readtable.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1182 ;; Do this after all the macros and dispatch chars above have been defined.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1183
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1184 (defconst reader::internal-standard-readtable (copy-readtable)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1185 "The original (CL-like) standard readtable. If you ever modify this
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1186 readtable, you won't be able to recover a standard readtable using
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1187 \(copy-readtable nil\)")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1188
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1189
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1190 ;; Replace built-in functions that call the built-in reader
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1191 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1192 ;; The following functions are replaced here:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1193 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1194 ;; read by reader::read
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1195 ;; read-from-string by reader::read-from-string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1196 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1197 ;; eval-expression by reader::eval-expression
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1198 ;; Why replace eval-expression? Not needed for Lucid Emacs since the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1199 ;; reader for arguments is also written in Lisp, and so may be overridden.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1200 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1201 ;; eval-current-buffer by reader::eval-current-buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1202 ;; eval-buffer by reader::eval-buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1203 ;; original-eval-region by reader::original-eval-region
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1204
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1205
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1206 ;; Temporary read buffer used for reading from strings
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1207 (defconst reader::tmp-buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1208 (get-buffer-create " *CL Read*"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1209
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1210 ;; Save a pointer to the original read function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1211 (or (fboundp 'reader::original-read)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1212 (fset 'reader::original-read (symbol-function 'read)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1213
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1214 (defun reader::read (&optional stream reader::recursive-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1215 "Read one Lisp expression as text from STREAM, return as Lisp object.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1216 If STREAM is nil, use the value of `standard-input' \(which see\).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1217 STREAM or the value of `standard-input' may be:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1218 a buffer \(read from point and advance it\)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1219 a marker \(read from where it points and advance it\)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1220 a string \(takes text from string, starting at the beginning\)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1221 t \(read text line using minibuffer and use it\).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1222
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1223 This is the cl-read replacement of the standard elisp function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1224 `read'. The only incompatibility is that functions as stream arguments
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1225 are not supported."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1226 (if (not cl-read-active)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1227 (reader::original-read stream)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1228 (if (null stream) ; read from standard-input
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1229 (setq stream standard-input))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1230
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1231 (if (eq stream 't) ; read from minibuffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1232 (setq stream (read-from-minibuffer "Common Lisp Expression: ")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1233
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1234 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1235
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1236 ((bufferp stream) ; read from buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1237 (reader::read-from-buffer stream reader::recursive-p))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1238
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1239 ((markerp stream) ; read from marker
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1240 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1241 (set-buffer (marker-buffer stream))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1242 (goto-char (marker-position stream))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1243 (reader::read-from-buffer (current-buffer) reader::recursive-p)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1244
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1245 ((stringp stream) ; read from string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1246 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1247 (set-buffer reader::tmp-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1248 (auto-save-mode -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1249 (erase-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1250 (insert stream)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1251 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1252 (reader::read-from-buffer reader::tmp-buffer reader::recursive-p)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1253 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1254 (reader::error "Not a valid stream: %s" stream)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1255
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1256 ;; read-from-string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1257 ;; save a pointer to the original `read-from-string' function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1258 (or (fboundp 'reader::original-read-from-string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1259 (fset 'reader::original-read-from-string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1260 (symbol-function 'read-from-string)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1261
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1262 (defun reader::read-from-string (string &optional start end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1263 "Read one Lisp expression which is represented as text by STRING.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1264 Returns a cons: (OBJECT-READ . FINAL-STRING-INDEX).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1265 START and END optionally delimit a substring of STRING from which to read;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1266 they default to 0 and (length STRING) respectively.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1267
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1268 This is the cl-read replacement of the standard elisp function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1269 `read-from-string'. It uses the reader macros in *readtable* if
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1270 `cl-read-active' is non-nil in the current buffer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1271
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1272 ;; Does it really make sense to have read-from-string depend on
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1273 ;; what the current buffer happens to be? Yes, so code that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1274 ;; has nothing to do with cl-read uses original reader.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1275 (if (not cl-read-active)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1276 (reader::original-read-from-string string start end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1277 (or start (setq start 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1278 (or end (setq end (length string)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1279 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1280 (set-buffer reader::tmp-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1281 (auto-save-mode -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1282 (erase-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1283 (insert (substring string 0 end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1284 (goto-char (1+ start))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1285 (cons
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1286 (reader::read-from-buffer reader::tmp-buffer nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1287 (1- (point))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1288
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1289 ;; (read-from-string "abc (car 'a) bc" 4)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1290 ;; (reader::read-from-string "abc (car 'a) bc" 4)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1291 ;; (read-from-string "abc (car 'a) bc" 2 11)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1292 ;; (reader::read-from-string "abc (car 'a) bc" 2 11)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1293 ;; (reader::read-from-string "`(car ,first ,@rest)")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1294 ;; (read-from-string ";`(car ,first ,@rest)")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1295 ;; (reader::read-from-string ";`(car ,first ,@rest)")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1296
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1297 ;; We should replace eval-expression, too, so that it reads (and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1298 ;; evals) in the current buffer. Alternatively, this could be fixed
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1299 ;; in C. In Lemacs 19.6 and later, this function is already written
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1300 ;; in lisp, and based on more primitive read functions we already
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1301 ;; replaced. The reading happens during the interactive parameter
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1302 ;; retrieval, which is written in lisp, too. So this replacement of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1303 ;; eval-expresssion is only required fro (FSF) Emacs 18 (and 19?).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1304
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1305 (or (fboundp 'reader::original-eval-expression)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1306 (fset 'reader::original-eval-expression
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1307 (symbol-function 'eval-expression)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1308
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1309 (defun reader::eval-expression (reader::expression)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1310 "Evaluate EXPRESSION and print value in minibuffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1311 Value is also consed on to front of variable `values'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1312 (interactive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1313 (list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1314 (car (read-from-string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1315 (read-from-minibuffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1316 "Eval: " nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1317 ;;read-expression-map ;; not for emacs 18
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1318 nil ;; use default map
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1319 nil ;; don't do read with minibuffer current.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1320 ;; 'edebug-expression-history ;; not for emacs 18
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1321 )))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1322 (setq values (cons (eval reader::expression) values))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1323 (prin1 (car values) t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1324
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1325 (require 'eval-reg "eval-reg")
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1326 ; (require 'advice)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1327
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1328
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1329 ;; installing/uninstalling the cl reader
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1330 ;; These two should always be used in pairs, or just install once and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1331 ;; never uninstall.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1332 (defun cl-reader-install ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1333 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1334 (fset 'read 'reader::read)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1335 (fset 'read-from-string 'reader::read-from-string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1336 (fset 'eval-expression 'reader::eval-expression)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1337 (elisp-eval-region-install))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1338
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1339 (defun cl-reader-uninstall ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1340 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1341 (fset 'read
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1342 (symbol-function 'reader::original-read))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1343 (fset 'read-from-string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1344 (symbol-function 'reader::original-read-from-string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1345 (fset 'eval-expression
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1346 (symbol-function 'reader::original-eval-expression))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1347 (elisp-eval-region-uninstall))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1348
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1349 ;; Globally installing the cl-read replacement functions is safe, even
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1350 ;; for buffers without cl read syntax. The buffer local variable
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1351 ;; `cl-read-active' controls whether the replacement funtions of this
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1352 ;; package or the original ones are actually called.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1353 (cl-reader-install)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1354 (cl-reader-uninstall)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1355
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1356 (add-hook 'emacs-lisp-mode-hook 'cl-reader-autoinstall-function)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1357
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1358 '(defvar read-syntax)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1359
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1360 '(defun cl-reader-autoinstall-function ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1361 "Activates the Common Lisp style reader for emacs-lisp-mode buffers,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1362 if the property line has a local variable setting like this:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1363 \;\; -*- Read-Syntax: Common-Lisp -*-"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1364 ;; this is a hack to avoid recursion in the case that the prop line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1365 ;; containes "Mode: emacs-lisp" entry
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1366 (or (boundp 'local-variable-hack-done)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1367 (let (local-variable-hack-done
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1368 (case-fold-search t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1369 ;; Usually `hack-local-variables-prop-line' is called only after
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1370 ;; installation of the major mode. But we need to know about the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1371 ;; local variables before that, so we call the local variable hack
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1372 ;; explicitly here:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1373 (hack-local-variables-prop-line 't)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1374 ;; But hack-local-variables-prop-line not defined in emacs 18.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1375 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1376 ((and (boundp 'read-syntax)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1377 read-syntax
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1378 (string-match "^common-lisp$" (symbol-name read-syntax)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1379 (require 'cl-read)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1380 (make-local-variable 'cl-read-active)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1381 (setq cl-read-active 't))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1382
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1383 ;; Emacs 18 doesnt have hack-local-variables-prop-line. So use this instead.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1384 (defun cl-reader-autoinstall-function ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1385 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1386 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1387 (let ((case-fold-search t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1388 (cond ((re-search-forward
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1389 "read-syntax: *common-lisp"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1390 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1391 (end-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1392 (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1393 t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1394 (require 'cl-read)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1395 (make-local-variable 'cl-read-active)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1396 (setq cl-read-active t))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1397
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1398
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1399 (run-hooks 'cl-read-load-hooks)
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1400
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1401 ;; cl-read.el ends here