annotate lisp/prim/syntax.el @ 0:376386a54a3c r19-14

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