From c96ad1b9ba35eb47f924d658f1494f8d9cf66267 Mon Sep 17 00:00:00 2001 From: Chris Mann Date: Sun, 23 Nov 2008 10:54:38 +1030 Subject: [PATCH] * wesnoth-mode.el (wesnoth-element-completion): Take completep argument. Improved behaviour. (wesnoth-indent-or-complete): No longer move point following an attribute. (wesnoth-complete-preprocessor, wesnoth-complete-tag, wesnoth-complete-attribute, wesnoth-complete-macro): No longer insert partial element when no match found. (wesnoth-determine-context): Fixed error when wesnoth-wml-start-pos not available. (wesnoth-forward-warning): Move to next line. (wesnoth-backward-warning): Move to previous line. (wesnoth-check-wml): Remove overlays from entire buffer. No longer use wesnoth-wml-start-pos. --- wesnoth-mode.el | 70 ++++++++++++++++++++++++++++++--------------------------- 1 file changed, 37 insertions(+), 33 deletions(-) diff --git a/wesnoth-mode.el b/wesnoth-mode.el index 54fd9a0..ac2c182 100644 --- a/wesnoth-mode.el +++ b/wesnoth-mode.el @@ -325,24 +325,23 @@ If LIMITED is non-nil, return a regexp which matches only the ;;; Insertion and completion -(defmacro wesnoth-element-completion (completions prompt partial) +(defmacro wesnoth-element-completion (completions prompt partial + &optional completep) "Process completion of COMPLETIONS, displaying PROMPT. PARTIAL is the partial string on which to attempt completion." `(let* ((element (when ,partial (try-completion ,partial ,completions)))) (cond ((eq element t) - (setq element nil)) - ((null element) - (setq element - (completing-read ,prompt ,completions nil nil nil - 'wesnoth-history-list))) + ,partial) + ((and completep (null element)) + nil) + ((and element (eq (try-completion element ,completions) t)) + element) ((not (if (listp (car ,completions)) (assoc element ,completions) (member element ,completions))) - (setq element - (completing-read ,prompt ,completions - nil nil ,partial - 'wesnoth-history-list)))) - element)) + (completing-read ,prompt ,completions + nil nil element + 'wesnoth-history-list))))) (defun wesnoth-parent-tag () "Return the name of the parent tag. @@ -403,7 +402,10 @@ matching tags." ((looking-back "\\(\\(\\w\\|_\\)+\\)[\t ]*$") (wesnoth-complete-attribute t)) (t - (wesnoth-indent)))) + (if (looking-back "^[^#]*=.*") + (save-excursion + (wesnoth-indent)) + (wesnoth-indent))))) (defun wesnoth-preprocessor-closed-p (preprocessor) "Determine whether PREPROCESSOR has been closed. @@ -431,9 +433,8 @@ If COMPLETEP is non-nil, attempt to complete preprocessor at point." (back-to-indentation) (when (looking-at "#\\(\\w+\\)$") (match-string-no-properties 1))))) - (preprocessor (or (wesnoth-element-completion - completions "Preprocessor: " partial) - partial)) + (preprocessor (wesnoth-element-completion + completions "Preprocessor: " partial completep)) (closedp (save-excursion (when preprocessor @@ -492,8 +493,8 @@ If COMPLETEP is non-nil, attempt to complete the macro at point." (save-excursion (when (looking-back "{\\(\\(\\w\\|_\\)*\\)") (match-string-no-properties 1))))) - (macro (or (wesnoth-element-completion completions "Macro: " partial) - partial)) + (macro (wesnoth-element-completion completions "Macro: " partial + completep)) (args (cadr (assoc macro macro-information)))) (when macro (if partial @@ -526,12 +527,10 @@ If COMPLETEP is non-nil, attempt to complete the attribute at point." (let* ((completions (wesnoth-build-completion 1)) (partial (when completep (save-excursion - (back-to-indentation) - (when (looking-at "\\(\\(\\w\\|_\\)+\\)") + (when (looking-back "^[\t ]*\\(\\(\\w\\|_\\)+\\)") (match-string-no-properties 1))))) - (attribute (or (wesnoth-element-completion completions "Attribute: " - partial) - partial))) + (attribute (wesnoth-element-completion completions "Attribute: " + partial completep))) (when attribute (if (and partial completep) (progn @@ -555,8 +554,8 @@ If COMPLETEP is non-nil, attempt to complete tag at point." (partial (when (and completep (looking-back "\\[\\(\\(\\w\\|_\\)+\\)")) (match-string-no-properties 1))) - (tag (or (wesnoth-element-completion completions "Tag: " partial) - partial)) + (tag (wesnoth-element-completion completions "Tag: " partial + completep)) (closedp (save-excursion (wesnoth-jump-to-matching (concat "[" tag "]")) @@ -953,13 +952,16 @@ determine the context." (match-string 1)) "")) (depth (wesnoth-within-define position))) - (while (and (> (wesnoth-within-define (point)) depth) + (while (and (wesnoth-wml-start-pos) + (> (wesnoth-within-define (point)) depth) (not (= (point) (wesnoth-wml-start-pos)))) (search-backward-regexp (wesnoth-element t) (wesnoth-wml-start-pos) t) (setq match (match-string 1))) - (when (and (= (point) (wesnoth-wml-start-pos)) (= depth 0) - (string-match "#define" match)) + (when (and (wesnoth-wml-start-pos) + (= (point) (wesnoth-wml-start-pos)) + (= depth 0) + (string-match "#define" match)) ;; Found nothing of use; reset match and assume top-level tag. (setq match "")) (cond @@ -1065,12 +1067,14 @@ END is the end of the region searched." (defun wesnoth-forward-warning () "Move to the next warning." (interactive) + (forward-line 1) (while (wesnoth-locate-warning (next-overlay-change (point)) (point-max) (point-min)))) (defun wesnoth-backward-warning () "Move to the previous warning." (interactive) + (forward-line -1) (while (wesnoth-locate-warning (previous-overlay-change (point)) (point-min) (point-max)))) @@ -1091,7 +1095,7 @@ If DETAILEDP or `wesnoth-check-display-type' are non-nil, report results in a separate buffer and as overlays in the current buffer." (interactive "P") (wesnoth-update-project-information) - (remove-overlays (or (wesnoth-wml-start-pos) (point-min)) (point-max)) + (remove-overlays (point-min) (point-max)) (when (= 0 (hash-table-count wesnoth-tag-hash-table)) (error "WML data not available; unable to generate report")) (setq wesnoth-define-blocks (wesnoth-find-macro-definitions)) @@ -1106,18 +1110,18 @@ results in a separate buffer and as overlays in the current buffer." (insert (format "Checking %s...\n" buffer)) (message (format "Checking %s..." buffer))))) (save-excursion - (goto-char (or (wesnoth-wml-start-pos) (point-min))) - (while (search-forward-regexp "[\t ]*{\\(\\(\\(\\w\\|_\\)+\\)[^= + (goto-char (point-min)) + (while (search-forward-regexp "{\\(\\(\\(\\w\\|_\\)+\\)[^= ]*\\)}" (point-max) t) - (dolist (macro (wesnoth-extract-macro-details - (match-string-no-properties 1))) + (dolist (macro (save-match-data (wesnoth-extract-macro-details + (match-string-no-properties 1)))) (unless (assoc macro (append (wesnoth-macro-arguments) wesnoth-local-macro-data wesnoth-macro-data)) (wesnoth-check-process "Unknown macro definition: '%s'" macro)))) - (goto-char (or (wesnoth-wml-start-pos) (point-min))) + (goto-char (point-min)) (while (search-forward-regexp ;; Match tags, preprocessor statements and attributes. (concat "^[\t ]*\\(\\[[+/]?\\([a-z]\\(\\w\\|_\\)+\\)\\]\\|" -- 2.11.4.GIT