From 1369053fee07a15641190be529c7637fc27407bb Mon Sep 17 00:00:00 2001 From: Chris Mann Date: Sat, 4 Oct 2008 16:26:05 +0930 Subject: [PATCH] * wesnoth-mode.el (wesnoth-mode-version): Updated version string to `1.2.5'. (wesnoth-tags-list): Added several new tags. (wesnoth-insert-tag): Cleaned up and fixed remaining positioning bugs. (wesnoth-nth-pair-position): New function. Ensure the closing tag is positioned correctly. (wesnoth-insert-element-separately, wesnoth-insert-missing-closing): Fixed remaining positioning bugs. (wesnoth-navigate-element): Trivial aethetic clean-up. (wesnoth-search-for-matching-tag): Return t on success. (wesnoth-indent): Fix positioning of attributes after a closing tag. (wesnoth-check-structure): Fixed a bug where #else would be added as an opening. --- wesnoth-mode.el | 138 +++++++++++++++++++++++++++++--------------------------- 1 file changed, 72 insertions(+), 66 deletions(-) diff --git a/wesnoth-mode.el b/wesnoth-mode.el index 170587a..6e19fdb 100644 --- a/wesnoth-mode.el +++ b/wesnoth-mode.el @@ -32,8 +32,9 @@ ;;; History: ;; 1.2.5 +;; * Fixed support for GNU Emacs 21. +;; * Added several new tags to `wesnoth-tags-list'. ;; * Added M-TAB binding for `wesnoth-insert-tag'. -;; * Revised `wesnoth-tags-list' to remove obsoleted tags. ;; * `wesnoth-insert-tag' now takes an optional numeric argument indicating ;; how many blocks to wrap across instead of a region. ;; * Support for `wesnoth-indent-preprocessor-bol' removed. @@ -102,7 +103,7 @@ ;; * Added support for #ifndef. ;;; Code: -(defconst wesnoth-mode-version "1.2.4+git" +(defconst wesnoth-mode-version "1.2.5" "The current version of `wesnoth-mode'.") (defgroup wesnoth-mode nil "Wesnoth-mode access" @@ -162,7 +163,6 @@ level as their parent.") (define-key map (kbd "C-c C-n") 'wesnoth-check-tag-names) (define-key map (kbd "C-c /") 'wesnoth-insert-missing-closing) (define-key map (kbd "C-c C-/") 'wesnoth-insert-missing-closing) - ;; Menu (define-key map [menu-bar wesnoth] (cons "WML" (make-sparse-keymap "WML"))) (define-key map [menu-bar wesnoth insert-tag] @@ -233,39 +233,37 @@ level as their parent.") ;;; Insertion (defvar wesnoth-tags-list (list - "abilities" "about" "advancefrom" "advancement" "advances" "ai" - "allow_recruit" "allow_undo" "animate_unit" "animation" "array" "attack" - "attack_filter" "attacks" "avoid base_unit" "binary_path" "bold" "campaign" - "capture_village" "choose" "clear_variable" "colour_adjust" "command" - "damage" "deaths" "debug_message" "defend" "defends" "defense" "delay" - "destination" "disallow_recruit" "do" "effect" "else" "end_turn" "endlevel" - "era" "event" "expenses" "filter" "filter_location" "filter_second" - "filter_vision" "fire_event" "format" "frame" "game_config" "generator" - "gold" "gold" "have_unit" "header" "hide_unit" "if" "illuminated_time" - "image" "img" "income" "insert_tag" "italic" "item" "jump" "join" "kill" + "abilities" "about" "advances" "advancefrom" "ai" "allow_recruit" "and" + "animation" "array" "attack" "attack_anim" "attacks" "avoid" "binary_path" + "bold" "campaign" "capture_village" "choose""clear_variable" + "colour_adjust" "command" "deaths" "debug_message" "defend" "defends" + "defense" "delay" "destination" "disallow_recruit" "do" "effect" "else" + "end_turn" "endlevel" "entry" "era" "event" "expenses" "filter" + "filter_attack" "filter_adjacent_location" "filter_location" + "filter_radius" "filter_second" "filter_vision" "format" "frame" + "game_config" "generator" "gold" "have_unit" "header" "hide_unit" "if" + "illuminated_time" "image" "img" "income" "italic" "item" "jump" "kill" "killed" "label" "language" "leader_goal" "main_map" "menu" "message" "mini_map" "missile_frame" "modifications" "modify_side" "modify_turns" - "move" "move_unit_fake" "movement costs" "movetype" "multiplayer" - "multiplayer_side" "music" "neighbour_unit_filter" "not" "num_units" - "object" "objectives" "objective" "observers" "option" "or" "panel" "part" - "place_shroud" "position" "print" "protect_location" "protect_unit" "race" - "random" "recall" "recalls" "recruit" "recruits" "redraw" "ref" - "remove_shroud" "remove_unit_overlay" "removeitem" "remove_sound_source" - "replay" "replay_start" "resistance" "resolution" "results" "role" "save" - "scenario" "scroll" "scroll_to" "scroll_to_unit" "secondary_attack_filter" - "secondary_unit_filter" "section" "set_menu_item" "set_recruit" - "set_variable" "set_variables" "side" "side_playing" "snapshot" "sound" - "sound_source" "source" "special_filter" "special_filter_second" "split" - "statistics" "status" "stone" "store_gold" "store_locations" - "store_map_dimensions" "store_starting_location" "store_side" "store_unit" - "story" "target" "team" "teleport" "teleport_anim" "terrain" - "terrain_graphics" "terrain_mask" "test" "textdomain" "theme" "then" "tile" - "time" "time_area" "time_of_day" "topic" "toplevel" "trait" "turn" - "tutorial" "unhide_unit" "unit" "unit_abilities" "unit_alignment" - "unit_description" "unit_filter" "unit_hp" "unit_image" "unit_level" - "unit_moves" "unit_overlay" "unit_profile" "unit_status" "unit_traits" - "unit_type" "unit_weapons" "unit_xp" "units" "unstone" "unstore_unit" - "upkeep" "variable" "variables" "village" "villages" "while" "wml_filter") + "move" "move_unit_fake" "movement_costs" "movetype" "multiplayer" + "multiplayer_side" "music" "not" "num_units" "object" "objectives" + "objective" "observers" "option" "or" "panel" "part" "place_shroud" + "position" "print" "protect_location" "protect_unit" "race" "random" + "recall" "recalls" "recruit" "recruits" "redraw" "ref" "remove_shroud" + "remove_unit_overlay" "removeitem" "replay" "replay_start" "resistance" + "resolution" "results" "role" "save" "scenario" "scroll" "scroll_to" + "scroll_to_unit" "section" "set_menu_item" "set_recruit" "set_specials" + "set_variable" "show_if" "side" "side_playing" "snapshot" "sound" "source" + "specials" "statistics" "status" "stone" "store_gold" "store_locations" + "store_starting_location" "store_side" "store_unit" "story" "target" "team" + "teleport" "teleport_anim" "terrain" "terrain_graphics" "terrain_mask" + "test" "text_input" "textdomain" "theme" "then" "tile" "time" "time_area" + "time_of_day" "topic" "toplevel" "trait" "turn" "tutorial" "unhide_unit" + "unit" "unit_abilities" "unit_alignment" "unit_description" "unit_hp" + "unit_image" "unit_level" "unit_moves" "unit_overlay" "unit_profile" + "unit_status" "unit_traits" "unit_type" "unit_weapons" "unit_xp" "units" + "unstone" "unstore_unit" "upkeep" "variable" "variables" "village" + "villages" "while" "wml_filter") "A list containing all tags which are available in WML.") (defvar wesnoth-completion-cache '() @@ -302,39 +300,49 @@ TAGNAME is the name of the tag to be inserted." (setq tagname (completing-read "Tag: " (wesnoth-build-completion)))) (or elements (setq elements 0)) (let ((depth 0) - (start (save-excursion (forward-line -1) (point)))) + (start (save-excursion (forward-line -1) (point))) + (end (unless (= elements 0) + (wesnoth-nth-pair-position elements)))) (wesnoth-insert-element-separately "[" tagname "]") - (when (= elements 0) - (newline)) (save-excursion - (when (= elements 0) - (newline)) - (while (> elements 0) - (wesnoth-search-for-matching-tag - 'search-forward-regexp wesnoth-element-closing 'point-max) - (decf elements) - (beginning-of-line)) + (if end + (goto-char (marker-position end)) + (newline 2)) (wesnoth-insert-element-separately "[/" tagname "]") - (indent-region start (point))) - (wesnoth-indent))) + (indent-region start (point) nil)) + (unless end + (forward-line 1))) + (wesnoth-indent)) + +(defun wesnoth-nth-pair-position (count) + "Return `point' after COUNT number of matching element pairs. +COUNT is a positive number representing the number of balanced +pairs to move across. +`point' is returned as a marker object." + (save-excursion + (while (> count 0) + ;; Currently looking-at target tag. Stop here to avoid + ;; incorrect nesting. + (unless (wesnoth-search-for-matching-tag + 'search-forward-regexp wesnoth-element-closing 'point-max) + (setq count 0) + (search-backward-regexp wesnoth-element-closing (point-min) t)) + (and (> (decf count) 0) (forward-line 1))) + (end-of-line) + (point-marker))) (defun wesnoth-insert-element-separately (&rest strings) "Concatenate STRINGS and insert them on a line of their own." - (let ((create-newline nil)) - (save-excursion - (beginning-of-line) - (unless (looking-at "^[\t ]*$") - (setq create-newline t))) + (let ((create-newline (save-excursion + (beginning-of-line) + (if (looking-at "^[\t ]*$") nil t)))) (when create-newline - (if (> (point) - (save-excursion - (back-to-indentation) - (point))) + (if (> (point) (save-excursion (back-to-indentation) (point))) (progn (end-of-line) (newline)) - (beginning-of-line)) - (open-line 1)) + (beginning-of-line) + (open-line 1))) (insert (apply 'concat strings)))) (defun wesnoth-insert-missing-closing (&optional start end) @@ -356,9 +364,6 @@ respectively." (error "%s" "Unable to find element to insert") (when (string= element "Unexpected end of file") (error "%s" element)) - (when (not (looking-at "[\t ]*$")) - (end-of-line) - (wesnoth-newline)) (wesnoth-insert-element-separately element))) (wesnoth-indent)) @@ -392,8 +397,7 @@ search." (or ,repeat (setq ,repeat 1)) (while (> ,repeat 0) (and (eq ,search-function 'search-forward-regexp) (end-of-line)) - (funcall ,search-function wesnoth-element-opening - ,bound t) + (funcall ,search-function wesnoth-element-opening ,bound t) (back-to-indentation) (decf ,repeat)))) @@ -429,7 +433,8 @@ BOUND is the bound to be passed to the search function." (funcall ,bound) t)) (if (string-match ,search-string (match-string 0)) (decf depth) - (incf depth)))))) + (incf depth))) + t))) (defun wesnoth-jump-to-matching () "Jump point to the matching opening/closing tag." @@ -477,7 +482,9 @@ CONTEXT represents the type of element which precedes the current element." (setq cur-indent (+ ref-indent wesnoth-base-indent)) (setq cur-indent ref-indent))) ((eq context 'closing) - (if (looking-at "^[\t ]*\\[/") + (if (or (looking-at "^[\t ]*\\[/") + (and (not wesnoth-indent-default-style) + (not (looking-at wesnoth-element-opening)))) (setq cur-indent (- ref-indent wesnoth-base-indent)) (setq cur-indent ref-indent)))))) (indent-line-to (max cur-indent 0)))) @@ -654,10 +661,9 @@ positions of the buffer, respectively." (not error-position)) (beginning-of-line) (if (or (looking-at "^[\t ]*\\[\\(\\(\\w\\|_\\)+\\)\\]") - (looking-at wesnoth-preprocessor-opening-regexp)) + (looking-at "[\t ]*#\\(define \\|ifdef \\|ifndef \\)")) (setq unmatched-tag-list (cons (match-string-no-properties 1) unmatched-tag-list)) - (cond ((wesnoth-element-requires "#else" "ifn?def ")) ((wesnoth-element-requires "#endif" "ifn?def " t)) -- 2.11.4.GIT