*WML* buffer can now be buried via 'q'.
[wesnoth-mode.git] / wesnoth-mode.texi
blob56568a886ef5a170e7bca7d18bed303a244a73e2
1 \input texinfo
2 @setfilename wesnoth-mode.info
3 @settitle Wesnoth Mode Manual
5 @set VERSION 1.3.5+git
6 @set WMLVERSION 1.5.14
7 @set DATE February 2009
9 @dircategory Emacs
10 @direntry
11 * Wesnoth Mode: (wesnoth-mode).         Major-mode for editing WML
12 @end direntry
14 @set MAINTAINERSITE @uref{http://www.wesnoth.org/forum/viewtopic.php?t=13798}
15 @set AUTHOR Chris Mann
16 @finalout
18 @copying
19 This manual is for Wesnoth Mode (version @value{VERSION}).
21 Copyright @copyright{} 2008, 2009 Chris Mann
23 @quotation
24 This program is free software; you can redistribute it and/or modify it
25 under the terms of the GNU General Public License as published by the
26 Free Software Foundation; either version 2 of the License, or (at your
27 option) any later version.
29 This program is distributed in the hope that it will be useful, but
30 WITHOUT ANY WARRANTY; without even the implied warranty of
31 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
32 General Public License for more details.
34 You should have received a copy of the GNU General Public License along
35 with this program; if not, write to the Free Software Foundation, Inc.,
36 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
37 @end quotation
38 @end copying
40 @titlepage
41 @title Wesnoth Mode Manual
42 @subtitle Version @value{VERSION}
43 @author by @value{AUTHOR}
44 @page
46 @vskip 0pt plus 1filll
47 @insertcopying
48 @end titlepage
50 @summarycontents
52 @ifnottex
53 @node Top, Introduction, (dir), (dir)
54 @top Wesnoth Mode Manual
56 @insertcopying
57 @end ifnottex
59 @menu
60 * Introduction::                Getting started
61 * Basic Usage::                 Moving around within WML
62 * Inserting Elements::          Insertion and completion of elements
63 * Validating WML::              Validating WML for common problems
64 * Customisation::               Available customisation options
66 @detailmenu
67  --- Detailed Node Listing ---
69 Introduction
71 * Summary::                     Introduction to Wesnoth Mode
72 * Getting Started::             How to start Wesnoth Mode
74 Basic Usage
76 * Indentation::                 Indentation usage and styles
77 * Navigation::                  Common WML navigation
78 * Editing Extras::              Specialised editing commands
80 Inserting Elements
82 * Standard Completion::         Completion commands and functionality
83 * Tab Completion::              Element tab completion
84 * Wrapping Elements::           Wrapping elements around sets of tags
85 * Missing Elements::            Finding and inserting missing elements
87 Validating WML
89 * Usage and Capabilities::      What to expect when validating WML
91 Customisation
93 * Modifying Indentation::       Customising WML indentation
94 * Wesnoth Update::              Using and configuring Wesnoth Update
95 * Addition File::               Extending known WML
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, save files, 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 validation and 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}.
151 Alternatively, the development version is available using git.  To
152 checkout the latest changes, the following command can be used:
153 @example
154 @code{git clone git://repo.or.cz/wesnoth-mode.git}.
155 @end example
157 @node Basic Usage, Inserting Elements, Introduction, Top
158 @chapter Basic Usage
160 @menu
161 * Indentation::                     Common WML navigation
162 * Navigation::                      Moving backward and forward across elements
163 * Editing Extras::                  Specialised editing commands
164 @end menu
166 @node Indentation, Navigation, Basic Usage, Basic Usage
167 @section Indentation
168 By default, Wesnoth Mode provides a style of indentation equivalent to
169 that provided by @code{wmlindent} tool distributed with Wesnoth.
170 @kbd{TAB} can be used to automatically indent the current line to the
171 correct depth.  Two actions can be performed depending on the context of
172 point.  When there is an incomplete element immediately preceding point,
173 completion will be attempted, otherwise indentation will be performed.
174 See @ref{Tab Completion}.
176 Wesnoth Mode will, by default, indent the current line appropriately
177 before inserting a newline when @kbd{RET} or @kbd{C-j} is
178 used. (@kbd{C-j} will also attempt to indent the new line.)
180 See @ref{Modifying Indentation} for information on how to customise the
181 behaviour of automatic indentation.
183 @node Navigation, Editing Extras, Indentation, Basic Usage
184 @section Navigation
186 Built-in commands for navigation are available.  This section describes
187 additional or modified navigation commands specific to Wesnoth Mode.
189 Next and previous opening elements can be navigated using @kbd{C-M-e}
190 and @kbd{C-M-a}, respectively.  In each case, point will be positioned
191 immediately before the element.  When no more elements are available in
192 that direction, the position of point will not change.
194 Moving to the matching element in a pair or locating the parent element
195 (depending on the position of point) can be performed via @kbd{C-c C-o}.
196 When point is on the same line as an opening element, such as an opening
197 tag or opening preprocessor statement it will be moved to the start of
198 the matching closing element.  Otherwise, the jump will position point
199 at the beginning of the corresponding opening element.
201 Structured navigation is available with @kbd{C-M-n} and @kbd{C-M-p}
202 providing the ability to move to the next and previous blocks
203 (respectively) which are at the same depth as the element where the
204 command was invoked.  @kbd{C-M-d} will move to the child of the element
205 at point and @kbd{C-M-u} moving to the corresponding parent element.
207 @node Editing Extras,  , Navigation, Basic Usage
208 @section Editing Extras
210 Additional commands have been added to assist editing regions of WML.
211 @kbd{C-M-k} can be used to kill the element at point up to the
212 corresponding closing element, including all contents.  A prefix
213 argument can be provided to kill the next @i{n} blocks of elements.
214 Also, when point is at an opening element, the mark can be placed at the
215 end of the corresponding closing element using @kbd{C-M-SPC}.
217 @node Inserting Elements, Validating WML, Basic Usage, Top
218 @chapter Inserting Elements
220 @menu
221 * Standard Completion::         Completion commands and functionality
222 * Tab Completion::              Element tab completion
223 * Wrapping Elements::           Wrapping elements around sets of tags
224 * Missing Elements::            Finding and inserting missing elements
225 @end menu
227 @node Standard Completion, Tab Completion, Inserting Elements, Inserting Elements
228 @section Standard Completion
230 Tags can be inserted via @kbd{C-c C-t} and alternatively @kbd{M-TAB}
231 (when this is not shadowed by the Window Manager, etc.) which will
232 prompt for the tag to add.  The tag entered into the minibuffer prompt
233 and its matching closing tag will be inserted and point positioned
234 between.
236 Attributes can be inserted via @kbd{C-c C-a}.  Any attribute entered at
237 the prompt will be inserted along with the `=', with point immediately
238 following.
240 Both tag and attribute completion is context-sensitive.  If an element
241 is available in WML and not listed for completion, it can be added to
242 the `addition file'.  See @ref{Addition File} for more information.
244 Macro insertion can be performed via @kbd{C-c C-m}.  Any arguments known
245 to be required for the macro will be prompted and inserted in order.
246 Insertion will be aborted if no value for an argument is provided.  When
247 within a macro definition, the arguments for the current macro are also
248 available for completion.  Any project-local or custom macros can be
249 made available for completion by opening the file in which they are
250 defined.  For information, see @ref{Macro Definitions}.
252 Preprocessor statements are available for insertion via @kbd{C-c C-p}.
253 Closing elements for preprocessor statements will be automatically
254 inserted where possible, with point positioned between.  Otherwise,
255 point will be placed immediately after the inserted text.
257 @node Tab Completion, Wrapping Elements, Standard Completion, Inserting Elements
258 @section Tab Completion
260 Completion can also be performed immediately within the buffer via
261 @kbd{TAB} on a partial element.  For example:
262 @example
263 [scenario]
264     vil-!-
265 @end example
266 Where @code{-!-} is the position of point.  Using @kbd{TAB} in the
267 example will complete to @code{vil} to @code{village_gold=}.  Tags,
268 macros and preprocessor statements can be completed similarly.  When the
269 current line does not contain a partially completed element, @kbd{TAB}
270 will perform indentation on the current line.
272 When there is more than one possible completion, a minibuffer prompt
273 will be provided, with the partial element entered.  @kbd{TAB} can be
274 used here to perform completion.  If multiple matches are available,
275 completion will be performed up to the smallest common substring with
276 further completion available via the minibuffer prompt.  When no matches
277 are found for the partial element, completion will not be prompted.
279 When completing opening preprocessor statements and tags, Wesnoth Mode
280 will also attempt to insert a matching closing element if one is not
281 already available, acting in much the same way as if the element was
282 added via the minibuffer prompt.  However, if an matching closing
283 element is available, only the element at point will be completed.
285 A numeric argument can be provided when performing tab completion of
286 opening elements to wrap around the next @i{n} blocks.  For
287 example, to wrap the completed opening and closing pair around the next
288 three blocks, @kbd{C-u 3 TAB} can be used.  See @ref{Wrapping Elements}
289 for more information.
291 @node Wrapping Elements, Missing Elements, Tab Completion, Inserting Elements
292 @section Wrapping Elements
293 When inserting tags and some preprocessor statements, either via their
294 respective insertion command or via @kbd{TAB}, an optional numeric
295 argument can be provided to specify the number of `blocks' to wrap the
296 element around.  For example:
298 @example
299 [multiplayer]
300  -!-[part]
301         ...
302     [/part]
303     [part]
304         ...
305     [/part]
306     [event]
307         ...
308 @end example
310 Where point is at the position indicated by @code{-!-}.  A pair of
311 @code{story} tags can be inserted around both existing @code{part} tags
312 using @kbd{C-u 2 C-c C-t story}.  When the number of blocks specified to
313 wrap around exceeds the number of blocks available, Wesnoth Mode will
314 only wrap around the number of available so that the nesting of elements
315 is correct.
317 @node Missing Elements, , Wrapping Elements, Inserting Elements
318 @section Missing Elements
319 Missing closing elements can be inserted using @kbd{C-c C-/}.  By
320 default, this will insert the first missing closing element found in the
321 current buffer at point.  If all elements appear to be matched or if
322 there is an excess of closing tags, a notification will be displayed and
323 no element will be inserted.
325 @node Validating WML, Customisation, Inserting Elements, Top
326 @chapter Validating WML
328 @menu
329 * Usage and Capabilities::      What to expect when validating WML
330 @end menu
332 @node Usage and Capabilities, , Validating WML, Validating WML
333 @section Usage and Capabilities
335 Validating WML in the current buffer can be performed using @kbd{C-c C-c},
336 with a summary of all warnings found reported in a separate buffer.
337 Point can be jumped to the next and previous warning using @kbd{C-c C-f}
338 (or @kbd{C-x `}) and @kbd{C-c C-b}, respectively.  For visibility,
339 warnings will be underlined in red by default.  @i{Note: Warning
340 underlines may not be available in XEmacs.}
342 The WML validation built-in to Wesnoth Mode is not intended to be an
343 alternative to tools such as `wmllint', but may often be a convenient
344 substitute while editing WML.
346 The following conditions can be tested in Wesnoth Mode:
347 @itemize
348 @item Correct nesting of tags and preprocessor statements
349 @item Known macro definitions @footnote{see @ref{Macro Definitions}}
350 @item Availability of elements within the given context
351 @item Arguments are given to preprocessor statements when required
352 @item Attributes have a value
353 @item Corresponding FOREACH..NEXT pairs
354 @end itemize
356 WML validation is specific to the version of WML known by Wesnoth Mode.
357 See @ref{Wesnoth Update} for more information.
359 @node Customisation, , Validating WML, Top
360 @chapter Customisation
362 @menu
363 * Modifying Indentation::       Customising WML indentation
364 * Wesnoth Update::              Using and configuring Wesnoth Update
365 * Addition File::               Extending known WML
366 * Macro Definitions::           Making project-local macros known
367 @end menu
369 @node Modifying Indentation, Wesnoth Update, Customisation, Customisation
370 @section Modifying Indentation
372 The style of indentation can be customised using
373 @code{wesnoth-indent-savefile}.  The default value is @code{t},
374 which results in all children being indented a level deeper than their
375 parent.  When set to @code{nil}, children will be indented to the same
376 level as their parent element.  This option is provided only for
377 consistency when editing (very) old WML.  It is recommended that this be
378 non-nil for all new WML.
380 @code{wesnoth-indent-preprocessor-bol} controls how preprocessor
381 statements should be indented.  If non-nil, all preprocessor statements
382 will be indented to the beginning of the line.  Otherwise, preprocessor
383 statements will be indented as to the level indicated by its context.
385 By default, Wesnoth Mode will attempt indentation of the current line
386 and create a newline and when @kbd{RET} or @kbd{C-j} are used.
387 @code{wesnoth-auto-indent-flag} controls whether Wesnoth Mode will
388 attempt to indent the current line automatically.  Setting this to
389 @code{nil} will prevent automatic indentation.  Note that this does not
390 affect the behaviour of @kbd{C-j} performing indentation following the
391 newline; this only determines whether indentation will be automatically
392 performed on the current line.
394 The following can be used to change @kbd{RET} to automatically indent the
395 newline:
396 @lisp
397 (add-hook 'wesnoth-mode-hook
398   '(lambda ()
399     (define-key wesnoth-mode-map (kbd ``C-m'')
400     'wesnoth-newline-and-indent)))
401 @end lisp
403 @code{wesnoth-base-indent} controls the depth of indentation for each
404 level.  Its value should be an integer.  This is set to `4' by default,
405 which is the convention used when indenting WML.
407 By default, Wesnoth Mode will use spaces for indentation.  Tabs can instead be used with the following:
408 @lisp
409 (add-hook 'wesnoth-mode-hook
410   '(lambda ()
411     (setq indent-tabs-mode t
412           tab-width wesnoth-base-indent)))
413 @end lisp
415 @code{wesnoth-warning-face} is the face used to display the overlay for
416 warnings detected when Validating WML (See @ref{Validating WML}).  By
417 default this is a red underline.  @i{Note: use of this face may not be supported
418 under XEmacs.}
420 @node Wesnoth Update, Addition File, Modifying Indentation, Customisation
421 @section Wesnoth Update
423 Wesnoth Update is an extension to Wesnoth Mode which retrieves
424 information regarding valid WML structure using WML included with
425 Wesnoth.  To update WML data known to Wesnoth Mode, two variables need
426 to be set appropriately: @code{wesnoth-root-directory} and
427 @code{wesnoth-update-output-directory}.
429 @code{wesnoth-root-directory} should be the path to the root directory
430 of a Wesnoth installation or Wesnoth source code.  Wesnoth Update will
431 search recursively in this directory for WML, using the information
432 found to provide context-sensitive completion and WML validation.
434 @code{wesnoth-update-output-directory} specifies the path to store the
435 WML data found.  This path should be within the @code{load-path}, and
436 preferably, in the same directory as Wesnoth Mode.
438 For example:
439 @lisp
440 (setq wesnoth-root-directory "/usr/local/share/wesnoth/"
441       wesnoth-update-output-directory "~/.emacs.d/wesnoth-mode/")
442 @end lisp
444 Once set, @kbd{M-x wesnoth-update} will generate and load a new cache of
445 WML data ready for use for the current and future sessions.  @i{Note:
446 'wesnoth-update' may take some time to run.}
448 Wesnoth Mode @value{VERSION} uses WML data retrieved from Wesnoth
449 @value{WMLVERSION}, by default.
451 @node Addition File, Macro Definitions, Wesnoth Update, Customisation
452 @section Addition File
454 @code{wesnoth-addition-file} specifies the `addition file' to use.  An
455 addition file is an outline of a valid WML structure which is processed
456 to provide more comprehensive completion and validation by providing
457 access to elements which may not have been available when running
458 @code{wesnoth-update}.
460 The value of @code{wesnoth-addition-file} should be set as the path to a
461 suitable addition file.  A sample addition file is included with Wesnoth
462 Mode.
464 For example, the following could be used to specify an addition file:
465 @lisp
466 (setq wesnoth-addition-file
467       "~/.emacs.d/wesnoth-mode/wesnoth-wml-additions.cfg")
468 @end lisp
470 The addition file is read and information regarding WML structure
471 updated any time WML information is required.  Therefore, no further
472 action is required to use the updated WML data once any changes to the
473 addition file are saved to disk.
475 @node Macro Definitions, , Addition File, Customisation
476 @section Macro Definitions
478 While built-in macros are always available, local macro definitions are
479 automatically scanned and made known to Wesnoth Mode for each WML file
480 which is loaded in the session. @kbd{C-c C-u} can be used to update the
481 known macro definitions for any buffer which has since been
482 modified. (Note that this is not required when the macro is defined in
483 the WML file currently being edited as such definitions will be
484 automatically updated when needed.)  @kbd{C-u C-c C-u} can be used to
485 clear known local macro definitions.
487 @bye
489 @c Local Variables: 
490 @c mode: texinfo
491 @c TeX-master: t
492 @c End: