Use the right minor mode name in the mode line spec so that the mode line menu works...
[gnus] / lisp / assistant.el
1 ;;; assistant.el --- guiding users through Emacs setup
2 ;; Copyright (C) 2004, 2005 Free Software Foundation, Inc.
3
4 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
5 ;; Keywords: util
6
7 ;; This file is part of GNU Emacs.
8
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)
12 ;; any later version.
13
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.
18
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.
23
24 ;;; Commentary:
25
26 ;;; Code:
27
28 (eval-when-compile
29   (require 'cl))
30
31 (require 'widget)
32 (require 'wid-edit)
33
34 (autoload 'gnus-error "gnus-util")
35 (autoload 'netrc-get "netrc")
36 (autoload 'netrc-machine "netrc")
37 (autoload 'netrc-parse "netrc")
38
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)))
45
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)
51
52 ;;; Internal variables
53
54 (defvar assistant-data nil)
55 (defvar assistant-current-node nil)
56 (defvar assistant-previous-nodes nil)
57 (defvar assistant-widgets nil)
58
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]+"))
64           (error "Dangling @")
65         (setq command (downcase (match-string 0)))
66         (goto-char (match-end 0)))
67       (setq value
68             (if (looking-at "[ \t]*\n")
69                 (let (start)
70                   (forward-line 1)
71                   (setq start (point))
72                   (unless (re-search-forward (concat "^@end " command) nil t)
73                     (error "No @end %s found" command))
74                   (beginning-of-line)
75                   (prog1
76                       (buffer-substring start (point))
77                     (forward-line 1)))
78               (skip-chars-forward " \t")
79               (prog1
80                   (buffer-substring (point) (point-at-eol))
81                 (forward-line 1))))
82       (push (list command (assistant-reader command value))
83             results))
84     (assistant-segment (nreverse results))))
85
86 (defun assistant-text-reader (text)
87   (with-temp-buffer
88     (insert text)
89     (goto-char (point-min))
90     (let ((start (point))
91           (sections nil))
92       (while (re-search-forward "@\\([^{]+\\){\\([^}]+\\)}" nil t)
93         (push (buffer-substring start (match-beginning 0))
94               sections)
95         (push (list (match-string 1) (match-string 2))
96               sections)
97         (setq start (point)))
98       (push (buffer-substring start (point-max))
99             sections)
100       (nreverse sections))))
101
102 ;; Segment the raw assistant data into a list of nodes.
103 (defun assistant-segment (list)
104   (let ((ast nil)
105         (node nil)
106         (title (pop list)))
107     (dolist (elem list)
108       (when (and (equal (car elem) "node")
109                  node)
110         (push (list "save" nil) node)
111         (push (nreverse node) ast)
112         (setq node nil))
113       (push elem node))
114     (when node
115       (push (list "save" nil) node)
116       (push (nreverse node) ast))
117     (cons title (nreverse ast))))
118
119 (defun assistant-reader (command&