From 9bd75bb70c963f787d2b374fa3fc42d344293304 Mon Sep 17 00:00:00 2001 From: Chris Mann Date: Mon, 6 Oct 2008 21:56:30 +1030 Subject: [PATCH] * wesnoth-mode.el: (require 'wesnoth-update) (wesnoth-check-output): New function. (wesnoth-check-wml): Output to buffer. --- wesnoth-mode.el | 117 +++++++++++++++++++++++++++++++------------------------- 1 file changed, 64 insertions(+), 53 deletions(-) diff --git a/wesnoth-mode.el b/wesnoth-mode.el index 4b7e19e..42d2f43 100644 --- a/wesnoth-mode.el +++ b/wesnoth-mode.el @@ -33,8 +33,8 @@ ;;; History: ;; 1.3.0 ;; * WML checking is now context sensitive; checks attributes and macros. -;; * Context-sensitive completion for attributes and tags implemented. -;; * Completion for built-in macros implemented. +;; * Context-sensitive completion for attributes and tags. +;; * Completion for built-in and project macros. ;; * Changed the following bindings: ;; `wesnoth-insert-tag' - C-c e -> C-c t ;; `wesnoth-jump-to-matching' - C-c m -> C-c o @@ -121,6 +121,7 @@ ;;; Code: (require 'cl) (require 'wesnoth-wml-data) +(require 'wesnoth-update) (defconst wesnoth-mode-version "1.3.0-git" "The current version of `wesnoth-mode'.") @@ -694,85 +695,95 @@ be performed." list)) wesnoth-tag-data :key position))))) +(defun wesnoth-check-output (format-string &rest args) + (save-excursion + (let ((lnap (line-number-at-pos))) + (set-buffer outbuf) + (insert (apply 'format (concat "%d: " format-string "\n") + lnap args))))) + (defun wesnoth-check-wml () "Perform context-sensitive checks on WML-code." (interactive) (wesnoth-update-project-information) (let ((unmatched-tag-list '()) - (error-pos nil)) + (outbuf (get-buffer-create "*WML*"))) + (save-excursion + (let ((buffer (buffer-name))) + (set-buffer outbuf) + (erase-buffer) + (insert (format "Checking %s...\n" buffer)))) (save-excursion (goto-char (or (wesnoth-wml-start-pos) (point-min))) - (while (and (search-forward-regexp - (concat "^[\t ]*\\(\\[[+/]?\\(\\(\\w\\|_\\)+\\)\\]\\|" - "\\(\\w\\|_\\)+=\\|{\\(\\(\\w\\|_\\)+\\).*}\\|" - wesnoth-preprocessor-regexp "\\)") - (point-max) t) - (not error-pos)) + (while (search-forward-regexp + (concat "^[\t ]*\\(\\[[+/]?\\(\\(\\w\\|_\\)+\\)\\]\\|" + "\\(\\w\\|_\\)+=\\|{\\(\\(\\w\\|_\\)+\\).*}\\|" + wesnoth-preprocessor-regexp "\\)") + (point-max) t) (beginning-of-line) (cond ((looking-at "^[\t ]*\\[\\+?\\(\\(\\w\\|_\\)+\\)\\]") - (if (wesnoth-check-element-type 'second - (car unmatched-tag-list)) - (setq unmatched-tag-list (cons - (match-string-no-properties 1) - unmatched-tag-list)) - (message "Tag not available in this context: %s" - (match-string-no-properties 1)) - (setq error-pos (point)))) + (unless (wesnoth-check-element-type 'second + (car unmatched-tag-list)) + (wesnoth-check-output "Tag not available in this context: %s" + (match-string-no-properties 1))) + (setq unmatched-tag-list (cons + (match-string-no-properties 1) + unmatched-tag-list))) ((looking-at "[\t ]*\\(#define\\|#ifdef\\|#ifndef\\) ") (setq unmatched-tag-list (cons (match-string-no-properties 1) unmatched-tag-list))) ((looking-at wesnoth-preprocessor-closing-regexp) - (if (string= (car unmatched-tag-list) - (second (find (match-string-no-properties 1) - '(("enddef" "#define") - ("ifdef" "#endif") - ("ifndef" "#endif")) - :key 'car :test 'string=))) - (setq unmatched-tag-list (cdr unmatched-tag-list)) - (message "Preprocessor statement does not nest correctly") - (setq error-pos (point)))) + (unless (string= (car unmatched-tag-list) + (second (find (match-string-no-properties 1) + '(("enddef" "#define") + ("ifdef" "#endif") + ("ifndef" "#endif")) + :key 'car :test 'string=))) + (wesnoth-check-output + "Preprocessor statement does not nest correctly")) + (setq unmatched-tag-list (cdr unmatched-tag-list))) ((looking-at "^[\t ]*\\(\\(\\w\\|_\\)+\\)=") (unless (wesnoth-check-element-type 'third (car unmatched-tag-list)) - (message "Attribute not available in this context: %s" - (match-string-no-properties 1)) - (setq error-pos (point)))) + (wesnoth-check-output "Attribute not available in this context: %s" + (match-string-no-properties 1)))) ((looking-at "^[\t ]*#else") (unless (string-match "ifn?def" (car unmatched-tag-list)) (if (string= (car unmatched-tag-list) "#define") - (message "Expecting: %s" (car unmatched-tag-list)) - (message "Expecting: [/%s]" (car unmatched-tag-list))))) + (wesnoth-check-output "Expecting: %s" + (car unmatched-tag-list)) + (wesnoth-check-output "Expecting: [/%s]" + (car unmatched-tag-list))))) ((looking-at "^[\t ]*{\\(\\(\\w\\|_\\)+\\).*}") (unless (find (match-string-no-properties 1) (append wesnoth-local-macro-data wesnoth-macro-data) :test 'string= :key 'car) - (message "Unknown macro definition: {%s}" - (match-string-no-properties 1)) - (setq error-pos (point)))) + (wesnoth-check-output "Unknown macro definition: {%s}" + (match-string-no-properties 1)))) ((or (looking-at "^[\t ]*\\[/\\(\\(\\w\\|_\\)+\\)\\]")) - (if (string= (match-string-no-properties 1) - (car unmatched-tag-list)) - (setq unmatched-tag-list (cdr unmatched-tag-list)) + (unless (string= (match-string-no-properties 1) + (car unmatched-tag-list)) (if (string= "#" (subseq (car unmatched-tag-list) 0 1)) - (message "Expecting: #%s" - (car - (find (car unmatched-tag-list) - '(("enddef" "#define") - ("ifdef" "#endif") - ("ifndef" "#endif")) - :key 'second :test 'string=))) - (message "Expecting: [/%s]" (car unmatched-tag-list))) - (setq error-pos (point))))) + (wesnoth-check-output "Expecting: #%s" + (car + (find (car unmatched-tag-list) + '(("enddef" "#define") + ("ifdef" "#endif") + ("ifndef" "#endif")) + :key 'second :test 'string=))) + (wesnoth-check-output "Expecting: [/%s]" + (car unmatched-tag-list)))) + (setq unmatched-tag-list (cdr unmatched-tag-list)))) (end-of-line)) (if unmatched-tag-list - (unless error-pos - (message "Unmatched tag: %s" (car unmatched-tag-list)) - (setq error-pos (point))) - (message "WML appears fine."))) - (when error-pos - (goto-char error-pos) - (back-to-indentation)))) + (dolist (tag unmatched-tag-list) + (wesnoth-check-output "Unmatched tag: %s" + (car unmatched-tag-list))))) + (save-excursion + (display-buffer outbuf t) + (set-buffer outbuf) + (insert (format "\nChecking complete.\n"))))) (defmacro wesnoth-element-requires (element requirement &optional pop) "Process requirements for corresponding preprocessor elements. -- 2.11.4.GIT