From c10bbd2e0e280ba6f3145e73c76441e661f71db6 Mon Sep 17 00:00:00 2001 From: Chris Mann Date: Tue, 7 Oct 2008 22:53:02 +1030 Subject: [PATCH] * wesnoth-mode.el: Make wesnoth-update, wesnoth-wml-data non-essential. (wesnoth-completion-available): New macro. (wesnoth-complete-macro, wesnoth-complete-attribute, wesnoth-complete-tag, wesnoth-check-wml, wesnoth-build-completion): Support lack of completion data. (wesnoth-element-completion): Moved to fix bug when byte-compiled. --- wesnoth-mode.el | 74 +++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 45 insertions(+), 29 deletions(-) diff --git a/wesnoth-mode.el b/wesnoth-mode.el index ff66230..f7c8b51 100644 --- a/wesnoth-mode.el +++ b/wesnoth-mode.el @@ -125,8 +125,10 @@ ;;; Code: (require 'cl) -(require 'wesnoth-wml-data) -(require 'wesnoth-update) +;; The following provide completion data, but otherwise are not strictly +;; necessary. +(require 'wesnoth-wml-data nil t) +(require 'wesnoth-update nil t) (defconst wesnoth-mode-version "1.3.0-git" "The current version of `wesnoth-mode'.") @@ -260,6 +262,23 @@ level as their parent.") "String to use for an opening or closing element.") ;;; Insertion and completion +(defmacro wesnoth-element-completion (completions prompt) + "Process completion of COMPLETIONS, displaying PROMPT." + (let ((partial (gensym)) + (element (gensym))) + `(let* ((,partial (match-string-no-properties 1)) + (,element (when ,partial (try-completion ,partial ,completions)))) + (cond ((eq ,element t) + (setq ,element nil)) + ((null ,element) + (setq ,element + (completing-read ,prompt ,completions))) + ((not (member ,element ,completions)) + (setq ,element + (completing-read ,prompt ,completions + nil nil ,partial)))) + ,element))) + (defun wesnoth-parent-tag () "Return the name of the parent tag, nil otherwise." (save-excursion @@ -272,6 +291,12 @@ level as their parent.") t (subseq parent 2 (1- (length parent)))))))) +(defmacro wesnoth-completion-available (list) + "Return symbol value of LIST when bound. +Used to support lack of completion data." + `(when (boundp ,list) + (symbol-value ,list))) + (defun wesnoth-indent-or-complete () "Indent or complete the line at point, depending on context." (interactive) @@ -297,8 +322,10 @@ level as their parent.") "Complete and insert the macro at point. If COMPLETEP is non-nil, attempt to complete the macro at point." (interactive) - (let* ((macro-information (append wesnoth-macro-data - wesnoth-local-macro-data)) + (let* ((macro-information (append (wesnoth-completion-available + 'wesnoth-macro-data) + (wesnoth-completion-available + 'wesnoth-local-macro-data))) (completions (wesnoth-emacs-completion-formats (mapcar 'car macro-information))) (partial (when completep @@ -375,23 +402,6 @@ If COMPLETEP is non-nil, attempt to complete tag at point." (end-of-line)) (wesnoth-insert-tag nil tag))))) -(defmacro wesnoth-element-completion (completions prompt) - "Process completion of COMPLETIONS, displaying PROMPT." - (let ((partial (gensym)) - (element (gensym))) - `(let* ((,partial (match-string-no-properties 1)) - (,element (when ,partial (try-completion ,partial ,completions)))) - (cond ((eq ,element t) - (setq ,element nil)) - ((null ,element) - (setq ,element - (completing-read ,prompt ,completions))) - ((not (member ,element ,completions)) - (setq ,element - (completing-read ,prompt ,completions - nil nil ,partial)))) - ,element))) - (defun wesnoth-build-completion (position) "Create a new list for tag completion if necessary. Rebuilding list is required for versions of GNU Emacs earlier @@ -401,9 +411,11 @@ than 22. POSITION is the argument passed to `nth' for (let* ((parent (wesnoth-parent-tag)) (candidates (if (or (stringp parent) (null parent)) - (nth position (find (wesnoth-parent-tag) wesnoth-tag-data - :key 'car :test 'string=)) - (mapcar 'car wesnoth-tag-data)))) + (nth position + (find (wesnoth-parent-tag) + (wesnoth-completion-available 'wesnoth-tag-data) + :key 'car :test 'string=)) + (mapcar 'car (wesnoth-completion-available 'wesnoth-tag-data))))) (wesnoth-emacs-completion-formats candidates))) (defun wesnoth-emacs-completion-formats (candidates) @@ -718,14 +730,15 @@ LAST-TAG is the parent element." (string= last-tag "#ifndef") (string= last-tag "#ifdef")) (member (match-string-no-properties 1) - (mapcar 'car wesnoth-tag-data)) + (mapcar 'car (wesnoth-completion-available 'wesnoth-tag-data))) (member last-tag (mapcar 'car (remove-if-not (lambda (list) (member (match-string-no-properties 1) list)) - wesnoth-tag-data :key position))))) + (wesnoth-completion-available 'wesnoth-tag-data) + :key position))))) (defun wesnoth-check-output (buffer format-string &rest args) "Output the string as passed to `format'. @@ -741,7 +754,8 @@ ARGS is any additional data required by `format' to handle FORMAT-STRING." (defun wesnoth-check-wml () "Perform context-sensitive analysis of WML-code." (interactive) - (wesnoth-update-project-information) + (when (fboundp 'wesnoth-update-project-information) + (funcall 'wesnoth-update-project-information)) (let ((unmatched-tag-list '()) (outbuf (get-buffer-create "*WML*"))) (save-excursion @@ -797,8 +811,10 @@ ARGS is any additional data required by `format' to handle FORMAT-STRING." (car unmatched-tag-list))))) ((looking-at "^[\t ]*{\\(\\(\\w\\|_\\)+\\).*}") (unless (find (match-string-no-properties 1) - (append wesnoth-local-macro-data - wesnoth-macro-data) + (append (wesnoth-completion-available + 'wesnoth-local-macro-data) + (wesnoth-completion-available + 'wesnoth-macro-data)) :test 'string= :key 'car) (wesnoth-check-output outbuf "Unknown macro definition: '{%s}'" (match-string-no-properties 1)))) -- 2.11.4.GIT