* wesnoth-mode.texi: Minor indentation change.
[wesnoth-mode.git] / wesnoth-mode.texi
blob6467b34bf9ce6ebb0cfb5e9f0ed2d469f6b394f4
1 \input texinfo
2 @c %**start of header
3 @setfilename wesnoth-mode.info
4 @settitle Wesnoth Mode Manual
6 @set VERSION 1.3.4
7 @set DATE January 2009
9 @dircategory Emacs
10 @direntry
11 * Wesnoth Mode: (wesnoth-mode).         Major-mode for editing WML
12 @end direntry
14 @c Contact information
15 @set MAINTAINERSITE @uref{http://www.wesnoth.org/forum/viewtopic.php?t=13798}
16 @set AUTHOR Chris Mann
17 @c %**end of header
18 @finalout
20 @copying
21 This manual is for Wesnoth Mode (version @value{VERSION}).
23 Copyright @copyright{} 2008, 2009 Chris Mann
25 @quotation
26 This program is free software; you can redistribute it and/or modify it
27 under the terms of the GNU General Public License as published by the
28 Free Software Foundation; either version 2 of the License, or (at your
29 option) any later version.
31 This program is distributed in the hope that it will be useful, but
32 WITHOUT ANY WARRANTY; without even the implied warranty of
33 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
34 General Public License for more details.
36 You should have received a copy of the GNU General Public License along
37 with this program; if not, write to the Free Software Foundation, Inc.,
38 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
39 @end quotation
40 @end copying
42 @titlepage
43 @title Wesnoth Mode Manual
44 @subtitle Version @value{VERSION}
45 @author by Chris Mann
47 @page
49 @vskip 0pt plus 1fill
50 @insertcopying
51 @end titlepage
53 @contents
54 @ifnottex
55 @node Top, Introduction, (dir), (dir)
56 @top Wesnoth Mode Manual
58 @insertcopying
59 @end ifnottex
61 @menu
62 * Introduction::                Getting started
63 * Basic Usage::                 Moving around within WML
64 * Inserting Elements::          Insertion and completion of elements
65 * Checking WML::                Checking WML for common problems
66 * Customisation::               Available customisation options
68 @detailmenu
69  --- Detailed Node Listing ---
71 Introduction
73 * Summary::                     Introduction to Wesnoth Mode
74 * Getting Started::             How to start Wesnoth Mode
76 Basic Usage
78 * Indentation::                 Indentation usage and styles
79 * Navigation::                  Common WML navigation
81 Inserting Elements
83 * Standard Completion::         Completion commands and functionality
84 * Tab-Completion::              Element tab-completion
85 * Wrapping Elements::           Wrapping elements around sets of tags
86 * Missing Elements::            Finding and inserting missing elements
88 Checking WML
90 * Usage and Capabilities::      What to expect when checking WML
92 Customisation
94 * Indentation::                 Customising WML indentation
95 * Wesnoth Update::              Using and configuring Wesnoth Update
96 * Macro Definitions::           Making project-local macros known
98 @end detailmenu
99 @end menu
101 @node Introduction, Basic Usage, Top, Top
102 @chapter Introduction
104 @menu
105 * Summary::                     Introduction to Wesnoth Mode
106 * Getting Started::             How to start Wesnoth Mode
107 @end menu
109 @node Summary, Getting Started, Introduction, Introduction
110 @section Summary
112 Wesnoth Mode is a major mode for Emacs which assists in the editing of
113 the markup language extensively used in Wesnoth, a turn-based fantasy
114 strategy game.  From the Wesnoth Wiki: "The Wesnoth Markup Language
115 (WML) is used to code almost everything in Wesnoth, including scenarios,
116 units, savefiles, and the user interface layout."
117 @footnote{@uref{http://www.wesnoth.org/wiki/ReferenceWML}}
119 Wesnoth Mode is supported under GNU Emacs 21 onwards and (with some
120 minor limitations) XEmacs 21.  Wesnoth Mode adds support for syntax
121 highlighting, automatic indentation, context-sensitive completion,
122 checking and much more when editing WML.
124 This documentation attempts to provide a comprehensive guide to
125 functionality available within Wesnoth Mode @value{VERSION}, and assumes
126 you are familiar with basic usage, terminology and customisation of
127 Emacs.  For more information, please refer to the Emacs
128 manual. @footnote{@uref{http://www.gnu.org/software/emacs/manual/html_node/emacs/}}
130 @node Getting Started, , Summary, Introduction
131 @section Getting Started
133 To use Wesnoth Mode, add the following to your @file{.emacs}:
134 @lisp
135 (add-to-list 'load-path "path/to/wesnoth-mode")
136 (autoload 'wesnoth-mode "wesnoth-mode" "Major mode for editing WML." t)
137 @end lisp
138 Optionally adding:
139 @lisp
140 (add-to-list 'auto-mode-alist '("\\.cfg\\'" . wesnoth-mode))
141 @end lisp
142 to automatically load Wesnoth Mode for all files with a `.cfg'
143 extension.
145 Wesnoth Mode can be activated as the current major-mode for a buffer via
146 @kbd{M-x wesnoth-mode}.
148 The latest version of Wesnoth Mode along with release notes can be found
149 at @uref{http://www.wesnoth.org/forum/viewtopic.php?t=13798}.
151 @node Basic Usage, Inserting Elements, Introduction, Top
152 @chapter Basic Usage
154 @menu
155 * Indentation::                     Common WML navigation
156 * Navigation::                      Moving backward and forward across elements
157 @end menu
159 @node Indentation, Navigation, Basic Usage, Basic Usage
160 @section Indentation
161 @kindex @kbd{TAB}
162 By default, Wesnoth Mode provides a style of indentation equivalent to
163 that provided by the @code{wmlindent} tool included with Wesnoth.
164 @kbd{TAB} can be used to indent the current line manually.  Wesnoth Mode
165 will, by default, indent the current line appropriately before inserting
166 a newline when @kbd{RET} or @kbd{C-j} is used. (@kbd{C-j} will also
167 attempt to indent the new line.)
169 See @ref{Modifying Indentation} for information on how to customise the
170 behaviour of automatic indentation.
172 @kbd{TAB} performs two actions depending on the context of point.  When
173 there is an incomplete element immediately preceeding point, completion
174 will be attempted, otherwise @kbd{TAB} will perform indentation.  See
175 @ref{Tab-Completion}.
177 @node Navigation,  , Indentation, Basic Usage
178 @section Navigation
180 Next and previous opening elements can be navigated using @kbd{C-M-e}
181 and @kbd{C-M-a}, respectively.  In each case, point will be positioned
182 immediately before the element.  When no more elements are available in
183 that direction, point will not move.
185 Moving to the matching element in a pair or locating the parent element
186 (depending on the position of point) can be performed via @kbd{C-c C-o}.
187 When point is on the same line as an opening element, such as an opening
188 tag or opening preprocessor statement it will be moved to the start of
189 the matching closing element.  Otherwise, the jump will position point
190 at the beginning of the corresponding opening element.
192 @node Inserting Elements, Checking WML, Basic Usage, Top
193 @chapter Inserting Elements
195 @menu
196 * Standard Completion::         Completion commands and functionality
197 * Tab-Completion::              Element tab-completion
198 * Wrapping Elements::           Wrapping elements around sets of tags
199 * Missing Elements::            Finding and inserting missing elements
200 @end menu
202 @node Standard Completion, Tab-Completion, Inserting Elements, Inserting Elements
203 @section Standard Completion
205 Tags can be inserted via @kbd{C-c C-t} and alternatively @kbd{M-TAB}
206 (when this is not shadowed by the Window Manager, etc.) which will
207 prompt for the tag to add.  The tag entered into the minibuffer prompt
208 and its matching closing tag will be inserted and point positioned
209 between.
211 Attributes can be inserted via @kbd{C-c C-a}.  Any attribute entered at
212 the prompt will be inserted along with the `=', with point immediately
213 following.
215 Both tag and attribute completion is context-sensitive.  If an element
216 is available in WML and not listed for completion, it can be added to
217 the `addition file'.  See @ref{Wesnoth Update} for more information.
219 Macro insertion can be performed via @kbd{C-c C-m}.  Any arguments known
220 to be required for the macro will be prompted and inserted in order.
221 Insertion will be aborted if no value for an argument is provided.  When
222 within a macro definition, the arguments for the current macro are also
223 available for completion.  Any project-local or custom macros can be
224 made available for completion by opening the file in which they are
225 defined.  For information, see @ref{Macro Definitions}.
227 Preprocessor statements are available for insertion via @kbd{C-c C-p}.
228 Closing elements for preprocessor statements will be automatically
229 inserted where possible, with point positioned between.  Otherwise,
230 point will be placed immediately after the inserted text.
232 @node Tab-Completion, Wrapping Elements, Standard Completion, Inserting Elements
233 @section Tab-Completion
235 Completion can also be performed immediately within the buffer via
236 @kbd{TAB} on a partial element.  For example:
237 @example
238 [scenario]
239     vil-!-
240 @end example
241 Where @code{-!-} is the position of point.  Using @kbd{TAB} in the
242 example will complete to @code{vil} to @code{village_gold=}.  Tags,
243 macros and preprocessor statements can be completed similarly.  When the
244 current line does not contain a partially completed element, @kbd{TAB}
245 will perform indentation on the current line.
247 When there is more than one possible completion, a minibuffer prompt
248 will be provided, with the partial element entered.  @kbd{TAB} can be
249 used here to perform completion.  If multiple matches are available,
250 completion will be performed up to the smallest common substring with
251 further completion available via the minubuffer prompt.  When no matches
252 are found for the partial element, completion will not be prompted.
254 When completing opening preprocessor statements and tags, Wesnoth Mode
255 will also attempt to insert a matching closing element if one is not
256 already available, acting in much the same way as if the element was
257 added via the minibuffer prompt.  However, if an matching closing
258 element is available, only the element at point will be completed.
260 A numeric argument can be provided when performing tab-completion of
261 opening elements to wrap around the next @i{n} blocks.  For
262 example, to wrap the completed opening and closing pair around the next
263 three blocks, @kbd{C-u 3 TAB} can be used.  See @ref{Wrapping Elements}
264 for more information.
266 @node Wrapping Elements, Missing Elements, Tab-Completion, Inserting Elements
267 @section Wrapping Elements
268 When inserting tags and some preprocessor statements, either via their
269 respective insertion command or via @kbd{TAB}, an optional numeric
270 argument can be provided to specify the number of `blocks' to wrap the
271 element around.  For example:
273 @example
274 [multiplayer]
275  -!-[part]
276         ...
277     [/part]
278     [part]
279         ...
280     [/part]
281     [event]
282         ...
283 @end example
285 Where point is at the position indicated by @code{-!-}.  A pair of
286 @code{story} tags can be inserted around both existing @code{part} tags
287 using @kbd{C-u 2 C-c C-t story}.  When the number of blocks specified to
288 wrap around exceeds the number of blocks available, Wesnoth Mode will
289 only wrap around the number of available so that the nesting of elements
290 is correct.
292 @node Missing Elements, , Wrapping Elements, Inserting Elements
293 @section Missing Elements
294 Missing closing elements can be inserted using @kbd{C-c C-/}.  By
295 default, this will insert the first missing closing element found in the
296 current buffer at point.  If all elements appear to be matched or if
297 there is an excess of closing tags, a notification will be displayed and
298 no element will be inserted.
300 @node Checking WML, Customisation, Inserting Elements, Top
301 @chapter Checking WML
303 @menu
304 * Usage and Capabilities::      What to expect when checking WML
305 @end menu
307 @node Usage and Capabilities, , Checking WML, Checking WML
308 @section Usage and Capabilities
310 Checking WML in the current buffer can be performed using @kbd{C-c C-c},
311 with a summary of all warnings found reported in a separate buffer.
312 Point can be jumped to the next and previous warning using @kbd{C-c C-f}
313 (or @kbd{C-x `}) and @kbd{C-c C-b}, respectively.  For visibility,
314 warnings will be underlined in red by default.  @i{Note: Warning
315 underlines may not be available in XEmacs.}
317 The WML checking built-in to Wesnoth Mode is not intended to be an
318 alternative to tools such as `wmllint', but may often be a convenient
319 substitute while editing WML.
321 The following conditions can be detected by WML checking in Wesnoth
322 Mode:
323 @itemize
324 @item Correct nesting of tags and preprocessor statements
325 @item Known macro definitions @footnote{see @ref{Macro Definitions}}
326 @item Availability of elements within the given context
327 @item Arguments are given to preprocessor statements when required
328 @item Attributes have a value assigned
329 @item Corresponding FOREACH..NEXT pairs
330 @end itemize
332 WML checking is specific to the version of WML known by Wesnoth Mode.
333 See @ref{Wesnoth Update} for more information.
335 @node Customisation, , Checking WML, Top
336 @chapter Customisation
338 @menu
339 * Modifying Indentation::       Customising WML indentation
340 * Wesnoth Update::              Using and configuring Wesnoth Update
341 * Macro Definitions::           making project-local macros known
342 @end menu
344 @node Modifying Indentation, Wesnoth Update, Customisation, Customisation
345 @section Modifying Indentation
347 The style of indentation can be customised using
348 @code{wesnoth-indent-savefile}.  The default value is @code{t},
349 which results in all children being indented a level deeper than their
350 parent.  When set to @code{nil}, children will be indented to the same
351 level as their parent element.  This option is provided only for
352 consistency when editing (very) old WML.  It is recommended that this be
353 non-nil for all new WML.
355 @code{wesnoth-indent-preprocessor-bol} controls how preprocessor
356 statements should be indented.  If non-nil, all preprocessor statements
357 will be indented to the beginning of the line.  Otherwise, preprocessor
358 statements will be indented as to the level indicated by its context.
360 By default, Wesnoth Mode will attempt indentation of the current line
361 and create a newline and when @kbd{RET} or @kbd{C-j} are used.
362 @code{wesnoth-auto-indent-flag} controls whether Wesnoth Mode will
363 attempt to indent the current line automatically.  Setting this to
364 @code{nil} will prevent automatic indentation.  Note that this does not
365 affect the behaviour of @kbd{C-j} performing indentation following the
366 newline; this only determines whether indentation will be automatically
367 performed on the current line.
369 The following can be used to change @kbd{RET} to automatically indent the
370 newline:
371 @example
372 (add-hook 'wesnoth-mode-hook
373   '(lambda ()
374     (define-key wesnoth-mode-map (kbd ``C-m'')
375     'wesnoth-newline-and-indent)))
376 @end example
378 @code{wesnoth-base-indent} controls the depth of indentation for each
379 level.  Its value should be an integer.  This is set to `4' by default,
380 which is the convention used when indenting WML.
382 By default, Wesnoth Mode will use spaces for indentation.  Tabs can instead be used with the following:
383 @example
384 (add-hook 'wesnoth-mode-hook
385   '(lambda ()
386     (setq indent-tabs-mode t
387           tab-width wesnoth-base-indent)))
388 @end example
390 @code{wesnoth-warning-face} is the face used to display the overlay for
391 warnings detected when checking WML (See @ref{Checking WML}).  By
392 default this is a red underline.  @i{Note: use of this face may not be supported
393 under XEmacs.}
395 @node Wesnoth Update, Macro Definitions, Modifying Indentation, Customisation
396 @section Wesnoth Update
398 Wesnoth Update controls the known WML data for Wesnoth Mode.  To update
399 this information, two variables need to be set appropriately:
400 @code{wesnoth-root-directory} and @code{wesnoth-update-output-directory}.
402 @code{wesnoth-root-directory} should be the path to the root directory
403 of a Wesnoth installation or Wesnoth source code.  Wesnoth Update will
404 search recursively in this directory for WML, using the information
405 found to provide context-sensitive completion and WML checking.
407 @code{wesnoth-update-output-directory} specifies the path to store the
408 WML data found.  This path should be within the @code{load-path}, and
409 preferably, in the same directory as Wesnoth Mode.
411 For example:
412 @example
413 (setq wesnoth-root-directory "/usr/local/share/wesnoth/"
414       wesnoth-update-output-directory "~/.emacs.d/wesnoth-mode/")
415 @end example
417 Once set, @kbd{M-x wesnoth-update} will generate and load a new cache of
418 WML data ready for use for the current and future sessions.  @i{Note:
419 @code{wesnoth-update} may take some time to run.}
421 @code{wesnoth-addition-file} specifies the `addition file' to use.  An
422 addition file is an outline of a valid WML file which is processed for
423 additional element data which may not have been detected when running
424 @code{wesnoth-update}.  This should be set as the path to a suitable
425 addition file.  A sample addition file is included with Wesnoth Mode.
427 The addition data is read from the file and updated any time tag
428 information is required, therefore no action needs to be taken to adjust
429 tag data other than saving the addition file when modified.
431 For example, the following could be used to specify an addition file:
432 @example
433 (setq wesnoth-addition-file
434       "~/.emacs.d/wesnoth-mode/wesnoth-wml-additions.cfg")
435 @end example
437 @node Macro Definitions, , Wesnoth Update, Customisation
438 @section Macro Definitions
440 While built-in macros are always available, local macro definitions are
441 automatically scanned and made known to Wesnoth Mode for each WML file
442 which is loaded in the session. @kbd{C-c C-u} can be used to update the
443 known macro definitions for any buffer which has since been
444 modified. (Note that this is not required when the macro is defined in
445 the WML file currently being edited as such definitions will be
446 automatically updated when needed.)  @kbd{C-u C-c C-u} can be used to
447 clear known local macro definitions.
449 @bye
451 @c Local Variables: 
452 @c mode: texinfo
453 @c TeX-master: t
454 @c End: