aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/cedet/srecode/insert.el
diff options
context:
space:
mode:
authorEric M. Ludlam2010-09-21 18:11:23 -0400
committerChong Yidong2010-09-21 18:11:23 -0400
commitb9749554532876da8bc15e10bc3fb8bd8c0f32ea (patch)
tree0d00b9800e8eb95e8466ab322fde1879e378fddb /lisp/cedet/srecode/insert.el
parentfbb3da770f233a8e0cf99d5f053b0c31cbbc8db4 (diff)
downloademacs-b9749554532876da8bc15e10bc3fb8bd8c0f32ea.tar.gz
emacs-b9749554532876da8bc15e10bc3fb8bd8c0f32ea.zip
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.
Diffstat (limited to 'lisp/cedet/srecode/insert.el')
-rw-r--r--lisp/cedet/srecode/insert.el162
1 files changed, 101 insertions, 61 deletions
diff --git a/lisp/cedet/srecode/insert.el b/lisp/cedet/srecode/insert.el
index 4ee6d467009..843b577e1eb 100644
--- a/lisp/cedet/srecode/insert.el
+++ b/lisp/cedet/srecode/insert.el
@@ -26,6 +26,9 @@
26;; Manage the insertion process for a template. 26;; Manage the insertion process for a template.
27;; 27;;
28 28
29(eval-when-compile
30 (require 'cl)) ;; for `lexical-let'
31
29(require 'srecode/compile) 32(require 'srecode/compile)
30(require 'srecode/find) 33(require 'srecode/find)
31(require 'srecode/dictionary) 34(require 'srecode/dictionary)
@@ -49,7 +52,7 @@ Possible values are:
49NOTE: The field feature does not yet work with XEmacs." 52NOTE: The field feature does not yet work with XEmacs."
50 :group 'srecode 53 :group 'srecode
51 :type '(choice (const :tag "Ask" ask) 54 :type '(choice (const :tag "Ask" ask)
52 (cons :tag "Field" field))) 55 (const :tag "Field" field)))
53 56
54(defvar srecode-insert-with-fields-in-progress nil 57(defvar srecode-insert-with-fields-in-progress nil
55 "Non-nil means that we are actively inserting a template with fields.") 58 "Non-nil means that we are actively inserting a template with fields.")
@@ -86,7 +89,6 @@ DICT-ENTRIES are additional dictionary values to add."
86 (car dict-entries) 89 (car dict-entries)
87 (car (cdr dict-entries))) 90 (car (cdr dict-entries)))
88 (setq dict-entries (cdr (cdr dict-entries)))) 91 (setq dict-entries (cdr (cdr dict-entries))))
89 ;;(srecode-resolve-arguments temp newdict)
90 (srecode-insert-fcn temp newdict) 92 (srecode-insert-fcn temp newdict)
91 ;; Don't put code here. We need to return the end-mark 93 ;; Don't put code here. We need to return the end-mark
92 ;; for this insertion step. 94 ;; for this insertion step.
@@ -100,6 +102,10 @@ has set everything up already."
100 ;; Perform the insertion. 102 ;; Perform the insertion.
101 (let ((standard-output (or stream (current-buffer))) 103 (let ((standard-output (or stream (current-buffer)))
102 (end-mark nil)) 104 (end-mark nil))
105 ;; Merge any template entries into the input dictionary.
106 (when (slot-boundp template 'dictionary)
107 (srecode-dictionary-merge dictionary (oref template dictionary)))
108
103 (unless skipresolver 109 (unless skipresolver
104 ;; Make sure the semantic tags are up to date. 110 ;; Make sure the semantic tags are up to date.
105 (semantic-fetch-tags) 111 (semantic-fetch-tags)
@@ -110,7 +116,7 @@ has set everything up already."
110 ;; If there is a buffer, turn off various hooks. This will cause 116 ;; If there is a buffer, turn off various hooks. This will cause
111 ;; the mod hooks to be buffered up during the insert, but 117 ;; the mod hooks to be buffered up during the insert, but
112 ;; prevent tools like font-lock from fontifying mid-template. 118 ;; prevent tools like font-lock from fontifying mid-template.
113 ;; Especialy important during insertion of complex comments that 119 ;; Especially important during insertion of complex comments that
114 ;; cause the new font-lock to comment-color stuff after the inserted 120 ;; cause the new font-lock to comment-color stuff after the inserted
115 ;; comment. 121 ;; comment.
116 ;; 122 ;;
@@ -239,6 +245,9 @@ ST can be a class, or an object."
239(defmethod srecode-insert-method ((st srecode-template) dictionary) 245(defmethod srecode-insert-method ((st srecode-template) dictionary)
240 "Insert the srecoder template ST." 246 "Insert the srecoder template ST."
241 ;; Merge any template entries into the input dictionary. 247 ;; Merge any template entries into the input dictionary.
248 ;; This may happen twice since some templates arguments need
249 ;; these dictionary values earlier, but these values always
250 ;; need merging for template inserting in other templates.
242 (when (slot-boundp st 'dictionary) 251 (when (slot-boundp st 'dictionary)
243 (srecode-dictionary-merge dictionary (oref st dictionary))) 252 (srecode-dictionary-merge dictionary (oref st dictionary)))
244 ;; Do an insertion. 253 ;; Do an insertion.
@@ -264,7 +273,7 @@ Use DICTIONARY to resolve any macros."
264;; Specific srecode inserters. 273;; Specific srecode inserters.
265;; The base class is from srecode-compile. 274;; The base class is from srecode-compile.
266;; 275;;
267;; Each inserter handles various macro codes from the temlate. 276;; Each inserter handles various macro codes from the template.
268;; The `code' slot specifies a character used to identify which 277;; The `code' slot specifies a character used to identify which
269;; inserter is to be created. 278;; inserter is to be created.
270;; 279;;
@@ -471,7 +480,7 @@ If SECONDNAME is nil, return VALUE."
471 ;; (setq val (format "%S" val)))) 480 ;; (setq val (format "%S" val))))
472 )) 481 ))
473 ;; Output the dumb thing unless the type of thing specifically 482 ;; Output the dumb thing unless the type of thing specifically
474 ;; did the inserting forus. 483 ;; did the inserting for us.
475 (when do-princ 484 (when do-princ
476 (princ val)))) 485 (princ val))))
477 486
@@ -498,7 +507,8 @@ If there is no entry, prompt the user for the value to use.
498The prompt text used is derived from the previous PROMPT command in the 507The prompt text used is derived from the previous PROMPT command in the
499template file.") 508template file.")
500 509
501(defmethod srecode-inserter-apply-state ((ins srecode-template-inserter-ask) STATE) 510(defmethod srecode-inserter-apply-state
511 ((ins srecode-template-inserter-ask) STATE)
502 "For the template inserter INS, apply information from STATE. 512 "For the template inserter INS, apply information from STATE.
503Loop over the prompts to see if we have a match." 513Loop over the prompts to see if we have a match."
504 (let ((prompts (oref STATE prompts)) 514 (let ((prompts (oref STATE prompts))
@@ -669,7 +679,13 @@ Arguments ESCAPE-START and ESCAPE-END are the current escape sequences in use."
669 ) 679 )
670 680
671(defvar srecode-template-inserter-point-override nil 681(defvar srecode-template-inserter-point-override nil
672 "When non-nil, the point inserter will do this function instead.") 682 "Point-positioning method for the SRecode template inserter.
683When nil, perform normal point-positioning behavior.
684When the value is a cons cell (DEPTH . FUNCTION), call FUNCTION
685instead, unless the template nesting depth, measured
686by (length (oref srecode-template active)), is greater than
687DEPTH.")
688
673 689
674(defclass srecode-template-inserter-point (srecode-template-inserter) 690(defclass srecode-template-inserter-point (srecode-template-inserter)
675 ((key :initform ?^ 691 ((key :initform ?^
@@ -702,15 +718,20 @@ Arguments ESCAPE-START and ESCAPE-END are the current escape sequences in use."
702 dictionary) 718 dictionary)
703 "Insert the STI inserter. 719 "Insert the STI inserter.
704Save point in the class allocated 'point' slot. 720Save point in the class allocated 'point' slot.
705If `srecode-template-inserter-point-override' then this generalized 721If `srecode-template-inserter-point-override' non-nil then this
706marker will do something else. See `srecode-template-inserter-include-wrap' 722generalized marker will do something else. See
707as an example." 723`srecode-template-inserter-include-wrap' as an example."
708 (if srecode-template-inserter-point-override 724 ;; If `srecode-template-inserter-point-override' is non-nil, its car
725 ;; is the maximum template nesting depth for which the override is
726 ;; valid. Compare this to the actual template nesting depth and
727 ;; maybe use the override function which is stored in the cdr.
728 (if (and srecode-template-inserter-point-override
729 (<= (length (oref srecode-template active))
730 (car srecode-template-inserter-point-override)))
709 ;; Disable the old override while we do this. 731 ;; Disable the old override while we do this.
710 (let ((over srecode-template-inserter-point-override) 732 (let ((over (cdr srecode-template-inserter-point-override))
711 (srecode-template-inserter-point-override nil)) 733 (srecode-template-inserter-point-override nil))
712 (funcall over dictionary) 734 (funcall over dictionary))
713 )
714 (oset sti point (point-marker)) 735 (oset sti point (point-marker))
715 )) 736 ))
716 737
@@ -751,9 +772,15 @@ Loops over the embedded CODE which was saved here during compilation.
751The template to insert is stored in SLOT." 772The template to insert is stored in SLOT."
752 (let ((dicts (srecode-dictionary-lookup-name 773 (let ((dicts (srecode-dictionary-lookup-name
753 dictionary (oref sti :object-name)))) 774 dictionary (oref sti :object-name))))
775 (when (not (listp dicts))
776 (error "Cannot insert section %S from non-section variable."
777 (oref sti :object-name)))
754 ;; If there is no section dictionary, then don't output anything 778 ;; If there is no section dictionary, then don't output anything
755 ;; from this section. 779 ;; from this section.
756 (while dicts 780 (while dicts
781 (when (not (srecode-dictionary-p (car dicts)))
782 (error "Cannot insert section %S from non-section variable."
783 (oref sti :object-name)))
757 (srecode-insert-subtemplate sti (car dicts) slot) 784 (srecode-insert-subtemplate sti (car dicts) slot)
758 (setq dicts (cdr dicts))))) 785 (setq dicts (cdr dicts)))))
759 786
@@ -853,39 +880,44 @@ this template instance."
853 ;; If there was no template name, throw an error 880 ;; If there was no template name, throw an error
854 (if (not templatenamepart) 881 (if (not templatenamepart)
855 (error "Include macro %s needs a template name" (oref sti :object-name))) 882 (error "Include macro %s needs a template name" (oref sti :object-name)))
856 ;; Find the template by name, and save it. 883
857 (if (or (not (slot-boundp sti 'includedtemplate)) 884 ;; NOTE: We used to cache the template and not look it up a second time,
858 (not (oref sti includedtemplate))) 885 ;; but changes in the template tables can change which template is
859 (let ((tmpl (srecode-template-get-table (srecode-table) 886 ;; eventually discovered, so now we always lookup that template.
860 templatenamepart)) 887
861 (active (oref srecode-template active)) 888 ;; Calculate and store the discovered template
862 ctxt) 889 (let ((tmpl (srecode-template-get-table (srecode-table)
890 templatenamepart))
891 (active (oref srecode-template active))
892 ctxt)
893 (when (not tmpl)
894 ;; If it isn't just available, scan back through
895 ;; the active template stack, searching for a matching
896 ;; context.
897 (while (and (not tmpl) active)
898 (setq ctxt (oref (car active) context))
899 (setq tmpl (srecode-template-get-table (srecode-table)
900 templatenamepart
901 ctxt))
863 (when (not tmpl) 902 (when (not tmpl)
864 ;; If it isn't just available, scan back through 903 (when (slot-boundp (car active) 'table)
865 ;; the active template stack, searching for a matching 904 (let ((app (oref (oref (car active) table) application)))
866 ;; context. 905 (when app
867 (while (and (not tmpl) active) 906 (setq tmpl (srecode-template-get-table
868 (setq ctxt (oref (car active) context)) 907 (srecode-table)
869 (setq tmpl (srecode-template-get-table (srecode-table) 908 templatenamepart
870 templatenamepart 909 ctxt app)))
871 ctxt)) 910 )))
872 (when (not tmpl) 911 (setq active (cdr active)))
873 (when (slot-boundp (car active) 'table) 912 (when (not tmpl)
874 (let ((app (oref (oref (car active) table) application))) 913 ;; If it wasn't in this context, look to see if it
875 (when app 914 ;; defines it's own context
876 (setq tmpl (srecode-template-get-table 915 (setq tmpl (srecode-template-get-table (srecode-table)
877 (srecode-table) 916 templatenamepart)))
878 templatenamepart 917 )
879 ctxt app))) 918
880 ))) 919 ;; Store the found template into this object for later use.
881 (setq active (cdr active))) 920 (oset sti :includedtemplate tmpl))
882 (when (not tmpl)
883 ;; If it wasn't in this context, look to see if it
884 ;; defines its own context
885 (setq tmpl (srecode-template-get-table (srecode-table)
886 templatenamepart)))
887 )
888 (oset sti :includedtemplate tmpl)))
889 921
890 (if (not (oref sti includedtemplate)) 922 (if (not (oref sti includedtemplate))
891 ;; @todo - Call into a debugger to help find the template in question. 923 ;; @todo - Call into a debugger to help find the template in question.
@@ -955,23 +987,31 @@ insert the section it wraps into the location in the included
955template where a ^ inserter occurs." 987template where a ^ inserter occurs."
956 ;; Step 1: Look up the included inserter 988 ;; Step 1: Look up the included inserter
957 (srecode-insert-include-lookup sti dictionary) 989 (srecode-insert-include-lookup sti dictionary)
958 ;; Step 2: Temporarilly override the point inserter. 990 ;; Step 2: Temporarily override the point inserter.
959 (let* ((vaguely-unique-name sti) 991 ;; We bind `srecode-template-inserter-point-override' to a cons cell
960 (srecode-template-inserter-point-override 992 ;; (DEPTH . FUNCTION) that has the maximum template nesting depth,
961 (lambda (dict2) 993 ;; for which the override is valid, in DEPTH and a lambda function
962 (if (srecode-dictionary-lookup-name 994 ;; which implements the wrap insertion behavior in FUNCTION. The
963 dict2 (oref vaguely-unique-name :object-name)) 995 ;; maximum valid nesting depth is just the current depth + 1.
964 ;; Insert our sectional part with looping. 996 (let ((srecode-template-inserter-point-override
965 (srecode-insert-method-helper 997 (lexical-let ((inserter1 sti))
966 vaguely-unique-name dict2 'template) 998 (cons
967 ;; Insert our sectional part just once. 999 ;; DEPTH
968 (srecode-insert-subtemplate vaguely-unique-name 1000 (+ (length (oref srecode-template active)) 1)
969 dict2 'template)) 1001 ;; FUNCTION
970 ))) 1002 (lambda (dict)
1003 (let ((srecode-template-inserter-point-override nil))
1004 (if (srecode-dictionary-lookup-name
1005 dict (oref inserter1 :object-name))
1006 ;; Insert our sectional part with looping.
1007 (srecode-insert-method-helper
1008 inserter1 dict 'template)
1009 ;; Insert our sectional part just once.
1010 (srecode-insert-subtemplate
1011 inserter1 dict 'template))))))))
971 ;; Do a regular insertion for an include, but with our override in 1012 ;; Do a regular insertion for an include, but with our override in
972 ;; place. 1013 ;; place.
973 (call-next-method) 1014 (call-next-method)))
974 ))
975 1015
976(provide 'srecode/insert) 1016(provide 'srecode/insert)
977 1017