X-Git-Url: http://git.chise.org/gitweb/?a=blobdiff_plain;f=lisp%2Fassistant.el;h=ef10be6484852c74059edc0ed1a8f96ebc7dfae3;hb=8047583c8c86a5c6a61bddc27b391042e39e1ce5;hp=25e13dc4a1ff1470cae78d7f9536e924bcedbebb;hpb=c6e880a94f860469eed8fdaeaf8fde9a7da1ab0e;p=elisp%2Fgnus.git- diff --git a/lisp/assistant.el b/lisp/assistant.el index 25e13dc..ef10be6 100644 --- a/lisp/assistant.el +++ b/lisp/assistant.el @@ -170,6 +170,9 @@ (pop ast)) (car ast))) +(defun assistant-node-name (node) + (assistant-get node "node")) + (defun assistant-previous-node-text (node) (format "<< Go back to %s" node)) @@ -210,6 +213,10 @@ (setcar (nthcdr 3 elem) value))))) (defun assistant-render-text (text node) + (unless (and text node) + (gnus-error + 5 + "The assistant was asked to render invalid text or node data")) (dolist (elem text) (if (stringp elem) ;; Ordinary text @@ -219,9 +226,8 @@ (variable (cadr elem)) (type (assistant-get-variable node variable 'type))) (cond - ((and (consp type) - (eq (car type) :radio)) - (push + ((eq (car-safe type) :radio) + (push (apply #'widget-create 'radio-button-choice @@ -239,6 +245,25 @@ "node"))) (cadr type)) assistant-widgets)) + ((eq (car-safe type) :set) + (push + (apply + #'widget-create + 'set + :assistant-variable variable + :assistant-node node + :value (assistant-get-variable node variable nil t) + :notify (lambda (widget &rest ignore) + (assistant-set-variable + (widget-get widget :assistant-node) + (widget-get widget :assistant-variable) + (widget-value widget)) + (assistant-render-node + (assistant-get + (widget-get widget :assistant-node) + "node"))) + (cadr type)) + assistant-widgets)) (t (push (widget-create @@ -261,10 +286,12 @@ (inhibit-read-only t) (previous assistant-current-node) (buffer-read-only nil)) + (unless node + (gnus-error 5 "The node for %s could not be found" node-name)) (set (make-local-variable 'assistant-widgets) nil) (assistant-set-defaults node) (if (equal (assistant-get node "type") "interstitial") - (assistant-render-node (assistant-find-next-node node-name)) + (assistant-render-node (nth 0 (assistant-find-next-nodes node-name))) (setq assistant-current-node node-name) (when previous (push previous assistant-previous-nodes)) @@ -283,9 +310,11 @@ (assistant-set-defaults (assistant-find-node node) 'force) (assistant-render-node node))) "Reset") - (insert " ") - (assistant-node-button 'next (assistant-find-next-node)) (insert "\n") + (dolist (nnode (assistant-find-next-nodes)) + (assistant-node-button 'next nnode) + (insert "\n")) + (goto-char (point-min)) (assistant-make-read-only)))) @@ -355,15 +384,34 @@ (error "%s" result)))) (assistant-set node "save" t))) -(defun assistant-find-next-node (&optional node) +;; (defun assistant-find-next-node (&optional node) +;; (let* ((node (assistant-find-node (or node assistant-current-node))) +;; (node-name (assistant-node-name node)) +;; (nexts (assistant-get-list node "next")) +;; next elem applicable) + +;; (while (setq elem (pop nexts)) +;; (when (assistant-eval (car (cadr elem))) +;; (setq applicable (cons elem applicable)))) + +;; ;; return the first thing we can +;; (cadr (cadr (pop applicable))))) + +(defun assistant-find-next-nodes (&optional node) (let* ((node (assistant-find-node (or node assistant-current-node))) (nexts (assistant-get-list node "next")) - next elem) - (while (and (setq elem (cadr (pop nexts))) - (not next)) - (when (setq next (assistant-eval (car elem))) - (setq next (or (cadr elem) next)))) - next)) + next elem applicable return) + + (while (setq elem (pop nexts)) + (when (assistant-eval (car (cadr elem))) + (setq applicable (cons elem applicable)))) + + ;; return the first thing we can + + (while (setq elem (pop applicable)) + (push (cadr (cadr elem)) return)) + + return)) (defun assistant-get-all-variables () (let ((variables nil)) @@ -377,9 +425,12 @@ (let ((bindings nil)) (dolist (variable (assistant-get-all-variables)) (setq variable (cadr variable)) - (push (list (car variable) (if (eq (nth 3 variable) 'default) - nil - (nth 3 variable))) + (push (list (car variable) + (if (eq (nth 3 variable) 'default) + nil + (if (listp (nth 3 variable)) + `(list ,@(nth 3 variable)) + (nth 3 variable)))) bindings)) (eval `(let ,bindings