* wesnoth-mode.el (wesnoth-kill-block): Add support for prefix arg and
[wesnoth-mode.git] / wesnoth-mode.texi
blob54f20458c1a5ceffb9f4ae8b422478200e55583d
1 \input texinfo
2 @setfilename wesnoth-mode.info
3 @settitle Wesnoth Mode Manual
5 @set VERSION 1.3.5
6 @set WMLVERSION 1.5.11
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, 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 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.  @kbd{TAB} can perform two actions depending on the
172 context of point.  When there is an incomplete element immediately
173 preceding point, completion will be attempted, otherwise @kbd{TAB} will
174 perform indentation.  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.  Also, when point
213 is at an opening element, the mark can be placed at the end of the
214 corresponding closing element using @kbd{C-M-SPC}.
216 @node Inserting Elements, Validating WML, Basic Usage, Top
217 @chapter Inserting Elements
219 @menu
220 * Standard Completion::         Completion commands and functionality
221 * Tab Completion::              Element tab completion
222 * Wrapping Elements::           Wrapping elements around sets of tags
223 * Missing Elements::            Finding and inserting missing elements
224 @end menu
226 @node Standard Completion, Tab Completion, Inserting Elements, Inserting Elements
227 @section Standard Completion
229 Tags can be inserted via @kbd{C-c C-t} and alternatively @kbd{M-TAB}
230 (when this is not shadowed by the Window Manager, etc.) which will
231 prompt for the tag to add.  The tag entered into the minibuffer prompt
232 and its matching closing tag will be inserted and point positioned
233 between.
235 Attributes can be inserted via @kbd{C-c C-a}.  Any attribute entered at
236 the prompt will be inserted along with the `=', with point immediately
237 following.
239 Both tag and attribute completion is context-sensitive.  If an element
240 is available in WML and not listed for completion, it can be added to
241 the `addition file'.  See @ref{Addition File} for more information.
243 Macro insertion can be performed via @kbd{C-c C-m}.  Any arguments known
244 to be required for the macro will be prompted and inserted in order.
245 Insertion will be aborted if no value for an argument is provided.  When
246 within a macro definition, the arguments for the current macro are also
247 available for completion.  Any project-local or custom macros can be
248 made available for completion by opening the file in which they are
249 defined.  For information, see @ref{Macro Definitions}.
251 Preprocessor statements are available for insertion via @kbd{C-c C-p}.
252 Closing elements for preprocessor statements will be automatically
253 inserted where possible, with point positioned between.  Otherwise,
254 point will be placed immediately after the inserted text.
256 @node Tab Completion, Wrapping Elements, Standard Completion, Inserting Elements
257 @section Tab Completion
259 Completion can also be performed immediately within the buffer via
260 @kbd{TAB} on a partial element.  For example:
261 @example
262 [scenario]
263     vil-!-
264 @end example
265 Where @code{-!-} is the position of point.  Using @kbd{TAB} in the
266 example will complete to @code{vil} to @code{village_gold=}.  Tags,
267 macros and preprocessor statements can be completed similarly.  When the
268 current line does not contain a partially completed element, @kbd{TAB}
269 will perform indentation on the current line.
271 When there is more than one possible completion, a minibuffer prompt
272 will be provided, with the partial element entered.  @kbd{TAB} can be
273 used here to perform completion.  If multiple matches are available,
274 completion will be performed up to the smallest common substring with
275 further completion available via the minibuffer prompt.  When no matches
276 are found for the partial element, completion will not be prompted.
278 When completing opening preprocessor statements and tags, Wesnoth Mode
279 will also attempt to insert a matching closing element if one is not
280 already available, acting in much the same way as if the element was
281 added via the minibuffer prompt.  However, if an matching closing
282 element is available, only the element at point will be completed.
284 A numeric argument can be provided when performing tab completion of
285 opening elements to wrap around the next @i{n} blocks.  For
286 example, to wrap the completed opening and closing pair around the next
287 three blocks, @kbd{C-u 3 TAB} can be used.  See @ref{Wrapping Elements}
288 for more information.
290 @node Wrapping Elements, Missing Elements, Tab Completion, Inserting Elements
291 @section Wrapping Elements
292 When inserting tags and some preprocessor statements, either via their
293 respective insertion command or via @kbd{TAB}, an optional numeric
294 argument can be provided to specify the number of `blocks' to wrap the
295 element around.  For example:
297 @example
298 [multiplayer]
299  -!-[part]
300         ...
301     [/part]
302     [part]
303         ...
304     [/part]
305     [event]
306         ...
307 @end example
309 Where point is at the position indicated by @code{-!-}.  A pair of
310 @code{story} tags can be inserted around both existing @code{part} tags
311 using @kbd{C-u 2 C-c C-t story}.  When the number of blocks specified to
312 wrap around exceeds the number of blocks available, Wesnoth Mode will
313 only wrap around the number of available so that the nesting of elements
314 is correct.
316 @node Missing Elements, , Wrapping Elements, Inserting Elements
317 @section Missing Elements
318 Missing closing elements can be inserted using @kbd{C-c C-/}.  By
319 default, this will insert the first missing closing element found in the
320 current buffer at point.  If all elements appear to be matched or if
321 there is an excess of closing tags, a notification will be displayed and
322 no element will be inserted.
324 @node Validating WML, Customisation, Inserting Elements, Top
325 @chapter Validating WML
327 @menu
328 * Usage and Capabilities::      What to expect when validating WML
329 @end menu
331 @node Usage and Capabilities, , Validating WML, Validating WML
332 @section Usage and Capabilities
334 Validating WML in the current buffer can be performed using @kbd{C-c C-c},
335 with a summary of all warnings found reported in a separate buffer.
336 Point can be jumped to the next and previous warning using @kbd{C-c C-f}
337 (or @kbd{C-x `}) and @kbd{C-c C-b}, respectively.  For visibility,
338 warnings will be underlined in red by default.  @i{Note: Warning
339 underlines may not be available in XEmacs.}
341 The WML validation built-in to Wesnoth Mode is not intended to be an
342 alternative to tools such as `wmllint', but may often be a convenient
343 substitute while editing WML.
345 The following conditions can be tested in Wesnoth Mode:
346 @itemize
347 @item Correct nesting of tags and preprocessor statements
348 @item Known macro definitions @footnote{see @ref{Macro Definitions}}
349 @item Availability of elements within the given context
350 @item Arguments are given to preprocessor statements when required
351 @item Attributes have a value assigned
352 @item Corresponding FOREACH..NEXT pairs
353 @end itemize
355 WML validation is specific to the version of WML known by Wesnoth Mode.
356 See @ref{Wesnoth Update} for more information.
358 @node Customisation, , Validating WML, Top
359 @chapter Customisation
361 @menu
362 * Modifying Indentation::       Customising WML indentation
363 * Wesnoth Update::              Using and configuring Wesnoth Update
364 * Addition File::               Extending known WML
365 * Macro Definitions::           Making project-local macros known
366 @end menu
368 @node Modifying Indentation, Wesnoth Update, Customisation, Customisation
369 @section Modifying Indentation
371 The style of indentation can be customised using
372 @code{wesnoth-indent-savefile}.  The default value is @code{t},
373 which results in all children being indented a level deeper than their
374 parent.  When set to @code{nil}, children will be indented to the same
375 level as their parent element.  This option is provided only for
376 consistency when editing (very) old WML.  It is recommended that this be
377 non-nil for all new WML.
379 @code{wesnoth-indent-preprocessor-bol} controls how preprocessor
380 statements should be indented.  If non-nil, all preprocessor statements
381 will be indented to the beginning of the line.  Otherwise, preprocessor
382 statements will be indented as to the level indicated by its context.
384 By default, Wesnoth Mode will attempt indentation of the current line
385 and create a newline and when @kbd{RET} or @kbd{C-j} are used.
386 @code{wesnoth-auto-indent-flag} controls whether Wesnoth Mode will
387 attempt to indent the current line automatically.  Setting this to
388 @code{nil} will prevent automatic indentation.  Note that this does not
389 affect the behaviour of @kbd{C-j} performing indentation following the
390 newline; this only determines whether indentation will be automatically
391 performed on the current line.
393 The following can be used to change @kbd{RET} to automatically indent the
394 newline:
395 @example
396 (add-hook 'wesnoth-mode-hook
397   '(lambda ()
398     (define-key wesnoth-mode-map (kbd ``C-m'')
399     'wesnoth-newline-and-indent)))
400 @end example
402 @code{wesnoth-base-indent} controls the depth of indentation for each
403 level.  Its value should be an integer.  This is set to `4' by default,
404 which is the convention used when indenting WML.
406 By default, Wesnoth Mode will use spaces for indentation.  Tabs can instead be used with the following:
407 @example
408 (add-hook 'wesnoth-mode-hook
409   '(lambda ()
410     (setq indent-tabs-mode t
411           tab-width wesnoth-base-indent)))
412 @end example
414 @code{wesnoth-warning-face} is the face used to display the overlay for
415 warnings detected when Validating WML (See @ref{Validating WML}).  By
416 default this is a red underline.  @i{Note: use of this face may not be supported
417 under XEmacs.}
419 @node Wesnoth Update, Addition File, Modifying Indentation, Customisation
420 @section Wesnoth Update
422 Wesnoth Update is an extension to Wesnoth Mode which retrieves
423 information regarding valid WML structure using WML included with
424 Wesnoth.  To update WML data known to Wesnoth Mode, two variables need
425 to be set appropriately: @code{wesnoth-root-directory} and
426 @code{wesnoth-update-output-directory}.
428 @code{wesnoth-root-directory} should be the path to the root directory
429 of a Wesnoth installation or Wesnoth source code.  Wesnoth Update will
430 search recursively in this directory for WML, using the information
431 found to provide context-sensitive completion and WML validation.
433 @code{wesnoth-update-output-directory} specifies the path to store the
434 WML data found.  This path should be within the @code{load-path}, and
435 preferably, in the same directory as Wesnoth Mode.
437 For example:
438 @example
439 (setq wesnoth-root-directory "/usr/local/share/wesnoth/"
440       wesnoth-update-output-directory "~/.emacs.d/wesnoth-mode/")
441 @end example
443 Once set, @kbd{M-x wesnoth-update} will generate and load a new cache of
444 WML data ready for use for the current and future sessions.  @i{Note:
445 'wesnoth-update' may take some time to run.}
447 Wesnoth Mode @value{VERSION} uses WML data retrieved from Wesnoth
448 @value{WMLVERSION}, by default.
450 @node Addition File, Macro Definitions, Wesnoth Update, Customisation
451 @section Addition File
453 @code{wesnoth-addition-file} specifies the `addition file' to use.  An
454 addition file is an outline of a valid WML structure which is processed
455 to provide more comprehensive completion and validation by providing
456 access to elements which may not have been available when running
457 @code{wesnoth-update}.
459 The value of @code{wesnoth-addition-file} should be set as the path to a
460 suitable addition file.  A sample addition file is included with Wesnoth
461 Mode.
463 For example, the following could be used to specify an addition file:
464 @example
465 (setq wesnoth-addition-file
466       "~/.emacs.d/wesnoth-mode/wesnoth-wml-additions.cfg")
467 @end example
469 The addition file is read and information regarding WML structure
470 updated any time WML information is required.  Therefore, no further
471 action is required to use the updated WML data once any changes to the
472 addition file are saved to disk.
474 @node Macro Definitions, , Addition File, Customisation
475 @section Macro Definitions
477 While built-in macros are always available, local macro definitions are
478 automatically scanned and made known to Wesnoth Mode for each WML file
479 which is loaded in the session. @kbd{C-c C-u} can be used to update the
480 known macro definitions for any buffer which has since been
481 modified. (Note that this is not required when the macro is defined in
482 the WML file currently being edited as such definitions will be
483 automatically updated when needed.)  @kbd{C-u C-c C-u} can be used to
484 clear known local macro definitions.
486 @bye
488 @c Local Variables: 
489 @c mode: texinfo
490 @c TeX-master: t
491 @c End: