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