From 47e5a7f5c7fac9ce0b78d6f1e97e3cadcb0643fd Mon Sep 17 00:00:00 2001 From: Chris Mann Date: Sun, 4 Jan 2009 11:16:14 +1030 Subject: [PATCH] * wesnoth-mode.el: Updated changelog. (wesnoth-insert-missing-closing): Improve positioning when prior to opening tag. (wesnoth-search-for-matching-tag): Changed from macro to function. --- wesnoth-mode.el | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/wesnoth-mode.el b/wesnoth-mode.el index 315dc33..c1342f2 100644 --- a/wesnoth-mode.el +++ b/wesnoth-mode.el @@ -34,7 +34,9 @@ ;;; History: ;; 1.3.4 -;; * Improved context detection for completion for some circumstances. +;; * 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 @@ -820,13 +822,24 @@ 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))))) + (match-string-no-properties 1))) + (message "%s" match))) (when match (if (string= (substring match 0 1) "[") (wesnoth-insert-element-separately @@ -914,21 +927,21 @@ 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 +(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))))) + (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)) + (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)))) -- 2.11.4.GIT