Function: srecode-compile-templates
srecode-compile-templates is an autoloaded, interactive and
byte-compiled function defined in compile.el.gz.
Signature
(srecode-compile-templates)
Documentation
Compile a semantic recode template file into a mode-local variable.
Key Bindings
Source Code
;; Defined in /usr/src/emacs/lisp/cedet/srecode/compile.el.gz
;;;###autoload
(defun srecode-compile-templates ()
"Compile a semantic recode template file into a mode-local variable."
(interactive)
(unless (semantic-active-p)
(error "You have to activate semantic-mode to compile SRecode templates"))
(require 'srecode/insert)
(when (called-interactively-p 'interactive)
(message "Compiling template %s..."
(file-name-nondirectory (buffer-file-name))))
(let ((tags (semantic-fetch-tags))
(tag nil)
(class nil)
(table nil)
(STATE (srecode-compile-state))
(mode nil)
(application nil)
(framework nil)
(priority nil)
(project nil)
(vars nil)
)
;;
;; COMPILE
;;
(while tags
(setq tag (car tags)
class (semantic-tag-class tag))
;; What type of item is it?
(cond
;; CONTEXT tags specify the context all future tags
;; belong to.
((eq class 'context)
(oset STATE context (semantic-tag-name tag))
)
;; PROMPT tags specify prompts for dictionary ? inserters
;; which appear in the following templates
((eq class 'prompt)
(srecode-compile-add-prompt STATE tag)
)
;; VARIABLE tags can specify operational control
((eq class 'variable)
(let* ((name (semantic-tag-name tag))
(value (semantic-tag-variable-default tag))
(firstvalue (car value)))
;; If it is a single string, and one value, then
;; look to see if it is one of our special variables.
(if (and (= (length value) 1) (stringp firstvalue))
(cond ((string= name "mode")
(setq mode (intern firstvalue)))
((string= name "escape_start")
(oset STATE escape_start firstvalue)
)
((string= name "escape_end")
(oset STATE escape_end firstvalue)
)
((string= name "application")
(setq application (read firstvalue)))
((string= name "framework")
(setq framework (read firstvalue)))
((string= name "priority")
(setq priority (read firstvalue)))
((string= name "project")
(setq project firstvalue))
(t
;; Assign this into some table of variables.
(setq vars (cons (cons name firstvalue) vars))
))
;; If it isn't a single string, then the value of the
;; variable belongs to a compound dictionary value.
;;
;; Create a compound dictionary value from "value".
(require 'srecode/dictionary)
(let ((cv (srecode-dictionary-compound-variable
:value value)))
(setq vars (cons (cons name cv) vars)))
))
)
;; FUNCTION tags are really templates.
((eq class 'function)
(setq table (cons (srecode-compile-one-template-tag tag STATE)
table))
)
;; Ooops
(t (error "Unknown TAG class %s" class))
)
;; Continue
(setq tags (cdr tags)))
;; MSG - Before install since nreverse whacks our list.
(when (called-interactively-p 'interactive)
(message "%d templates compiled for %s"
(length table) mode))
;;
;; APPLY TO MODE
;;
(if (not mode)
(error "You must specify a MODE for your templates"))
;;
;; Calculate priority
;;
(if (not priority)
(let ((d (expand-file-name (file-name-directory (buffer-file-name))))
(sd (expand-file-name (file-name-directory (locate-library "srecode"))))
(defaultdelta (if (eq mode 'default) 0 10)))
;; @TODO : WHEN INTEGRATING INTO EMACS
;; The location of Emacs default templates needs to be specified
;; here to also have a lower priority.
(if (string-match (concat "^" sd) d)
(setq priority (+ 30 defaultdelta))
;; If the user created template is for a project, then
;; don't add as much as if it is unique to just some user.
(if (stringp project)
(setq priority (+ 50 defaultdelta))
(setq priority (+ 80 defaultdelta))))
(when (called-interactively-p 'interactive)
(message "Templates %s has estimated priority of %d"
(file-name-nondirectory (buffer-file-name))
priority)))
(when (called-interactively-p 'interactive)
(message "Compiling templates %s priority %d... done!"
(file-name-nondirectory (buffer-file-name))
priority)))
;; Save it up!
(srecode-compile-template-table table mode priority application framework project vars)
)
)