Mercurial > emacs
comparison lisp/cedet/srecode/find.el @ 110534:826d60163924
Merge changes from emacs-23 branch.
author | Chong Yidong <cyd@stupidchicken.com> |
---|---|
date | Thu, 23 Sep 2010 22:10:54 -0400 |
parents | 67ff8ad45bd5 |
children | 376148b31b5e |
comparison
equal
deleted
inserted
replaced
110517:64945cefe6a6 | 110534:826d60163924 |
---|---|
90 (when (or (not mt) (not (srecode-mode-table-find mt (car f)))) | 90 (when (or (not mt) (not (srecode-mode-table-find mt (car f)))) |
91 (srecode-compile-file (car f))) | 91 (srecode-compile-file (car f))) |
92 )) | 92 )) |
93 )) | 93 )) |
94 | 94 |
95 ;;; PROJECT | |
96 ;; | |
97 ;; Find if a template table has a project set, and if so, is the | |
98 ;; current buffer in that project. | |
99 (defmethod srecode-template-table-in-project-p ((tab srecode-template-table)) | |
100 "Return non-nil if the table TAB can be used in the current project. | |
101 If TAB has a :project set, check that the directories match. | |
102 If TAB is nil, then always return t." | |
103 (let ((proj (oref tab :project))) | |
104 ;; Return t if the project wasn't set. | |
105 (if (not proj) t | |
106 ;; If the project directory was set, lets check it. | |
107 (let ((dd (expand-file-name default-directory)) | |
108 (projexp (regexp-quote (directory-file-name proj)))) | |
109 (if (string-match (concat "^" projexp) dd) | |
110 t nil))))) | |
111 | |
95 ;;; SEARCH | 112 ;;; SEARCH |
96 ;; | 113 ;; |
97 ;; Find a given template based on name, and features of the current | 114 ;; Find a given template based on name, and features of the current |
98 ;; buffer. | 115 ;; buffer. |
99 (defmethod srecode-template-get-table ((tab srecode-template-table) | 116 (defmethod srecode-template-get-table ((tab srecode-template-table) |
101 context application) | 118 context application) |
102 "Find in the template in table TAB, the template with TEMPLATE-NAME. | 119 "Find in the template in table TAB, the template with TEMPLATE-NAME. |
103 Optional argument CONTEXT specifies that the template should part | 120 Optional argument CONTEXT specifies that the template should part |
104 of a particular context. | 121 of a particular context. |
105 The APPLICATION argument is unused." | 122 The APPLICATION argument is unused." |
106 (if context | 123 (when (srecode-template-table-in-project-p tab) |
107 ;; If a context is specified, then look it up there. | 124 (if context |
108 (let ((ctxth (gethash context (oref tab contexthash)))) | 125 ;; If a context is specified, then look it up there. |
109 (when ctxth | 126 (let ((ctxth (gethash context (oref tab contexthash)))) |
110 (gethash template-name ctxth))) | 127 (when ctxth |
111 ;; No context, perhaps a merged name? | 128 (gethash template-name ctxth))) |
112 (gethash template-name (oref tab namehash)))) | 129 ;; No context, perhaps a merged name? |
130 (gethash template-name (oref tab namehash))))) | |
113 | 131 |
114 (defmethod srecode-template-get-table ((tab srecode-mode-table) | 132 (defmethod srecode-template-get-table ((tab srecode-mode-table) |
115 template-name &optional | 133 template-name &optional |
116 context application) | 134 context application) |
117 "Find in the template in mode table TAB, the template with TEMPLATE-NAME. | 135 "Find in the template in mode table TAB, the template with TEMPLATE-NAME. |
142 (defmethod srecode-template-get-table-for-binding | 160 (defmethod srecode-template-get-table-for-binding |
143 ((tab srecode-template-table) binding &optional context) | 161 ((tab srecode-template-table) binding &optional context) |
144 "Find in the template name in table TAB, the template with BINDING. | 162 "Find in the template name in table TAB, the template with BINDING. |
145 Optional argument CONTEXT specifies that the template should part | 163 Optional argument CONTEXT specifies that the template should part |
146 of a particular context." | 164 of a particular context." |
147 (let* ((keyout nil) | 165 (when (srecode-template-table-in-project-p tab) |
148 (hashfcn (lambda (key value) | 166 (let* ((keyout nil) |
149 (when (and (slot-boundp value 'binding) | 167 (hashfcn (lambda (key value) |
150 (oref value binding) | 168 (when (and (slot-boundp value 'binding) |
151 (= (aref (oref value binding) 0) binding)) | 169 (oref value binding) |
152 (setq keyout key)))) | 170 (= (aref (oref value binding) 0) binding)) |
153 (contextstr (cond ((listp context) | 171 (setq keyout key)))) |
154 (car-safe context)) | 172 (contextstr (cond ((listp context) |
155 ((stringp context) | 173 (car-safe context)) |
156 context) | 174 ((stringp context) |
157 (t nil))) | 175 context) |
158 ) | 176 (t nil))) |
159 (if context | 177 ) |
160 (let ((ctxth (gethash contextstr (oref tab contexthash)))) | 178 (if context |
161 (when ctxth | 179 (let ((ctxth (gethash contextstr (oref tab contexthash)))) |
162 ;; If a context is specified, then look it up there. | 180 (when ctxth |
163 (maphash hashfcn ctxth) | 181 ;; If a context is specified, then look it up there. |
164 ;; Context hashes EXCLUDE the context prefix which | 182 (maphash hashfcn ctxth) |
165 ;; we need to include, so concat it here | 183 ;; Context hashes EXCLUDE the context prefix which |
166 (when keyout | 184 ;; we need to include, so concat it here |
167 (setq keyout (concat contextstr ":" keyout))) | 185 (when keyout |
168 ))) | 186 (setq keyout (concat contextstr ":" keyout))) |
169 (when (not keyout) | 187 ))) |
170 ;; No context, or binding in context. Try full hash. | 188 (when (not keyout) |
171 (maphash hashfcn (oref tab namehash))) | 189 ;; No context, or binding in context. Try full hash. |
172 keyout)) | 190 (maphash hashfcn (oref tab namehash))) |
191 keyout))) | |
173 | 192 |
174 (defmethod srecode-template-get-table-for-binding | 193 (defmethod srecode-template-get-table-for-binding |
175 ((tab srecode-mode-table) binding &optional context application) | 194 ((tab srecode-mode-table) binding &optional context application) |
176 "Find in the template name in mode table TAB, the template with BINDING. | 195 "Find in the template name in mode table TAB, the template with BINDING. |
177 Optional argument CONTEXT specifies a context a particular template | 196 Optional argument CONTEXT specifies a context a particular template |
218 (let* ((mt (srecode-get-mode-table mmode)) | 237 (let* ((mt (srecode-get-mode-table mmode)) |
219 (tabs (when mt (oref mt :tables))) | 238 (tabs (when mt (oref mt :tables))) |
220 ) | 239 ) |
221 (while tabs | 240 (while tabs |
222 ;; Exclude templates for a perticular application. | 241 ;; Exclude templates for a perticular application. |
223 (when (not (oref (car tabs) :application)) | 242 (when (and (not (oref (car tabs) :application)) |
243 (srecode-template-table-in-project-p (car tabs))) | |
224 (maphash (lambda (key temp) | 244 (maphash (lambda (key temp) |
225 (puthash key temp mhash) | 245 (puthash key temp mhash) |
226 ) | 246 ) |
227 (oref (car tabs) namehash))) | 247 (oref (car tabs) namehash))) |
228 (setq tabs (cdr tabs))) | 248 (setq tabs (cdr tabs))) |