annotate lisp/prim/syntax.el @ 16:0293115a14e9 r19-15b91

Import from CVS: tag r19-15b91
author cvs
date Mon, 13 Aug 2007 08:49:20 +0200
parents 376386a54a3c
children 131b0175ea99
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 ;; Syntax-table hacking stuff, moved from syntax.c
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2 ;; Copyright (C) 1993 Free Software Foundation, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4 ;; This file is part of XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 ;; XEmacs is free software; you can redistribute it and/or modify it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 ;; under the terms of the GNU General Public License as published by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 ;; the Free Software Foundation; either version 2, or (at your option)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 ;; any later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 ;; XEmacs is distributed in the hope that it will be useful, but
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 ;; General Public License for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 ;; You should have received a copy of the GNU General Public License
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 0
diff changeset
17 ;; along with XEmacs; see the file COPYING. If not, write to the
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 0
diff changeset
18 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 0
diff changeset
19 ;; Boston, MA 02111-1307, USA.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 ;;; Synched up with: FSF 19.28.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 ;;; Note: FSF does not have a file syntax.el. This stuff is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23 ;;; in syntax.c. See comments there about not merging past 19.28.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 (defun make-syntax-table (&optional oldtable)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 "Return a new syntax table.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 It inherits all letters and control characters from the standard
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 syntax table; other characters are copied from the standard syntax table."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 (if oldtable
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 (copy-syntax-table oldtable)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 (let ((table (copy-syntax-table))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 i)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 (setq i 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 (while (<= i 31)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 (aset table i 13)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 (setq i (1+ i)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 (setq i ?A)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 (while (<= i ?Z)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 (aset table i 13)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 (setq i (1+ i)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 (setq i ?a)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 (while (<= i ?z)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 (aset table i 13)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 (setq i (1+ i)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 (setq i 128)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 (while (<= i 255)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 (aset table i 13)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 (setq i (1+ i)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 table)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 (defun modify-syntax-entry (char spec &optional table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 "Set syntax for character CHAR according to string S.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 The syntax is changed only for table TABLE, which defaults to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 the current buffer's syntax table.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 The first character of S should be one of the following:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 Space whitespace syntax. w word constituent.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 _ symbol constituent. . punctuation.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 \( open-parenthesis. \) close-parenthesis.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 \" string quote. \\ character-quote.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 $ paired delimiter. ' expression quote or prefix operator.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 < comment starter. > comment ender.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 / character-quote. @ inherit from `standard-syntax-table'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 Only single-character comment start and end sequences are represented thus.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 Two-character sequences are represented as described below.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 The second character of S is the matching parenthesis,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 used only if the first character is `(' or `)'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 Any additional characters are flags.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 Defined flags are the characters 1, 2, 3, 4, 5, 6, 7, 8, p, a, and b.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 1 means C is the first of a two-char comment start sequence of style a.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 2 means C is the second character of such a sequence.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 3 means C is the first of a two-char comment end sequence of style a.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 4 means C is the second character of such a sequence.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 5 means C is the first of a two-char comment start sequence of style b.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 6 means C is the second character of such a sequence.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 7 means C is the first of a two-char comment end sequence of style b.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 8 means C is the second character of such a sequence.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 p means C is a prefix character for `backward-prefix-chars';
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 such characters are treated as whitespace when they occur
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 between expressions.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 a means C is comment starter or comment ender for comment style a (default)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 b means C is comment starter or comment ender for comment style b."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 (interactive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 ;; I really don't know why this is interactive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 ;; help-form should at least be made useful whilst reading the second arg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 "cSet syntax for character: \nsSet syntax for %c to: ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 (cond ((syntax-table-p table))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 ((not table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 (setq table (syntax-table)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 (setq table
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 (wrong-type-argument 'syntax-table-p table))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 (let* ((code nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 (bflag nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 (b3 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 i)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 (setq code (string-match (regexp-quote (char-to-string (elt spec 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 (syntax-designator-chars)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 (or code
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 (error "Invalid syntax designator: %S" spec))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 (setq i 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 (while (< i (length spec))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 (let ((ch (elt spec i)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 (setq i (1+ i))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 (cond ((= ch ?1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 (setq b3 (logior b3 128)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 ((= ch ?2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 (setq b3 (logior b3 32)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 ((= ch ?3)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 (setq b3 (logior b3 8)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 ((= ch ?4)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 (setq b3 (logior b3 2)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 ((= ch ?5)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 (setq b3 (logior b3 64)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 ((= ch ?6)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 (setq b3 (logior b3 16)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 ((= ch ?7)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 (setq b3 (logior b3 4)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 ((= ch ?8)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 (setq b3 (logior b3 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 ((= ch ?a)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 (cond ((= (elt spec 0) ?<)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 (setq b3 (logior b3 128)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 ((= (elt spec 0) ?>)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 (setq b3 (logior b3 8)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 ((= ch ?b)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 (cond ((= (elt spec 0) ?<)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 (setq b3 (logior b3 64)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 bflag t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 ((= (elt spec 0) ?>)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 (setq b3 (logior b3 4)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 bflag t))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 ((= ch ?p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 (setq code (logior code (lsh 1 7))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 ((= ch ?\ )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 ;; ignore for compatibility
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 (error "Invalid syntax description flag: %S" spec)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 ;; default single char style is a if b has not been seen
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 (if (not bflag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 (cond ((= (elt spec 0) ?<)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 (setq b3 (logior b3 128)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 ((= (elt spec 0) ?>)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 (setq b3 (logior b3 8)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 (aset table
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 char
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 (logior code
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 (if (and (> (length spec) 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 ;; tough luck if you want to make space a paren!
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 (/= (elt spec 1) ?\ ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 ;; tough luck if you want to make \000 a paren!
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 (lsh (elt spec 1) 8)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 (lsh b3 16)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 ;(defun test-xm ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 ; (let ((o (copy-syntax-table))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 ; (n (copy-syntax-table))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 ; (codes (syntax-designator-chars))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 ; (flags "12345678abp"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 ; (while t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 ; (let ((spec (concat (char-to-string (elt codes
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 ; (random (length codes))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 ; (if (= (random 4) 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 ; "b"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 ; " ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 ; (let* ((n (random 4))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 ; (s (make-string n 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 ; (while (> n 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 ; (setq n (1- n))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 ; (aset s n (aref flags (random (length flags)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 ; s))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 ; (message "%S..." spec)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 ; (modify-syntax-entry ?a spec o)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 ; (xmodify-syntax-entry ?a spec n)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 ; (or (= (aref o ?a) (aref n ?a))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 ; (error "%s"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 ; (format "fucked with %S: %x %x"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 ; spec (aref o ?a) (aref n ?a))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 (defun describe-syntax-table (table stream)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 (let* (;(limit (cond ((numberp ctl-arrow) ctl-arrow)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 ; ((memq ctl-arrow '(t nil)) 256)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 ; (t 160)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 (describe-one #'(lambda (first last)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 (let* ((tem (text-char-description first))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 (pos (length tem)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 (princ tem stream)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 (if (> last first)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 (princ " .. " stream)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 (setq tem (text-char-description last))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 (princ tem stream)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 (setq pos (+ pos (length tem) 4))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 (while (progn (write-char ?\ stream)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 (setq pos (1+ pos))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 (< pos 16))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 (describe-syntax-code (elt table first) stream))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 (let ((range 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 (i 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 (code (elt table 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 (while (cond ((= i (length table))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 (funcall describe-one (1- i) (1- i))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 ((eq code (elt table i))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 (funcall describe-one range (1- i))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 (setq code (elt table i)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 range i)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 (setq i (1+ i))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 (defun describe-syntax-code (code stream)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 (let ((codes (syntax-designator-chars))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 (invalid (gettext "**invalid**")) ;(empty "") ;constants
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 (standard-output (or stream standard-output))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 ;; #### I18N3 should temporarily set buffer to output-translatable
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 (in #'(lambda (string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 (princ ",\n\t\t\t\t ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 (princ string))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 (if (or (not (integerp code))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 (> (logand code 127) (length codes)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 (princ invalid)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 (let* ((spec (elt codes (logand code 127)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 (match (logand (lsh code -8) 255))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 (b3 (lsh code -16))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 (start1 (/= 0 (logand b3 128))) ;logtest!
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 (start1b (/= 0 (logand b3 64)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 (start2 (/= 0 (logand b3 32)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 (start2b (/= 0 (logand b3 16)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 (end1 (/= 0 (logand b3 8)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 (end1b (/= 0 (logand b3 4)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 (end2 (/= 0 (logand b3 2)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 (end2b (/= 0 (logand b3 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 (prefix (/= 0 (logand code 128)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 (single-char-p (or (= spec ?<) (= spec ?>)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 (write-char spec)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 (write-char (if (= 0 match) 32 match))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 ;; (if start1 (if single-char-p (write-char ?a) (write-char ?1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 (if start1 (if single-char-p (write-char ? ) (write-char ?1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 (if start2 (write-char ?2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 ;; (if end1 (if single-char-p (write-char ?a) (write-char ?3)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 (if end1 (if single-char-p (write-char ? ) (write-char ?3)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 (if end2 (write-char ?4))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 (if start1b (if single-char-p (write-char ?b) (write-char ?5)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 (if start2b (write-char ?6))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 (if end1b (if single-char-p (write-char ?b) (write-char ?7)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 (if end2b (write-char ?8))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 (if prefix (write-char ?p))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 (princ "\tmeaning: ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 (princ (aref ["whitespace" "punctuation" "word-constituent"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 "symbol-constituent" "open-paren" "close-paren"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 "expression-prefix" "string-quote" "paired-delimiter"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 "escape" "character-quote" "comment-begin" "comment-end"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 "inherit" "extended-word-constituent"]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 (logand code 127)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 (if (/= 0 match)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 (princ ", matches ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 (princ (text-char-description match))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 (if start1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 (if single-char-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 (princ ", style A")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 (funcall in (gettext "first character of comment-start sequence A"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 (if start2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 (funcall in (gettext "second character of comment-start sequence A")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 (if end1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 (if single-char-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 (princ ", style A")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 (funcall in (gettext "first character of comment-end sequence A"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 (if end2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 (funcall in (gettext "second character of comment-end sequence A")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 (if start1b
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 (if single-char-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 (princ ", style B")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 (funcall in (gettext "first character of comment-start sequence B"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 (if start2b
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 (funcall in (gettext "second character of comment-start sequence B")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 (if end1b
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 (if single-char-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 (princ ", style B")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289 (funcall in (gettext "first character of comment-end sequence B"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290 (if end2b
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 (funcall in (gettext "second character of comment-end sequence B")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292 (if prefix
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 (funcall in (gettext "prefix character for `backward-prefix-chars'")))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294 (terpri stream)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 (defun symbol-near-point ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297 "Return the first textual item to the nearest point."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299 ;alg stolen from etag.el
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301 (if (not (memq (char-syntax (preceding-char)) '(?w ?_)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 (while (not (looking-at "\\sw\\|\\s_\\|\\'"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 (forward-char 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 (while (looking-at "\\sw\\|\\s_")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305 (forward-char 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 (if (re-search-backward "\\sw\\|\\s_" nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 (regexp-quote
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 (progn (forward-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 (buffer-substring (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310 (progn (forward-sexp -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 (while (looking-at "\\s'")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312 (forward-char 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 (point)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 nil)))