* wesnoth-mode.el (wesnoth-guess-element-type): Rewritten to avoid recursion.
[wesnoth-mode.git] / wesnoth-mode.texi
blob5609670e5de55c0c6ca135d0e4c4171636eeb6da
1 \input texinfo
2 @c %**start of header
3 @setfilename wesnoth-mode.info
4 @settitle Wesnoth Mode Manual
6 @set VERSION 1.3.3
7 @set DATE October 2008
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 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 * Navigation::                  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
67 * Key Index::                   Index of Key-Bindings
69 @detailmenu
70  --- Detailed Node Listing ---
72 Introduction
74 * Summary::                     Introduction to Wesnoth Mode
75 * Getting Started::             How to start Wesnoth Mode
77 Navigation
79 * Navigation Introduction::     Common WML navigation
80 * Moving Across Elements::      Moving backward and forward across elements
81 * Matching Elements::           Moving to the matching element
83 Inserting Elements
85 * Standard Completion::         Completion commands and functionality
86 * Tab-Completion::              Element tab-completion
87 * Wrapping Elements::           Wrapping elements around sets of tags
88 * Missing Elements::            Finding and inserting missing elements
90 Checking WML
92 * Usage and Capabilities::      What to expect when checking WML
94 Customisation
96 * Indentation::                 Customising WML indentation
97 * Wesnoth Update::              Using and configuring Wesnoth Update
98 * Macro Definitions::           Making project-local macros known
100 @end detailmenu
101 @end menu
103 @node Introduction, Navigation, Top, Top
104 @chapter Introduction
106 @menu
107 * Summary::                     Introduction to Wesnoth Mode
108 * Getting Started::             How to start Wesnoth Mode
109 @end menu
111 @node Summary, Getting Started, Introduction, Introduction
112 @section Summary
114 Wesnoth Mode is a major mode for Emacs which assists in the editing of the
115 markup language extensively used in Wesnoth, a turn-based fantasy strategy
116 game.  From the Wesnoth Wiki: "The Wesnoth Markup Language (WML) is used to
117 code almost everything in Wesnoth, including scenarios, units, savefiles, and
118 the user interface layout." @footnote{@uref{http://www.wesnoth.org/wiki/ReferenceWML}}
120 Wesnoth Mode is supported under GNU Emacs 21 onwards and (with some
121 minor limitations) XEmacs 21.  Wesnoth Mode adds support for syntax
122 highlighting, automatic indentation, context-sensitive completion,
123 checking and much more when editing WML.
125 This documentation attempts to provide a comprehensive guide to
126 functionality available within Wesnoth Mode 1.3.3, and assumes you are
127 familiar with basic usage, terminology and customisation of Emacs.  For
128 more information, please refer to the Emacs
129 manual. @footnote{@uref{http://www.gnu.org/software/emacs/manual/html_node/emacs/}}
131 @node Getting Started, , Summary, Introduction
132 @section Getting Started
134 To use Wesnoth Mode, add the following to your @file{.emacs}:
135 @lisp
136 (add-to-list 'load-path "path/to/wesnoth-mode")
137 (autoload 'wesnoth-mode "wesnoth-mode" "Major mode for editing WML." t)
138 @end lisp
139 Optionally adding:
140 @lisp
141 (add-to-list 'auto-mode-alist '("\\.cfg\\'" . wesnoth-mode))
142 @end lisp
143 to automatically load Wesnoth Mode for all files with a `.cfg' extension.
145 If Wesnoth Mode is not the currently active major-mode for the current
146 buffer, it can be started via @kbd{M-x wesnoth-mode}.
148 The latest version of Wesnoth Mode along with release notes can be found at
149 @uref{http://www.wesnoth.org/forum/viewtopic.php?t=13798}.
151 @node Navigation, Inserting Elements, Introduction, Top
152 @chapter Navigation
154 @menu
155 * Navigation Introduction::     Common WML navigation
156 * Moving Across Elements::      Moving backward and forward across elements
157 * Matching Elements::           Moving to the matching element
158 @end menu
160 @node Navigation Introduction, Moving Across Elements, Navigation, Navigation
161 @section Navigation Introduction
163 Emacs provides many powerful built-in navigation commands which are
164 ideal for editing WML.  Common navigation commands, such as @kbd{C-n},
165 @kbd{C-s}, and (in recent Emacsen) @kbd{M-g g}, will behave as usual
166 within Wesnoth Mode.  However, some navigation commands have been
167 adjusted or added for increased productivity.  These will be explained
168 in the following sections.
170 @node Moving Across Elements, Matching Elements, Navigation Introduction, Navigation
171 @section Moving Across Elements
172 @kindex @kbd{C-M-a}
173 @kindex @kbd{C-M-e}
175 Next and previous opening elements can be navigated using @kbd{C-M-e}
176 and @kbd{C-M-a}, respectively.  In each case, point will be positioned
177 immediately before the element.  When there are no more elements are
178 available in that direction, point will not move.
180 @node Matching Elements,  , Moving Across Elements, Navigation
181 @section Matching Elements
182 @kindex @kbd{C-c C-o}
184 Moving to the matching element in a pair or locating the parent element
185 (depending on the position of point) can be performed via @kbd{C-c C-o}.
186 When point is on the same line as an opening element, such as an opening
187 tag or opening preprocessor statement it will be moved to the start of
188 the matching closing element.  Otherwise, the jump will position point
189 at the beginning of the corresponding opening element.
191 @node Inserting Elements, Checking WML, Navigation, Top
192 @chapter Inserting Elements
194 @menu
195 * Standard Completion::         Completion commands and functionality
196 * Tab-Completion::              Element tab-completion
197 * Wrapping Elements::           Wrapping elements around sets of tags
198 * Missing Elements::            Finding and inserting missing elements
199 @end menu
201 @node Standard Completion, Tab-Completion, Inserting Elements, Inserting Elements
202 @section Standard Completion
203 @kindex @kbd{C-c C-t}
204 @kindex @kbd{M-TAB}
205 @kindex @kbd{C-c C-a}
206 @kindex @kbd{C-c C-m}
207 @kindex @kbd{C-c C-p}
209 Tags can be inserted via @kbd{C-c C-t} and alternatively @kbd{M-TAB}
210 (when this is not shadowed by the Window Manager, etc.).  This will
211 prompt for the tag to add.  The tag entered into the mini-buffer prompt
212 and its matching closing tag will be inserted and point positioned
213 between.
215 Attributes can be inserted via @kbd{C-c C-a}.  The attribute entered at
216 the prompt will be inserted along with the `=', with point immediately
217 after.
219 Both tag and attribute completion is context-sensitive.  If an element
220 is available in WML and not listed for completion, you may want to add
221 it to your `addition file'.  See @ref{Wesnoth Update} for more
222 information.
224 Macro insertion can be performed via @kbd{C-c C-m}.  Any arguments known
225 to be required for the macro will be prompted and inserted in order.
226 Insertion will be aborted if no value for an argument is provided.  When
227 within a macro definition, macro arguments are also available to be
228 inserted.  Project-local macros will not be available until Wesnoth Mode
229 has scanned the buffer in which they are defined.  For information on
230 completing project-local macros, see @ref{Macro Definitions}.
232 Preprocessor statements are available for insertion via @kbd{C-c C-p}.
233 Closing elements for preprocessor statements will be automatically
234 inserted where possible, with point positioned between.  Otherwise,
235 point will be placed immediately after the inserted text.
237 @node Tab-Completion, Wrapping Elements, Standard Completion, Inserting Elements
238 @section Tab-Completion
239 @kindex @kbd{TAB}
240 Completion can also be performed immediately within the buffer via
241 @kbd{TAB} on a partial element.  For example:
242 @example
243 [scenario]
244     vil-!-
245 @end example
246 Where @code{-!-} is the position of point.  Using @kbd{TAB} in the
247 example will complete to @code{vil} to @code{village_gold=}.  Tags,
248 macros and preprocessor statements can be completed similarly.  When the
249 current line does not contain a partially completed element, @kbd{TAB}
250 will perform indentation on the current line.
252 When there is more than one possible completion, a minibuffer prompt
253 will be provided, with the partial element entered.  @kbd{TAB} can be
254 used here to perform completion.  If multiple matches are available,
255 completion will be performed up to the smallest common substring with
256 further completion available via the minubuffer prompt.  When no matches
257 are found, completion will not be prompted.
259 When completing opening preprocessor statements and tags, Wesnoth Mode
260 will also attempt to insert a matching closing element if one is not
261 already available, acting in much the same way as if the element was
262 added via the minibuffer prompt.  However, if an matching closing
263 element is available, only the element at point will be completed.
265 A numeric argument can be provided when performing tab-completion of
266 opening elements to wrap around the following @i{n} blocks.  For
267 example, to wrap the completed opening and closing pair around the next
268 three blocks, @kbd{C-u 3 TAB} can be used.  See @ref{Wrapping Elements}
269 for more information.
271 @node Wrapping Elements, Missing Elements, Tab-Completion, Inserting Elements
272 @section Wrapping Elements
273 When inserting tags and some preprocessor statements, either via their
274 respective insertion command or via @kbd{TAB}, an optional numeric
275 argument can be provided to specify the number of `blocks' to wrap the
276 element around.  For example:
278 @example
279 [multiplayer]
280  -!-[part]
281         ...
282     [/part]
283     [part]
284         ...
285     [/part]
286     [event]
287         ...
288 @end example
290 Where point is at the position indicated by @code{-!-}.  A pair of
291 @code{story} tags can be inserted around both existing @code{part} tags using
292 @kbd{C-u 2 C-c C-t story}.  When the number of blocks specified to wrap
293 around exceeds the number of blocks available, Wesnoth Mode will only
294 wrap around the number of available so that the nesting of elements is
295 correct.
297 @node Missing Elements, , Wrapping Elements, Inserting Elements
298 @section Missing Elements
299 @kindex @kbd{C-c C-/}
300 Missing closing elements can be inserted using @kbd{C-c C-/}.  By
301 default, this will insert the first missing closing element found in the
302 current buffer at point.  If all elements appear to be matched or if
303 there is an excess of closing tags, an appropriate message will be
304 displayed in the echo area.
306 @node Checking WML,  Customisation, Inserting Elements, Top
307 @chapter Checking WML
309 @menu
310 * Usage and Capabilities::      What to expect when checking WML
311 @end menu
313 @node Usage and Capabilities, , Checking WML, Checking WML
314 @section Usage and Capabilities
315 @kindex @kbd{C-c C-c}
316 @kindex @kbd{C-x `}
317 @kindex @kbd{C-c C-f}
318 @kindex @kbd{C-c C-b}
319 Checking of the current buffer can be performed using @kbd{C-c C-c}.  A
320 summary of all warnings located will be provided in a separate buffer.
321 Point can be jumped to the next and previous warning using @kbd{C-c C-f}
322 (or @kbd{C-x `}) and @kbd{C-c C-b}, respectively.  For visibility,
323 warnings in the checked WML buffer will be underlined in red by default.
324 @i{Note: Warning underlines may not be available in XEmacs.}
326 The WML checking built-in to Wesnoth Mode is not intended to
327 be an alternative to tools such as `wmllint', but may often be a
328 convenient substitute while editing WML.
330 The following conditions can be detected by WML checking in Wesnoth Mode:
331 @itemize
332 @item Correct nesting of tags and preprocessor statements
333 @item Known macro definitions @footnote{see @ref{Macro Definitions}}
334 @item Availability of elements within the given context
335 @item Arguments are given to preprocessor statements when required
336 @item Attributes have a value assigned
337 @item Corresponding FOREACH..NEXT pairs
338 @end itemize
340 WML checking is specific to the version of WML known by Wesnoth Mode.
341 See @ref{Wesnoth Update} for more information.
343 @node Customisation, Key Index, Checking WML, Top
344 @chapter Customisation
346 @menu
347 * Indentation::                 Customising WML indentation
348 * Wesnoth Update::              Using and configuring Wesnoth Update
349 * Macro Definitions::           making project-local macros known
350 @end menu
352 @node Indentation, Wesnoth Update, Customisation, Customisation
353 @section Indentation
355 The style of indentation can be customised using
356 @code{wesnoth-indent-savefile}.  The default value is @code{non-nil},
357 which results in all children being indented a level deeper than their
358 parent.  When set to @code{nil}, children will be indented to the same
359 level as their parent element.  This option is provided only for
360 consistency when editing (very) old WML.  It is recommended that all new
361 code be written using the new convention.
363 By default, Wesnoth Mode will attempt indentation of the current line
364 and create a newline and when @kbd{RET} or @kbd{C-j} are used.
365 @code{wesnoth-auto-indent-flag} controls whether Wesnoth Mode will
366 attempt to indent the current line automatically.  Setting this to
367 @code{nil} will prevent automatic indentation.  Note that this does not
368 affect the behaviour of @kbd{C-j} performing indentation following the
369 newline; this only determines whether indentation will be automatically
370 performed on the current line.
372 @code{wesnoth-base-indent} controls the depth of indentation for each
373 level.  Its value should be an integer.  This is set to `4' by default,
374 which is the convention used when indenting WML.
376 @code{wesnoth-warning-face} is the face used to display the overlay for
377 warnings detected when checking WML (See @ref{Checking WML}).  By
378 default this is a red underline.  Use of this face may not be supported
379 under XEmacs.
381 @node Wesnoth Update, Macro Definitions, Indentation, Customisation
382 @section Wesnoth Update
384 Wesnoth Update controls the known WML data for Wesnoth Mode.  To update
385 this information, three variables need to be set appropriately:
386 @code{wesnoth-root-directory}, @code{wesnoth-update-output-directory}
387 and @code{wesnoth-addition-file}.
389 @code{wesnoth-root-directory} should be the path to the root directory
390 of a Wesnoth installation or Wesnoth source code.  Wesnoth Update will
391 search recursively in this directory for WML, using the information
392 found to provide context-sensitive completion and WML checking.
394 @code{wesnoth-update-output-directory} specifies the path to store the
395 WML data found.  This path should be within the @code{load-path}, and
396 preferably, in the same directory as Wesnoth Mode.
398 @code{wesnoth-addition-file} specifies the `addition file' to use.  An
399 addition file is an outline of a valid WML file which is processed for
400 additional element data.  This should be set as the path a suitable
401 addition file.  A sample addition file is included with Wesnoth Mode.
403 For example:
404 @example
405 (setq wesnoth-root-directory "/usr/local/share/wesnoth/"
406       wesnoth-addition-file
407       "~/.emacs.d/wesnoth-mode/wesnoth-wml-additions.cfg"
408       wesnoth-update-output-directory "~/.emacs.d/wesnoth-mode/"
409 @end example
411 Once set, @kbd{M-x wesnoth-update} will generate and load a new cache of
412 WML data ready for use for the current and future sessions.  (Please
413 note, @code{wesnoth-update} may take some time to run.)
415 @node Macro Definitions, , Wesnoth Update, Customisation
416 @section Macro Definitions
417 @kindex @kbd{C-c C-u}
419 While built-in macros are always available, local macro definitions are
420 automatically scanned and made known to Wesnoth Mode for each WML file
421 which is loaded in the session. @kbd{C-c C-u} can be used to update the
422 known macro definitions for any buffer which has since been
423 modified. (Note that this is not required when the macro is defined in
424 the WML file currently being edited as such definitions will be
425 automatically updated when needed.)  @kbd{C-u C-c C-u} can be used to
426 clear known local macro definitions.
428 @node Key Index,  , Customisation, Top
429 @unnumbered Key Index
430 @printindex ky
432 @bye
434 @c Local Variables: 
435 @c mode: texinfo
436 @c TeX-master: t
437 @c End: