Mercurial > emacs
comparison lisp/cedet/srecode/compile.el @ 110531:67ff8ad45bd5
Synch SRecode to CEDET 1.0.
* lisp/cedet/cedet.el (cedet-version):
* lisp/cedet/srecode.el (srecode-version): Bump version to 1.0.
* lisp/cedet/pulse.el (pulse-momentary-highlight-overlay): If pulse-flag is
'never, disable all pulsing.
* lisp/cedet/srecode/compile.el (srecode-compile-templates): Fix directory
compare of built-in templates. Give built-ins lower piority.
Support special variable "project".
(srecode-compile-template-table): Set :project slot of new tables.
(srecode-compile-one-template-tag): Use
srecode-create-dictionaries-from-tags.
* lisp/cedet/srecode/cpp.el (srecode-cpp): New defgroup.
(srecode-cpp-namespaces): New option.
(srecode-semantic-handle-:using-namespaces)
(srecode-cpp-apply-templates): New functions.
(srecode-semantic-apply-tag-to-dict): Handle template parameters
by calling `srecode-cpp-apply-templates'.
* lisp/cedet/srecode/dictionary.el (srecode-dictionary-add-template-table):
Do not add variables in tables not for the current project.
(srecode-compound-toString): Handle cases where the default value
is another compound value.
(srecode-dictionary-lookup-name): New optional argument
NON-RECURSIVE, which inhibits visiting dictionary parents.
(srecode-dictionary-add-section-dictionary)
(srecode-dictionary-merge): New optional argument FORCE adds
values even if an identically named entry exists.
(srecode-dictionary-add-entries): New method.
(srecode-create-dictionaries-from-tags): New function.
* lisp/cedet/srecode/fields.el (srecode-fields-exit-confirmation): New option.
(srecode-field-exit-ask): Use it.
* lisp/cedet/srecode/find.el (srecode-template-get-table)
(srecode-template-get-table-for-binding)
(srecode-all-template-hash): Skip if not in current project.
(srecode-template-table-in-project-p): New method.
* lisp/cedet/srecode/getset.el (srecode-insert-getset): Force tag table
update. Don't query the class if it is empty.
* lisp/cedet/srecode/insert.el (srecode-insert-fcn): Merge template
dictionary before resolving arguments.
(srecode-insert-method-helper): Add error checking to make sure
that we only have dictionaries.
(srecode-insert-method): Check template nesting depth when using
point inserter override.
(srecode-insert-method): Install override with depth limit.
* lisp/cedet/srecode/map.el (srecode-map-update-map): Make map loading more
robust.
* lisp/cedet/srecode/mode.el (srecode-bind-insert): Call
srecode-load-tables-for-mode.
(srecode-minor-mode-templates-menu): Do not list templates that
are not in the current project.
(srecode-menu-bar): Add binding for srecode-macro-help.
* lisp/cedet/srecode/table.el (srecode-template-table): Add :project slot.
(srecode-dump): Dump it.
* lisp/cedet/srecode/texi.el (srecode-texi-insert-tag-as-doc): New function.
(semantic-insert-foreign-tag): Use it.
author | Chong Yidong <cyd@stupidchicken.com> |
---|---|
date | Tue, 21 Sep 2010 18:11:23 -0400 |
parents | 1d1d5d9bd884 |
children | 376148b31b5e |
comparison
equal
deleted
inserted
replaced
110530:2d0eee1a24b9 | 110531:67ff8ad45bd5 |
---|---|
33 | 33 |
34 (eval-when-compile (require 'cl)) | 34 (eval-when-compile (require 'cl)) |
35 (require 'semantic) | 35 (require 'semantic) |
36 (require 'eieio) | 36 (require 'eieio) |
37 (require 'eieio-base) | 37 (require 'eieio-base) |
38 (require 'srecode) | |
39 (require 'srecode/table) | 38 (require 'srecode/table) |
39 (require 'srecode/dictionary) | |
40 | 40 |
41 (declare-function srecode-template-inserter-newline-child-p "srecode/insert" | 41 (declare-function srecode-template-inserter-newline-child-p "srecode/insert" |
42 t t) | 42 t t) |
43 (declare-function srecode-create-section-dictionary "srecode/dictionary") | |
44 (declare-function srecode-dictionary-compound-variable "srecode/dictionary") | |
45 | 43 |
46 ;;; Code: | 44 ;;; Code: |
47 | 45 |
48 ;;; Template Class | 46 ;;; Template Class |
49 ;; | 47 ;; |
50 ;; Templatets describe a patter of text that can be inserted into a | 48 ;; Templates describe a pattern of text that can be inserted into a |
51 ;; buffer. | 49 ;; buffer. |
52 ;; | 50 ;; |
53 (defclass srecode-template (eieio-named) | 51 (defclass srecode-template (eieio-named) |
54 ((context :initarg :context | 52 ((context :initarg :context |
55 :initform nil | 53 :initform nil |
211 (STATE (srecode-compile-state (file-name-nondirectory | 209 (STATE (srecode-compile-state (file-name-nondirectory |
212 (buffer-file-name)))) | 210 (buffer-file-name)))) |
213 (mode nil) | 211 (mode nil) |
214 (application nil) | 212 (application nil) |
215 (priority nil) | 213 (priority nil) |
214 (project nil) | |
216 (vars nil) | 215 (vars nil) |
217 ) | 216 ) |
218 | 217 |
219 ;; | 218 ;; |
220 ;; COMPILE | 219 ;; COMPILE |
254 ) | 253 ) |
255 ((string= name "application") | 254 ((string= name "application") |
256 (setq application (read firstvalue))) | 255 (setq application (read firstvalue))) |
257 ((string= name "priority") | 256 ((string= name "priority") |
258 (setq priority (read firstvalue))) | 257 (setq priority (read firstvalue))) |
258 ((string= name "project") | |
259 (setq project firstvalue)) | |
259 (t | 260 (t |
260 ;; Assign this into some table of variables. | 261 ;; Assign this into some table of variables. |
261 (setq vars (cons (cons name firstvalue) vars)) | 262 (setq vars (cons (cons name firstvalue) vars)) |
262 )) | 263 )) |
263 ;; If it isn't a single string, then the value of the | 264 ;; If it isn't a single string, then the value of the |
295 | 296 |
296 ;; | 297 ;; |
297 ;; Calculate priority | 298 ;; Calculate priority |
298 ;; | 299 ;; |
299 (if (not priority) | 300 (if (not priority) |
300 (let ((d (file-name-directory (buffer-file-name))) | 301 (let ((d (expand-file-name (file-name-directory (buffer-file-name)))) |
301 (sd (file-name-directory (locate-library "srecode"))) | 302 (sd (expand-file-name (file-name-directory (locate-library "srecode")))) |
302 (defaultdelta (if (eq mode 'default) 20 0))) | 303 (defaultdelta (if (eq mode 'default) 0 10))) |
303 (if (string= d sd) | 304 ;; @TODO : WHEN INTEGRATING INTO EMACS |
304 (setq priority (+ 80 defaultdelta)) | 305 ;; The location of Emacs default templates needs to be specified |
305 (setq priority (+ 30 defaultdelta))) | 306 ;; here to also have a lower priority. |
307 (if (string-match (concat "^" sd) d) | |
308 (setq priority (+ 30 defaultdelta)) | |
309 ;; If the user created template is for a project, then | |
310 ;; don't add as much as if it is unique to just some user. | |
311 (if (stringp project) | |
312 (setq priority (+ 50 defaultdelta)) | |
313 (setq priority (+ 80 defaultdelta)))) | |
306 (message "Templates %s has estimated priority of %d" | 314 (message "Templates %s has estimated priority of %d" |
307 (file-name-nondirectory (buffer-file-name)) | 315 (file-name-nondirectory (buffer-file-name)) |
308 priority)) | 316 priority)) |
309 (message "Compiling templates %s priority %d... done!" | 317 (message "Compiling templates %s priority %d... done!" |
310 (file-name-nondirectory (buffer-file-name)) | 318 (file-name-nondirectory (buffer-file-name)) |
311 priority)) | 319 priority)) |
312 | 320 |
313 ;; Save it up! | 321 ;; Save it up! |
314 (srecode-compile-template-table table mode priority application vars) | 322 (srecode-compile-template-table table mode priority application project vars) |
315 ) | 323 ) |
316 ) | 324 ) |
317 | 325 |
318 (defun srecode-compile-one-template-tag (tag STATE) | 326 (defun srecode-compile-one-template-tag (tag state) |
319 "Compile a template tag TAG into an srecode template class. | 327 "Compile a template tag TAG into a srecode template object. |
320 STATE is the current compile state as an object `srecode-compile-state'." | 328 STATE is the current compile state as an object of class |
321 (require 'srecode/dictionary) | 329 `srecode-compile-state'." |
322 (let* ((context (oref STATE context)) | 330 (let* ((context (oref state context)) |
323 (codeout (srecode-compile-split-code | 331 (code (cdr (srecode-compile-split-code |
324 tag (semantic-tag-get-attribute tag :code) | 332 tag (semantic-tag-get-attribute tag :code) |
325 STATE)) | 333 state))) |
326 (code (cdr codeout)) | 334 (args (semantic-tag-function-arguments tag)) |
327 (args (semantic-tag-function-arguments tag)) | 335 (binding (semantic-tag-get-attribute tag :binding)) |
328 (binding (semantic-tag-get-attribute tag :binding)) | 336 (dict-tags (semantic-tag-get-attribute tag :dictionaries)) |
329 (rawdicts (semantic-tag-get-attribute tag :dictionaries)) | 337 (root-dict (when dict-tags |
330 (sdicts (srecode-create-section-dictionary rawdicts STATE)) | 338 (srecode-create-dictionaries-from-tags |
331 (addargs nil) | 339 dict-tags state))) |
332 ) | 340 (addargs)) |
333 ; (message "Compiled %s to %d codes with %d args and %d prompts." | 341 ;; Examine arguments. |
334 ; (semantic-tag-name tag) | 342 (dolist (arg args) |
335 ; (length code) | 343 (let ((symbol (intern arg))) |
336 ; (length args) | 344 (push symbol addargs) |
337 ; (length prompts)) | 345 |
338 (while args | 346 ;; If we have a wrap, then put wrap inserters on both ends of |
339 (setq addargs (cons (intern (car args)) addargs)) | 347 ;; the code. |
340 (when (eq (car addargs) :blank) | 348 (when (eq symbol :blank) |
341 ;; If we have a wrap, then put wrap inserters on both | 349 (setq code (append |
342 ;; ends of the code. | 350 (list (srecode-compile-inserter |
343 (setq code (append | 351 "BLANK" |
344 (list (srecode-compile-inserter "BLANK" | 352 "\r" |
345 "\r" | 353 state |
346 STATE | 354 :secondname nil |
347 :secondname nil | 355 :where 'begin)) |
348 :where 'begin)) | 356 code |
349 code | 357 (list (srecode-compile-inserter |
350 (list (srecode-compile-inserter "BLANK" | 358 "BLANK" |
351 "\r" | 359 "\r" |
352 STATE | 360 state |
353 :secondname nil | 361 :secondname nil |
354 :where 'end)) | 362 :where 'end))))))) |
355 ))) | 363 |
356 (setq args (cdr args))) | 364 ;; Construct and return the template object. |
357 (srecode-template (semantic-tag-name tag) | 365 (srecode-template (semantic-tag-name tag) |
358 :context context | 366 :context context |
359 :args (nreverse addargs) | 367 :args (nreverse addargs) |
360 :dictionary sdicts | 368 :dictionary root-dict |
361 :binding binding | 369 :binding binding |
362 :code code) | 370 :code code)) |
363 )) | 371 ) |
364 | 372 |
365 (defun srecode-compile-do-hard-newline-p (comp) | 373 (defun srecode-compile-do-hard-newline-p (comp) |
366 "Examine COMP to decide if the upcoming newline should be hard. | 374 "Examine COMP to decide if the upcoming newline should be hard. |
367 It is hard if the previous inserter is a newline object." | 375 It is hard if the previous inserter is a newline object." |
368 (while (and comp (stringp (car comp))) | 376 (while (and comp (stringp (car comp))) |
512 ) | 520 ) |
513 (setq classes (cdr classes))) | 521 (setq classes (cdr classes))) |
514 (if (not new) (error "SRECODE: Unknown macro code %S" key)) | 522 (if (not new) (error "SRECODE: Unknown macro code %S" key)) |
515 new))) | 523 new))) |
516 | 524 |
517 (defun srecode-compile-template-table (templates mode priority application vars) | 525 (defun srecode-compile-template-table (templates mode priority application project vars) |
518 "Compile a list of TEMPLATES into an semantic recode table. | 526 "Compile a list of TEMPLATES into an semantic recode table. |
519 The table being compiled is for MODE, or the string \"default\". | 527 The table being compiled is for MODE, or the string \"default\". |
520 PRIORITY is a numerical value that indicates this tables location | 528 PRIORITY is a numerical value that indicates this tables location |
521 in an ordered search. | 529 in an ordered search. |
522 APPLICATION is the name of the application these templates belong to. | 530 APPLICATION is the name of the application these templates belong to. |
531 PROJECT is a directory name which these templates scope to. | |
523 A list of defined variables VARS provides a variable table." | 532 A list of defined variables VARS provides a variable table." |
524 (let ((namehash (make-hash-table :test 'equal | 533 (let ((namehash (make-hash-table :test 'equal |
525 :size (length templates))) | 534 :size (length templates))) |
526 (contexthash (make-hash-table :test 'equal :size 10)) | 535 (contexthash (make-hash-table :test 'equal :size 10)) |
527 (lp templates) | 536 (lp templates) |
547 (puthash objname (car lp) hs) | 556 (puthash objname (car lp) hs) |
548 ) | 557 ) |
549 | 558 |
550 (setq lp (cdr lp)))) | 559 (setq lp (cdr lp)))) |
551 | 560 |
561 (when (stringp project) | |
562 (setq project (expand-file-name project))) | |
563 | |
552 (let* ((table (srecode-mode-table-new mode (buffer-file-name) | 564 (let* ((table (srecode-mode-table-new mode (buffer-file-name) |
553 :templates (nreverse templates) | 565 :templates (nreverse templates) |
554 :namehash namehash | 566 :namehash namehash |
555 :contexthash contexthash | 567 :contexthash contexthash |
556 :variables vars | 568 :variables vars |
557 :major-mode mode | 569 :major-mode mode |
558 :priority priority | 570 :priority priority |
559 :application application)) | 571 :application application |
572 :project project)) | |
560 (tmpl (oref table templates))) | 573 (tmpl (oref table templates))) |
561 ;; Loop over all the templates, and xref. | 574 ;; Loop over all the templates, and xref. |
562 (while tmpl | 575 (while tmpl |
563 (oset (car tmpl) :table table) | 576 (oset (car tmpl) :table table) |
564 (setq tmpl (cdr tmpl)))) | 577 (setq tmpl (cdr tmpl)))) |