Function: srecode-semantic-insert-tag
srecode-semantic-insert-tag is a byte-compiled function defined in
semantic.el.gz.
Signature
(srecode-semantic-insert-tag TAG &optional STYLE-OPTION POINT-INSERT-FCN &rest DICT-ENTRIES)
Documentation
Insert TAG into a buffer using srecode templates at point.
Optional STYLE-OPTION is a list of minor configuration of styles,
such as the symbol prototype for prototype functions, or
system for system includes, and doxygen, for a doxygen style
comment.
Optional third argument POINT-INSERT-FCN is a hook that is run after TAG is inserted that allows an opportunity to fill in the body of some thing. This hook function is called with one argument, the TAG being inserted.
The rest of the arguments are DICT-ENTRIES. DICT-ENTRIES is of the form ( NAME1 VALUE1 NAME2 VALUE2 ... NAMEn VALUEn).
The exact template used is based on the current context.
The template used is found within the toplevel context as calculated
by srecode-calculate-context, such as declaration, classdecl,
or code.
For various conditions, this function looks for a template with
the name CLASS-tag, where CLASS is the tag class. If it cannot
find that, it will look for that template in the declaration
context (if the current context was not declaration).
If PROTOTYPE is specified, it will first look for templates with the name CLASS-tag-prototype, or CLASS-prototype as above.
See srecode-semantic-apply-tag-to-dict for details on what is in
the dictionary when the templates are called.
This function returns to location in the buffer where the
inserted tag ENDS, and will leave point inside the inserted
text based on any occurrence of a point-inserter. Templates such
as function will leave point where code might be inserted.
Source Code
;; Defined in /usr/src/emacs/lisp/cedet/srecode/semantic.el.gz
(defun srecode-semantic-insert-tag (tag &optional style-option
point-insert-fcn
&rest dict-entries)
"Insert TAG into a buffer using srecode templates at point.
Optional STYLE-OPTION is a list of minor configuration of styles,
such as the symbol `prototype' for prototype functions, or
`system' for system includes, and `doxygen', for a doxygen style
comment.
Optional third argument POINT-INSERT-FCN is a hook that is run after
TAG is inserted that allows an opportunity to fill in the body of
some thing. This hook function is called with one argument, the TAG
being inserted.
The rest of the arguments are DICT-ENTRIES. DICT-ENTRIES
is of the form ( NAME1 VALUE1 NAME2 VALUE2 ... NAMEn VALUEn).
The exact template used is based on the current context.
The template used is found within the toplevel context as calculated
by `srecode-calculate-context', such as `declaration', `classdecl',
or `code'.
For various conditions, this function looks for a template with
the name CLASS-tag, where CLASS is the tag class. If it cannot
find that, it will look for that template in the `declaration'
context (if the current context was not `declaration').
If PROTOTYPE is specified, it will first look for templates with
the name CLASS-tag-prototype, or CLASS-prototype as above.
See `srecode-semantic-apply-tag-to-dict' for details on what is in
the dictionary when the templates are called.
This function returns to location in the buffer where the
inserted tag ENDS, and will leave point inside the inserted
text based on any occurrence of a point-inserter. Templates such
as `function' will leave point where code might be inserted."
(srecode-load-tables-for-mode major-mode)
(let* ((ctxt (srecode-calculate-context))
(top (car ctxt))
(tname (symbol-name (semantic-tag-class tag)))
(dict (srecode-create-dictionary))
(temp nil)
(errtype tname)
(prototype (memq 'prototype style-option))
)
;; Try some special cases.
(cond ((and (semantic-tag-of-class-p tag 'function)
(semantic-tag-get-attribute tag :constructor-flag))
(setq temp (srecode-semantic-find-template
"constructor" prototype ctxt))
)
((and (semantic-tag-of-class-p tag 'function)
(semantic-tag-get-attribute tag :destructor-flag))
(setq temp (srecode-semantic-find-template
"destructor" prototype ctxt))
)
((and (semantic-tag-of-class-p tag 'function)
(semantic-tag-function-parent tag))
(setq temp (srecode-semantic-find-template
"method" prototype ctxt))
)
((and (semantic-tag-of-class-p tag 'variable)
(semantic-tag-get-attribute tag :constant-flag))
(setq temp (srecode-semantic-find-template
"variable-const" prototype ctxt))
)
((and (semantic-tag-of-class-p tag 'include)
(semantic-tag-get-attribute tag :system-flag))
(setq temp (srecode-semantic-find-template
"system-include" prototype ctxt))
)
)
(when (not temp)
;; Try the basics
(setq temp (srecode-semantic-find-template
tname prototype ctxt)))
;; Try some backup template names.
(when (not temp)
(cond
;; Types might split things up based on the type's type.
((and (eq (semantic-tag-class tag) 'type)
(semantic-tag-type tag))
(setq temp (srecode-semantic-find-template
(semantic-tag-type tag) prototype ctxt))
(setq errtype (concat errtype " or " (semantic-tag-type tag)))
)
;; A function might be an externally declared method.
((and (eq (semantic-tag-class tag) 'function)
(semantic-tag-function-parent tag))
(setq temp (srecode-semantic-find-template
"method" prototype ctxt)))
(t
nil)
))
;; Can't find one? Drat!
(when (not temp)
(error "Cannot find template %s in %s for inserting tag %S"
errtype top (semantic-format-tag-summarize tag)))
;; Resolve arguments
(let ((srecode-semantic-selected-tag tag))
(srecode-resolve-arguments temp dict))
;; Resolve TAG into the dictionary. We may have a :tag arg
;; from the macro such that we don't need to do this.
(when (not (srecode-dictionary-lookup-name dict "TAG"))
(let ((tagobj (srecode-semantic-tag (semantic-tag-name tag) :prime tag))
)
(srecode-semantic-apply-tag-to-dict tagobj dict)))
;; Insert dict-entries into the dictionary LAST so that previous
;; items can be overridden.
(let ((entries dict-entries))
(while entries
(srecode-dictionary-set-value dict
(car entries)
(car (cdr entries)))
(setq entries (cdr (cdr entries)))))
;; Insert the template.
(let ((endpt (srecode-insert-fcn temp dict nil t)))
(if (functionp point-insert-fcn)
(funcall point-insert-fcn tag)
(dolist (f point-insert-fcn) (funcall f tag)))
;;(sit-for 1)
(cond
((semantic-tag-of-class-p tag 'type)
;; Insert all the members at the current insertion point.
(dolist (m (semantic-tag-type-members tag))
(when (stringp m)
(setq m (semantic-tag-new-variable m nil nil)))
;; We do prototypes w/in the class decl?
(let ((me (srecode-semantic-insert-tag m '(prototype))))
(goto-char me))
))
)
endpt)
))