(assistant-node-name): new convenience function
authorTeodor Zlatanov <tzz@lifelogs.com>
Thu, 3 Jun 2004 19:35:24 +0000 (19:35 +0000)
committerTeodor Zlatanov <tzz@lifelogs.com>
Thu, 3 Jun 2004 19:35:24 +0000 (19:35 +0000)
(assistant-render-text, assistant-render-node): error handling,
plus handle multiple next nodes
(assistant-find-next-node): commented out for now
(assistant-find-next-nodes): new function, returns list of next
nodes

lisp/ChangeLog
lisp/assistant.el

index 287a7f4..c2a0dc6 100644 (file)
@@ -1,3 +1,12 @@
+2004-06-03  Teodor Zlatanov  <tzz@lifelogs.com>
+
+       * assistant.el (assistant-node-name): new convenience function
+       (assistant-render-text, assistant-render-node): error handling,
+       plus handle multiple next nodes
+       (assistant-find-next-node): commented out for now
+       (assistant-find-next-nodes): new function, returns list of next
+       nodes
+
 2004-06-02  Reiner Steib  <Reiner.Steib@gmx.de>
 
        * mail-source.el (mail-source-directory): Fix doc-string.
index 68c6baf..79f83d5 100644 (file)
       (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))
 
        (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
        (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))
                   (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))))
 
          (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))