From d60e5062f0494fea0f36313264b5175096a57b86 Mon Sep 17 00:00:00 2001 From: Chris Mann Date: Wed, 29 Oct 2008 19:32:02 +1030 Subject: [PATCH] * wesnoth-mode.el (wesnoth-preprocessor-regexp): Fixed regexp incompatibility causing preprocessor pairs not to be found. (wesnoth-search-for-matching-tag): Minor clean-up. (wesnoth-jump-to-matching): Jump to opening when not on an element pair, instead of signalling an error. --- wesnoth-mode.el | 100 ++++++++++++++++++++++++++++++-------------------------- 1 file changed, 53 insertions(+), 47 deletions(-) diff --git a/wesnoth-mode.el b/wesnoth-mode.el index 2555bf9..93c2d76 100644 --- a/wesnoth-mode.el +++ b/wesnoth-mode.el @@ -165,7 +165,7 @@ level as their parent.") :group 'wesnoth-mode) (defconst wesnoth-preprocessor-regexp - "[\t ]*#\\(enddef\\|define\\|e\\(lse\\|nd\\(\\(de\\|i\\)f\\)\\)\\|\\(ifn?\\|un\\)def\\)" + "[\t ]*#\\(enddef\\|define \\|e\\(lse\\|nd\\(\\(de\\|i\\)f\\)\\)\\|\\(ifn?\\|un\\)def \\)" "Regular expression to match all preprocessor statements.") (defconst wesnoth-preprocessor-opening-regexp @@ -707,16 +707,16 @@ 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 (or (and ,skip (forward-line 1)) - (funcall ,search-function (wesnoth-element) (funcall ,bound) t)) - (when (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)) - (decf depth) - (incf depth))) - (= depth 0))))) + (when (and (or (and ,skip (forward-line 1)) + (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)) + (decf depth) + (incf depth))) + (= depth 0)))) (defun wesnoth-jump-to-matching (&optional opening) "Jump point to the matching opening/closing tag. @@ -726,44 +726,50 @@ OPENING is an opening preprocessor statement to attempt to find a match for." (let ((target nil) (first-element nil)) (save-excursion - (if (or (and (stringp opening) - (string-match (wesnoth-element-opening) opening)) - (looking-at (wesnoth-element-opening))) - (progn - (setq first-element (match-string-no-properties 0 opening)) - (when (wesnoth-search-for-matching-tag - 'search-forward-regexp (wesnoth-element-closing) 'point-max - (stringp opening)) - (beginning-of-line) - (if (and (string-match wesnoth-preprocessor-opening-regexp - first-element) - (looking-at (wesnoth-element-closing))) - (when (string= (match-string-no-properties 0) - (cdr (assoc first-element - '(("#define " . "#enddef") - ("#ifndef " . "#endif") - ("#ifdef " . "#endif"))))) - (setq target (point))) - (setq target (point))))) - (when (looking-at (wesnoth-element-closing)) - (setq first-element (match-string-no-properties 0)) - (end-of-line) + (cond + ((or (and (stringp opening) + (string-match (wesnoth-element-opening) opening)) + (looking-at (wesnoth-element-opening))) + (progn + (setq first-element (match-string-no-properties 0 opening)) (when (wesnoth-search-for-matching-tag - 'search-backward-regexp (wesnoth-element-opening) - 'wesnoth-wml-start-pos) - (if (and (string-match wesnoth-preprocessor-closing-regexp + 'search-forward-regexp (wesnoth-element-closing) 'point-max + (stringp opening)) + (beginning-of-line) + (if (and (string-match wesnoth-preprocessor-opening-regexp first-element) - (looking-at (wesnoth-element-opening))) - (progn - (when (or (and (string= "#enddef" first-element) - (string= "#define " - (match-string-no-properties 0))) - (and (string= "#endif" first-element) - (string-match - "#ifn?def " - (match-string-no-properties 0)))) - (setq target (point)))) - (setq target (point))))))) + (looking-at (wesnoth-element-closing))) + (when (string= (match-string-no-properties 0) + (cdr (assoc first-element + '(("#define " . "#enddef") + ("#ifndef " . "#endif") + ("#ifdef " . "#endif"))))) + (setq target (point))) + (setq target (point)))))) + ((looking-at (wesnoth-element-closing)) + (end-of-line) + (setq first-element (match-string-no-properties 0)) + (when (wesnoth-search-for-matching-tag + 'search-backward-regexp (wesnoth-element-opening) + 'wesnoth-wml-start-pos) + (if (and (string-match wesnoth-preprocessor-closing-regexp + first-element) + (looking-at (wesnoth-element-opening))) + (progn + (when (or (and (string= "#enddef" first-element) + (string= "#define " + (match-string-no-properties + 0))) + (and (string= "#endif" first-element) + (string-match + "#ifn?def " + (match-string-no-properties + 0)))) + (setq target (point)))) + (setq target (point))))) + (t + (search-backward-regexp (wesnoth-element-opening) (point-min) t) + (setq target (point))))) (if target (goto-char target) (when (interactive-p) -- 2.11.4.GIT