upstream update of the emacs mode to version 1.3.4a
This commit is contained in:
parent
5896ab5195
commit
380c17e462
5 changed files with 431 additions and 251 deletions
|
@ -1,5 +1,5 @@
|
|||
;;; wesnoth-mode.el --- A major mode for editing WML.
|
||||
;; Copyright (C) 2006, 2007, 2008 Chris Mann
|
||||
;; Copyright (C) 2006, 2007, 2008, 2009 Chris Mann
|
||||
|
||||
;; This file is part of wesnoth-mode.
|
||||
|
||||
|
@ -33,6 +33,22 @@
|
|||
;; to automatically load wesnoth-mode for all files ending in '.cfg'.
|
||||
|
||||
;;; History:
|
||||
;; 1.3.4a
|
||||
;; * #ifdef, #ifndef preprocessor statements now indent their contents relative
|
||||
;; to themselves when `wesnoth-indent-preprocessor-bol' is nil.
|
||||
;; * Fixed a bug which could prevent element completion immediately within a
|
||||
;; preprocessor statement.
|
||||
;; 1.3.4
|
||||
;; * Fixed some errors produced when wesnoth-mode.el is byte-compiled.
|
||||
;; * Improve detection and position of inserted closing tags in some
|
||||
;; circustances.
|
||||
;; * Improved context detection for completion in some circumstances.
|
||||
;; * Read `wesnoth-addition-file' as needed; M-x wesnoth-update no longer
|
||||
;; required.
|
||||
;; * `wesnoth-indent-preprocessor-bol' has been re-introduced to control
|
||||
;; whether preprocessor statements are indented to the beginning of the line
|
||||
;; or as tags.
|
||||
;; * Many minor bug fixes.
|
||||
;; 1.3.3
|
||||
;; * Improve performance when inserting missing elements. Support for
|
||||
;; searching for missing elements over a region has been removed;
|
||||
|
@ -162,7 +178,7 @@
|
|||
(require 'wesnoth-update)
|
||||
(require 'wesnoth-wml-data)
|
||||
|
||||
(defconst wesnoth-mode-version "1.3.3"
|
||||
(defconst wesnoth-mode-version "1.3.4a"
|
||||
"The current version of `wesnoth-mode'.")
|
||||
|
||||
(defgroup wesnoth-mode nil "Wesnoth-mode access"
|
||||
|
@ -174,6 +190,11 @@
|
|||
:type 'boolean
|
||||
:group 'wesnoth-mode)
|
||||
|
||||
(defcustom wesnoth-indent-preprocessor-bol t
|
||||
"Whether to indent Preprocessor statements to the beginning of the line."
|
||||
:type 'boolean
|
||||
:group 'wesnoth-mode)
|
||||
|
||||
(defcustom wesnoth-indent-savefile t
|
||||
"Non-nil means to use the current indentation conventions.
|
||||
If nil, use the old convention for indentation.
|
||||
|
@ -253,7 +274,10 @@ level as their parent.")
|
|||
|
||||
(defvar wesnoth-syntax-table
|
||||
(let ((wesnoth-syntax-table (make-syntax-table)))
|
||||
(modify-syntax-entry ?# "<" wesnoth-syntax-table)
|
||||
(modify-syntax-entry ?\" "\"" wesnoth-syntax-table)
|
||||
(modify-syntax-entry ?= "." wesnoth-syntax-table)
|
||||
(modify-syntax-entry ?| "w" wesnoth-syntax-table)
|
||||
(modify-syntax-entry ?_ "_" wesnoth-syntax-table)
|
||||
(modify-syntax-entry ?- "_" wesnoth-syntax-table)
|
||||
(modify-syntax-entry ?. "_" wesnoth-syntax-table)
|
||||
|
@ -266,9 +290,8 @@ level as their parent.")
|
|||
;; pre-processor statements.
|
||||
(defvar wesnoth-syntactic-keywords
|
||||
(list
|
||||
'("\\([\t ]*\\(#\\(?:define \\|e\\(?:lse\\|nd\\(?:\\(?:de\\|i\\)f\\)\\)\\|\\(?:ifn?\\|un\\)def \\)\\)\\)" 1 "w")
|
||||
'("\\(#[\t ]*.*$\\)" 1 "<"))
|
||||
"Highlighting syntactic keywords within `wesnoth-mode'.")
|
||||
'("\\([\t ]*\\(#\\(?:define \\|e\\(?:lse\\|nd\\(?:\\(?:de\\|i\\)f\\)\\)\\|\\(?:ifn?\\|un\\)def \\)\\)\\)" 1 "w"))
|
||||
"Syntactic keywords for preprocessor statements within `wesnoth-mode'.")
|
||||
|
||||
(defvar wesnoth-font-lock-keywords
|
||||
(list
|
||||
|
@ -294,6 +317,9 @@ If LIMITED is non-nil, return a regexp which matches only the
|
|||
(if limited
|
||||
"#enddef"
|
||||
"#end\\(?:def\\|if\\)")
|
||||
(if (and (not wesnoth-indent-preprocessor-bol) limited)
|
||||
"\\|#endif"
|
||||
"")
|
||||
"\\)"))
|
||||
|
||||
(defun wesnoth-element-opening (&optional limited)
|
||||
|
@ -302,8 +328,11 @@ If LIMITED is non-nil, return a regexp which matches only the
|
|||
#define preprocessor."
|
||||
(concat "^[\t ]*\\(\\[\\+?\\(\\w\\|_\\)+\\]\\|#define "
|
||||
(if limited
|
||||
"{FOREACH .+}"
|
||||
"\\|{FOREACH .+}"
|
||||
"\\|#ifn?def ")
|
||||
(if (and (not wesnoth-indent-preprocessor-bol) limited)
|
||||
"\\|#ifn?def \\|#else"
|
||||
"")
|
||||
"\\)"))
|
||||
|
||||
(defun wesnoth-element (&optional limited)
|
||||
|
@ -314,6 +343,9 @@ If LIMITED is non-nil, return a regexp which matches only the
|
|||
(if limited
|
||||
"#define \\|#enddef"
|
||||
(substring wesnoth-preprocessor-regexp 5))
|
||||
(if (and (not wesnoth-indent-preprocessor-bol) limited)
|
||||
"\\|#\\(ifn?def \\|endif\\|else\\)"
|
||||
"")
|
||||
"\\)"))
|
||||
|
||||
(defun wesnoth-find-next (type)
|
||||
|
@ -364,27 +396,31 @@ of the element."
|
|||
("\\[\\+?[^/]+?\\]" . tag-opening)
|
||||
("\\[/.+?\\]" . tag-closing)
|
||||
("\\(\\w\\|_\\)+[\t ]*=" . attribute)
|
||||
("#\\(enddef\\|define \\|e\\(lse\\|nd\\(\\(de\\|i\\)f\\)\\)\\|\\(ifn?\\|un\\)def \\)" . preprocessor)
|
||||
("#\\(enddef\\|define \\|e\\(lse\\|nd\\(\\(de\\|i\\)f\\)\\)\\|\\(ifn?\\|un\\)def \\)"
|
||||
. preprocessor)
|
||||
("#.*$" . comment)
|
||||
("[^\t\n |]+") . nil)))
|
||||
("[^\t ]+") . nil)))
|
||||
(catch 'result
|
||||
(dolist (pair element-matches)
|
||||
(when (looking-at (car pair))
|
||||
(throw 'result (list (cdr pair)
|
||||
(match-beginning 0)
|
||||
(match-end 0))))))))
|
||||
(min (save-excursion (forward-line 1) (point))
|
||||
(match-end 0)))))))))
|
||||
|
||||
(defun wesnoth-estimate-element-type (point)
|
||||
"Return match data for a partial element at POINT."
|
||||
(save-excursion
|
||||
(goto-char point)
|
||||
(let ((element-matches
|
||||
'(("{\\(.*?[/\]\\)+$" . nil) ;; pathnames
|
||||
'(("{\\(.*?[/\]\\)+$" . nil) ; pathnames
|
||||
("{\\(\\w\\|_\\)*$" . macro)
|
||||
("\\[/\\(\\w\\|_\\)*$" . tag-closing)
|
||||
("\\[\\+?\\(\\w\\|_\\)*$" . tag-opening)
|
||||
("^[\t ]*\\(\\w\\|_\\)+$" . attribute)
|
||||
("^[\t ]*#\\w*$" . preprocessor))))
|
||||
("[\t ]*#\\(enddef\\|define \\|e\\(lse\\|nd\\(\\(de\\|i\\)f\\)\\)\\|\\(ifn?\\|un\\)def \\)"
|
||||
. nil) ; not a partial match
|
||||
("[\t ]*#\\w*$" . preprocessor))))
|
||||
(catch 'result
|
||||
(dolist (pair element-matches)
|
||||
(when (looking-at (car pair))
|
||||
|
@ -431,6 +467,21 @@ If COMPLETEP is non-nil, do not prompt if no completion is found."
|
|||
(t
|
||||
element))))
|
||||
|
||||
(defun wesnoth-active-parent-tag ()
|
||||
"Return the name of the active parent tag.
|
||||
Finds the relevant parent tag, ignoring any conditional tags."
|
||||
(save-excursion
|
||||
(let ((parent (wesnoth-parent-tag)))
|
||||
(while (and (stringp (car parent))
|
||||
(string-match "else\\|then"
|
||||
(car parent)))
|
||||
(goto-char (cdr parent))
|
||||
(setq parent (wesnoth-parent-tag))
|
||||
(when (string= (car parent) "if")
|
||||
(goto-char (cdr parent))
|
||||
(setq parent (wesnoth-parent-tag))))
|
||||
(car parent))))
|
||||
|
||||
(defun wesnoth-parent-tag ()
|
||||
"Return the name of the parent tag.
|
||||
If the parent is a preprocessor statement, return non-nil.
|
||||
|
@ -450,9 +501,10 @@ Otherwise, return a string containing the name of the parent tag."
|
|||
(setq depth (1- depth))))
|
||||
(beginning-of-line)
|
||||
(if (> depth 0)
|
||||
nil
|
||||
(cons nil nil)
|
||||
(when (looking-at (wesnoth-element-opening))
|
||||
(let ((parent (match-string-no-properties 1)))
|
||||
(let ((parent (match-string-no-properties 1))
|
||||
(position (point)))
|
||||
(if (or (string-match wesnoth-preprocessor-opening-regexp parent)
|
||||
;; Check if we're immediately within a macro
|
||||
(and (goto-char start-point)
|
||||
|
@ -462,8 +514,8 @@ Otherwise, return a string containing the name of the parent tag."
|
|||
(not (and (search-backward parent (point-min) t)
|
||||
(search-backward-regexp "[}{]" (point-min) t)
|
||||
(string= (match-string 0) "{")))))
|
||||
t
|
||||
(substring parent 1 (1- (length parent))))))))))
|
||||
(cons t position)
|
||||
(cons (substring parent 1 (1- (length parent))) position))))))))
|
||||
|
||||
(defun wesnoth-partial-macro-p ()
|
||||
"Return non-nil if point is in a partial macro."
|
||||
|
@ -532,6 +584,7 @@ If COMPLETEP is non-nil, attempt to complete preprocessor at point."
|
|||
(match-string-no-properties 1)))))
|
||||
(preprocessor (wesnoth-element-completion
|
||||
completions "Preprocessor: " partial completep))
|
||||
(details (wesnoth-guess-element-type (point)))
|
||||
(closedp
|
||||
(save-excursion
|
||||
(when preprocessor
|
||||
|
@ -540,15 +593,7 @@ If COMPLETEP is non-nil, attempt to complete preprocessor at point."
|
|||
(when (string-match "#\\(define\\|ifn?def\\|undef\\)" preprocessor)
|
||||
(setq preprocessor (concat preprocessor " ")))
|
||||
(when partial
|
||||
(delete-region
|
||||
(save-excursion
|
||||
(progn (search-backward
|
||||
"#"
|
||||
(save-excursion (back-to-indentation)
|
||||
(point))
|
||||
t)
|
||||
(point)))
|
||||
(point)))
|
||||
(delete-region (nth 1 details) (nth 2 details)))
|
||||
(wesnoth-preprocessor-closed-p preprocessor)))))
|
||||
(when preprocessor
|
||||
(when partial
|
||||
|
@ -594,9 +639,11 @@ If COMPLETEP is non-nil, attempt to complete preprocessor at point."
|
|||
If COMPLETEP is non-nil, attempt to complete the macro at point."
|
||||
(interactive)
|
||||
(wesnoth-update-project-information)
|
||||
(let* ((macro-information (append (wesnoth-macro-arguments)
|
||||
wesnoth-macro-data
|
||||
wesnoth-local-macro-data))
|
||||
(let* ((macro-information (wesnoth-merge-macro-data
|
||||
wesnoth-macro-data
|
||||
(wesnoth-macro-additions)
|
||||
wesnoth-local-macro-data
|
||||
(wesnoth-macro-arguments)))
|
||||
(completions (wesnoth-emacs-completion-formats
|
||||
(mapcar 'car macro-information)))
|
||||
(details (wesnoth-guess-element-type (point)))
|
||||
|
@ -636,10 +683,13 @@ If COMPLETEP is non-nil, attempt to complete the macro at point."
|
|||
"Insert the attribute at point.
|
||||
If COMPLETEP is non-nil, attempt to complete the attribute at point."
|
||||
(interactive)
|
||||
(let* ((completions (wesnoth-build-completion 1))
|
||||
(details (save-excursion
|
||||
(wesnoth-refresh-wml-data)
|
||||
(let* ((details (save-excursion
|
||||
(back-to-indentation)
|
||||
(wesnoth-guess-element-type (point))))
|
||||
(completions (save-excursion (when (nth 1 details)
|
||||
(goto-char (nth 1 details)))
|
||||
(wesnoth-build-completion 1)))
|
||||
(partial (when completep
|
||||
(when (save-excursion
|
||||
(back-to-indentation)
|
||||
|
@ -665,8 +715,10 @@ ELEMENTS is the number of elements to wrap around.
|
|||
If COMPLETEP is non-nil, attempt to complete tag at point."
|
||||
(interactive "P")
|
||||
(or elements (setq elements 0))
|
||||
(let* ((completions (wesnoth-build-completion 0))
|
||||
(details (wesnoth-guess-element-type (point)))
|
||||
(let* ((details (wesnoth-guess-element-type (point)))
|
||||
(completions (save-excursion (and (nth 1 details)
|
||||
(goto-char (nth 1 details)))
|
||||
(wesnoth-build-completion 0)))
|
||||
(partial (save-excursion
|
||||
(when (and completep
|
||||
(eq (car details) 'tag-opening)
|
||||
|
@ -700,11 +752,12 @@ Rebuilding list is required for versions of GNU Emacs earlier
|
|||
than 22. POSITION is the argument passed to `nth' for
|
||||
`wesnoth-tag-data'."
|
||||
(interactive "P")
|
||||
(let ((parent (wesnoth-parent-tag)))
|
||||
(let ((parent (wesnoth-active-parent-tag))
|
||||
(tag-data (wesnoth-refresh-wml-data)))
|
||||
(wesnoth-emacs-completion-formats
|
||||
(if (or (stringp parent) (null parent))
|
||||
(nth position (gethash parent wesnoth-tag-hash-table))
|
||||
(mapcar 'car wesnoth-tag-data)))))
|
||||
(mapcar 'car tag-data)))))
|
||||
|
||||
(defun wesnoth-emacs-completion-formats (candidates)
|
||||
"Return the completions in the correct format for `emacs-major-version'.
|
||||
|
@ -785,11 +838,21 @@ TAGNAME is the name of the tag to be inserted."
|
|||
If COMPLETEP is non-nil, do not move forward a line when scanning
|
||||
for the matching tag."
|
||||
(interactive)
|
||||
(let ((match nil))
|
||||
(let ((match nil)
|
||||
(skip t))
|
||||
(save-excursion
|
||||
(when (and (null completep)
|
||||
(<= (point) (save-excursion (back-to-indentation) (point))))
|
||||
(if (save-excursion (beginning-of-line)
|
||||
(looking-at (wesnoth-element-opening)))
|
||||
(forward-line -1)
|
||||
(when
|
||||
(save-excursion (beginning-of-line)
|
||||
(looking-at (wesnoth-element-closing)))
|
||||
(setq skip nil))))
|
||||
(when (wesnoth-search-for-matching-tag
|
||||
'search-backward-regexp (wesnoth-element-opening) 'point-min
|
||||
(if completep nil 1))
|
||||
(and skip (if completep nil 1)))
|
||||
(setq match (and (looking-at (wesnoth-element-opening))
|
||||
(match-string-no-properties 1)))))
|
||||
(when match
|
||||
|
@ -812,7 +875,7 @@ ARGS is a list of strings to be inserted."
|
|||
(wesnoth-indent))
|
||||
|
||||
(defun wesnoth-newline (&optional indent)
|
||||
"Indent both the current line and the newline created.
|
||||
"Indent the current line and create a newline.
|
||||
If `wesnoth-auto-indent-flag' is nil, indentation will not be
|
||||
performed. Indentation can be forced by setting INDENT to
|
||||
non-nil."
|
||||
|
@ -879,24 +942,24 @@ jump backward the specified number of tags."
|
|||
(wesnoth-forward-element (abs repeat))
|
||||
(wesnoth-navigate-element repeat 'search-backward-regexp (point-min))))
|
||||
|
||||
(defmacro wesnoth-search-for-matching-tag (search-function
|
||||
search-string bound &optional skip)
|
||||
(defun wesnoth-search-for-matching-tag (search-function
|
||||
search-string bound &optional skip)
|
||||
"Search for the matching tag for the current line.
|
||||
SEARCH-FUNCTION is the name of the function used to perform the search.
|
||||
SEARCH-STRING is a string representing the matching tag type.
|
||||
BOUND is the bound to be passed to the search function.
|
||||
If SKIP is non-nil, skip the first element and continue from there."
|
||||
`(let ((depth 1))
|
||||
(when (and (or (and (numberp ,skip) (forward-line ,skip))
|
||||
(funcall ,search-function (wesnoth-element) (funcall ,bound) t))
|
||||
(or ,skip (not (string-match ,search-string (match-string 0)))))
|
||||
(while (and (> depth 0)
|
||||
(funcall ,search-function (wesnoth-element)
|
||||
(funcall ,bound) t))
|
||||
(if (string-match ,search-string (match-string 0))
|
||||
(setq depth (1- depth))
|
||||
(setq depth (1+ depth))))
|
||||
(= depth 0))))
|
||||
(let ((depth 1))
|
||||
(when (and (or (and (numberp skip) (forward-line skip))
|
||||
(funcall search-function (wesnoth-element) (funcall bound) t))
|
||||
(or skip (not (string-match search-string (match-string 0)))))
|
||||
(while (and (> depth 0)
|
||||
(funcall search-function (wesnoth-element)
|
||||
(funcall bound) t))
|
||||
(if (string-match search-string (match-string 0))
|
||||
(setq depth (1- depth))
|
||||
(setq depth (1+ depth))))
|
||||
(= depth 0))))
|
||||
|
||||
(defun wesnoth-jump-to-matching (&optional element)
|
||||
"Jump point to the matching opening/closing tag.
|
||||
|
@ -981,7 +1044,8 @@ CONTEXT represents the type of element which precedes the current element."
|
|||
(wesnoth-element t) (point-min) t)
|
||||
(point))
|
||||
point))
|
||||
(looking-at wesnoth-preprocessor-regexp)))
|
||||
(and (looking-at wesnoth-preprocessor-regexp)
|
||||
wesnoth-indent-preprocessor-bol)))
|
||||
|
||||
(defun wesnoth-indent ()
|
||||
"Indent the current line as WML."
|
||||
|
@ -994,21 +1058,31 @@ CONTEXT represents the type of element which precedes the current element."
|
|||
(unless (wesnoth-first-column-indent-p (point))
|
||||
(cond
|
||||
((eq context 'opening)
|
||||
(if (or (and wesnoth-indent-savefile
|
||||
(or (looking-at "[\t ]*{NEXT ")
|
||||
(and (not (looking-at (wesnoth-element-closing t)))
|
||||
(not (looking-at "[\t ]*{NEXT ")))))
|
||||
(looking-at (wesnoth-element-opening t))
|
||||
(looking-at "[\t ]*{FOREACH "))
|
||||
(setq cur-indent (+ ref-indent wesnoth-base-indent))
|
||||
(setq cur-indent ref-indent)))
|
||||
(if (and (looking-at "^[\t ]*#else")
|
||||
(not wesnoth-indent-preprocessor-bol))
|
||||
(setq cur-indent ref-indent)
|
||||
(if (or (and wesnoth-indent-savefile
|
||||
(or (looking-at "[\t ]*{NEXT ")
|
||||
(and (not (looking-at (wesnoth-element-closing t)))
|
||||
(not (looking-at "[\t ]*{NEXT ")))))
|
||||
(looking-at (wesnoth-element-opening t))
|
||||
(looking-at "[\t ]*{FOREACH "))
|
||||
(setq cur-indent (+ ref-indent wesnoth-base-indent))
|
||||
(setq cur-indent ref-indent))))
|
||||
((eq context 'closing)
|
||||
(if (or (looking-at "^[\t ]*\\(\\[/\\)")
|
||||
(and (not wesnoth-indent-savefile)
|
||||
(not (looking-at (wesnoth-element-opening t)))
|
||||
(not (looking-at "[\t ]*{FOREACH "))))
|
||||
(setq cur-indent (- ref-indent wesnoth-base-indent))
|
||||
(setq cur-indent ref-indent)))))
|
||||
(if (and (looking-at "^[\t ]*#else")
|
||||
(not wesnoth-indent-preprocessor-bol))
|
||||
(setq cur-indent (- ref-indent wesnoth-base-indent))
|
||||
(if (or (looking-at (concat "^[\t ]*\\(\\[/\\|\\#enddef"
|
||||
(if (not wesnoth-indent-preprocessor-bol)
|
||||
"\\|#endif"
|
||||
"")
|
||||
"\\)"))
|
||||
(and (not wesnoth-indent-savefile)
|
||||
(not (looking-at (wesnoth-element-opening t)))
|
||||
(not (looking-at "[\t ]*{FOREACH "))))
|
||||
(setq cur-indent (- ref-indent wesnoth-base-indent))
|
||||
(setq cur-indent ref-indent))))))
|
||||
(indent-line-to (max cur-indent 0))))
|
||||
(when (> (save-excursion (back-to-indentation) (point))
|
||||
(point))
|
||||
|
@ -1076,7 +1150,7 @@ POSITION is the buffer position of the element for which to
|
|||
determine the context."
|
||||
(save-excursion
|
||||
(let* ((elements (concat (substring (wesnoth-element t)
|
||||
0 (- (length (wesnoth-element t)) 3))
|
||||
0 (- (length (wesnoth-element t)) 2))
|
||||
"\\|{FOREACH .+}\\|{NEXT .+}\\)"))
|
||||
(match (or
|
||||
(and (search-backward-regexp
|
||||
|
@ -1103,13 +1177,20 @@ determine the context."
|
|||
;; Found nothing of use; reset match and assume top-level tag.
|
||||
(setq match ""))
|
||||
(cond
|
||||
((string-match "\\[/\\|#enddef" match)
|
||||
((string-match (concat "\\[/\\|#enddef"
|
||||
(if (not wesnoth-indent-preprocessor-bol)
|
||||
"\\|#endif"
|
||||
""))
|
||||
match)
|
||||
(cons 'closing (current-indentation)))
|
||||
((string-match "{NEXT " match)
|
||||
(cons 'closing (if wesnoth-indent-savefile
|
||||
(- (current-indentation) wesnoth-base-indent)
|
||||
(current-indentation))))
|
||||
((string-match "\\[[^/]?\\|#define\\|{FOREACH " match)
|
||||
((string-match (concat "\\[[^/]?\\|#define\\|{FOREACH "
|
||||
(if (not wesnoth-indent-preprocessor-bol)
|
||||
"\\|#ifn?def \\|#else"
|
||||
"")) match)
|
||||
(cons 'opening (current-indentation)))))))
|
||||
|
||||
(defun wesnoth-newline-and-indent (&optional indent)
|
||||
|
@ -1128,12 +1209,20 @@ be performed."
|
|||
(defun wesnoth-check-element-type (position)
|
||||
"Determine the context of the element.
|
||||
POSITION is the position of the element in the list."
|
||||
(let ((parent (save-match-data (wesnoth-parent-tag))))
|
||||
(let ((parent (save-match-data (car (wesnoth-parent-tag)))))
|
||||
(if (or (stringp parent) (null parent))
|
||||
(member (match-string-no-properties 1)
|
||||
(nth position (gethash parent wesnoth-tag-hash-table)))
|
||||
(member (match-string-no-properties 1)
|
||||
(mapcar 'car wesnoth-tag-data)))))
|
||||
(let ((result '()))
|
||||
(mapc
|
||||
'(lambda (x)
|
||||
(let ((value (nth position (cdr x))))
|
||||
(and value (mapc '(lambda (y)
|
||||
(setq result (cons y result)))
|
||||
value))))
|
||||
(or wesnoth-tmp-tag-data (wesnoth-refresh-wml-data)))
|
||||
result)))))
|
||||
|
||||
;; Provide `line-number-at-pos' implementation (not available in Emacs 21).
|
||||
(defun wesnoth-line-number-at-pos (&optional pos)
|
||||
|
@ -1261,6 +1350,8 @@ the end of the region to place the overlay."
|
|||
(defun wesnoth-check-wml ()
|
||||
"Perform context-sensitive analysis of WML-code."
|
||||
(interactive)
|
||||
;; Temporarily cache all tag-data.
|
||||
(setq wesnoth-tmp-tag-data (wesnoth-refresh-wml-data))
|
||||
(wesnoth-update-project-information)
|
||||
(if (fboundp 'delete-overlay)
|
||||
(dolist (overlay (overlays-in (point-min) (point-max)))
|
||||
|
@ -1296,9 +1387,11 @@ the end of the region to place the overlay."
|
|||
(wesnoth-extract-macro-details
|
||||
(match-string-no-properties 0))))
|
||||
(unless (assoc macro
|
||||
(append (wesnoth-macro-arguments)
|
||||
wesnoth-local-macro-data
|
||||
wesnoth-macro-data))
|
||||
(wesnoth-merge-macro-data
|
||||
wesnoth-macro-data
|
||||
(wesnoth-macro-additions)
|
||||
wesnoth-local-macro-data
|
||||
(wesnoth-macro-arguments)))
|
||||
(wesnoth-check-process "Unknown macro: '%s'"
|
||||
macro)))
|
||||
(save-match-data
|
||||
|
@ -1380,7 +1473,8 @@ the end of the region to place the overlay."
|
|||
(dolist (element unmatched)
|
||||
(wesnoth-check-process "Unmatched element: '%s'" element))))
|
||||
(save-excursion
|
||||
(setq wesnoth-define-blocks nil)
|
||||
(setq wesnoth-define-blocks nil
|
||||
wesnoth-tmp-tag-data nil)
|
||||
(set-buffer outbuf)
|
||||
(toggle-read-only t)
|
||||
(let ((buffer (buffer-name))
|
||||
|
@ -1412,7 +1506,7 @@ the end of the region to place the overlay."
|
|||
(font-lock-syntactic-keywords . wesnoth-syntactic-keywords)))
|
||||
(setq indent-tabs-mode nil)
|
||||
(easy-menu-add wesnoth-menu wesnoth-mode-map)
|
||||
(wesnoth-create-wml-hash-table)
|
||||
(wesnoth-refresh-wml-data)
|
||||
(wesnoth-update-project-information)
|
||||
(run-hooks 'wesnoth-mode-hook))
|
||||
|
||||
|
|
|
@ -3,8 +3,8 @@
|
|||
@setfilename wesnoth-mode.info
|
||||
@settitle Wesnoth Mode Manual
|
||||
|
||||
@set VERSION 1.3.3
|
||||
@set DATE October 2008
|
||||
@set VERSION 1.3.4
|
||||
@set DATE January 2009
|
||||
|
||||
@dircategory Emacs
|
||||
@direntry
|
||||
|
@ -20,7 +20,7 @@
|
|||
@copying
|
||||
This manual is for Wesnoth Mode (version @value{VERSION}).
|
||||
|
||||
Copyright @copyright{} 2008 Chris Mann
|
||||
Copyright @copyright{} 2008, 2009 Chris Mann
|
||||
|
||||
@quotation
|
||||
This program is free software; you can redistribute it and/or modify it
|
||||
|
@ -60,11 +60,10 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
|
||||
@menu
|
||||
* Introduction:: Getting started
|
||||
* Navigation:: Moving around within WML
|
||||
* Basic Usage:: Moving around within WML
|
||||
* Inserting Elements:: Insertion and completion of elements
|
||||
* Checking WML:: Checking WML for common problems
|
||||
* Customisation:: Available customisation options
|
||||
* Key Index:: Index of Key-Bindings
|
||||
|
||||
@detailmenu
|
||||
--- Detailed Node Listing ---
|
||||
|
@ -74,11 +73,10 @@ Introduction
|
|||
* Summary:: Introduction to Wesnoth Mode
|
||||
* Getting Started:: How to start Wesnoth Mode
|
||||
|
||||
Navigation
|
||||
Basic Usage
|
||||
|
||||
* Navigation Introduction:: Common WML navigation
|
||||
* Moving Across Elements:: Moving backward and forward across elements
|
||||
* Matching Elements:: Moving to the matching element
|
||||
* Indentation:: Indentation usage and styles
|
||||
* Navigation:: Common WML navigation
|
||||
|
||||
Inserting Elements
|
||||
|
||||
|
@ -100,7 +98,7 @@ Customisation
|
|||
@end detailmenu
|
||||
@end menu
|
||||
|
||||
@node Introduction, Navigation, Top, Top
|
||||
@node Introduction, Basic Usage, Top, Top
|
||||
@chapter Introduction
|
||||
|
||||
@menu
|
||||
|
@ -111,11 +109,12 @@ Customisation
|
|||
@node Summary, Getting Started, Introduction, Introduction
|
||||
@section Summary
|
||||
|
||||
Wesnoth Mode is a major mode for Emacs which assists in the editing of the
|
||||
markup language extensively used in Wesnoth, a turn-based fantasy strategy
|
||||
game. From the Wesnoth Wiki: "The Wesnoth Markup Language (WML) is used to
|
||||
code almost everything in Wesnoth, including scenarios, units, savefiles, and
|
||||
the user interface layout." @footnote{@uref{http://www.wesnoth.org/wiki/ReferenceWML}}
|
||||
Wesnoth Mode is a major mode for Emacs which assists in the editing of
|
||||
the markup language extensively used in Wesnoth, a turn-based fantasy
|
||||
strategy game. From the Wesnoth Wiki: "The Wesnoth Markup Language
|
||||
(WML) is used to code almost everything in Wesnoth, including scenarios,
|
||||
units, savefiles, and the user interface layout."
|
||||
@footnote{@uref{http://www.wesnoth.org/wiki/ReferenceWML}}
|
||||
|
||||
Wesnoth Mode is supported under GNU Emacs 21 onwards and (with some
|
||||
minor limitations) XEmacs 21. Wesnoth Mode adds support for syntax
|
||||
|
@ -123,9 +122,9 @@ highlighting, automatic indentation, context-sensitive completion,
|
|||
checking and much more when editing WML.
|
||||
|
||||
This documentation attempts to provide a comprehensive guide to
|
||||
functionality available within Wesnoth Mode @value{VERSION}, and assumes you are
|
||||
familiar with basic usage, terminology and customisation of Emacs. For
|
||||
more information, please refer to the Emacs
|
||||
functionality available within Wesnoth Mode @value{VERSION}, and assumes
|
||||
you are familiar with basic usage, terminology and customisation of
|
||||
Emacs. For more information, please refer to the Emacs
|
||||
manual. @footnote{@uref{http://www.gnu.org/software/emacs/manual/html_node/emacs/}}
|
||||
|
||||
@node Getting Started, , Summary, Introduction
|
||||
|
@ -140,46 +139,48 @@ Optionally adding:
|
|||
@lisp
|
||||
(add-to-list 'auto-mode-alist '("\\.cfg\\'" . wesnoth-mode))
|
||||
@end lisp
|
||||
to automatically load Wesnoth Mode for all files with a `.cfg' extension.
|
||||
to automatically load Wesnoth Mode for all files with a `.cfg'
|
||||
extension.
|
||||
|
||||
If Wesnoth Mode is not the currently active major-mode for the current
|
||||
buffer, it can be started via @kbd{M-x wesnoth-mode}.
|
||||
Wesnoth Mode can be activated as the current major-mode for a buffer via
|
||||
@kbd{M-x wesnoth-mode}.
|
||||
|
||||
The latest version of Wesnoth Mode along with release notes can be found at
|
||||
@uref{http://www.wesnoth.org/forum/viewtopic.php?t=13798}.
|
||||
The latest version of Wesnoth Mode along with release notes can be found
|
||||
at @uref{http://www.wesnoth.org/forum/viewtopic.php?t=13798}.
|
||||
|
||||
@node Navigation, Inserting Elements, Introduction, Top
|
||||
@chapter Navigation
|
||||
@node Basic Usage, Inserting Elements, Introduction, Top
|
||||
@chapter Basic Usage
|
||||
|
||||
@menu
|
||||
* Navigation Introduction:: Common WML navigation
|
||||
* Moving Across Elements:: Moving backward and forward across elements
|
||||
* Matching Elements:: Moving to the matching element
|
||||
* Indentation:: Common WML navigation
|
||||
* Navigation:: Moving backward and forward across elements
|
||||
@end menu
|
||||
|
||||
@node Navigation Introduction, Moving Across Elements, Navigation, Navigation
|
||||
@section Navigation Introduction
|
||||
@node Indentation, Navigation, Basic Usage, Basic Usage
|
||||
@section Indentation
|
||||
@kindex @kbd{TAB}
|
||||
By default, Wesnoth Mode provides a style of indentation equivalent to
|
||||
that provided by the @code{wmlindent} tool included with Wesnoth.
|
||||
@kbd{TAB} can be used to indent the current line manually. Wesnoth Mode
|
||||
will, by default, indent the current line appropriately before inserting
|
||||
a newline when @kbd{RET} or @kbd{C-j} is used. (@kbd{C-j} will also
|
||||
attempt to indent the new line.)
|
||||
|
||||
Emacs provides many powerful built-in navigation commands which are
|
||||
ideal for editing WML. Common navigation commands, such as @kbd{C-n},
|
||||
@kbd{C-s}, and (in recent Emacsen) @kbd{M-g g}, will behave as usual
|
||||
within Wesnoth Mode. However, some navigation commands have been
|
||||
adjusted or added for increased productivity. These will be explained
|
||||
in the following sections.
|
||||
See @ref{Modifying Indentation} for information on how to customise the
|
||||
behaviour of automatic indentation.
|
||||
|
||||
@node Moving Across Elements, Matching Elements, Navigation Introduction, Navigation
|
||||
@section Moving Across Elements
|
||||
@kindex @kbd{C-M-a}
|
||||
@kindex @kbd{C-M-e}
|
||||
@kbd{TAB} performs two actions depending on the context of point. When
|
||||
there is an incomplete element immediately preceeding point, completion
|
||||
will be attempted, otherwise @kbd{TAB} will perform indentation. See
|
||||
@ref{Tab-Completion}.
|
||||
|
||||
@node Navigation, , Indentation, Basic Usage
|
||||
@section Navigation
|
||||
|
||||
Next and previous opening elements can be navigated using @kbd{C-M-e}
|
||||
and @kbd{C-M-a}, respectively. In each case, point will be positioned
|
||||
immediately before the element. When there are no more elements are
|
||||
available in that direction, point will not move.
|
||||
|
||||
@node Matching Elements, , Moving Across Elements, Navigation
|
||||
@section Matching Elements
|
||||
@kindex @kbd{C-c C-o}
|
||||
immediately before the element. When no more elements are available in
|
||||
that direction, point will not move.
|
||||
|
||||
Moving to the matching element in a pair or locating the parent element
|
||||
(depending on the position of point) can be performed via @kbd{C-c C-o}.
|
||||
|
@ -188,7 +189,7 @@ tag or opening preprocessor statement it will be moved to the start of
|
|||
the matching closing element. Otherwise, the jump will position point
|
||||
at the beginning of the corresponding opening element.
|
||||
|
||||
@node Inserting Elements, Checking WML, Navigation, Top
|
||||
@node Inserting Elements, Checking WML, Basic Usage, Top
|
||||
@chapter Inserting Elements
|
||||
|
||||
@menu
|
||||
|
@ -200,34 +201,28 @@ at the beginning of the corresponding opening element.
|
|||
|
||||
@node Standard Completion, Tab-Completion, Inserting Elements, Inserting Elements
|
||||
@section Standard Completion
|
||||
@kindex @kbd{C-c C-t}
|
||||
@kindex @kbd{M-TAB}
|
||||
@kindex @kbd{C-c C-a}
|
||||
@kindex @kbd{C-c C-m}
|
||||
@kindex @kbd{C-c C-p}
|
||||
|
||||
Tags can be inserted via @kbd{C-c C-t} and alternatively @kbd{M-TAB}
|
||||
(when this is not shadowed by the Window Manager, etc.). This will
|
||||
prompt for the tag to add. The tag entered into the mini-buffer prompt
|
||||
(when this is not shadowed by the Window Manager, etc.) which will
|
||||
prompt for the tag to add. The tag entered into the minibuffer prompt
|
||||
and its matching closing tag will be inserted and point positioned
|
||||
between.
|
||||
|
||||
Attributes can be inserted via @kbd{C-c C-a}. The attribute entered at
|
||||
Attributes can be inserted via @kbd{C-c C-a}. Any attribute entered at
|
||||
the prompt will be inserted along with the `=', with point immediately
|
||||
after.
|
||||
following.
|
||||
|
||||
Both tag and attribute completion is context-sensitive. If an element
|
||||
is available in WML and not listed for completion, you may want to add
|
||||
it to your `addition file'. See @ref{Wesnoth Update} for more
|
||||
information.
|
||||
is available in WML and not listed for completion, it can be added to
|
||||
the `addition file'. See @ref{Wesnoth Update} for more information.
|
||||
|
||||
Macro insertion can be performed via @kbd{C-c C-m}. Any arguments known
|
||||
to be required for the macro will be prompted and inserted in order.
|
||||
Insertion will be aborted if no value for an argument is provided. When
|
||||
within a macro definition, macro arguments are also available to be
|
||||
inserted. Project-local macros will not be available until Wesnoth Mode
|
||||
has scanned the buffer in which they are defined. For information on
|
||||
completing project-local macros, see @ref{Macro Definitions}.
|
||||
within a macro definition, the arguments for the current macro are also
|
||||
available for completion. Any project-local or custom macros can be
|
||||
made available for completion by opening the file in which they are
|
||||
defined. For information, see @ref{Macro Definitions}.
|
||||
|
||||
Preprocessor statements are available for insertion via @kbd{C-c C-p}.
|
||||
Closing elements for preprocessor statements will be automatically
|
||||
|
@ -236,7 +231,7 @@ point will be placed immediately after the inserted text.
|
|||
|
||||
@node Tab-Completion, Wrapping Elements, Standard Completion, Inserting Elements
|
||||
@section Tab-Completion
|
||||
@kindex @kbd{TAB}
|
||||
|
||||
Completion can also be performed immediately within the buffer via
|
||||
@kbd{TAB} on a partial element. For example:
|
||||
@example
|
||||
|
@ -254,7 +249,7 @@ will be provided, with the partial element entered. @kbd{TAB} can be
|
|||
used here to perform completion. If multiple matches are available,
|
||||
completion will be performed up to the smallest common substring with
|
||||
further completion available via the minubuffer prompt. When no matches
|
||||
are found, completion will not be prompted.
|
||||
are found for the partial element, completion will not be prompted.
|
||||
|
||||
When completing opening preprocessor statements and tags, Wesnoth Mode
|
||||
will also attempt to insert a matching closing element if one is not
|
||||
|
@ -263,7 +258,7 @@ added via the minibuffer prompt. However, if an matching closing
|
|||
element is available, only the element at point will be completed.
|
||||
|
||||
A numeric argument can be provided when performing tab-completion of
|
||||
opening elements to wrap around the following @i{n} blocks. For
|
||||
opening elements to wrap around the next @i{n} blocks. For
|
||||
example, to wrap the completed opening and closing pair around the next
|
||||
three blocks, @kbd{C-u 3 TAB} can be used. See @ref{Wrapping Elements}
|
||||
for more information.
|
||||
|
@ -288,22 +283,21 @@ element around. For example:
|
|||
@end example
|
||||
|
||||
Where point is at the position indicated by @code{-!-}. A pair of
|
||||
@code{story} tags can be inserted around both existing @code{part} tags using
|
||||
@kbd{C-u 2 C-c C-t story}. When the number of blocks specified to wrap
|
||||
around exceeds the number of blocks available, Wesnoth Mode will only
|
||||
wrap around the number of available so that the nesting of elements is
|
||||
correct.
|
||||
@code{story} tags can be inserted around both existing @code{part} tags
|
||||
using @kbd{C-u 2 C-c C-t story}. When the number of blocks specified to
|
||||
wrap around exceeds the number of blocks available, Wesnoth Mode will
|
||||
only wrap around the number of available so that the nesting of elements
|
||||
is correct.
|
||||
|
||||
@node Missing Elements, , Wrapping Elements, Inserting Elements
|
||||
@section Missing Elements
|
||||
@kindex @kbd{C-c C-/}
|
||||
Missing closing elements can be inserted using @kbd{C-c C-/}. By
|
||||
default, this will insert the first missing closing element found in the
|
||||
current buffer at point. If all elements appear to be matched or if
|
||||
there is an excess of closing tags, an appropriate message will be
|
||||
displayed in the echo area.
|
||||
there is an excess of closing tags, a notification will be displayed and
|
||||
no element will be inserted.
|
||||
|
||||
@node Checking WML, Customisation, Inserting Elements, Top
|
||||
@node Checking WML, Customisation, Inserting Elements, Top
|
||||
@chapter Checking WML
|
||||
|
||||
@menu
|
||||
|
@ -312,22 +306,20 @@ displayed in the echo area.
|
|||
|
||||
@node Usage and Capabilities, , Checking WML, Checking WML
|
||||
@section Usage and Capabilities
|
||||
@kindex @kbd{C-c C-c}
|
||||
@kindex @kbd{C-x `}
|
||||
@kindex @kbd{C-c C-f}
|
||||
@kindex @kbd{C-c C-b}
|
||||
Checking of the current buffer can be performed using @kbd{C-c C-c}. A
|
||||
summary of all warnings located will be provided in a separate buffer.
|
||||
|
||||
Checking WML in the current buffer can be performed using @kbd{C-c C-c},
|
||||
with a summary of all warnings found reported in a separate buffer.
|
||||
Point can be jumped to the next and previous warning using @kbd{C-c C-f}
|
||||
(or @kbd{C-x `}) and @kbd{C-c C-b}, respectively. For visibility,
|
||||
warnings in the checked WML buffer will be underlined in red by default.
|
||||
@i{Note: Warning underlines may not be available in XEmacs.}
|
||||
warnings will be underlined in red by default. @i{Note: Warning
|
||||
underlines may not be available in XEmacs.}
|
||||
|
||||
The WML checking built-in to Wesnoth Mode is not intended to
|
||||
be an alternative to tools such as `wmllint', but may often be a
|
||||
convenient substitute while editing WML.
|
||||
The WML checking built-in to Wesnoth Mode is not intended to be an
|
||||
alternative to tools such as `wmllint', but may often be a convenient
|
||||
substitute while editing WML.
|
||||
|
||||
The following conditions can be detected by WML checking in Wesnoth Mode:
|
||||
The following conditions can be detected by WML checking in Wesnoth
|
||||
Mode:
|
||||
@itemize
|
||||
@item Correct nesting of tags and preprocessor statements
|
||||
@item Known macro definitions @footnote{see @ref{Macro Definitions}}
|
||||
|
@ -340,25 +332,30 @@ The following conditions can be detected by WML checking in Wesnoth Mode:
|
|||
WML checking is specific to the version of WML known by Wesnoth Mode.
|
||||
See @ref{Wesnoth Update} for more information.
|
||||
|
||||
@node Customisation, Key Index, Checking WML, Top
|
||||
@node Customisation, , Checking WML, Top
|
||||
@chapter Customisation
|
||||
|
||||
@menu
|
||||
* Indentation:: Customising WML indentation
|
||||
* Modifying Indentation:: Customising WML indentation
|
||||
* Wesnoth Update:: Using and configuring Wesnoth Update
|
||||
* Macro Definitions:: making project-local macros known
|
||||
@end menu
|
||||
|
||||
@node Indentation, Wesnoth Update, Customisation, Customisation
|
||||
@section Indentation
|
||||
@node Modifying Indentation, Wesnoth Update, Customisation, Customisation
|
||||
@section Modifying Indentation
|
||||
|
||||
The style of indentation can be customised using
|
||||
@code{wesnoth-indent-savefile}. The default value is @code{non-nil},
|
||||
@code{wesnoth-indent-savefile}. The default value is @code{t},
|
||||
which results in all children being indented a level deeper than their
|
||||
parent. When set to @code{nil}, children will be indented to the same
|
||||
level as their parent element. This option is provided only for
|
||||
consistency when editing (very) old WML. It is recommended that all new
|
||||
code be written using the new convention.
|
||||
consistency when editing (very) old WML. It is recommended that this be
|
||||
non-nil for all new WML.
|
||||
|
||||
@code{wesnoth-indent-preprocessor-bol} controls how preprocessor
|
||||
statements should be indented. If non-nil, all preprocessor statements
|
||||
will be indented to the beginning of the line. Otherwise, preprocessor
|
||||
statements will be indented as to the level indicated by its context.
|
||||
|
||||
By default, Wesnoth Mode will attempt indentation of the current line
|
||||
and create a newline and when @kbd{RET} or @kbd{C-j} are used.
|
||||
|
@ -369,22 +366,38 @@ affect the behaviour of @kbd{C-j} performing indentation following the
|
|||
newline; this only determines whether indentation will be automatically
|
||||
performed on the current line.
|
||||
|
||||
The following can be used to change @kbd{RET} to automatically indent the
|
||||
newline:
|
||||
@example
|
||||
(add-hook 'wesnoth-mode-hook
|
||||
'(lambda ()
|
||||
(define-key wesnoth-mode-map (kbd ``C-m'')
|
||||
'wesnoth-newline-and-indent)))
|
||||
@end example
|
||||
|
||||
@code{wesnoth-base-indent} controls the depth of indentation for each
|
||||
level. Its value should be an integer. This is set to `4' by default,
|
||||
which is the convention used when indenting WML.
|
||||
|
||||
By default, Wesnoth Mode will use spaces for indentation. Tabs can instead be used with the following:
|
||||
@example
|
||||
(add-hook 'wesnoth-mode-hook
|
||||
'(lambda ()
|
||||
(setq indent-tabs-mode t
|
||||
tab-width wesnoth-base-indent)))
|
||||
@end example
|
||||
|
||||
@code{wesnoth-warning-face} is the face used to display the overlay for
|
||||
warnings detected when checking WML (See @ref{Checking WML}). By
|
||||
default this is a red underline. Use of this face may not be supported
|
||||
under XEmacs.
|
||||
default this is a red underline. @i{Note: use of this face may not be supported
|
||||
under XEmacs.}
|
||||
|
||||
@node Wesnoth Update, Macro Definitions, Indentation, Customisation
|
||||
@node Wesnoth Update, Macro Definitions, Modifying Indentation, Customisation
|
||||
@section Wesnoth Update
|
||||
|
||||
Wesnoth Update controls the known WML data for Wesnoth Mode. To update
|
||||
this information, three variables need to be set appropriately:
|
||||
@code{wesnoth-root-directory}, @code{wesnoth-update-output-directory}
|
||||
and @code{wesnoth-addition-file}.
|
||||
this information, two variables need to be set appropriately:
|
||||
@code{wesnoth-root-directory} and @code{wesnoth-update-output-directory}.
|
||||
|
||||
@code{wesnoth-root-directory} should be the path to the root directory
|
||||
of a Wesnoth installation or Wesnoth source code. Wesnoth Update will
|
||||
|
@ -395,26 +408,34 @@ found to provide context-sensitive completion and WML checking.
|
|||
WML data found. This path should be within the @code{load-path}, and
|
||||
preferably, in the same directory as Wesnoth Mode.
|
||||
|
||||
@code{wesnoth-addition-file} specifies the `addition file' to use. An
|
||||
addition file is an outline of a valid WML file which is processed for
|
||||
additional element data. This should be set as the path a suitable
|
||||
addition file. A sample addition file is included with Wesnoth Mode.
|
||||
|
||||
For example:
|
||||
@example
|
||||
(setq wesnoth-root-directory "/usr/local/share/wesnoth/"
|
||||
wesnoth-addition-file
|
||||
"~/.emacs.d/wesnoth-mode/wesnoth-wml-additions.cfg"
|
||||
wesnoth-update-output-directory "~/.emacs.d/wesnoth-mode/"
|
||||
wesnoth-update-output-directory "~/.emacs.d/wesnoth-mode/")
|
||||
@end example
|
||||
|
||||
Once set, @kbd{M-x wesnoth-update} will generate and load a new cache of
|
||||
WML data ready for use for the current and future sessions. (Please
|
||||
note, @code{wesnoth-update} may take some time to run.)
|
||||
WML data ready for use for the current and future sessions. @i{Note:
|
||||
@code{wesnoth-update} may take some time to run.}
|
||||
|
||||
@code{wesnoth-addition-file} specifies the `addition file' to use. An
|
||||
addition file is an outline of a valid WML file which is processed for
|
||||
additional element data which may not have been detected when running
|
||||
@code{wesnoth-update}. This should be set as the path to a suitable
|
||||
addition file. A sample addition file is included with Wesnoth Mode.
|
||||
|
||||
The addition data is read from the file and updated any time tag
|
||||
information is required, therefore no action needs to be taken to adjust
|
||||
tag data other than saving the addition file when modified.
|
||||
|
||||
For example, the following could be used to specify an addition file:
|
||||
@example
|
||||
(setq wesnoth-addition-file
|
||||
"~/.emacs.d/wesnoth-mode/wesnoth-wml-additions.cfg")
|
||||
@end example
|
||||
|
||||
@node Macro Definitions, , Wesnoth Update, Customisation
|
||||
@section Macro Definitions
|
||||
@kindex @kbd{C-c C-u}
|
||||
|
||||
While built-in macros are always available, local macro definitions are
|
||||
automatically scanned and made known to Wesnoth Mode for each WML file
|
||||
|
@ -425,10 +446,6 @@ the WML file currently being edited as such definitions will be
|
|||
automatically updated when needed.) @kbd{C-u C-c C-u} can be used to
|
||||
clear known local macro definitions.
|
||||
|
||||
@node Key Index, , Customisation, Top
|
||||
@unnumbered Key Index
|
||||
@printindex ky
|
||||
|
||||
@bye
|
||||
|
||||
@c Local Variables:
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
;;; wesnoth-update.el --- Update known WML data via existing valid WML.
|
||||
;; Copyright (C) 2008 Chris Mann
|
||||
;; Copyright (C) 2008, 2009 Chris Mann
|
||||
|
||||
;; This file is part of wesnoth-mode.
|
||||
|
||||
|
@ -59,6 +59,9 @@
|
|||
;; available to `wesnoth-mode'.
|
||||
|
||||
;;; History:
|
||||
;; 0.1.4
|
||||
;; * Fixed inaccuracies when updating project information.
|
||||
;; * WML data from the addition file can now read when as it is required.
|
||||
;; 0.1.3
|
||||
;; * Any arguments are now stored for each macro.
|
||||
;; 0.1.2
|
||||
|
@ -73,7 +76,7 @@
|
|||
;; * Initial version
|
||||
|
||||
;;; Code:
|
||||
(defvar wesnoth-update-version "0.1.3"
|
||||
(defvar wesnoth-update-version "0.1.4"
|
||||
"Version of `wesnoth-update'.")
|
||||
|
||||
(defcustom wesnoth-root-directory nil
|
||||
|
@ -99,6 +102,12 @@ This is relative to the wesnoth directory in `wesnoth-root-directory.'.")
|
|||
(defvar wesnoth-found-cfgs '()
|
||||
"Temporary list of all .cfg files found.")
|
||||
|
||||
(defvar wesnoth-tmp-tag-data '()
|
||||
"Temporary list of tag data.")
|
||||
|
||||
(defvar wesnoth-tmp-macro-data '()
|
||||
"Temporary list of macro data.")
|
||||
|
||||
(defvar wesnoth-tag-data '()
|
||||
"All information regarding the relation of tags and attributes.")
|
||||
|
||||
|
@ -112,12 +121,15 @@ This is relative to the wesnoth directory in `wesnoth-root-directory.'.")
|
|||
:size 350)
|
||||
"Hash table of known WML tag data.")
|
||||
|
||||
(defun wesnoth-create-wml-hash-table (&optional force)
|
||||
"Handle generation of `wesnoth-tag-hash-table'."
|
||||
(defun wesnoth-create-wml-hash-table (tag-data &optional force)
|
||||
"Handle generation of `wesnoth-tag-hash-table'.
|
||||
TAG-DATA is the data to add to the hash-table. If FORCE is
|
||||
non-nil, update the hash-table regardless of whether it replacing
|
||||
any existing data."
|
||||
(when (or (= (hash-table-count wesnoth-tag-hash-table) 0)
|
||||
force)
|
||||
(clrhash wesnoth-tag-hash-table)
|
||||
(dolist (tag wesnoth-tag-data)
|
||||
(dolist (tag tag-data)
|
||||
(puthash (car tag) (cdr tag) wesnoth-tag-hash-table))))
|
||||
|
||||
(defun wesnoth-file-cfg-p (file)
|
||||
|
@ -216,9 +228,9 @@ DIR-OR-FILE can be a file, a directory, or a list of files."
|
|||
(defun wesnoth-append-tag-information (tag subtag attribute)
|
||||
"Add the information regarding TAG to the list.
|
||||
SUBTAG and ATTRIBUTE are a children of TAG to be added."
|
||||
(let ((match (assoc tag wesnoth-tag-data)))
|
||||
(let ((match (assoc tag wesnoth-tmp-tag-data)))
|
||||
(if (not match)
|
||||
(add-to-list 'wesnoth-tag-data (list tag (and subtag (list subtag))
|
||||
(add-to-list 'wesnoth-tmp-tag-data (list tag (and subtag (list subtag))
|
||||
(and attribute (list attribute))))
|
||||
(if subtag
|
||||
(let ((tmp (nth 1 match)))
|
||||
|
@ -229,29 +241,27 @@ SUBTAG and ATTRIBUTE are a children of TAG to be added."
|
|||
(when (not (member attribute tmp))
|
||||
(add-to-list 'tmp attribute)
|
||||
(setq match (list tag (nth 1 match) tmp))))))
|
||||
(setq wesnoth-tag-data
|
||||
(remove (assoc tag wesnoth-tag-data)
|
||||
wesnoth-tag-data))
|
||||
(add-to-list 'wesnoth-tag-data match))))
|
||||
(setq wesnoth-tmp-tag-data
|
||||
(remove (assoc tag wesnoth-tmp-tag-data)
|
||||
wesnoth-tmp-tag-data))
|
||||
(add-to-list 'wesnoth-tmp-tag-data match))))
|
||||
|
||||
(defmacro wesnoth-determine-macro-information (macro-list)
|
||||
(defun wesnoth-determine-macro-information ()
|
||||
"Process the buffer, retrieving macro definition information.
|
||||
MACRO-LIST is the variable to append macro information."
|
||||
`(save-excursion
|
||||
(goto-char (point-min))
|
||||
(while (search-forward-regexp
|
||||
"#define \\(\\(?:\\w\\|_\\)+\\)\\(\\([\t ]+\\(\\w\\|_\\)+\\)*\\)"
|
||||
(point-max) t)
|
||||
(beginning-of-line)
|
||||
(add-to-list ,macro-list (list (match-string-no-properties 1)
|
||||
(and (match-string 2)
|
||||
(split-string
|
||||
(match-string-no-properties 2)))))
|
||||
(end-of-line))))
|
||||
|
||||
(defun wesnoth-determine-macro-builtins ()
|
||||
"Retrieve built-in macro definition information."
|
||||
(wesnoth-determine-macro-information 'wesnoth-macro-data))
|
||||
(save-excursion
|
||||
(goto-char (point-min))
|
||||
(while (search-forward-regexp
|
||||
"#define \\(\\(?:\\w\\|_\\)+\\)\\(\\([\t ]+\\(\\w\\|_\\)+\\)*\\)"
|
||||
(point-max) t)
|
||||
(beginning-of-line)
|
||||
(add-to-list 'wesnoth-tmp-macro-data
|
||||
(list (match-string-no-properties 1)
|
||||
(and (match-string 2)
|
||||
(split-string
|
||||
(match-string-no-properties 2)))))
|
||||
(end-of-line))
|
||||
wesnoth-tmp-macro-data))
|
||||
|
||||
(defun wesnoth-output-path ()
|
||||
"Determine the path to output wml information via `wesnoth-update'."
|
||||
|
@ -260,12 +270,29 @@ MACRO-LIST is the variable to append macro information."
|
|||
(symbol-value 'user-emacs-directory)
|
||||
"~/.emacs.d/")))
|
||||
|
||||
(defun wesnoth-update-wml-additions ()
|
||||
"Update WML information contained in `wesnoth-addition-file'."
|
||||
(defun wesnoth-read-tmp-tag-data ()
|
||||
"Read `wesnoth-tmp-tag-data' and reset its value."
|
||||
(let ((results wesnoth-tmp-tag-data))
|
||||
(setq wesnoth-tmp-tag-data nil)
|
||||
results))
|
||||
|
||||
(defun wesnoth-tag-additions ()
|
||||
"Update WML tag information contained in `wesnoth-addition-file'."
|
||||
(setq wesnoth-tmp-tag-data nil)
|
||||
(wesnoth-determine-details wesnoth-addition-file
|
||||
'wesnoth-extract-tag-information)
|
||||
(wesnoth-determine-details wesnoth-addition-file
|
||||
'wesnoth-determine-macro-builtins))
|
||||
(wesnoth-read-tmp-tag-data))
|
||||
|
||||
(defun wesnoth-macro-additions ()
|
||||
"Update WML macro information contained in `wesnoth-addition-file'."
|
||||
(setq wesnoth-tmp-macro-data nil)
|
||||
(wesnoth-determine-details
|
||||
wesnoth-addition-file
|
||||
(lambda ()
|
||||
(wesnoth-determine-macro-information)))
|
||||
(let ((results wesnoth-tmp-macro-data))
|
||||
(setq wesnoth-tmp-macro-data nil)
|
||||
results))
|
||||
|
||||
(defun wesnoth-update ()
|
||||
"Update WML information.
|
||||
|
@ -274,7 +301,9 @@ Path to WML information included in wesnoth is set by
|
|||
(interactive)
|
||||
(setq wesnoth-tag-data nil
|
||||
wesnoth-macro-data nil
|
||||
wesnoth-found-cfgs nil)
|
||||
wesnoth-found-cfgs nil
|
||||
wesnoth-tmp-macro-data nil
|
||||
wesnoth-tmp-tag-data nil)
|
||||
(unless (and (stringp wesnoth-root-directory)
|
||||
(file-exists-p wesnoth-root-directory))
|
||||
;; Update failed; restore data.
|
||||
|
@ -284,10 +313,14 @@ Path to WML information included in wesnoth is set by
|
|||
(message "Updating WML information...")
|
||||
(wesnoth-determine-details wesnoth-root-directory
|
||||
'wesnoth-extract-tag-information)
|
||||
(wesnoth-update-wml-additions)
|
||||
(wesnoth-determine-details (concat wesnoth-root-directory
|
||||
wesnoth-macro-directory)
|
||||
'wesnoth-determine-macro-builtins)
|
||||
(wesnoth-determine-details
|
||||
(concat wesnoth-root-directory wesnoth-macro-directory)
|
||||
(lambda ()
|
||||
(wesnoth-determine-macro-information)))
|
||||
(setq wesnoth-tag-data wesnoth-tmp-tag-data
|
||||
wesnoth-tmp-tag-data nil
|
||||
wesnoth-macro-data wesnoth-tmp-macro-data
|
||||
wesnoth-tmp-macro-data nil)
|
||||
(with-temp-buffer
|
||||
(insert (format "(setq wesnoth-tag-data '%S)\n\n" wesnoth-tag-data))
|
||||
(insert (format "(setq wesnoth-macro-data '%S)\n\n" wesnoth-macro-data))
|
||||
|
@ -295,26 +328,63 @@ Path to WML information included in wesnoth is set by
|
|||
(write-file (expand-file-name (format "wesnoth-wml-data.el")
|
||||
(wesnoth-output-path)))
|
||||
(load "wesnoth-wml-data"))
|
||||
(wesnoth-create-wml-hash-table t)
|
||||
(message "Updating WML information...done"))
|
||||
|
||||
(defun wesnoth-merge-macro-data (&rest macro-data)
|
||||
"Merge WML macro information and return the result.
|
||||
MACRO-DATA is the macro-data to merge."
|
||||
(let ((set-data '())
|
||||
(macro-base-data (car macro-data)))
|
||||
(while (setq macro-data (cdr macro-data))
|
||||
(setq set-data (car macro-data))
|
||||
(while set-data
|
||||
(setq macro-base-data
|
||||
(append (list (car set-data))
|
||||
(remove (assoc (car (car set-data)) macro-base-data)
|
||||
macro-base-data))
|
||||
set-data (cdr set-data))))
|
||||
macro-base-data))
|
||||
|
||||
(defun wesnoth-merge-tag-data (&rest tag-data)
|
||||
"Merge WML tag information and return the result.
|
||||
TAG-DATA is the tag-data to merge."
|
||||
(setq wesnoth-tmp-tag-data (car tag-data))
|
||||
(let ((set-data '()))
|
||||
(while (setq tag-data (cdr tag-data))
|
||||
(setq set-data (car tag-data))
|
||||
(while set-data
|
||||
(let ((subtags (nth 1 (car set-data))))
|
||||
(while subtags
|
||||
(wesnoth-append-tag-information (caar set-data) (car subtags)
|
||||
nil)
|
||||
(setq subtags (cdr subtags))))
|
||||
(let ((attributes (nth 2 (car set-data))))
|
||||
(while attributes
|
||||
(wesnoth-append-tag-information (caar set-data) nil
|
||||
(car attributes))
|
||||
(setq attributes (cdr attributes))))
|
||||
(setq set-data (cdr set-data))))
|
||||
(wesnoth-read-tmp-tag-data)))
|
||||
|
||||
(defun wesnoth-update-project-information (&optional clear)
|
||||
"Update WML macro information for the current project."
|
||||
"Update WML macro information for the current project.
|
||||
If CLEAR is non-nil, reset `wesnoth-local-macro-data'."
|
||||
(interactive "P")
|
||||
(setq wesnoth-tmp-macro-data nil)
|
||||
(if clear
|
||||
(setq wesnoth-local-macro-data nil)
|
||||
(wesnoth-determine-macro-information 'wesnoth-local-macro-data)))
|
||||
(setq wesnoth-local-macro-data
|
||||
(wesnoth-merge-macro-data wesnoth-local-macro-data
|
||||
(wesnoth-determine-macro-information)))
|
||||
(setq wesnoth-tmp-macro-data nil)))
|
||||
|
||||
(defun wesnoth-update-teach-wesnoth-mode (file-or-dir)
|
||||
"Update WML tag and attribute information for the current project.
|
||||
If FILE-OR-DIR is provided, perform the update using only that location."
|
||||
(interactive)
|
||||
(wesnoth-determine-details
|
||||
file-or-dir
|
||||
(lambda ()
|
||||
(wesnoth-determine-macro-information 'wesnoth-macro-data)))
|
||||
(wesnoth-determine-details file-or-dir
|
||||
'wesnoth-extract-tag-information))
|
||||
(defun wesnoth-refresh-wml-data ()
|
||||
"Return merged WML tag data and WML data from the addition file."
|
||||
(save-match-data
|
||||
(let ((result (wesnoth-merge-tag-data
|
||||
wesnoth-tag-data (wesnoth-tag-additions))))
|
||||
(wesnoth-create-wml-hash-table result t)
|
||||
result)))
|
||||
|
||||
(provide 'wesnoth-update)
|
||||
|
||||
|
|
|
@ -1,23 +1,22 @@
|
|||
# This is a sample file to demonstrate the format for providing additional WML
|
||||
# information to wesnoth-mode. The format is an outline of a valid element
|
||||
# structure in WML; attributes do not currently requiring a value.
|
||||
# structure in WML; attributes do not currently require a value.
|
||||
|
||||
[multiplayer]
|
||||
[music]
|
||||
name=
|
||||
append=
|
||||
play_once=
|
||||
immediate=
|
||||
ms_before=
|
||||
ms_after=
|
||||
|
||||
[/music]
|
||||
[event]
|
||||
[message]
|
||||
side_for=
|
||||
duration=
|
||||
[/message]
|
||||
[set_variable]
|
||||
modulo=
|
||||
[/set_variable]
|
||||
[unit]
|
||||
[status]
|
||||
poisoned=
|
||||
slowed=
|
||||
stone=
|
||||
hides=
|
||||
|
||||
[/status]
|
||||
[modifications]
|
||||
[object]
|
||||
|
|
File diff suppressed because one or more lines are too long
Loading…
Add table
Reference in a new issue