forked from fgeller/emacs-mac-port
/
srecode.info
2363 lines (1766 loc) · 86.3 KB
/
srecode.info
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
This is /home/cyd/emacs/doc/misc/../../info/srecode.info, produced by
makeinfo version 4.13 from /home/cyd/emacs/doc/misc/srecode.texi.
Copyright (C) 2007-2012 Free Software Foundation, Inc.
Permission is granted to copy, distribute and/or modify this
document under the terms of the GNU Free Documentation License,
Version 1.3 or any later version published by the Free Software
Foundation; with no Invariant Sections, with the Front-Cover texts
being "A GNU Manual," and with the Back-Cover Texts as in (a)
below. A copy of the license is included in the section entitled
"GNU Free Documentation License".
(a) The FSF's Back-Cover Text is: "You have the freedom to copy and
modify this GNU manual. Buying copies from the FSF supports it in
developing GNU and promoting software freedom."
INFO-DIR-SECTION Emacs misc features
START-INFO-DIR-ENTRY
* SRecode: (srecode). Template code generator.
END-INFO-DIR-ENTRY
File: srecode.info, Node: Top, Next: Quick Start, Up: (dir)
SRecoder Manual
***************
SRecode is the Semantic Recoder. Where Semantic will parse source
files into lists of tags, the Semantic Recoder will aid in converting
Semantic tags and various other information back into various types of
code.
While the SRecode tool provides a template language, templates for
several languages, and even a sequence of heuristics that aid the user
in choosing a template to insert, this is not the main goal of SRecode.
The goal of SRecode is to provide an application framework where
someone can write a complex code generator, and the underlying template
commonality allows it to work in multiple languages with ease.
Copyright (C) 2007-2012 Free Software Foundation, Inc.
Permission is granted to copy, distribute and/or modify this
document under the terms of the GNU Free Documentation License,
Version 1.3 or any later version published by the Free Software
Foundation; with no Invariant Sections, with the Front-Cover texts
being "A GNU Manual," and with the Back-Cover Texts as in (a)
below. A copy of the license is included in the section entitled
"GNU Free Documentation License".
(a) The FSF's Back-Cover Text is: "You have the freedom to copy and
modify this GNU manual. Buying copies from the FSF supports it in
developing GNU and promoting software freedom."
* Menu:
* Quick Start:: Basic Setup for template insertion.
* User Templates:: Custom User Templates
* Parts of SRecode:: Parts of the system
* SRecode Minor Mode:: A minor mode for using templates
* Template Writing:: How to write a template
* Dictionaries:: How dictionaries work
* Developing Template Functions:: How to write your own template insert functions.
* Template Naming Conventions:: Creating a set of core templates
* Inserting Tag Lists:: Inserting Semantic tags via templates
* Application Writing:: Writing an SRecoder application
* GNU Free Documentation License:: The license for this documentation.
* Index::
File: srecode.info, Node: Quick Start, Next: User Templates, Prev: Top, Up: Top
1 Quick Start
*************
When you install CEDET and enable SRecode, an `SRecoder' menu item
should appear.
To toggle SRecode minor mode on and off use:
M-x srecode-minor-mode RET
or
M-x global-srecode-minor-mode RET
or add
(srecode-minor-mode 1)
into a language hook function to force it on (which is the default)
or pass in `-1' to force it off.
See *note SRecode Minor Mode:: for more on using the minor mode.
Use the menu to insert templates into the current file.
You can add your own templates in `~/.srecode', or update the
template map path:
-- Option: srecode-map-load-path
Global load path for SRecode template files.
Once installed, you can start inserting templates using the menu, or
the command:
-- Command: srecode-insert template-name &rest dict-entries
Insert the template TEMPLATE-NAME into the current buffer at point.
DICT-ENTRIES are additional dictionary values to add.
SRecode Insert will prompt for a template name. Template names are
specific to each major mode. A typical name is of the form:
`CONTEXT:NAME' where a CONTEXT might be something like `file' or
`declaration'. The same NAME can occur in multiple contexts.
File: srecode.info, Node: User Templates, Next: Parts of SRecode, Prev: Quick Start, Up: Top
2 User Templates
****************
SRecode builds and maintains a map of all template files. The root
template files resides in the SRecode distribution. User written
templates files are saved in `~/.srecode', along with the SRecode map
file.
-- Variable: srecode-map-save-file
The save location for SRecode's map file.
Template files end with a `.srt' extension. Details on how to write
templates are in *note Template Writing::.
Each template file you write is dedicated to a single major mode. In
it, you can write templates within the same context and with the same
name as core templates. You can force your templates to override the
core templates for a particular major mode by setting the priority.
See *note Special Variables::.
To get going quickly, open a new `.srt' file. It will start in the
SRecode template writing mode. Use the SRecode minor mode menu to
insert the `empty' file template.
When using templates in other modes (such as C++ or Emacs Lisp
templates), use the "Edit Template" menu to find a template you would
like to update. Copy it into your user template file, and change it.
If you were to update `declaration:function' in your user template
file, then you would get this new template instead of the one that
comes with SRecode. Higher level applications should always use
`declaration:function' when generating their own code, so higher level
templates will then adopt your changes to `declaration:function' into
themselves.
You can also override variables. Core variables are stored in the
SRecode root template file `default.srt', and that contains the
copyright usually used, and some basic file setup formats. Override
variables like this by specifying a `mode' of `default' like this:
set mode "default"
File: srecode.info, Node: Parts of SRecode, Next: SRecode Minor Mode, Prev: User Templates, Up: Top
3 Parts of SRecode
******************
The SRecode system is made up of several layers which work together to
generate code.
3.1 Template Layer
==================
The template layer provides a way to write, and compile templates. The
template layer is the scheme used to insert text into an Emacs buffer.
The SRecode template layer is more advanced than other modes like the
Emacs packages `skeleton' or `tempo' in that it allows multiple layers
of templates to be created with the same names. This means that
SRecode can provide a wide range of templates, and users can override
only the small sections they want, instead of either accepting someone
else's template, or writing large new templates of their own.
Templates are written in `.srt' files. You can learn how to author
new `.srt' files *note Template Writing::.
While the template system was designed for SRecode based
applications it can also be used independently for simple template
insertion during typical coding.
3.2 Template Manager
====================
Once templates have been written, a scheme for loading and selecting
templates is needed. The template manager has a loader for finding
template files, and determining which templates are relevant to the
current buffer. Template files are sorted by priority, with user
templates being found first, and system level default templates last.
Templates are also sorted by application. Each application has its own
templates, and are kept seperate from the generic templates.
3.3 Dictionary
==============
Dictionaries contain values associated with variable. Variables are
used in macros in a template. Variables are what allows a generic
template such as a function to be made specific, such as a function
named foo. The value of a variable can be one of three things; a
string, a list of more dictionaries, or a special
`srecode-dictionary-compound-value' object subclass. See *note
Variables:: for more.
3.4 Template Insertion
======================
The template insertion layer involves extensions to the basic template
layer. A wide range of custom variables are available for mixing
derived data as macros into the plain text of a template.
In addition, templates can be declared with arguments. These
arguments represent predetermined sets of dictionary values, such as
features of the current file name, user name, time, etc.
Some arguments are major-mode specific, such as the `:el' or `:cpp'
arguments.
3.5 Template Insertion Context
==============================
A context can be provided for templates in a file. This helps
auto-selection of templates by name, or allows templates in different
contexts to have the same name. Some standard contexts are `file',
`declaration', and `classdecl'.
A context can be automatically derived as well based on the parsing
state from Semantic. *note Semantic Manual: (semantic)Top.
3.6 Applications
================
Commands that do a particular user task which involves also writing
Emacs Lisp code. Applications are at the top layer. These
applications have their own template files and logic needed to fill in
dictionaries or position a cursor. SRecode comes with an example
`srecode-document' application for creating comments for Semantic tags.
The CEDET application EDE has a project type that is an SRecode
application.
3.7 Field Editing
=================
If the variable `srecode-insert-ask-variable-method' is set to 'field,
then variables that would normally ask a question, will instead create
"fields" in the buffer. A field-editing layer provides simple
interaction through the fields. Typing in a field will cause all
variable locations that are the same to edit at the same time.
Pressing TAB on a field will move you to the next field.
File: srecode.info, Node: SRecode Minor Mode, Next: Template Writing, Prev: Parts of SRecode, Up: Top
4 SRecode Minor Mode
********************
The Semantic Recode minor mode enables a keymap and menu that provides
simple access to different templates or template applications.
The key prefix is <C-c />.
If the variable `srecode-takeover-INS-key' is set, then the key
<<insert>> can also be used.
The most important key is bound to `srecode-insert' which is <C-c /
/>, or <insert insert>. *note Quick Start::.
Major keybindings are:
<C-c / />
Insert a template whose name is typed into the minibuffer.
<C-c / <lower case letter>>
Reserved for direct binding of simple templates to keys using a
keybinding command in the template file.
<C-c / <upper case letter>>
Reserved for template applications (Such as comment or get/set
inserter.)
<C-c / E>
Edit the code of a template.
<C-c / .>
Insert template again. This will cause the previously inserted
template to be inserted again.
4.1 Field Editing
=================
By default, when inserting a template, if the user needs to enter text
to fill in a part of the template, then the minibuffer is used to query
for that information. SRecode also supports a field-edting mode that
can be used instead. To enable it set:
-- Function: srecode-insert-ask-variable-method
Determine how to ask for a dictionary value when inserting a
template. Only the ASK style inserter will query the user for a
value. Dictionary value references that ask begin with the ?
character. Possible values are:
`ask'
Prompt in the minibuffer as the value is inserted.
`field'
Use the dictionary macro name as the inserted value, and
place a field there. Matched fields change together.
NOTE: The field feature does not yet work with XEmacs.
Field editing mode is supported in newer versions of Emacs. You
will not be prompted to fill in values while the template is inserted.
Instead, short regions will be highlighted, and the cursor placed in a
field. Typing in the field will then fill in the value. Several
fields might be linked together. In that case, typing in one area will
modify the other linked areas. Pressing TAB will move between editable
fields in the template.
Once the cursor moves out of the are inserted by the template, all
the fields are cancelled.
NOTE: Some conveniences in templates, such as completion, or
character restrictins are lost when using field editing mode.
File: srecode.info, Node: Template Writing, Next: Dictionaries, Prev: SRecode Minor Mode, Up: Top
5 Template Writing
******************
`srecode-template-mode' is the major mode used for designing new
templates. SRecode files (Extension `.srt') are made up of variable
settings and template declarations.
Here is an overview of the terminology you will need for the next few
sections:
template file
A file with a `.srt' extension which contains settings, variables,
and templates.
template
One named entity which represents a block of text that will be
inserted. The text is compiled into a sequence of insertable
entities. The entities are string constants, and macros.
macro
A macro is a text sequence within template text that is replaced
with some other value.
dictionary
A table of variable names and values.
subdictionary
A dictionary that is subordinate under another dictionary as a
value to some variable.
variable
A variable is an entry in a dictionary which has a value.
* Menu:
* Variables:: Creating special and regular variables.
* Templates:: Creating templates
* Contexts:: Templates are grouped by context
* Prompts:: Setting prompts for interactive insert macros
File: srecode.info, Node: Variables, Next: Templates, Up: Template Writing
5.1 Variables
=============
Variables can be set up and used in templates. Many variables you may
use are set up via template arguments, but some may be preferences a
user can set up that are used in system templates.
When expanding a template, variables are stored in a "dictionary".
Dictionary entries are variables. Variables defined in templates can
have string like values.
A variable can be set like this:
set VARNAME "some value"
Note that a VARIABLE is a name in a dictionary that can be used in a
MACRO in a template. The macro referernces some variable by name.
* Menu:
* String Values:: Basic Variable values
* Multi-string Values:: Complex variable values
* Section Show:: Enabling the display of a named section.
* Special Variables:: Variables with special names
* Automatic Loop Variables:: Variables automatically set in section loops.
* Compound Variable Values:: Compound Variable Values
File: srecode.info, Node: String Values, Next: Multi-string Values, Up: Variables
5.1.1 String Values
-------------------
Variables can be set to strings. Strings may contain newlines or any
other characters. Strings are interpreted by the Emacs Lisp reader so
`\n', `\t', and `\"' work.
When a string is inserted as part of a template, nothing within the
string is interperted, such as template escape characters.
File: srecode.info, Node: Multi-string Values, Next: Section Show, Prev: String Values, Up: Variables
5.1.2 Multi-string Values
-------------------------
A variable can be set to multiple strings. A compound value is usually
used when you want to use dictionary entries as part of a variable
later on.
Multi-string variable values are set like string values except there
are more than one. For example
set NAME "this" "-mode"
These two strings will be concatenated together.
A more useful thing is to include dictionary variables and
concatenate those into the string. Use the "macro" keyword to include
the name of a variable. This is like macros in a template. For
example:
set NAME macro "MODE" "-mode"
will extract the value of the dictionary variable MODE and append
"-mode" to the end.
File: srecode.info, Node: Section Show, Next: Special Variables, Prev: Multi-string Values, Up: Variables
5.1.3 Section Show
------------------
To set a variable to show a template section, use the `show' command.
Sections are blocks of a template wrapped in section macros. If there
is a section macro using NAME it will be shown for each dictionary
associated with the NAME macro.
show NAME
This will enable that section.
NOTE: May 11, 2008 - I haven't used this yet, so I don't know if it
works.
File: srecode.info, Node: Special Variables, Next: Automatic Loop Variables, Prev: Section Show, Up: Variables
5.1.4 Special Variables
-----------------------
Some variables have special meaning that changes attributes when
templates are compiled, including:
`escape-start'
This is the character sequence that escapes from raw text to
template macro names. The ability to change the escape characters
are key for enabling SRecode templates to work across many kinds
of languages.
`escape-end'
This is the character sequence that escapes the end of a template
macro name.
Example:
set escape_start "$"
set escape_end "$"
`mode'
This is the major mode, as a string with the full Emacs Lisp
symbol in it. All templates in this file will be installed into
the template table for this major mode.
Multiple template files can use the same mode, and all those
templates will be available in buffers of that mode.
Example:
set mode "emacs-lisp-mode"
`priority'
The priority of a file is a number in a string constant that
indicates where it lies in the template search order. System
templates default to low priority numbers. User templates default
to high priority numbers. You can specify the priority of your
template to insert it anywhere in the template search list.
If there are multiple templates with the same context and name, the
template with the highest priority number will be used.
If multiple files have the same priority, then then sort order is
unpredictable. If no template names match, then it doesn't matter.
Example:
set priority "35"
`application'
If a template file contains templates only needed for a particular
application, then specify an application. Template files for an
application are stored in the template repository, but are not
used in the generic template insertion case.
The application with a particular name will access these templates
from Lisp code.
Example:
set application "document"
`project'
If a template file contains templates, or template overrides
specific to a set of files under a particular directory, then that
template file can specify a "project" that it belongs to.
Set the "project" special variable to a directory name. Only files
under that directory will be able to access the templates in that
file.
Any template file that has a project specified will get have a
priority that is set between SRecode base templates, and user
defined templates.
Templates can be compiled via a project system, such as EDE. EDE
loaded templates will get a PROJECT set automatically.
Example:
set project "/tmp/testproject"
If you need to insert the characters that belong to the variables
`escape_start' or `escape_end', then place those into a variable. For
example
set escape_start "$"
set escape_end "$"
set DOLLAR "$"
File: srecode.info, Node: Automatic Loop Variables, Next: Compound Variable Values, Prev: Special Variables, Up: Variables
5.1.5 Automatic Loop Variables
------------------------------
When section macros are used, that section is repeated for each
subdictionary bound to the loop variable.
Each dictionary added will automatically get values for positional
macros which will enable different SECTIONS. The automatic section
variables are.
* FIRST - The first entry in the table.
* NOTFIRST - Not the first entry in the table.
* LAST - The last entry in the table
* NOTLAST - Not the last entry in the table.
File: srecode.info, Node: Compound Variable Values, Prev: Automatic Loop Variables, Up: Variables
5.1.6 Compound Variable Values
------------------------------
A variable can also have a compound value. This means the value of the
variable is an EIEIO object, which is a subclass of
`srecode-dictionary-compound-value'.
New compound variables can only be setup from Lisp code. See *note
Compound Dictionary Values:: for details on setting up compound
variables from Lisp.
File: srecode.info, Node: Templates, Next: Contexts, Prev: Variables, Up: Template Writing
5.2 Templates
=============
A template represents a text pattern that can be inserted into a buffer.
A basic template is declaired like this:
template TEMPLATENAME :arg1 :arg2
"Optional documentation string"
----
The text to your template goes here.
----
bind "a"
Templates are stored in a template table by name, and are inserted by
the TEMPLATENAME provided.
The documentation string is optional. This documentation string will
be used to aid users in selecting which template they want to use.
The code that makes up the raw template occurs between the lines that
contain the text "----".
* Menu:
* Template Section Dictionaries:: Template Scoped Macro values
* Template Macros:: Macros occuring in template patterns
File: srecode.info, Node: Template Section Dictionaries, Next: Template Macros, Up: Templates
5.2.1 Template Section Dictionaries
-----------------------------------
To add variable values to section dictionaries used within a specific
template, you can add them to the beginning of the template declaration
like this:
template TEMPLATENAME :arg1 :arg2
"Optional documentation string"
sectiondictionary "A"
set NAME "foo"
----
A beginning line {{NAME}}
{{#A}}Optional string {{NAME}} here{{/A}}
An end line
----
In this example, the NAME variable gets the value "foo", but only
while it is inside section macro A. The outer scoped NAME will be
empty.
This is particularly useful while using an include macro to pull in a
second template. In this way, you can pass values known from one
template to a subordinate template where some value is not known.
From the Emacs Lisp default template file, a syntax table is just a
variable with a specialized value.
If a variable is declared like this (where $ is the escape
character):
template variable :el
"Insert a variable.
DOC is optional."
----
(defvar $?NAME$ $^$
"$DOC$")
----
then you can see that there is a NAME and DOC that is needed. The
`^' point inserter is also a handy key here.
The syntax table wants a variable, but knows the values of some of
these variables, and can recast the problem like this by using template
specific `sectiondictionary' macro declarations.
template syntax-table
"Create a syntax table."
sectiondictionary "A"
set NAME macro "?MODESYM" "-mode-syntax-table"
set DOC "Syntax table used in " macro "?MODESYM" " buffers."
----
$<A:variable$
(let ((table (make-syntax-table (standard-syntax-table))))
(modify-syntax-entry ?\; ". 12" table) ;; SEMI, Comment start ;;
;; ...
table)
$/A$
----
In this way, NAME can be set as a user posed question for MODESYM
with "-mode-syntax-table" appended. A simplified doc string will also
be inserted.
Lastly, the A section contains more macro text which is inserted at
the `^' point marker.
By creating useful base templates for things like function or
variable declarations, and recycling them in higher-order templates, an
end user can override the basic declarator, and the higher order
templates will then obey the new format, or perhaps even work in more
than one major mode.
File: srecode.info, Node: Template Macros, Prev: Template Section Dictionaries, Up: Templates
5.2.2 Template Macros
---------------------
Template macros occur in the template text. The default escape
characters are "{{" and "}}", though they can be changed in the
top-level variables. See *note Variables::.
Thus, if you have the template code that looks like this:
;; Author: {{AUTHOR}}
Then the text between {{ and }} are a macro, and substituted by the
value of the variable AUTHOR.
Macros can be specialized to be more than just a text string. For
example, the macro above could be augmented with an Emacs Lisp function.
;; Author: {{AUTHOR:upcase}}
In this case, the Emacs Lisp function `upcase' will be called on the
text value of the AUTHOR variable.
Macros can also be specialized to have different behaviors by using a
prefix, non-alpha character or symbol. For example:
{{! This is a comment inside macro escape characters }}
shows that the "!" symbol is for comments.
Alternately, a macro could query the user during insertion:
(defun {{?NAME}} ()
{{^}}
) ;; End of {{NAME}}
the "?" symbol indicates that if the symbol NAME isn't in the
dictionary, then the user should be queried for the NAME variable. If
NAME appears again in the template, the original value specified by the
user will be inserted again.
If the text from a dictionary value is to be placed in column format,
you can use the "|" symbol to indicate you want column control. For
example:
| this | that |{{#A}}
| {{|THIS:4}} | {{|THAT:4}} |{{/A}}
For each repeated section "#A" the dictionary values for THIS and
THAT will be inserted and either trimmed to, or expanded to 4
characters in width.
Macros that are prefixed with the "#" symbol denote a section. A
macro of the same name with a "/" prefix denotes the end of that
section.
{{#MOOSE}}
Here is some text describing moose.
{{/MOOSE}}
In this example if the section MOOSE was "shown" in the active
dictionary, then the text between the # and / macros will also be
inserted.
All the text and macros within a section are either not shown at all
(if that section is not 'visible') or the section is shown one time for
each dictionary added to that symbol. *Note Developing Template
Functions::.
Macros prefixed with ">" will include another template. Include
macros would look like this:
{{>FOO:defun}}
where `FOO' is the dictionary variable for the sub-dictionary used
for expanding the template `defun'. The `defun' template will be
looked up in the template repository for the current mode, or in any
inherited modes.
Another way to include another template is with an include macro that
will also wrap section text. The includewrap insertion method looks
like this:
{{<FOO:defun}}Handy Text goes here{{/FOO}}
In this case, `defun' is included just as above. If the `defun'
template has a {{^}} macro in it, then the section text "Handy Text
goes here" will be inserted at that point, and that location will not
be saved as the cursor location.
If there is no {{^}}, then the text will not be inserted.
For both kinds of include macros, you may need to include a template
from a different context. You can use `:' separate the context from
the name, like this:
{{>FOO:declaration:function}}
File: srecode.info, Node: Contexts, Next: Prompts, Prev: Templates, Up: Template Writing
5.3 Context
===========
Each template belongs to a context. When promting for a template by
name, such as with `C-c / /', the name is prefixed by the current
context. If there is no context, it defaults to `declaration'.
You can change context like this:
context NAME
where NAME is some symbol that represents any context.
A context resides over all templates that come after it until the
next context statement. Thus:
context C1
template foo
"Foo template in C1"
----
----
context C2
temlate foo
"Foo template in C2"
----
----
creates two `foo' templates. The first one is when in context C1.
The second is available in context C2.
This is useful if there are multiple ways to declare something like a
function or variable that differ only by where it is in the syntax of
the lanugage. The name `foo' is not ambiguous because each is in a
different context.
File: srecode.info, Node: Prompts, Prev: Contexts, Up: Template Writing
5.4 Prompt
==========
Some templates use promtping macro insertion. A macro that needs a
prompt looks like this:
{{?NAME}}
where ? comes after the first escape character.
by default, it will use a prompt like this when it is encountered:
Specify NAME:
For such macros, you can pre-define prompts for any dictionary entry.
When that dictionary entry is first encountered, the user is prompted,
and subsequent occurances of that dictionary entry use the same value.
To get a different prompt, use a prompt command like this:
prompt VARNAME "Nice Way to ask for VARNAME: "
Now, if you put this in a template:
template variable
----
(defvar {{?VARNAME}} nil
"")
----
when VARNAME is encountered, it will use the nice prompt.
Prompts can be extended as well. For example:
prompt VARNAME "VARNAME: " default "srecode" read y-or-n-p
In this case, the `default' keyword indicates that `"srecode"' is
the default string to use, and `y-or-n-p' is the function to use to ask
the question.
For `y-or-n-p' if you type "y" it inserts the default string,
otherwise it inserts empty.
For any other symbol that occurs after the `read' token, it is
expected to take the same argument list as `read-string'. As such, you
can create your own prompts that do completing reads on deterministic
values.
To have the default be calculated later from a dictionary entry, you
need to use the `defaultmacro' keyword instead.
prompt VARNAME "Varname: " defaultmacro "PREFIX"
now, when it attempts to read in VARNAME, it will pre-populte the
text editing section with whatever the value of PREFIX is.
Some language arguments may supply possible prefixes for prompts.
Look for these when creating your prompts.
File: srecode.info, Node: Dictionaries, Next: Developing Template Functions, Prev: Template Writing, Up: Top
6 Dictionaries
**************
Dictionaries are a set of variables. The values associated with the
variable names could be anything, but how it is handled is dependent on
the type of macro being inserted.
Most of this chapter is for writing Lisp programs that use SRecode.
If you only want to write template files, then you only need to read
the *note Template Argument Dictionary Entries:: section.
* Menu:
* Create a Dictionary::
* Setting Dictionary Values:: Basic dictionary values
* Compound Dictionary Values:: Complex dictionary values
* Argument Resolution:: Automatic template argument resolution
* Creating new Arguments:: Create new arguments for use in templates
* Querying a Dictionary:: Querying a dictionary for values.
* Template Argument Dictionary Entries:: Catalog of arguments
File: srecode.info, Node: Create a Dictionary, Next: Setting Dictionary Values, Up: Dictionaries
6.1 Create a Dictionary
=======================
-- Function: srecode-create-dictionary &optional buffer
Create a dictionary for BUFFER. If BUFFER is not specified, use
the current buffer. The dictionary is initialized with no
variables or enabled sections. Any variables defined with `set'
in the template, however, becomes a name in the dictionary.
File: srecode.info, Node: Setting Dictionary Values, Next: Compound Dictionary Values, Prev: Create a Dictionary, Up: Dictionaries
6.2 Setting Dictionary Values
=============================
When building an SRecode based application, you will need to setup your
dictionary values yourself. There are several utility functions for
this.
In the simplest form, you can assocate a string with a variable.
-- Function: srecode-dictionary-set-value dict name value
In dictionary DICT, set NAME to have VALUE.
For section macros, you can have alternate values. A section can
either be toggled as visible, or it can act as a loop.
-- Function: srecode-dictionary-show-section dict name
In dictionary DICT, indicate that the section NAME should be
exposed.
-- Function: srecode-dictionary-add-section-dictionary dict name
show-only
In dictionary DICT, add a section dictionary for section macro
NAME. Return the new dictionary.
You can add several dictionaries to the same section entry. For
each dictionary added to a variable, the block of codes in the
template will be repeated.
If optional argument SHOW-ONLY is non-`nil', then don't add a new
dictionarly if there is already one in place. Also, don't add
FIRST/LAST entries. These entries are not needed when we are just
showing a section.
Each dictionary added will automatically get values for positional
macros which will enable SECTIONS to be enabled.
FIRST
The first entry in the table.
NOTFIRST
Not the first entry in the table.
LAST
The last entry in the table
NOTLAST
Not the last entry in the table.
Adding a new dictionary will alter these values in previously
inserted dictionaries.
File: srecode.info, Node: Compound Dictionary Values, Next: Argument Resolution, Prev: Setting Dictionary Values, Up: Dictionaries
6.3 Compound Dictionary Values
==============================
If you want to associate a non-string value with a dictionary variable,
then you will need to use a compound value. Compound dictionary values
are derived using EIEIO from a base class for handling arbitrary data
in a macro.
-- Type: srecode-dictionary-compound-value
A compound dictionary value. Values stored in a dictionary must
be a STRING, a dictionary for showing sections, or an instance of
a subclass of this class.