aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric M. Ludlam2012-12-12 09:15:25 -0800
committerGlenn Morris2012-12-12 09:15:25 -0800
commitac1d9ddee6098e829f87523a6328e81e98dfba70 (patch)
treeee3835cc698235ad0ad65bea725dbd0d88f1452e
parent63aa098259339e924d8a7d40c59a34e579132af6 (diff)
downloademacs-ac1d9ddee6098e829f87523a6328e81e98dfba70.tar.gz
emacs-ac1d9ddee6098e829f87523a6328e81e98dfba70.zip
Import srecode manual from CEDET trunk
Ref http://lists.gnu.org/archive/html/emacs-devel/2012-11/msg00419.html and preceding discussion Imported from bzr://cedet.bzr.sourceforge.net/bzrroot/cedet/code/trunk doc/texi/srecode.texi bzr log shows (very) tiny changes from authors with assignments: Alex Ott <ottalex@users.sourceforge.net> David Engster <dengste@eml.cc> Vincent Belaïche <vincentb1@users.sourceforge.net> and from: emacsman@users.sourceforge.net scymtym@users.sourceforge.net Fixes: debbugs:9966
-rw-r--r--doc/misc/ChangeLog4
-rw-r--r--doc/misc/srecode.texi1768
2 files changed, 1772 insertions, 0 deletions
diff --git a/doc/misc/ChangeLog b/doc/misc/ChangeLog
index b96345ba135..8bc178e005b 100644
--- a/doc/misc/ChangeLog
+++ b/doc/misc/ChangeLog
@@ -1,3 +1,7 @@
12012-12-12 Eric Ludlam <zappo@gnu.org>
2
3 * srecode.texi: New file, imported from CEDET trunk.
4
12012-12-12 Bastien Guerry <bzg@gnu.org> 52012-12-12 Bastien Guerry <bzg@gnu.org>
2 6
3 * org.texi (Summary, Code block specific header arguments) 7 * org.texi (Summary, Code block specific header arguments)
diff --git a/doc/misc/srecode.texi b/doc/misc/srecode.texi
new file mode 100644
index 00000000000..e2f0ec79c2e
--- /dev/null
+++ b/doc/misc/srecode.texi
@@ -0,0 +1,1768 @@
1\input texinfo @c -*-texinfo-*-
2@c
3@c $Id: srecode.texi,v 1.24 2010-05-30 20:22:40 scymtym Exp $
4@c
5@c %**start of header
6@setfilename srecode.info
7@set TITLE SRecoder Manual
8@set AUTHOR Eric M. Ludlam
9@settitle @value{TITLE}
10@c %**end of header
11
12@ifinfo
13@dircategory Emacs
14@format
15START-INFO-DIR-ENTRY
16* srecode: (srecode). Template code generator
17END-INFO-DIR-ENTRY
18@end format
19@end ifinfo
20
21@titlepage
22@sp 10
23@center @titlefont{srecode}
24@vskip 0pt plus 1 fill
25Copyright @copyright{} 2007, 2008, 2009, 2010, 2011 Eric M. Ludlam
26@end titlepage
27
28@macro semantic{}
29@i{semantic}
30@end macro
31
32@macro EIEIO{}
33@i{EIEIO}
34@end macro
35
36@macro srecode{}
37@i{SRecode}
38@end macro
39
40@node Top
41@top @value{TITLE}
42
43@srecode{} is the @i{Semantic Recoder}. Where @semantic{} will parse
44source files into lists of tags, the @i{Semantic Recoder} will aid in
45converting @semantic{} tags and various other information back into
46various types of code.
47
48While the @srecode{} tool provides a template language, templates for
49several languages, and even a sequence of heuristics that aid the user
50in choosing a template to insert, this is not the main goal of
51@srecode{}.
52
53The goal of @srecode{} is to provide an application framework where
54someone can write a complex code generator, and the underlying
55template commonality allows it to work in multiple languages with
56ease.
57
58@menu
59* Quick Start:: Basic Setup for template insertion.
60* User Templates:: Custom User Templates
61* Parts of SRecode:: Parts of the system
62* SRecode Minor Mode:: A minor mode for using templates
63* Template Writing:: How to write a template
64* Dictionaries:: How dictionaries work
65* Developing Template Functions:: How to write your own template insert functions.
66* Template Naming Conventions:: Creating a set of core templates
67* Inserting Tag Lists:: Inserting Semantic tags via templates
68* Application Writing:: Writing an @srecode{}r application
69* Index::
70@end menu
71
72
73@node Quick Start
74@chapter Quick Start
75
76When you install CEDET and enable @srecode{}, an @code{SRecoder} menu
77item should appear.
78
79To toggle @srecode{} minor mode on and off use:
80
81@example
82M-x srecode-minor-mode RET
83@end example
84or
85@example
86M-x global-srecode-minor-mode RET
87@end example
88
89or add
90
91@example
92(srecode-minor-mode 1)
93@end example
94
95into a language hook function to force it on (which is the default) or
96pass in @code{-1} to force it off.
97
98See @ref{SRecode Minor Mode} for more on using the minor mode.
99
100Use the menu to insert templates into the current file.
101
102You can add your own templates in @file{~/.srecode}, or update the
103template map path:
104
105@deffn Option srecode-map-load-path
106@anchor{srecode-map-load-path}
107Global load path for SRecode template files.
108@end deffn
109
110
111Once installed, you can start inserting templates using the menu, or
112the command:
113
114@deffn Command srecode-insert template-name &rest dict-entries
115@anchor{srecode-insert}
116Insert the template @var{template-name} into the current buffer at point.
117@var{dict-entries} are additional dictionary values to add.
118@end deffn
119
120SRecode Insert will prompt for a template name. Template names are
121specific to each major mode. A typical name is of the form:
122@code{CONTEXT:NAME} where a @var{CONTEXT} might be something like
123@code{file} or @code{declaration}. The same @var{NAME} can occur in
124multiple contexts.
125
126@node User Templates
127@chapter User Templates
128
129@srecode{} builds and maintains a map of all template files. The root
130template files resides in the @srecode{} distribution. User written
131templates files are saved in @file{~/.srecode}, along with the
132@srecode{} map file.
133
134@defvar srecode-map-save-file
135@anchor{srecode-map-save-file}
136The save location for SRecode's map file.
137@end defvar
138
139Template files end with a @file{.srt} extension. Details on how to
140write templates are in @ref{Template Writing}.
141
142Each template file you write is dedicated to a single major mode. In
143it, you can write templates within the same context and with the same
144name as core templates. You can force your templates to override the
145core templates for a particular major mode by setting the
146priority. See @ref{Special Variables}.
147
148To get going quickly, open a new @file{.srt} file. It will start in
149the @srecode{} template writing mode. Use the @srecode{} minor mode
150menu to insert the @code{empty} file template.
151
152When using templates in other modes (such as C++ or Emacs Lisp
153templates), use the ``Edit Template'' menu to find a template you
154would like to update. Copy it into your user template file, and
155change it.
156
157If you were to update @code{declaration:function} in your user
158template file, then you would get this new template instead of the one
159that comes with @srecode{}. Higher level applications should always
160use @code{declaration:function} when generating their own code, so
161higher level templates will then adopt your changes to
162@code{declaration:function} into themselves.
163
164You can also override variables. Core variables are stored in the
165@srecode{} root template file @file{default.srt}, and that contains
166the copyright usually used, and some basic file setup formats.
167Override variables like this by specifying a @code{mode} of
168@code{default} like this:
169
170@example
171set mode "default"
172@end example
173
174@node Parts of SRecode
175@chapter Parts of SRecode
176
177The @srecode{} system is made up of several layers which work together
178to generate code.
179
180@section Template Layer
181The template layer provides a way to write, and compile templates. The
182template layer is the scheme used to insert text into an Emacs buffer.
183
184The @srecode{} template layer is more advanced than other modes like the
185Emacs packages @code{skeleton} or @code{tempo} in that it allows
186multiple layers of templates to be created with the same names. This
187means that @srecode{} can provide a wide range of templates, and users
188can override only the small sections they want, instead of either
189accepting someone else's template, or writing large new templates of
190their own.
191
192Templates are written in @file{.srt} files. You can learn how to
193author new @file{.srt} files @ref{Template Writing}.
194
195While the template system was designed for @srecode{} based
196applications it can also be used independently for simple template
197insertion during typical coding.
198
199@section Template Manager
200Once templates have been written, a scheme for loading and selecting
201templates is needed. The template manager has a loader for finding
202template files, and determining which templates are relevant to the
203current buffer. Template files are sorted by priority, with user
204templates being found first, and system level default templates last.
205Templates are also sorted by application. Each application has its
206own templates, and are kept seperate from the generic templates.
207
208@section Dictionary
209Dictionaries contain values associated with variable. Variables are
210used in macros in a template. Variables are what allows a generic
211template such as a function to be made specific, such as a function
212named foo. The value of a variable can be one of three things; a
213string, a list of more dictionaries, or a special
214@code{srecode-dictionary-compound-value} object subclass. See
215@ref{Variables} for more.
216
217@section Template Insertion
218The template insertion layer involves extensions to the basic template
219layer. A wide range of custom variables are available for mixing derived
220data as macros into the plain text of a template.
221
222In addition, templates can be declared with arguments. These
223arguments represent predetermined sets of dictionary values, such as
224features of the current file name, user name, time, etc.
225
226Some arguments are major-mode specific, such as the @code{:el} or
227@code{:cpp} arguments.
228@refill
229
230@section Template Insertion Context
231A context can be provided for templates in a file. This helps
232auto-selection of templates by name, or allows templates in different
233contexts to have the same name. Some standard contexts are
234@code{file}, @code{declaration}, and @code{classdecl}.
235
236A context can be automatically derived as well based on the parsing
237state from @i{Semantic}. @inforef{Top, Semantic Manual, semantic}.
238@refill
239
240@section Applications
241Commands that do a particular user task which involves also writing
242Emacs Lisp code. Applications are at the top layer. These
243applications have their own template files and logic needed to fill in
244dictionaries or position a cursor. SRecode comes with an example
245@code{srecode-document} application for creating comments for Semantic
246tags. The CEDET application @i{EDE} has a project type that is an
247@srecode{} application.
248
249@section Field Editing
250If the variable @code{srecode-insert-ask-variable-method} is set to
251'field, then variables that would normally ask a question, will
252instead create ``fields'' in the buffer. A field-editing layer
253provides simple interaction through the fields. Typing in a field
254will cause all variable locations that are the same to edit at the
255same time. Pressing TAB on a field will move you to the next field.
256
257@node SRecode Minor Mode
258@chapter SRecode Minor Mode
259
260The Semantic Recode minor mode enables a keymap and menu that provides
261simple access to different templates or template applications.
262
263The key prefix is @key{C-c /}.
264
265If the variable @code{srecode-takeover-INS-key} is set, then the key
266@key{<insert>} can also be used.
267
268The most important key is bound to @code{srecode-insert} which is
269@key{C-c / /}, or @key{insert insert}. @ref{Quick Start}.
270
271Major keybindings are:
272
273@table @key
274@item C-c / /
275Insert a template whose name is typed into the minibuffer.
276@item C-c / <lower case letter>
277Reserved for direct binding of simple templates to keys using a
278keybinding command in the template file.
279@item C-c / <upper case letter>
280Reserved for template applications (Such as comment or get/set inserter.)
281@item C-c / E
282Edit the code of a template.
283@item C-c / .
284Insert template again. This will cause the previously inserted
285template to be inserted again.
286@end table
287
288@section Field Editing
289
290By default, when inserting a template, if the user needs to enter text
291to fill in a part of the template, then the minibuffer is used to
292query for that information. SRecode also supports a field-edting mode
293that can be used instead. To enable it set:
294
295@defun srecode-insert-ask-variable-method
296@anchor{srecode-insert-ask-variable-method}
297Determine how to ask for a dictionary value when inserting a template.
298Only the @var{ASK} style inserter will query the user for a value.
299Dictionary value references that ask begin with the ? character.
300Possible values are:
301@table @code
302@item ask
303Prompt in the minibuffer as the value is inserted.
304@item field
305Use the dictionary macro name as the inserted value,
306and place a field there. Matched fields change together.
307@end table
308
309@b{NOTE}: The field feature does not yet work with XEmacs.
310@end defun
311
312Field editing mode is supported in newer versions of Emacs. You
313will not be prompted to fill in values while the template is
314inserted. Instead, short regions will be highlighted, and the cursor
315placed in a field. Typing in the field will then fill in the value.
316Several fields might be linked together. In that case, typing in one
317area will modify the other linked areas. Pressing TAB will move
318between editable fields in the template.
319
320Once the cursor moves out of the are inserted by the template, all the
321fields are cancelled.
322
323@b{NOTE}: Some conveniences in templates, such as completion, or
324character restrictins are lost when using field editing mode.
325
326@node Template Writing
327@chapter Template Writing
328@anchor{@code{SRecode-template-mode}}
329
330@code{srecode-template-mode} is the major mode used for designing new
331templates. @srecode{} files (Extension @file{.srt}) are made up of
332variable settings and template declarations.
333
334Here is an overview of the terminology you will need for the next few
335sections:
336
337@table @asis
338@item template file
339A file with a @file{.srt} extension which contains settings,
340variables, and templates.
341@item template
342One named entity which represents a block of text that will be
343inserted. The text is compiled into a sequence of insertable
344entities. The entities are string constants, and macros.
345@item macro
346A macro is a text sequence within template text that is replaced with
347some other value.
348@item dictionary
349A table of variable names and values.
350@item subdictionary
351A dictionary that is subordinate under another dictionary as a value
352to some variable.
353@item variable
354A variable is an entry in a dictionary which has a value.
355@end table
356
357@menu
358* Variables:: Creating special and regular variables.
359* Templates:: Creating templates
360* Contexts:: Templates are grouped by context
361* Prompts:: Setting prompts for interactive insert macros
362@end menu
363
364@node Variables
365@section Variables
366
367Variables can be set up and used in templates. Many variables you may
368use are set up via template arguments, but some may be preferences a
369user can set up that are used in system templates.
370
371When expanding a template, variables are stored in a @dfn{dictionary}.
372Dictionary entries are variables. Variables defined in templates can
373have string like values.
374
375A variable can be set like this:
376@example
377set VARNAME "some value"
378@end example
379
380Note that a VARIABLE is a name in a dictionary that can be used in a
381MACRO in a template. The macro referernces some variable by name.
382
383@menu
384* String Values:: Basic Variable values
385* Multi-string Values:: Complex variable values
386* Section Show:: Enabling the display of a named section.
387* Special Variables:: Variables with special names
388* Automatic Loop Variables:: Variables automatically set in section loops.
389* Compound Variable Values:: Compound Variable Values
390@end menu
391
392@node String Values
393@subsection String Values
394
395Variables can be set to strings. Strings may contain newlines or any
396other characters. Strings are interpreted by the Emacs Lisp reader so
397@code{\n}, @code{\t}, and @code{\"} work.
398
399When a string is inserted as part of a template, nothing within the
400string is interperted, such as template escape characters.
401
402@node Multi-string Values
403@subsection Multi-string Values
404
405A variable can be set to multiple strings. A compound value is
406usually used when you want to use dictionary entries as part of a
407variable later on.
408
409Multi-string variable values are set like string values except there
410are more than one. For example
411
412@example
413set NAME "this" "-mode"
414@end example
415
416These two strings will be concatenated together.
417
418A more useful thing is to include dictionary variables and concatenate
419those into the string. Use the ``macro'' keyword to include the name
420of a variable. This is like macros in a template. For example:
421
422@example
423set NAME macro "MODE" "-mode"
424@end example
425
426will extract the value of the dictionary variable MODE and append
427``-mode'' to the end.
428
429@node Section Show
430@subsection Section Show
431
432To set a variable to show a template section, use the @code{show}
433command. Sections are blocks of a template wrapped in section macros.
434If there is a section macro using @var{NAME} it will be shown for each
435dictionary associated with the @var{NAME} macro.
436
437@example
438show NAME
439@end example
440
441This will enable that section.
442
443
444NOTE: May 11, 2008 - I haven't used this yet, so I don't know if it works.
445
446
447@node Special Variables
448@subsection Special Variables
449
450Some variables have special meaning that changes attributes when
451templates are compiled, including:
452
453@table @code
454@item escape-start
455This is the character sequence that escapes from raw text to template
456macro names. The ability to change the escape characters are key for
457enabling @srecode{} templates to work across many kinds of languages.
458@item escape-end
459This is the character sequence that escapes the end of a template
460macro name.
461
462Example:
463@example
464set escape_start "$"
465set escape_end "$"
466@end example
467@item mode
468This is the major mode, as a string with the full Emacs Lisp symbol in
469it. All templates in this file will be installed into the template
470table for this major mode.
471
472Multiple template files can use the same mode, and all those templates
473will be available in buffers of that mode.
474
475Example:
476@example
477set mode "emacs-lisp-mode"
478@end example
479
480@item priority
481The priority of a file is a number in a string constant that
482indicates where it lies in the template search order. System
483templates default to low priority numbers. User templates default to
484high priority numbers. You can specify the priority of your template
485to insert it anywhere in the template search list.
486
487If there are multiple templates with the same context and name, the
488template with the highest priority number will be used.
489
490If multiple files have the same priority, then then sort order is
491unpredictable. If no template names match, then it doesn't matter.
492
493Example:
494@example
495set priority "35"
496@end example
497
498@item application
499If a template file contains templates only needed for a particular
500application, then specify an application. Template files for an
501application are stored in the template repository, but are not used in
502the generic template insertion case.
503
504The application with a particular name will access these templates
505from Lisp code.
506
507Example:
508@example
509set application "document"
510@end example
511
512@item project
513If a template file contains templates, or template overrides specific
514to a set of files under a particular directory, then that template
515file can specify a ``project'' that it belongs to.
516
517Set the ``project'' special variable to a directory name. Only files
518under that directory will be able to access the templates in that
519file.
520
521Any template file that has a project specified will get have a
522priority that is set between SRecode base templates, and user defined
523templates.
524
525Templates can be compiled via a project system, such as EDE. EDE
526loaded templates will get a @var{project} set automatically.
527
528Example:
529@example
530set project "/tmp/testproject"
531@end example
532
533@end table
534
535If you need to insert the characters that belong to the variables
536@code{escape_start} or @code{escape_end}, then place those into
537a variable. For example
538
539@example
540set escape_start "$"
541set escape_end "$"
542set DOLLAR "$"
543@end example
544
545@node Automatic Loop Variables
546@subsection Automatic Loop Variables
547
548When section macros are used, that section is repeated for each
549subdictionary bound to the loop variable.
550
551Each dictionary added will automatically get values for positional
552macros which will enable different @var{sections}. The automatic
553section variables are.
554
555@itemize @bullet
556@item @var{first} - The first entry in the table.
557@item @var{notfirst} - Not the first entry in the table.
558@item @var{last} - The last entry in the table
559@item @var{notlast} - Not the last entry in the table.
560@end itemize
561
562@node Compound Variable Values
563@subsection Compound Variable Values
564
565A variable can also have a compound value. This means the value of
566the variable is an @EIEIO{} object, which is a subclass of
567@code{srecode-dictionary-compound-value}.
568
569New compound variables can only be setup from Lisp code. See
570@ref{Compound Dictionary Values} for details on setting up compound
571variables from Lisp.
572
573@node Templates
574@section Templates
575
576A template represents a text pattern that can be inserted into
577a buffer.
578
579A basic template is declaired like this:
580
581@example
582template TEMPLATENAME :arg1 :arg2
583"Optional documentation string"
584----
585The text to your template goes here.
586----
587bind "a"
588@end example
589
590Templates are stored in a template table by name, and are inserted by
591the @var{templatename} provided.
592
593The documentation string is optional. This documentation string will
594be used to aid users in selecting which template they want to use.
595
596The code that makes up the raw template occurs between the lines that
597contain the text "-----".
598
599@menu
600* Template Section Dictionaries:: Template Scoped Macro values
601* Template Macros:: Macros occuring in template patterns
602@end menu
603
604@node Template Section Dictionaries
605@subsection Template Section Dictionaries
606
607To add variable values to section dictionaries used within a specific
608template, you can add them to the beginning of the template
609declaration like this:
610
611@example
612template TEMPLATENAME :arg1 :arg2
613"Optional documentation string"
614sectiondictionary "A"
615set NAME "foo"
616----
617A beginning line @{@{NAME@}@}
618@{@{#A@}@}Optional string @{@{NAME@}@} here@{@{/A@}@}
619An end line
620----
621@end example
622
623In this example, the @var{NAME} variable gets the value ``foo'', but
624only while it is inside section macro A. The outer scoped NAME will
625be empty.
626
627This is particularly useful while using an include macro to pull in a
628second template. In this way, you can pass values known from one
629template to a subordinate template where some value is not known.
630
631From the Emacs Lisp default template file, a syntax table is just a
632variable with a specialized value.
633
634If a variable is declared like this (where $ is the escape character):
635
636@example
637template variable :el
638"Insert a variable.
639DOC is optional."
640----
641(defvar $?NAME$ $^$
642 "$DOC$")
643----
644@end example
645
646then you can see that there is a NAME and DOC that is needed.
647The @code{^} point inserter is also a handy key here.
648
649The syntax table wants a variable, but knows the values of some of
650these variables, and can recast the problem like this by using
651template specific @code{sectiondictionary} macro declarations.
652
653@example
654template syntax-table
655"Create a syntax table."
656sectiondictionary "A"
657set NAME macro "?MODESYM" "-mode-syntax-table"
658set DOC "Syntax table used in " macro "?MODESYM" " buffers."
659----
660$<A:variable$
661 (let ((table (make-syntax-table (standard-syntax-table))))
662 (modify-syntax-entry ?\; ". 12" table) ;; SEMI, Comment start ;;
663 ;; ...
664 table)
665$/A$
666----
667@end example
668
669In this way, @var{NAME} can be set as a user posed question for
670@var{MODESYM} with ``-mode-syntax-table'' appended. A simplified doc
671string will also be inserted.
672
673Lastly, the @var{A} section contains more macro text which is inserted
674at the @code{^} point marker.
675
676By creating useful base templates for things like function or variable
677declarations, and recycling them in higher-order templates, an end
678user can override the basic declarator, and the higher order templates
679will then obey the new format, or perhaps even work in more than one
680major mode.
681
682@node Template Macros
683@subsection Template Macros
684
685Template macros occur in the template text. The default escape
686characters are ``@{@{`` and ``@}@}'', though they can be changed
687in the top-level variables. See @ref{Variables}.
688
689Thus, if you have the template code that looks like this:
690
691@example
692;; Author: @{@{AUTHOR@}@}
693@end example
694
695Then the text between @{@{ and @}@} are a macro, and substituted by
696the value of the variable @var{AUTHOR}.
697
698Macros can be specialized to be more than just a text string. For
699example, the macro above could be augmented with an Emacs Lisp
700function.
701
702@example
703;; Author: @{@{AUTHOR:upcase@}@}
704@end example
705
706In this case, the Emacs Lisp function @code{upcase} will be called on
707the text value of the @var{AUTHOR} variable.
708
709Macros can also be specialized to have different behaviors by using a
710prefix, non-alpha character or symbol. For example:
711
712@example
713@{@{! This is a comment inside macro escape characters @}@}
714@end example
715
716shows that the ``!'' symbol is for comments.
717
718Alternately, a macro could query the user during insertion:
719
720@example
721(defun @{@{?NAME@}@} ()
722 @{@{^@}@}
723 ) ;; End of @{@{NAME@}@}
724@end example
725
726the ``?'' symbol indicates that if the symbol @var{NAME} isn't in the
727dictionary, then the user should be queried for the @var{NAME}
728variable. If @var{NAME} appears again in the template, the original
729value specified by the user will be inserted again.
730
731If the text from a dictionary value is to be placed in column format,
732you can use the ``|'' symbol to indicate you want column control. For
733example:
734
735@example
736 | this | that |@{@{#A@}@}
737 | @{@{|THIS:4@}@} | @{@{|THAT:4@}@} |@{@{/A@}@}
738@end example
739
740For each repeated section ``#A'' the dictionary values for @var{THIS}
741and @var{THAT} will be inserted and either trimmed to, or expanded to
7424 characters in width.
743
744Macros that are prefixed with the ``#'' symbol denote a section. A
745macro of the same name with a ``/'' prefix denotes the end of that
746section.
747
748@example
749@{@{#MOOSE@}@}
750Here is some text describing moose.
751@{@{/MOOSE@}@}
752@end example
753
754In this example if the section MOOSE was ``shown'' in the active
755dictionary, then the text between the # and / macros will also be
756inserted.
757
758All the text and macros within a section are either not shown at all
759(if that section is not 'visible') or the section is shown one time
760for each dictionary added to that symbol.
761@xref{Developing Template Functions}.
762@refill
763
764Macros prefixed with ``>'' will include another template. Include
765macros would look like this:
766
767@example
768@{@{>FOO:defun@}@}
769@end example
770
771where @code{FOO} is the dictionary variable for the sub-dictionary used for
772expanding the template @code{defun}. The @code{defun} template will
773be looked up in the template repository for the current mode, or in
774any inherited modes.
775
776Another way to include another template is with an include macro that
777will also wrap section text. The includewrap insertion method looks
778like this:
779
780@example
781@{@{<FOO:defun@}@}Handy Text goes here@{@{/FOO@}@}
782@end example
783
784In this case, @code{defun} is included just as above. If the
785@code{defun} template has a @{@{^@}@} macro in it, then the
786section text ``Handy Text goes here'' will be inserted at that point,
787and that location will not be saved as the cursor location.
788
789If there is no @{@{^@}@}, then the text will not be inserted.
790
791For both kinds of include macros, you may need to include a template
792from a different context. You can use @code{:} separate the context
793from the name, like this:
794
795@example
796@{@{>FOO:declaration:function@}@}
797@end example
798
799@node Contexts
800@section Context
801
802Each template belongs to a context. When promting for a template by
803name, such as with @kbd{C-c / /}, the name is prefixed by the current
804context. If there is no context, it defaults to @code{declaration}.
805
806You can change context like this:
807
808@example
809context NAME
810@end example
811
812where @var{name} is some symbol that represents any context.
813
814A context resides over all templates that come after it until the next
815context statement. Thus:
816
817@example
818context C1
819
820template foo
821"Foo template in C1"
822----
823----
824
825context C2
826
827temlate foo
828"Foo template in C2"
829----
830----
831@end example
832
833creates two @code{foo} templates. The first one is when in context
834C1. The second is available in context C2.
835
836This is useful if there are multiple ways to declare something like a
837function or variable that differ only by where it is in the syntax of
838the lanugage. The name @code{foo} is not ambiguous because each is in
839a different context.
840
841@node Prompts
842@section Prompt
843
844Some templates use promtping macro insertion. A macro that needs a
845prompt looks like this:
846
847@example
848@{@{?NAME@}@}
849@end example
850
851where ? comes after the first escape character.
852
853by default, it will use a prompt like this when it is encountered:
854
855@example
856Specify NAME:
857@end example
858
859For such macros, you can pre-define prompts for any dictionary entry.
860When that dictionary entry is first encountered, the user is prompted,
861and subsequent occurances of that dictionary entry use the same value.
862
863To get a different prompt, use a prompt command like this:
864
865@example
866prompt VARNAME "Nice Way to ask for VARNAME: "
867@end example
868
869Now, if you put this in a template:
870
871@example
872template variable
873----
874(defvar @{@{?VARNAME@}@} nil
875 "")
876----
877@end example
878
879when VARNAME is encountered, it will use the nice prompt.
880
881Prompts can be extended as well. For example:
882
883@example
884prompt VARNAME "VARNAME: " default "srecode" read y-or-n-p
885@end example
886
887In this case, the @code{default} keyword indicates that
888@code{"srecode"} is the default string to use, and @code{y-or-n-p} is
889the function to use to ask the question.
890
891For @code{y-or-n-p} if you type ``y'' it inserts the default string,
892otherwise it inserts empty.
893
894For any other symbol that occurs after the @code{read} token, it is
895expected to take the same argument list as @code{read-string}. As
896such, you can create your own prompts that do completing reads on
897deterministic values.
898
899To have the default be calculated later from a dictionary entry, you
900need to use the @code{defaultmacro} keyword instead.
901
902@example
903prompt VARNAME "Varname: " defaultmacro "PREFIX"
904@end example
905
906now, when it attempts to read in VARNAME, it will pre-populte the text
907editing section with whatever the value of PREFIX is.
908
909Some language arguments may supply possible prefixes for prompts.
910Look for these when creating your prompts.
911
912@node Dictionaries
913@chapter Dictionaries
914
915Dictionaries are a set of variables. The values associated with the
916variable names could be anything, but how it is handled is dependent
917on the type of macro being inserted.
918
919Most of this chapter is for writing Lisp programs that use @srecode{}.
920If you only want to write template files, then you only need to read
921the @ref{Template Argument Dictionary Entries} section.
922
923@menu
924* Create a Dictionary::
925* Setting Dictionary Values:: Basic dictionary values
926* Compound Dictionary Values:: Complex dictionary values
927* Argument Resolution:: Automatic template argument resolution
928* Creating new Arguments:: Create new arguments for use in templates
929* Querying a Dictionary:: Querying a dictionary for values.
930* Template Argument Dictionary Entries:: Catalog of arguments
931@end menu
932
933@node Create a Dictionary
934@section Create a Dictionary
935
936@defun srecode-create-dictionary &optional buffer
937@anchor{srecode-create-dictionary}
938Create a dictionary for @var{buffer}.
939If @var{buffer} is not specified, use the current buffer.
940The dictionary is initialized with no variables or enabled sections.
941Any variables defined with @code{set} in the template, however,
942becomes a name in the dictionary.
943@end defun
944
945@node Setting Dictionary Values
946@section Setting Dictionary Values
947
948When building an @srecode{} based application, you will need to setup
949your dictionary values yourself. There are several utility functions
950for this.
951
952In the simplest form, you can assocate a string with a variable.
953
954@defun srecode-dictionary-set-value dict name value
955@anchor{srecode-dictionary-set-value}
956In dictionary @var{dict}, set @var{name} to have @var{value}.
957@end defun
958
959For section macros, you can have alternate values. A section can
960either be toggled as visible, or it can act as a loop.
961
962@defun srecode-dictionary-show-section dict name
963@anchor{srecode-dictionary-show-section}
964In dictionary @var{dict}, indicate that the section @var{name} should be exposed.
965@end defun
966
967
968@defun srecode-dictionary-add-section-dictionary dict name show-only
969@anchor{srecode-dictionary-add-section-dictionary}
970In dictionary @var{DICT}, add a section dictionary for section macro @var{NAME}.
971Return the new dictionary.
972
973You can add several dictionaries to the same section entry.
974For each dictionary added to a variable, the block of codes in
975the template will be repeated.
976
977If optional argument @var{SHOW-ONLY} is non-@code{nil}, then don't add a new dictionarly
978if there is already one in place. Also, don't add @var{FIRST}/@var{LAST} entries.
979These entries are not needed when we are just showing a section.
980
981Each dictionary added will automatically get values for positional macros
982which will enable @var{SECTIONS} to be enabled.
983
984@table @var
985@item first
986The first entry in the table.
987@item notfirst
988Not the first entry in the table.
989@item last
990The last entry in the table
991@item notlast
992Not the last entry in the table.
993@end table
994
995Adding a new dictionary will alter these values in previously
996inserted dictionaries.
997@end defun
998
999@node Compound Dictionary Values
1000@section Compound Dictionary Values
1001
1002If you want to associate a non-string value with a dictionary
1003variable, then you will need to use a compound value. Compound
1004dictionary values are derived using @EIEIO{} from a base class for
1005handling arbitrary data in a macro.
1006
1007@deffn Type srecode-dictionary-compound-value
1008@anchor{srecode-dictionary-compound-value}
1009A compound dictionary value.
1010Values stored in a dictionary must be a @var{string},
1011a dictionary for showing sections, or an instance of a subclass
1012of this class.
1013
1014Compound dictionary values derive from this class, and must
1015provide a sequence of method implementations to convert into
1016a string.
1017@end deffn
1018
1019Your new subclass of the compound value needs to implement these
1020methods:
1021
1022@defun srecode-compound-toString cp function dictionary
1023@anchor{srecode-compound-toString}
1024Convert the compound dictionary value @var{cp} to a string.
1025If @var{function} is non-@code{nil}, then @var{function} is somehow applied to an aspect
1026of the compound value. The @var{function} could be a fraction
1027of some function symbol with a logical prefix excluded.
1028@end defun
1029
1030The next method is for dumping out tables during debugging.
1031
1032@defun srecode-dump cp &optional indent
1033@anchor{srecode-dump}
1034Display information about this compound value.
1035@end defun
1036
1037
1038Here is an example of wrapping a semantic tag in a compound value:
1039
1040@example
1041(defclass srecode-semantic-tag (srecode-dictionary-compound-value)
1042 ((prime :initarg :prime
1043 :type semantic-tag
1044 :documentation
1045 "This is the primary insertion tag.")
1046 )
1047 "Wrap up a collection of semantic tag information.
1048This class will be used to derive dictionary values.")
1049
1050(defmethod srecode-compound-toString((cp srecode-semantic-tag)
1051 function
1052 dictionary)
1053 "Convert the compound dictionary value CP to a string.
1054If FUNCTION is non-nil, then FUNCTION is somehow applied to an
1055aspect of the compound value."
1056 (if (not function)
1057 ;; Just format it in some handy dandy way.
1058 (semantic-format-tag-prototype (oref cp :prime))
1059 ;; Otherwise, apply the function to the tag itself.
1060 (funcall function (oref cp :prime))
1061 ))
1062@end example
1063
1064@node Argument Resolution
1065@section Argument Resolution
1066
1067Some dictionary entries can be set via template arguments in the
1068template declaration. For examples of template arguments, see
1069@ref{Template Argument Dictionary Entries}.
1070
1071 You can resolve an argument list into a dictionary with:
1072
1073@defun srecode-resolve-arguments temp dict
1074@anchor{srecode-resolve-arguments}
1075Resolve all the arguments needed by the template @var{temp}.
1076Apply anything learned to the dictionary @var{dict}.
1077@end defun
1078
1079@node Creating new Arguments
1080@section Creating new Arguments
1081
1082You can create new arguments for use in template files by writing new
1083Emacs Lisp functions. Doing so is easy. Here is an example for the
1084@code{:user} argument:
1085
1086@example
1087(defun srecode-semantic-handle-:user (dict)
1088 "Add macros into the dictionary DICT based on the current :user."
1089 (srecode-dictionary-set-value dict "AUTHOR" (user-full-name))
1090 (srecode-dictionary-set-value dict "LOGIN" (user-login-name))
1091 ;; ...
1092 )
1093@end example
1094
1095In this case, a function with the name prefix
1096@code{srecode-semantic-handle-} that ends in @code{:user} creates a
1097new argument @code{:user} that can be used in a template.
1098
1099Your argument handler must take one argument @var{dict}, which is the
1100dictionary to fill in. Inside your function, you can do whatever you
1101want, but adding dictionary values is the right thing.
1102
1103@node Querying a Dictionary
1104@section Querying a Dictionary
1105
1106When creating a new argument, it may be useful to ask the dicitonary
1107what entries are already set there, and conditionally create new
1108entries based on those.
1109
1110In this way, a template author can get additional logic through more
1111advanced arguments.
1112
1113@defun srecode-dictionary-lookup-name dict name
1114@anchor{srecode-dictionary-lookup-name}
1115Return information about the current @var{DICT}'s value for @var{NAME}.
1116@var{DICT} is a dictionary, and @var{NAME} is a string that is the name of
1117a symbol in the dictionary.
1118This function derives values for some special NAMEs, such as @var{FIRST}
1119and '@var{LAST}'.
1120@end defun
1121
1122
1123
1124@node Template Argument Dictionary Entries
1125@section Template Argument Dictionary Entries
1126
1127When a dictionary is initialized for a template, then the dictionary
1128will be initialized with a predefined set of macro values.
1129
1130A template of the form:
1131
1132@example
1133template template-name :arg1 :arg2
1134----
1135Your template goes here
1136----
1137@end example
1138
1139specifies two arguments :arg1, and :arg2.
1140
1141The following built-in simple arguments are available:
1142
1143@menu
1144* Base Arguments::
1145* Semantic Arguments::
1146* Language Arguments::
1147@end menu
1148
1149@node Base Arguments
1150@subsection Base Arguments
1151
1152@subsubsection Argument :indent
1153
1154Supplies the @code{INDENT} macro. When @code{INDENT} is non-nil, then
1155each line is individually indented with
1156@code{indent-according-to-mode} during macro processing.
1157
1158@subsubsection Argument :blank
1159
1160Specifying this argument adds a special @code{:blank} handler at the
1161beginning and end of the template. This handler will insert @code{\n}
1162if the insertion point is not on a line by itself.
1163
1164@subsubsection Argument :region
1165
1166If there is an active region via @code{transient-mark-mode}, or
1167@code{mouse-drag-region}, then the @code{REGION} section will be
1168enabled.
1169
1170In addition, @code{REGIONTEXT} will be set the the text in the region,
1171and that region of text will be ``killed'' from the current buffer.
1172
1173If standard-output is NOT the current buffer, then the region will not
1174be deleted. In this way, you can safely use @code{:region} using
1175templates in arbitrary output streams.
1176
1177@subsubsection Argument :user
1178
1179Sets up variables about the current user.
1180
1181@table @code
1182@item AUTHOR
1183Value of the Emacs function @code{user-full-name}
1184@item EMAIL
1185Current Emacs user's email address.
1186@item LOGIN
1187Current Emacs user's login name.
1188@item UID
1189Current Emacs user's login ID.
1190@item EMACSINITFILE
1191This Emacs sessions' init file.
1192@end table
1193
1194@subsubsection Argument :time
1195
1196Sets up variables with the current date and time.
1197
1198@table @code
1199@item YEAR
1200The current year.
1201@item MONTH
1202The current month as a number.
1203@item MONTHNAME
1204The current month name, unabbreviated.
1205@item DAY
1206The current day as a number.
1207@item WEEKDAY
1208The current day of the week as an abbreviated name
1209@item HOUR
1210The current hour in 24 hour format.
1211@item HOUR12
1212The current hour in 12 hour format.
1213@item AMPM
1214Locale equivalent of AM or PM. Usefule with HOUR12.
1215@item MINUTE
1216The current minute.
1217@item SECOND
1218The current second.
1219@item TIMEZONE
1220The timezone string.
1221@item DATE
1222The Locale supported date (%D).
1223@item TIME
1224The Locale supported time format (%X).
1225@end table
1226
1227@subsubsection Argument :file
1228
1229Sets up variables with details about the current file.
1230
1231@table @code
1232@item FILENAME
1233The filename without the directory part of the current buffer.
1234@item FILE
1235The filename without the directory or extension
1236@item EXTENSION
1237The filename extension.
1238@item DIRECTORY
1239The directory in which the current buffer resides.
1240@item MODE
1241Major mode of this buffer.
1242@item SHORTMODE
1243Major mode of this buffer without ``-mode''.
1244Useful for inserting the Emacs mode specifier.
1245@item section RCS
1246Show the section RCS if there is a CVS or RCS directory here.
1247@end table
1248
1249@subsubsection Argument :system
1250
1251Sets up variables with computer system information.
1252
1253@table @code
1254@item SYSTEMCONF
1255The ``system-configuration''.
1256@item SYSTEMTYPE
1257The ``system-type''.
1258@item SYSTEMNAME
1259The ``system-name''.
1260@item MAILHOST
1261The name of the machine Emacs derived mail ``comes from''.
1262@end table
1263
1264@subsubsection Argument :kill
1265
1266@table @code
1267@item KILL
1268The top-most item from the kill ring.
1269@item KILL2
1270The second item in the kill ring.
1271@item KILL3
1272The third item in the kill ring.
1273@item KILL4
1274The fourth item in the kill ring.
1275@end table
1276
1277@node Semantic Arguments
1278@subsection Semantic Arguments
1279
1280@subsubsection Argument :tag
1281
1282The :tag argument is filled in with information from Semantic.
1283The tag in question is queried from the senator tag ring, or passed
1284in from @srecode{} utilities that use tags in templates.
1285
1286@table @code
1287@item TAG
1288This is a compound value for the tag in the current senator kill ring,
1289or something handled via the variable
1290@code{srecode-semantic-selected-tag}.
1291
1292@defvar srecode-semantic-selected-tag
1293@anchor{srecode-semantic-selected-tag}
1294The tag selected by a @code{:tag} template argument.
1295If this is @code{nil}, then @code{senator-tag-ring} is used.
1296@end defvar
1297
1298Use the function part of a macro insert to extract obscure parts
1299of the tag.
1300@item NAME
1301The name of the tag as a string.
1302@item TYPE
1303The data type of the tag as a string.
1304@end table
1305
1306If @var{tag} is a function, you will get these additional dictionary
1307entries.
1308
1309@table @code
1310@item ARGS
1311A Loop macro value. Each argument is inserted in ARGS. To create a
1312comma separated list of arguments, you might do this:
1313
1314@example
1315@{@{#ARGS@}@}@{@{TYPE@}@} @{@{NAME@}@}@{@{#NOTLAST@}@},@{@{/NOTLAST@}@}@{@{/ARGS@}@}
1316@end example
1317
1318Within the section dictionaries for each argument, you will find both
1319@var{NAME} and @var{TYPE}, in addition to the automatic section values
1320for @var{FIRST}, @var{LAST}, @var{NOTFIRST}, and @var{NOTLAST}.
1321@item PARENT
1322The string name of the parent of this function, if the function is a
1323method of some class.
1324@item THROWS
1325In each @var{THROWS} entry, the @var{NAME} of the signal thrown is specified.
1326@end table
1327
1328If @var{tag} is a variable, you will get these dictionary entries.
1329
1330@table @code
1331@item DEFAULTVALUE
1332Enabled if there is a @var{VALUE}.
1333@item VALUE
1334An entry in the @var{HAVEDEFAULT} subdictionary that represents the
1335textual representation of the default value of this variable.
1336@end table
1337
1338If @var{tag} is a datatype, you will get these dictionary entries.
1339
1340@table @code
1341@item PARENTS
1342Section dictionaries for the parents of this class. Each parent will
1343have a @var{NAME}.
1344@item INTERFACES
1345Section dictionaries for all the implemented interfaces of this
1346class. Each interface will have a @var{NAME}.
1347@end table
1348
1349Note that data type templates should always have a @code{@{@{^@}@}}
1350macro in it where the core contents of that type will go. This is why
1351data types don't have subdictionaries full of the slots in the classes
1352or structs.
1353
1354@node Language Arguments
1355@subsection language Arguments
1356
1357Each language typically has its own argument. These arguments can be
1358used to fill in language specific values that will be useful.
1359
1360@subsubsection Argument :srt
1361
1362Used for SRecoder template files.
1363
1364@table @code
1365@item ESCAPE_START
1366The characters used for an escape start
1367@item ESCAPE_END
1368The characters used for an escape end
1369@end table
1370
1371@subsubsection Argument :cpp
1372
1373@table @code
1374@item HEADER
1375Shows this section if the current file is a header file.
1376@item NOTHEADER
1377The opposite of @code{HEADER}.
1378@item FILENAME_SYMBOL
1379The current filename reformatted as a C friendly symbol.
1380@end table
1381
1382@subsection Argument :java
1383
1384@table @code
1385@item FILENAME_AS_PACKAGE
1386Converts the filename into text that would be suitable as a package
1387name.
1388@item FILENAME_AS_CLASS
1389Converts the filename into text that would be suitable as a class-name
1390for the main class in the file.
1391@item CURRENT_PACKAGE
1392Finds the occurance of ``package'' and gets its value.
1393@end table
1394
1395@subsubsection Argument :el
1396
1397Sets @code{PRENAME}. This would be a common prefix from all the
1398tags in the current buffer.
1399
1400Most Emacs Lisp packages have some common prefix used in a way similar
1401to namespaces in other languages.
1402
1403@subsubsection Argument :el-custom
1404
1405@table @code
1406@item GROUP
1407The name of the Emacs Custom group that instances of @code{defcustom}
1408ought to use.
1409@item FACEGROUP
1410The name of the Emacs Custom group that faces delcared with
1411@code{defface} ought to use.
1412@end table
1413
1414@subsubsection Argument :texi
1415
1416@table @code
1417@item LEVEL
1418The current section level, such as @code{chapter} or @code{section}.
1419@item NEXTLEVEL
1420The next level down, so if @code{LEVEL} is @code{chapter}, then
1421@code{NEXTLEVEL} would be @code{section}.
1422@end table
1423
1424@subsubsection Argument :texitag
1425
1426The @code{:texitag} argument is like the @code{:tag} argument, except that
1427additional variable @code{TAGDOC} is provided for each tag.
1428
1429The @code{TAGDOC} is filled with derived documentation from the tag in
1430question, and that documentation is also reformatted to be mostly
1431texinfo compatible.
1432
1433@subsection Argument :android
1434
1435The @code{:android} argument pulls in information from your current
1436project.
1437
1438@@TODO - add more here.
1439
1440@node Developing Template Functions
1441@chapter Developing Template Functions
1442
1443You can develop your own custom template insertion functions.
1444Doing so is relatively simple, and requires that you write an Emacs
1445Lisp command.
1446
1447If the built in commands don't provide enough options, you will need
1448to write your own function in order to provide your dictionaries with
1449the values needed for custom templates.
1450
1451In this way, you can build your own code generator for any language
1452based on a set of predefined macros whos values you need to derive
1453from Emacs Lisp code yourself.
1454
1455For example:
1456
1457@example
1458(defun my-srecode-insert (template-name)
1459 "Insert the template TEMPLATE-NAME into the current buffer at point."
1460
1461 ;; Read in a template name.
1462 (interactive (list (srecode-read-template-name "Template Name: ")))
1463 (if (not (srecode-table))
1464 (error "No template table found for mode %s" major-mode))
1465 (let ((temp (srecode-template-get-table (srecode-table) template-name))
1466
1467 ;; Create a new dictionary
1468 (newdict (srecode-create-dictionary)))
1469
1470 (if (not temp)
1471 (error "No Template named %s" template-name))
1472
1473 ;; Add some values into the dictionary!
1474 (srecode-dictionary-set-value newdict "FOO" (my-get-value-of-foo))
1475 ;; Optionally show a section
1476 (srecode-dictionary-show-section newdict "BLARG")
1477
1478 ;; Add in several items over a loop
1479 (let ((my-stuff (get-my-stuff-list)))
1480 (while my-stuff
1481 (let ((subdict (srecode-dictionary-add-section-dictionary
1482 newdict "LOOP")))
1483 (srecode-dictionary-set-value subdict "NAME" (nth 0 my-stuff))
1484 (srecode-dictionary-set-value subdict "ARG" (nth 1 my-stuff))
1485 (srecode-dictionary-set-value subdict "MOOSE" (nth 2 my-stuff))
1486 )
1487 (setq my-stuff (cdr my-stuff)))
1488
1489 ;; Some templates have arguments that need to be resolved.
1490 (srecode-resolve-arguments temp newdict)
1491
1492 ;; Do the expansion
1493 (srecode-insert-fcn temp newdict)
1494 ))
1495@end example
1496
1497Lets look at the key functions involved above:
1498
1499@section Interactive Completion:
1500
1501@defun srecode-read-template-name prompt
1502@anchor{srecode-read-template-name}
1503Completing read for Semantic Recoder template names.
1504@var{prompt} is used to query for the name of the template desired.
1505@end defun
1506
1507@section Template Lookup
1508
1509Even if your program does not query the user for a template name, you
1510will need to locate a template. First, you need to locate the table
1511to look the template up in.
1512
1513@defun srecode-table &optional mode
1514@anchor{srecode-table}
1515Return the currently active Semantic Recoder table for this buffer.
1516Optional argument @var{MODE} specifies the mode table to use.
1517@end defun
1518
1519
1520@defun srecode-template-get-table tab template-name &optional context application
1521@anchor{srecode-template-get-table}
1522Find in the template in mode table @var{TAB}, the template with @var{TEMPLATE-NAME}.
1523Optional argument @var{CONTEXT} specifies a context a particular template
1524would belong to.
1525Optional argument @var{APPLICATION} restricts searches to only template tables
1526belonging to a specific application. If @var{APPLICATION} is @code{nil}, then only
1527tables that do not belong to an application will be searched.
1528@end defun
1529
1530For purposes of an @srecode{} application, it is important to decide
1531what to call yoru application, and use that with this method call.
1532
1533@section Creating dictionaries
1534
1535Several dictionary calls are made in this example, including:
1536@table @code
1537@item srecode-create-dictionary
1538@item srecode-dictionary-set-value
1539@item srecode-dictionary-show-section
1540@item srecode-dictionary-add-section-dictionary
1541@end table
1542
1543These are documented more fully @ref{Dictionaries}.
1544
1545Also used is @code{srecode-resolve-arguments}. To learn more about
1546that, see @ref{Argument Resolution}.
1547
1548@section Template Insertion Commands
1549
1550There are several ways to insert a template. It is easiest to just
1551start with the main entry point.
1552
1553@defun srecode-insert-fcn template dictionary &optional stream
1554@anchor{srecode-insert-fcn}
1555Insert @var{template} using @var{dictionary} into @var{stream}.
1556If @var{stream} is nil, then use the current buffer.
1557@end defun
1558
1559@node Template Naming Conventions
1560@chapter Template Naming Conventions
1561
1562For @srecode{} to work across langauges reliably, templates need to
1563follow a predictable pattern. For every language of similar nature
1564(OO, functional, doc based) if they all provide the same base
1565templates, then an application can be written against the base
1566templates, and it will work in each of the supported language.
1567
1568Having consistent templates also makes it easy to use those templates
1569from a user perspective during basic interactive insertion via
1570@code{srecode-minor-mode}.
1571
1572
1573NOTES ON THIS CHAPTER:
1574
1575These conventions are being worked on. Check w/ CEDET-DEVEL mailing
1576list if you want to support a language, or write an application and
1577provide your opinions on this topic. Any help is appreciated.
1578
1579
1580@section Context: File
1581
1582Each language should support the @code{file:empty} template. This
1583will generally use the default copyright insertion mechanism.
1584
1585@section Context: Declaration
1586
1587Functional languages should attempt to support the following:
1588
1589@table @code
1590@item function
1591A standalone function. Not a method, external method, or other.
1592@item method
1593A method belonging to some class declaired outside the textual bounds
1594of that class' declaration.
1595@item variable
1596A global variable.
1597@item type
1598A data type. If the language supports several types of datatypes
1599then do not use this, use more specific ones instead.
1600@item class
1601For OO languages, use this instead of @code{type}.
1602@item include
1603Include files.
1604@end table
1605
1606For any @semantic{} tag class in your language, you will likely want
1607to have a corresponding template.
1608
1609In order for the @srecode{} function
1610@code{srecode-semantic-insert-tag} to work, you can create templates
1611similar to those mentioned above, except with @code{-tag} appended to
1612the end. This lets a template like @code{function} have user
1613conveniences when referencing @code{function-tag}, while also
1614allowing the tag inserter to do its job with a simpler template.
1615
1616@section Context: Classdef
1617
1618Inside a class definition. These are to be inserted inside the
1619textual bounds of a class declaration.
1620
1621@table @code
1622@item function
1623This would be a method of the class being inserted into.
1624@item constructor
1625@itemx destructor
1626Like @code{function} but specific to alloc/delete of an object.
1627@item variable
1628This would be a field of the class being inserted into.
1629@end table
1630
1631@section Context: Code
1632
1633Inside a body of code, such as a function or method body.
1634
1635 - no conventions yet.
1636
1637@section Standard Dictionary Values
1638
1639For these variables to be useful, standard names should be used.
1640These values could be provided directly from a Semantic tag, or by an
1641application.
1642
1643@table @var
1644@item NAME
1645The name of the declaration being created.
1646@item PARENT
1647If the item belongs to some parent type, it would be the full name of
1648that type, including namespaces.
1649@item TYPE
1650A datatype name for a variable, or the return value of a function.
1651@item DOC
1652If there is some documentation associated with the item, then DOC
1653should contain the value. (Optional)
1654@item ARGS
1655The ARGS variable defines a section for 0 or more arguments to a function
1656or method. Each entry in ARGS will follow the rest of these naming
1657conventions, such as for NAME and TYPE.
1658@end table
1659
1660For templates used by @code{srecode-semantic-insert-tag}, there is
1661also the following useful dictionary values.
1662
1663@table @var
1664@item TAG
1665A special insertion value TAG. You can use semantic functions to turn
1666the tag into a string.
1667@item HAVEDEFAULT
1668@itemx DEFAULT
1669Default value for a variable.
1670@end table
1671
1672@node Inserting Tag Lists
1673@chapter Inserting Tag Lists
1674
1675Since @srecode{} is the @i{Semantic Recoder}, the ultimate goal for
1676@srecode{} is to convert lists of tags, as produced by @semantic{}
1677back into code.
1678
1679A single function provides the interface for programs to do this, but
1680it requires any particular language to have provided the correct
1681templates to make it work.
1682
1683@defun srecode-semantic-insert-tag tag &optional style-option point-insert-fcn &rest dict-entries
1684@anchor{srecode-semantic-insert-tag}
1685Insert @var{tag} into a buffer using srecode templates at point.
1686
1687Optional @var{style-option} is a list of minor configuration of styles,
1688such as the symbol @code{'prototype} for prototype functions, or
1689@code{'system} for system includes, and @code{'doxygen}, for a doxygen style
1690comment.
1691
1692Optional third argument @var{point-insert-fcn} is a hook that is run after
1693@var{tag} is inserted that allows an opportunity to fill in the body of
1694some thing. This hook function is called with one argument, the @var{tag}
1695being inserted.
1696
1697The rest of the arguments are @var{dict-entries}. @var{dict-entries}
1698is of the form ( @var{name1} @var{value1} @var{name2} @var{value2} @dots{} NAMEn VALUEn).
1699
1700The exact template used is based on the current context.
1701The template used is found within the toplevel context as calculated
1702by @dfn{srecode-calculate-context}, such as @code{declaration}, @code{classdecl},
1703or @code{code}.
1704
1705For various conditions, this function looks for a template with
1706the name @var{class}-tag, where @var{class} is the tag class. If it cannot
1707find that, it will look for that template in the
1708@code{declaration}context (if the current context was not @code{declaration}).
1709
1710If @var{prototype} is specified, it will first look for templates with
1711the name @var{class}-tag-prototype, or @var{class}-prototype as above.
1712
1713See @dfn{srecode-semantic-apply-tag-to-dict} for details on what is in
1714the dictionary when the templates are called.
1715
1716This function returns to location in the buffer where the
1717inserted tag @var{ends}, and will leave point inside the inserted
1718text based on any occurrence of a point-inserter. Templates such
1719as @dfn{function} will leave point where code might be inserted.
1720@end defun
1721
1722
1723@node Application Writing
1724@chapter Application Writing
1725
1726The main goal of @srecode{} is to provide a strong platform for
1727writing code generating applications.
1728
1729Any templates that are application specific should make an application
1730declaration for each template file they use. This prevents those
1731templates from being used outside of that application.
1732
1733For example, add this to a file:
1734@example
1735set application "getset"
1736@end example
1737
1738In your application Emacs Lisp code, you would then load those
1739templates. A typical initialization would look like this:
1740
1741@example
1742 (srecode-load-tables-for-mode major-mode)
1743 (srecode-load-tables-for-mode major-mode 'getset)
1744@end example
1745
1746These two lines will load in the base templates for the major mode,
1747and then the application specific templates.
1748
1749@defun srecode-load-tables-for-mode mmode &optional appname
1750@anchor{srecode-load-tables-for-mode}
1751Load all the template files for @var{mmode}.
1752Templates are found in the SRecode Template Map.
1753See @dfn{srecode-get-maps} for more.
1754@var{appname} is the name of an application. In this case,
1755all template files for that application will be loaded.
1756@end defun
1757
1758
1759 todo - Add examples. Most core stuff is already described above.
1760
1761
1762
1763@node Index
1764@chapter Index
1765
1766@contents
1767
1768@bye