annotate lisp/cedet/srecode/table.el @ 107903:aaff69467d86

Merge from mainline.
author Katsumi Yamaoka <yamaoka@jpl.org>
date Mon, 29 Mar 2010 10:22:46 +0000
parents 7c79bc199c73
children 67ff8ad45bd5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
104498
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1 ;;; srecode/table.el --- Tables of Semantic Recoders
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
2
106815
1d1d5d9bd884 Add 2010 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 105377
diff changeset
3 ;; Copyright (C) 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
104498
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
4
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
5 ;; Author: Eric M. Ludlam <eric@siege-engine.com>
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
6
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
7 ;; This file is part of GNU Emacs.
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
8
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
9 ;; GNU Emacs is free software: you can redistribute it and/or modify
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
10 ;; it under the terms of the GNU General Public License as published by
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
11 ;; the Free Software Foundation, either version 3 of the License, or
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
12 ;; (at your option) any later version.
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
13
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
14 ;; GNU Emacs is distributed in the hope that it will be useful,
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
17 ;; GNU General Public License for more details.
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
18
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
19 ;; You should have received a copy of the GNU General Public License
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
20 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
21
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
22 ;;; Commentary:
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
23 ;;
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
24 ;; Semantic Recoder tables manage lists of templates and the major
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
25 ;; modes they are associated with.
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
26 ;;
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
27
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
28 (require 'eieio)
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
29 (require 'eieio-base)
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
30 (require 'mode-local)
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
31 (require 'srecode)
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
32
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
33 (declare-function srecode-load-tables-for-mode "srecode/find")
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
34
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
35 ;;; Code:
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
36
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
37 ;;; TEMPLATE TABLE
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
38 ;;
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
39 (defclass srecode-template-table ()
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
40 (;;
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
41 ;; Raw file tracking
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
42 ;;
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
43 (file :initarg :file
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
44 :type string
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
45 :documentation
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
46 "The name of the file this table was built from.")
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
47 (filesize :initarg :filesize
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
48 :type number
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
49 :documentation
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
50 "The size of the file when it was parsed.")
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
51 (filedate :initarg :filedate
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
52 :type cons
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
53 :documentation
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
54 "Date from the inode of the file when it was last edited.
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
55 Format is from the `file-attributes' function.")
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
56 (major-mode :initarg :major-mode
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
57 :documentation
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
58 "The major mode this table of templates is associated with.")
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
59 ;;
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
60 ;; Template file sorting data
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
61 ;;
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
62 (application :initarg :application
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
63 :type symbol
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
64 :documentation
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
65 "Tracks the name of the application these templates belong to.
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
66 If this is nil, then this template table belongs to a set of generic
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
67 templates that can be used with no additional dictionary values.
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
68 When it is non-nil, it is assumed the template macros need specialized
107532
7c79bc199c73 Fix typos.
Juanma Barranquero <lekktu@gmail.com>
parents: 106815
diff changeset
69 Emacs Lisp code to fill in the dictionary.")
104498
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
70 (priority :initarg :priority
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
71 :type number
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
72 :documentation
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
73 "For file of this Major Mode, what is the priority of this file.
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
74 When there are multiple template files with similar names, templates with
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
75 the highest priority are scanned last, allowing them to override values in
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
76 previous template files.")
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
77 ;;
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
78 ;; Parsed Data from the template file
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
79 ;;
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
80 (templates :initarg :templates
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
81 :type list
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
82 :documentation
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
83 "The list of templates compiled into this table.")
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
84 (namehash :initarg :namehash
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
85 :documentation
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
86 "Hash table containing the names of all the templates.")
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
87 (contexthash :initarg :contexthash
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
88 :documentation
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
89 "")
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
90 (variables :initarg :variables
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
91 :documentation
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
92 "AList of variables.
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
93 These variables are used to initialize dictionaries.")
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
94 )
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
95 "Semantic recoder template table.
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
96 A Table contains all templates from a single .srt file.
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
97 Tracks various lookup hash tables.")
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
98
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
99 ;;; MODE TABLE
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
100 ;;
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
101 (defvar srecode-mode-table-list nil
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
102 "List of all the SRecode mode table classes that have been built.")
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
103
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
104 (defclass srecode-mode-table (eieio-instance-tracker)
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
105 ((tracking-symbol :initform 'srecode-mode-table-list)
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
106 (major-mode :initarg :major-mode
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
107 :documentation
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
108 "Table of template tables for this major-mode.")
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
109 (tables :initarg :tables
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
110 :documentation
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
111 "All the tables that have been defined for this major mode.")
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
112 )
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
113 "Track template tables for a particular major mode.
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
114 Tracks all the template-tables for a specific major mode.")
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
115
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
116 (defun srecode-get-mode-table (mode)
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
117 "Get the SRecoder mode table for the major mode MODE.
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
118 Optional argument SOFT indicates to not make a new one if a table
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
119 was not found."
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
120 (let ((ans nil))
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
121 (while (and (not ans) mode)
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
122 (setq ans (eieio-instance-tracker-find
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
123 mode 'major-mode 'srecode-mode-table-list)
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
124 mode (get-mode-local-parent mode)))
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
125 ans))
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
126
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
127 (defun srecode-make-mode-table (mode)
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
128 "Get the SRecoder mode table for the major mode MODE."
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
129 (let ((old (eieio-instance-tracker-find
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
130 mode 'major-mode 'srecode-mode-table-list)))
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
131 (if old
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
132 old
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
133 (let* ((ms (if (stringp mode) mode (symbol-name mode)))
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
134 (new (srecode-mode-table ms
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
135 :major-mode mode
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
136 :tables nil)))
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
137 ;; Save this new mode table in that mode's variable.
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
138 (eval `(setq-mode-local ,mode srecode-table ,new))
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
139
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
140 new))))
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
141
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
142 (defmethod srecode-mode-table-find ((mt srecode-mode-table) file)
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
143 "Look in the mode table MT for a template table from FILE.
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
144 Return nil if there was none."
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
145 (object-assoc file 'file (oref mt tables)))
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
146
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
147 (defun srecode-mode-table-new (mode file &rest init)
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
148 "Create a new template table for MODE in FILE.
105328
2f2bc20297c6 Doc/message fixes.
Glenn Morris <rgm@gnu.org>
parents: 104498
diff changeset
149 INIT are the initialization parameters for the new template table."
104498
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
150 (let* ((mt (srecode-make-mode-table mode))
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
151 (old (srecode-mode-table-find mt file))
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
152 (attr (file-attributes file))
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
153 (new (apply 'srecode-template-table
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
154 (file-name-nondirectory file)
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
155 :file file
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
156 :filesize (nth 7 attr)
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
157 :filedate (nth 5 attr)
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
158 :major-mode mode
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
159 init
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
160 )))
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
161 ;; Whack the old table.
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
162 (when old (object-remove-from-list mt 'tables old))
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
163 ;; Add the new table
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
164 (object-add-to-list mt 'tables new)
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
165 ;; Sort the list in reverse order. When other routines
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
166 ;; go front-to-back, the highest priority items are put
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
167 ;; into the search table first, allowing lower priority items
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
168 ;; to be the items found in the search table.
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
169 (object-sort-list mt 'tables (lambda (a b)
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
170 (> (oref a :priority)
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
171 (oref b :priority))))
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
172 ;; Return it.
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
173 new))
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
174
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
175 (defun object-sort-list (object slot predicate)
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
176 "Sort the items in OBJECT's SLOT.
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
177 Use PREDICATE is the same as for the `sort' function."
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
178 (when (slot-boundp object slot)
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
179 (when (listp (eieio-oref object slot))
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
180 (eieio-oset object slot (sort (eieio-oref object slot) predicate)))))
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
181
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
182 ;;; DEBUG
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
183 ;;
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
184 ;; Dump out information about the current srecoder compiled templates.
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
185 ;;
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
186 (defun srecode-dump-templates (mode)
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
187 "Dump a list of the current templates for MODE."
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
188 (interactive "sMode: ")
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
189 (require 'srecode/find)
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
190 (let ((modesym (cond ((string= mode "")
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
191 major-mode)
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
192 ((not (string-match "-mode" mode))
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
193 (intern-soft (concat mode "-mode")))
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
194 (t
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
195 (intern-soft mode)))))
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
196 (srecode-load-tables-for-mode modesym)
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
197 (let ((tmp (srecode-get-mode-table modesym))
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
198 )
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
199 (if (not tmp)
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
200 (error "No table found for mode %S" modesym))
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
201 (with-output-to-temp-buffer "*SRECODE DUMP*"
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
202 (srecode-dump tmp))
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
203 )))
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
204
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
205 (defmethod srecode-dump ((tab srecode-mode-table))
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
206 "Dump the contents of the SRecode mode table TAB."
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
207 (princ "MODE TABLE FOR ")
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
208 (princ (oref tab :major-mode))
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
209 (princ "\n--------------------------------------------\n\nNumber of tables: ")
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
210 (let ((subtab (oref tab :tables)))
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
211 (princ (length subtab))
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
212 (princ "\n\n")
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
213 (while subtab
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
214 (srecode-dump (car subtab))
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
215 (setq subtab (cdr subtab)))
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
216 ))
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
217
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
218 (defmethod srecode-dump ((tab srecode-template-table))
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
219 "Dump the contents of the SRecode template table TAB."
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
220 (princ "Template Table for ")
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
221 (princ (object-name-string tab))
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
222 (princ "\nPriority: ")
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
223 (prin1 (oref tab :priority))
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
224 (when (oref tab :application)
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
225 (princ "\nApplication: ")
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
226 (princ (oref tab :application)))
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
227 (princ "\n\nVariables:\n")
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
228 (let ((vars (oref tab variables)))
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
229 (while vars
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
230 (princ (car (car vars)))
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
231 (princ "\t")
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
232 (if (< (length (car (car vars))) 9)
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
233 (princ "\t"))
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
234 (prin1 (cdr (car vars)))
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
235 (princ "\n")
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
236 (setq vars (cdr vars))))
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
237 (princ "\n\nTemplates:\n")
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
238 (let ((temp (oref tab templates)))
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
239 (while temp
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
240 (srecode-dump (car temp))
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
241 (setq temp (cdr temp))))
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
242 )
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
243
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
244
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
245 (provide 'srecode/table)
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
246
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
247 ;;; srecode/table.el ends here
41dc39934483 lisp/cedet/srecode.el:
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
248
105377
7f4c7f5c0eba Add arch tagline
Miles Bader <miles@gnu.org>
parents: 105328
diff changeset
249 ;; arch-tag: 547d2f1d-2694-49b3-ab13-b2cda6b25b4d