* README: Added reference to online documentation.
[wesnoth-mode.git] / wesnoth-mode.texi
blob60298b281b0fab721467d8fb04cc9e4d340e6dcf
1 \input texinfo
2 @c %**start of header
3 @setfilename wesnoth-mode.info
4 @settitle Wesnoth Mode Manual
6 @set VERSION 1.3.2
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, 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 (assuming 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}.  If the macro
225 entered is known to require arguments, point will be positioned before
226 the closing curly bracket ready to input any arguments, otherwise it
227 will be positioned immediately after.  When within a macro definition,
228 macro arguments are also available to be inserted.  Project-local macros
229 will not be available until Wesnoth Mode has scanned the buffer in which
230 they are defined.  For information on completing project-local macros,
231 see @ref{Macro Definitions}.
233 Preprocessor statements are available for insertion via @kbd{C-c C-p}.
234 Closing elements for preprocessor statements will be automatically
235 inserted where possible, with point positioned between.  Otherwise,
236 point will be placed immediately after the inserted text.
238 @node Tab-Completion, Wrapping Elements, Standard Completion, Inserting Elements
239 @section Tab-Completion
240 @kindex @kbd{TAB}
241 Completion can also be performed immediately within the buffer via
242 @kbd{TAB} on a partial element.  For example:
243 @example
244 [scenario]
245     vil-!-
246 @end example
247 Where @code{-!-} is the position of point.  Using @kbd{TAB} in the
248 example will complete to @code{vil} to @code{village_gold=}.  Tags,
249 macros and preprocessor statements can be completed similarly.
251 When there is more than one possible completion, a mini-buffer prompt
252 will be provided, with the partial element entered.  @kbd{TAB} can be
253 used here to perform completion, and if no unique match is available,
254 provide a list of possible completions.
256 When completing opening preprocessor statements and tags, Wesnoth Mode
257 will also attempt to insert a matching closing element if one is not
258 already available, acting in much the same way as if the element was
259 added via the mini-buffer prompt.  However, if an matching closing
260 element is available, only the element at point will be completed.
262 A numeric argument can be provided when performing tab-completion of
263 opening elements to wrap around the following @i{n} blocks.  For
264 example, to wrap the completed opening and closing pair around the next
265 three blocks, @kbd{C-u 3 TAB} can be used.  See @ref{Wrapping Elements}
266 for more information.
268 @node Wrapping Elements, Missing Elements, Tab-Completion, Inserting Elements
269 @section Wrapping Elements
270 When inserting tags and some preprocessor statements, either via their
271 respective insertion command or via @kbd{TAB}, an optional numeric
272 argument can be provided to specify the number of `blocks' to wrap the
273 element around.  For example, this was an outline of the buffer:
275 @example
276 [multiplayer]
277  -!-[part]
278         ...
279     [/part]
280     [part]
281         ...
282     [/part]
283     [event]
284         ...
285 @end example
287 Where point is at the position indicated by @code{-!-}.  A pair of
288 @code{story} tags can be inserted around both existing @code{part} tags using
289 @kbd{C-u 2 C-c C-t story}.  When the number of blocks specified to wrap
290 around exceeds the number of blocks available, Wesnoth Mode will only
291 wrap around the number of available so that the nesting of elements is
292 correct.
294 @node Missing Elements, , Wrapping Elements, Inserting Elements
295 @section Missing Elements
296 @kindex @kbd{C-c C-/}
297 Missing closing elements can be inserted using @kbd{C-c C-/}.  By
298 default, this will insert the first missing closing element found in the
299 current buffer at point.  If all elements appear to be matched or if
300 there is an excess of closing tags, an appropriate message will be
301 displayed in the echo area.
303 @i{Note: The following does not apply to XEmacs.}
305 The region Wesnoth Mode checks for missing elements can be adjusted
306 enabling transient-mark-mode prior to inserting the missing element.  To
307 narrow the region checked, move to the start of the region and enable
308 transient-mark-mode (this is bound to @kbd{C-Space C-Space} by default)
309 at point temporarily by default.  Then move point to the location to
310 insert the missing element and use @kbd{C-c C-/}.  The first missing tag
311 located in the region will be inserted at point.
313 @node Checking WML,  Customisation, Inserting Elements, Top
314 @chapter Checking WML
316 @menu
317 * Usage and Capabilities::      What to expect when checking WML
318 @end menu
320 @node Usage and Capabilities, , Checking WML, Checking WML
321 @section Usage and Capabilities
322 @kindex @kbd{C-c C-c}
323 Checking of the current buffer can be performed using @kbd{C-c C-c}.
324 Any potential problems found will be reported in a separate buffer named
325 ``*WML*''.  The WML checking built-in to Wesnoth Mode is not intended to
326 act as an alternative to tools such as `wmllint', but may often be
327 a convenient substitute while editing WML.
329 The following conditions can be detected by WML checking in Wesnoth Mode:
330 @itemize
331 @item Correct tag / preprocessor nesting
332 @item Known macro definitions @footnote{see @ref{Macro Definitions}}
333 @item Availability of elements within the given context
334 @item Arguments are given to preprocessor statements when required
335 @item Whether attributes have been given a value
336 @end itemize
338 When a problem has been found, Wesnoth Mode will provide the line number
339 and a description of the problem in the report.  WML checking is
340 specific to the version of WML known by Wesnoth Mode.  See @ref{Wesnoth
341 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 `savefile style'.
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 @node Wesnoth Update, Macro Definitions, Indentation, Customisation
377 @section Wesnoth Update
379 Wesnoth Update controls the known WML data for Wesnoth Mode.  To update
380 this information, three variables need to be set appropriately:
381 @code{wesnoth-root-directory}, @code{wesnoth-update-output-directory}
382 and @code{wesnoth-addition-file}.
384 @code{wesnoth-root-directory} should be the path to the root directory
385 of a Wesnoth installation or Wesnoth source code.  Wesnoth Update will
386 search recursively in this directory for WML, using the information
387 found to provide context-sensitive completion and WML checking.
389 @code{wesnoth-update-output-directory} specifies the path to store the
390 WML data found.  This path should be within the @code{load-path}, and
391 preferably, in the same directory as Wesnoth Mode.
393 @code{wesnoth-addition-file} specifies the `addition file' to use.  An
394 addition file is an outline of a valid WML file which is processed for
395 additional element data.  This should be set as the path a suitable
396 addition file.  A sample addition file is included with Wesnoth Mode.
398 For example:
399 @example
400 (setq wesnoth-root-directory "/usr/local/share/wesnoth/"
401       wesnoth-addition-file
402       "~/.emacs.d/wesnoth-mode/wesnoth-wml-additions.cfg"
403       wesnoth-update-output-directory "~/.emacs.d/wesnoth-mode/"
404 @end example
406 Once set, @kbd{M-x wesnoth-update} will generate and load a new cache of
407 WML data ready for use for the current and future sessions.  (Please
408 note, @code{wesnoth-update} may take some time to run.)
410 @node Macro Definitions, , Wesnoth Update, Customisation
411 @section Macro Definitions
412 @kindex @kbd{C-c C-u}
414 While built-in macros are always available, local macro definitions are
415 automatically scanned and made known to Wesnoth Mode for each WML file
416 which is loaded in the session. @kbd{C-c C-u} can be used to update the
417 known macro definitions for any buffer which has since been
418 modified. (Note that this is not required when the macro is defined in
419 the WML file currently being edited as such definitions will be
420 automatically updated when needed.)  @kbd{C-u C-c C-u} can be used to
421 clear known local macro definitions.
423 @node Key Index,  , Customisation, Top
424 @unnumbered Key Index
425 @printindex ky
427 @bye
429 @c Local Variables: 
430 @c mode: texinfo
431 @c TeX-master: t
432 @c End: