* wesnoth-wml-data.el: Updated for WML used in Wesnoth 1.5.11.
[wesnoth-mode.git] / wesnoth-mode.texi
blob4ff0ae58b8d8ef149044a25e84e9148b9c4a6a2d
1 \input texinfo
2 @c %**start of header
3 @setfilename wesnoth-mode.info
4 @settitle Wesnoth Mode Manual
6 @set VERSION 1.3.5-git
7 @set DATE February 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 @value{AUTHOR}
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 release of Wesnoth Mode along with release notes can be found
149 at @uref{http://www.wesnoth.org/forum/viewtopic.php?t=13798}.
150 Alternatively, the development version is available using git.  To
151 checkout the latest changes, the following command can be used:
152 @code{git clone git://repo.or.cz/wesnoth-mode.git}.
154 @node Basic Usage, Inserting Elements, Introduction, Top
155 @chapter Basic Usage
157 @menu
158 * Indentation::                     Common WML navigation
159 * Navigation::                      Moving backward and forward across elements
160 @end menu
162 @node Indentation, Navigation, Basic Usage, Basic Usage
163 @section Indentation
164 By default, Wesnoth Mode provides a style of indentation equivalent to
165 that provided by @code{wmlindent} tool distributed with Wesnoth.
166 @kbd{TAB} can be used to automatically indent the current line to the
167 correct depth.  @kbd{TAB} can perform two actions depending on the
168 context of point.  When there is an incomplete element immediately
169 preceeding point, completion will be attempted, otherwise @kbd{TAB} will
170 perform indentation.  See @ref{Tab-Completion}.
172 Wesnoth Mode will, by default, indent the current line appropriately
173 before inserting a newline when @kbd{RET} or @kbd{C-j} is
174 used. (@kbd{C-j} will also attempt to indent the new line.)
176 See @ref{Modifying Indentation} for information on how to customise the
177 behaviour of automatic indentation.
179 @node Navigation,  , Indentation, Basic Usage
180 @section Navigation
182 Built-in commands for navigation are available.  This section describes
183 additional or modified navigation commands specific to Wesnoth Mode.
185 Next and previous opening elements can be navigated using @kbd{C-M-e}
186 and @kbd{C-M-a}, respectively.  In each case, point will be positioned
187 immediately before the element.  When no more elements are available in
188 that direction, the position of point will not change.
190 Moving to the matching element in a pair or locating the parent element
191 (depending on the position of point) can be performed via @kbd{C-c C-o}.
192 When point is on the same line as an opening element, such as an opening
193 tag or opening preprocessor statement it will be moved to the start of
194 the matching closing element.  Otherwise, the jump will position point
195 at the beginning of the corresponding opening element.
197 Structured navigation is available with @kbd{C-M-n} and @kbd{C-M-p}
198 providing the ability to move to the next and previous blocks
199 (respectively) which are at the same depth as the element where the
200 command was invoked.  @kbd{C-M-d} will move to the child of the element
201 at point and @kbd{C-M-u} moving to the corresponding parent element.
203 @node Inserting Elements, Checking WML, Basic Usage, Top
204 @chapter Inserting Elements
206 @menu
207 * Standard Completion::         Completion commands and functionality
208 * Tab-Completion::              Element tab-completion
209 * Wrapping Elements::           Wrapping elements around sets of tags
210 * Missing Elements::            Finding and inserting missing elements
211 @end menu
213 @node Standard Completion, Tab-Completion, Inserting Elements, Inserting Elements
214 @section Standard Completion
216 Tags can be inserted via @kbd{C-c C-t} and alternatively @kbd{M-TAB}
217 (when this is not shadowed by the Window Manager, etc.) which will
218 prompt for the tag to add.  The tag entered into the minibuffer prompt
219 and its matching closing tag will be inserted and point positioned
220 between.
222 Attributes can be inserted via @kbd{C-c C-a}.  Any attribute entered at
223 the prompt will be inserted along with the `=', with point immediately
224 following.
226 Both tag and attribute completion is context-sensitive.  If an element
227 is available in WML and not listed for completion, it can be added to
228 the `addition file'.  See @ref{Wesnoth Update} for more information.
230 Macro insertion can be performed via @kbd{C-c C-m}.  Any arguments known
231 to be required for the macro will be prompted and inserted in order.
232 Insertion will be aborted if no value for an argument is provided.  When
233 within a macro definition, the arguments for the current macro are also
234 available for completion.  Any project-local or custom macros can be
235 made available for completion by opening the file in which they are
236 defined.  For information, see @ref{Macro Definitions}.
238 Preprocessor statements are available for insertion via @kbd{C-c C-p}.
239 Closing elements for preprocessor statements will be automatically
240 inserted where possible, with point positioned between.  Otherwise,
241 point will be placed immediately after the inserted text.
243 @node Tab-Completion, Wrapping Elements, Standard Completion, Inserting Elements
244 @section Tab-Completion
246 Completion can also be performed immediately within the buffer via
247 @kbd{TAB} on a partial element.  For example:
248 @example
249 [scenario]
250     vil-!-
251 @end example
252 Where @code{-!-} is the position of point.  Using @kbd{TAB} in the
253 example will complete to @code{vil} to @code{village_gold=}.  Tags,
254 macros and preprocessor statements can be completed similarly.  When the
255 current line does not contain a partially completed element, @kbd{TAB}
256 will perform indentation on the current line.
258 When there is more than one possible completion, a minibuffer prompt
259 will be provided, with the partial element entered.  @kbd{TAB} can be
260 used here to perform completion.  If multiple matches are available,
261 completion will be performed up to the smallest common substring with
262 further completion available via the minubuffer prompt.  When no matches
263 are found for the partial element, completion will not be prompted.
265 When completing opening preprocessor statements and tags, Wesnoth Mode
266 will also attempt to insert a matching closing element if one is not
267 already available, acting in much the same way as if the element was
268 added via the minibuffer prompt.  However, if an matching closing
269 element is available, only the element at point will be completed.
271 A numeric argument can be provided when performing tab-completion of
272 opening elements to wrap around the next @i{n} blocks.  For
273 example, to wrap the completed opening and closing pair around the next
274 three blocks, @kbd{C-u 3 TAB} can be used.  See @ref{Wrapping Elements}
275 for more information.
277 @node Wrapping Elements, Missing Elements, Tab-Completion, Inserting Elements
278 @section Wrapping Elements
279 When inserting tags and some preprocessor statements, either via their
280 respective insertion command or via @kbd{TAB}, an optional numeric
281 argument can be provided to specify the number of `blocks' to wrap the
282 element around.  For example:
284 @example
285 [multiplayer]
286  -!-[part]
287         ...
288     [/part]
289     [part]
290         ...
291     [/part]
292     [event]
293         ...
294 @end example
296 Where point is at the position indicated by @code{-!-}.  A pair of
297 @code{story} tags can be inserted around both existing @code{part} tags
298 using @kbd{C-u 2 C-c C-t story}.  When the number of blocks specified to
299 wrap around exceeds the number of blocks available, Wesnoth Mode will
300 only wrap around the number of available so that the nesting of elements
301 is correct.
303 @node Missing Elements, , Wrapping Elements, Inserting Elements
304 @section Missing Elements
305 Missing closing elements can be inserted using @kbd{C-c C-/}.  By
306 default, this will insert the first missing closing element found in the
307 current buffer at point.  If all elements appear to be matched or if
308 there is an excess of closing tags, a notification will be displayed and
309 no element will be inserted.
311 @node Checking WML, Customisation, Inserting Elements, Top
312 @chapter Checking WML
314 @menu
315 * Usage and Capabilities::      What to expect when checking WML
316 @end menu
318 @node Usage and Capabilities, , Checking WML, Checking WML
319 @section Usage and Capabilities
321 Checking WML in the current buffer can be performed using @kbd{C-c C-c},
322 with a summary of all warnings found reported in a separate buffer.
323 Point can be jumped to the next and previous warning using @kbd{C-c C-f}
324 (or @kbd{C-x `}) and @kbd{C-c C-b}, respectively.  For visibility,
325 warnings will be underlined in red by default.  @i{Note: Warning
326 underlines may not be available in XEmacs.}
328 The WML checking built-in to Wesnoth Mode is not intended to be an
329 alternative to tools such as `wmllint', but may often be a convenient
330 substitute while editing WML.
332 The following conditions can be detected by WML checking in Wesnoth
333 Mode:
334 @itemize
335 @item Correct nesting of tags and preprocessor statements
336 @item Known macro definitions @footnote{see @ref{Macro Definitions}}
337 @item Availability of elements within the given context
338 @item Arguments are given to preprocessor statements when required
339 @item Attributes have a value assigned
340 @item Corresponding FOREACH..NEXT pairs
341 @end itemize
343 WML checking is specific to the version of WML known by Wesnoth Mode.
344 See @ref{Wesnoth Update} for more information.
346 @node Customisation, , Checking WML, Top
347 @chapter Customisation
349 @menu
350 * Modifying Indentation::       Customising WML indentation
351 * Wesnoth Update::              Using and configuring Wesnoth Update
352 * Macro Definitions::           making project-local macros known
353 @end menu
355 @node Modifying Indentation, Wesnoth Update, Customisation, Customisation
356 @section Modifying Indentation
358 The style of indentation can be customised using
359 @code{wesnoth-indent-savefile}.  The default value is @code{t},
360 which results in all children being indented a level deeper than their
361 parent.  When set to @code{nil}, children will be indented to the same
362 level as their parent element.  This option is provided only for
363 consistency when editing (very) old WML.  It is recommended that this be
364 non-nil for all new WML.
366 @code{wesnoth-indent-preprocessor-bol} controls how preprocessor
367 statements should be indented.  If non-nil, all preprocessor statements
368 will be indented to the beginning of the line.  Otherwise, preprocessor
369 statements will be indented as to the level indicated by its context.
371 By default, Wesnoth Mode will attempt indentation of the current line
372 and create a newline and when @kbd{RET} or @kbd{C-j} are used.
373 @code{wesnoth-auto-indent-flag} controls whether Wesnoth Mode will
374 attempt to indent the current line automatically.  Setting this to
375 @code{nil} will prevent automatic indentation.  Note that this does not
376 affect the behaviour of @kbd{C-j} performing indentation following the
377 newline; this only determines whether indentation will be automatically
378 performed on the current line.
380 The following can be used to change @kbd{RET} to automatically indent the
381 newline:
382 @example
383 (add-hook 'wesnoth-mode-hook
384   '(lambda ()
385     (define-key wesnoth-mode-map (kbd ``C-m'')
386     'wesnoth-newline-and-indent)))
387 @end example
389 @code{wesnoth-base-indent} controls the depth of indentation for each
390 level.  Its value should be an integer.  This is set to `4' by default,
391 which is the convention used when indenting WML.
393 By default, Wesnoth Mode will use spaces for indentation.  Tabs can instead be used with the following:
394 @example
395 (add-hook 'wesnoth-mode-hook
396   '(lambda ()
397     (setq indent-tabs-mode t
398           tab-width wesnoth-base-indent)))
399 @end example
401 @code{wesnoth-warning-face} is the face used to display the overlay for
402 warnings detected when checking WML (See @ref{Checking WML}).  By
403 default this is a red underline.  @i{Note: use of this face may not be supported
404 under XEmacs.}
406 @node Wesnoth Update, Macro Definitions, Modifying Indentation, Customisation
407 @section Wesnoth Update
409 Wesnoth Update controls the known WML data for Wesnoth Mode.  To update
410 this information, two variables need to be set appropriately:
411 @code{wesnoth-root-directory} and @code{wesnoth-update-output-directory}.
413 @code{wesnoth-root-directory} should be the path to the root directory
414 of a Wesnoth installation or Wesnoth source code.  Wesnoth Update will
415 search recursively in this directory for WML, using the information
416 found to provide context-sensitive completion and WML checking.
418 @code{wesnoth-update-output-directory} specifies the path to store the
419 WML data found.  This path should be within the @code{load-path}, and
420 preferably, in the same directory as Wesnoth Mode.
422 For example:
423 @example
424 (setq wesnoth-root-directory "/usr/local/share/wesnoth/"
425       wesnoth-update-output-directory "~/.emacs.d/wesnoth-mode/")
426 @end example
428 Once set, @kbd{M-x wesnoth-update} will generate and load a new cache of
429 WML data ready for use for the current and future sessions.  @i{Note:
430 @code{wesnoth-update} may take some time to run.}
432 @code{wesnoth-addition-file} specifies the `addition file' to use.  An
433 addition file is an outline of a valid WML file which is processed for
434 additional element data which may not have been detected when running
435 @code{wesnoth-update}.  This should be set as the path to a suitable
436 addition file.  A sample addition file is included with Wesnoth Mode.
438 The addition data is read from the file and updated any time tag
439 information is required, therefore no action needs to be taken to adjust
440 tag data other than saving the addition file when modified.
442 For example, the following could be used to specify an addition file:
443 @example
444 (setq wesnoth-addition-file
445       "~/.emacs.d/wesnoth-mode/wesnoth-wml-additions.cfg")
446 @end example
448 @node Macro Definitions, , Wesnoth Update, Customisation
449 @section Macro Definitions
451 While built-in macros are always available, local macro definitions are
452 automatically scanned and made known to Wesnoth Mode for each WML file
453 which is loaded in the session. @kbd{C-c C-u} can be used to update the
454 known macro definitions for any buffer which has since been
455 modified. (Note that this is not required when the macro is defined in
456 the WML file currently being edited as such definitions will be
457 automatically updated when needed.)  @kbd{C-u C-c C-u} can be used to
458 clear known local macro definitions.
460 @bye
462 @c Local Variables: 
463 @c mode: texinfo
464 @c TeX-master: t
465 @c End: