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