1 ;;; assistant.el --- guiding users through Emacs setup
2 ;; Copyright (C) 2004, 2005 Free Software Foundation, Inc.
4 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
7 ;; This file is part of GNU Emacs.
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 3, or (at your option)
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the
21 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22 ;; Boston, MA 02110-1301, USA.
34 (autoload 'gnus-error "gnus-util")
35 (autoload 'netrc-get "netrc")
36 (autoload 'netrc-machine "netrc")
37 (autoload 'netrc-parse "netrc")
39 (defvar assistant-readers
40 '(("variable" assistant-variable-reader)
41 ("validate" assistant-sexp-reader)
42 ("result" assistant-list-reader)
43 ("next" assistant-list-reader)
44 ("text" assistant-text-reader)))
46 (defface assistant-field '((t (:bold t)))
47 "Face used for editable fields."
48 :group 'gnus-article-emphasis)
49 ;; backward-compatibility alias
50 (put 'assistant-field-face 'face-alias 'assistant-field)
52 ;;; Internal variables
54 (defvar assistant-data nil)
55 (defvar assistant-current-node nil)
56 (defvar assistant-previous-nodes nil)
57 (defvar assistant-widgets nil)
59 (defun assistant-parse-buffer ()
60 (let (results command value)
61 (goto-char (point-min))
62 (while (search-forward "@" nil t)
63 (if (not (looking-at "[^ \t\n]+"))
65 (setq command (downcase (match-string 0)))
66 (goto-char (match-end 0)))
68 (if (looking-at "[ \t]*\n")
72 (unless (re-search-forward (concat "^@end " command) nil t)
73 (error "No @end %s found" command))
76 (buffer-substring start (point))
78 (skip-chars-forward " \t")
80 (buffer-substring (point) (point-at-eol))
82 (push (list command (assistant-reader command value))
84 (assistant-segment (nreverse results))))
86 (defun assistant-text-reader (text)
89 (goto-char (point-min))
92 (while (re-search-forward "@\\([^{]+\\){\\([^}]+\\)}" nil t)
93 (push (buffer-substring start (match-beginning 0))
95 (push (list (match-string 1) (match-string 2))
98 (push (buffer-substring start (point-max))
100 (nreverse sections))))
102 ;; Segment the raw assistant data into a list of nodes.
103 (defun assistant-segment (list)
108 (when (and (equal (car elem) "node")
110 (push (list "save" nil) node)
111 (push (nreverse node) ast)
115 (push (list "save" nil) node)
116 (push (nreverse node) ast))
117 (cons title (nreverse ast))))
119 (defun assistant-reader (command&