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