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