* wesnoth-mode.el (wesnoth-element): Removed FOREACH and NEXT. Interferes
[wesnoth-mode.git] / wesnoth-mode.texi
blob68b795c1357f6fa717f83b943b67f4a7dfc7274a
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 22 and 21 and (with some minor
121 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 mini-buffer prompt
253 will be provided, with the partial element entered.  @kbd{TAB} can be
254 used here to perform completion, and if no unique match is available,
255 provide a list of possible completions.
257 When completing opening preprocessor statements and tags, Wesnoth Mode
258 will also attempt to insert a matching closing element if one is not
259 already available, acting in much the same way as if the element was
260 added via the mini-buffer prompt.  However, if an matching closing
261 element is available, only the element at point will be completed.
263 A numeric argument can be provided when performing tab-completion of
264 opening elements to wrap around the following @i{n} blocks.  For
265 example, to wrap the completed opening and closing pair around the next
266 three blocks, @kbd{C-u 3 TAB} can be used.  See @ref{Wrapping Elements}
267 for more information.
269 @node Wrapping Elements, Missing Elements, Tab-Completion, Inserting Elements
270 @section Wrapping Elements
271 When inserting tags and some preprocessor statements, either via their
272 respective insertion command or via @kbd{TAB}, an optional numeric
273 argument can be provided to specify the number of `blocks' to wrap the
274 element around.  For example, this was an outline of the buffer:
276 @example
277 [multiplayer]
278  -!-[part]
279         ...
280     [/part]
281     [part]
282         ...
283     [/part]
284     [event]
285         ...
286 @end example
288 Where point is at the position indicated by @code{-!-}.  A pair of
289 @code{story} tags can be inserted around both existing @code{part} tags using
290 @kbd{C-u 2 C-c C-t story}.  When the number of blocks specified to wrap
291 around exceeds the number of blocks available, Wesnoth Mode will only
292 wrap around the number of available so that the nesting of elements is
293 correct.
295 @node Missing Elements, , Wrapping Elements, Inserting Elements
296 @section Missing Elements
297 @kindex @kbd{C-c C-/}
298 Missing closing elements can be inserted using @kbd{C-c C-/}.  By
299 default, this will insert the first missing closing element found in the
300 current buffer at point.  If all elements appear to be matched or if
301 there is an excess of closing tags, an appropriate message will be
302 displayed in the echo area.
304 @i{Note: The following does not apply to XEmacs.}
306 The region Wesnoth Mode checks for missing elements can be adjusted
307 enabling transient-mark-mode prior to inserting the missing element.  To
308 narrow the region checked, move to the start of the region and enable
309 transient-mark-mode (this is bound to @kbd{C-Space C-Space} by default)
310 at point temporarily by default.  Then move point to the location to
311 insert the missing element and use @kbd{C-c C-/}.  The first missing tag
312 located in the region will be inserted at point.
314 @node Checking WML,  Customisation, Inserting Elements, Top
315 @chapter Checking WML
317 @menu
318 * Usage and Capabilities::      What to expect when checking WML
319 @end menu
321 @node Usage and Capabilities, , Checking WML, Checking WML
322 @section Usage and Capabilities
323 @kindex @kbd{C-c C-c}
324 @kindex @kbd{C-x `}
325 @kindex @kbd{C-c C-f}
326 @kindex @kbd{C-c C-b}
327 Checking of the current buffer can be performed using @kbd{C-c C-c}.  A
328 summary of all warnings located will be provided in a separate buffer.
329 Point can be jumped to the next and previous warning using @kbd{C-c C-f}
330 (or @kbd{C-x `}) and @kbd{C-c C-b}, respectively.  For visibility,
331 warnings in the checked WML buffer will be underlined in red by default.
333 The WML checking built-in to Wesnoth Mode is not intended to
334 be an alternative to tools such as `wmllint', but may often be a
335 convenient substitute while editing WML.
337 The following conditions can be detected by WML checking in Wesnoth Mode:
338 @itemize
339 @item Correct nesting of tags and preprocessor statements
340 @item Known macro definitions @footnote{see @ref{Macro Definitions}}
341 @item Availability of elements within the given context
342 @item Arguments are given to preprocessor statements when required
343 @item Attributes have a value assigned
344 @end itemize
346 WML checking is specific to the version of WML known by Wesnoth Mode.
347 See @ref{Wesnoth Update} for more information.
349 @node Customisation, Key Index, Checking WML, Top
350 @chapter Customisation
352 @menu
353 * Indentation::                 Customising WML indentation
354 * Wesnoth Update::              Using and configuring Wesnoth Update
355 * Macro Definitions::           making project-local macros known
356 @end menu
358 @node Indentation, Wesnoth Update, Customisation, Customisation
359 @section Indentation
361 The style of indentation can be customised using
362 @code{wesnoth-indent-savefile}.  The default value is @code{non-nil},
363 which results in all children being indented a level deeper than their
364 parent.  When set to @code{nil}, children will be indented to the same
365 level as their parent element.  This option is provided only for
366 consistency when editing (very) old WML.  It is recommended that all new
367 code be written using the `savefile style'.
369 By default, Wesnoth Mode will attempt indentation of the current line
370 and create a newline and when @kbd{RET} or @kbd{C-j} are used.
371 @code{wesnoth-auto-indent-flag} controls whether Wesnoth Mode will
372 attempt to indent the current line automatically.  Setting this to
373 @code{nil} will prevent automatic indentation.  Note that this does not
374 affect the behaviour of @kbd{C-j} performing indentation following the
375 newline; this only determines whether indentation will be automatically
376 performed on the current line.
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 @code{wesnoth-warning-face} the face used to display the overlay on
383 warnings, by default, this is a red underline.
385 @node Wesnoth Update, Macro Definitions, Indentation, Customisation
386 @section Wesnoth Update
388 Wesnoth Update controls the known WML data for Wesnoth Mode.  To update
389 this information, three variables need to be set appropriately:
390 @code{wesnoth-root-directory}, @code{wesnoth-update-output-directory}
391 and @code{wesnoth-addition-file}.
393 @code{wesnoth-root-directory} should be the path to the root directory
394 of a Wesnoth installation or Wesnoth source code.  Wesnoth Update will
395 search recursively in this directory for WML, using the information
396 found to provide context-sensitive completion and WML checking.
398 @code{wesnoth-update-output-directory} specifies the path to store the
399 WML data found.  This path should be within the @code{load-path}, and
400 preferably, in the same directory as Wesnoth Mode.
402 @code{wesnoth-addition-file} specifies the `addition file' to use.  An
403 addition file is an outline of a valid WML file which is processed for
404 additional element data.  This should be set as the path a suitable
405 addition file.  A sample addition file is included with Wesnoth Mode.
407 For example:
408 @example
409 (setq wesnoth-root-directory "/usr/local/share/wesnoth/"
410       wesnoth-addition-file
411       "~/.emacs.d/wesnoth-mode/wesnoth-wml-additions.cfg"
412       wesnoth-update-output-directory "~/.emacs.d/wesnoth-mode/"
413 @end example
415 Once set, @kbd{M-x wesnoth-update} will generate and load a new cache of
416 WML data ready for use for the current and future sessions.  (Please
417 note, @code{wesnoth-update} may take some time to run.)
419 @node Macro Definitions, , Wesnoth Update, Customisation
420 @section Macro Definitions
421 @kindex @kbd{C-c C-u}
423 While built-in macros are always available, local macro definitions are
424 automatically scanned and made known to Wesnoth Mode for each WML file
425 which is loaded in the session. @kbd{C-c C-u} can be used to update the
426 known macro definitions for any buffer which has since been
427 modified. (Note that this is not required when the macro is defined in
428 the WML file currently being edited as such definitions will be
429 automatically updated when needed.)  @kbd{C-u C-c C-u} can be used to
430 clear known local macro definitions.
432 @node Key Index,  , Customisation, Top
433 @unnumbered Key Index
434 @printindex ky
436 @bye
438 @c Local Variables: 
439 @c mode: texinfo
440 @c TeX-master: t
441 @c End: