annotate lisp/utils/symbol-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 ;;; symbol-syntax.el --- find chars with symbol syntax
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) 1992, 1993 Free Software Foundation, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4 ;; Copyright (C) 1995 Sun Microsystems.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 ;; Created by: JBW, JBW@_CORTEZ
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 ;; Created on: Wed Jun 20 15:15:34 1990
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 ;; Last modified by: Ben Wing, wing@666.com
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 ;; Last modified on: Mon Oct 2 02:32:05 GMT 1995
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 ;; Filename: symbol-syntax.el
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 ;; Keywords: matching
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ;; This file is part of XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 ;; XEmacs is free software; you can redistribute it and/or modify it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 ;; under the terms of the GNU General Public License as published by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 ;; the Free Software Foundation; either version 2, or (at your option)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 ;; any later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 ;; XEmacs is distributed in the hope that it will be useful, but
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23 ;; General Public License for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 ;; You should have received a copy of the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 ;; along with XEmacs; see the file COPYING. If not, write to the Free
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 ;; Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 ;;; Synched up with: Not in FSF.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 (defvar symbol-syntax-table-alist nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 ;; '((c-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 ;; (emacs-lisp-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 ;; (lisp-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 ;; (text-mode-syntax-table)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 (defun update-symbol-syntax-table-alist ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 (let ((alist symbol-syntax-table-alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 item)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 (while (consp alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 (cond ((null (car alist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 (error "Missing alist item"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 ((null (car (car alist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 (error "Alist item with null car"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 ;; this functionality not used
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 ((symbolp (setq item (car (car alist))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 (or (null (cdr (car alist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 (error "Alist item expected to have null cdr"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 (while (symbolp item)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 (setq item (symbol-value item)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 (setcar (car alist) item)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 (cond ((not (syntax-table-p (car (car alist))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 (error "Alist item car expected to be symbol table"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 ((null (cdr (car alist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 (setcdr (car alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 (make-symbol-syntax-table (car (car alist))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 (setq alist (cdr alist)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 (defun get-symbol-syntax-table (norm-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 (let (result)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 (if (setq result (assq norm-table symbol-syntax-table-alist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 (update-symbol-syntax-table-alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 (if (setq result (assq norm-table symbol-syntax-table-alist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 (setq symbol-syntax-table-alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 (cons (list norm-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 symbol-syntax-table-alist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 (update-symbol-syntax-table-alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 (or (setq result (assq norm-table symbol-syntax-table-alist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 (error "Syntax table missing from symbol-syntax-table-alist"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 (or (setq result (cdr result))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 (error "Alist item has null cdr"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 (or (syntax-table-p result)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 (error "Non-syntax-table item in alist"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 result))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 (defun make-symbol-syntax-table (in-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 (let ((osyn (syntax-table))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 (out-table (copy-syntax-table in-table))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 (i 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 (syntax nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 (while (< i 256)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 (setq syntax (aref out-table i))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 (if (eq 3 (logand 255 syntax))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 (aset out-table i (logior 2 (logand (lognot 255) syntax))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 (setq i (1+ i)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 out-table))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 ;; stuff for examining contents of syntax tables
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 ;;(show-chars-with-syntax
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 ;; '(c-mode-syntax-table
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 ;; emacs-lisp-mode-syntax-table
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 ;; lisp-mode-syntax-table
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 ;; text-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 ;; ?_)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 (defun show-chars-with-syntax (tables syntax)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 (let ((osyn (syntax-table))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 (schars nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 (unwind-protect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 (while (consp tables)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 (let* ((chars nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 (table-symbol (car tables))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 (table table-symbol)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 (i 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 (or (symbolp table-symbol)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 (error "bad argument non-symbol"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 (while (symbolp table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 (setq table (symbol-value table)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 (set-syntax-table table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 (while (< i 256)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 (if (eq syntax (char-syntax i))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 (setq chars (cons (format "%c" i) chars)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 (setq i (1+ i)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 (setq schars (cons (list table-symbol
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 (mapconcat 'identity (nreverse chars) ""))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 schars)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 (setq tables (cdr tables)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 (set-syntax-table osyn))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 (nreverse schars)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 (provide 'symbol-syntax)