srecode.texi 55 KB

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