Contents in 1999-06-04-13 of release-21-2.
[chise/xemacs-chise.git.1] / lisp / help-nomule.el
1 ;;; help-nomule.el --- Help functions when not in Mule
2
3 ;; Copyright (C) 1997 by Free Software Foundation, Inc.
4
5 ;; Maintainer: XEmacs Development Team
6 ;; Keywords: help, internal, dumped
7
8 ;; This file is part of XEmacs.
9
10 ;; XEmacs is free software; you can redistribute it and/or modify it
11 ;; under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
13 ;; any later version.
14
15 ;; XEmacs is distributed in the hope that it will be useful, but
16 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18 ;; General Public License for more details.
19
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with XEmacs; see the file COPYING.  If not, write to the Free
22 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
23 ;; 02111-1307, USA.
24
25 ;;; Synched up with: Not in FSF
26
27 ;;; Commentary:
28
29 ;; This file is dumped with XEmacs.
30
31 ;;; Code:
32
33 (defconst tutorial-supported-languages
34   '(("French" fr iso-8859-1)
35     ("German" de iso-8859-1)
36     ("Norwegian" no iso-8859-1)
37     ("Croatian" hr iso-8859-2)
38     ("Polish" pl iso-8859-2)
39     ("Romanian" ro iso-8859-2))
40   "Alist of supported languages in TUTORIAL files.
41 Add languages here, as more are translated.")
42
43 ;; TUTORIAL arg is XEmacs addition
44 (defun help-with-tutorial (&optional tutorial language)
45   "Select the XEmacs learn-by-doing tutorial.
46 Optional arg TUTORIAL specifies the tutorial file; default is \"TUTORIAL\".
47 With a prefix argument, choose the language."
48   (interactive "i\nP")
49   (or tutorial
50       (setq tutorial "TUTORIAL"))
51   (when (and language (consp language))
52     (let ((completion-ignore-case t))
53       (setq language (assoc (completing-read "Language: "
54                                              tutorial-supported-languages
55                                              nil t)
56                             tutorial-supported-languages))))
57   (when language
58     (setq tutorial (format "%s.%s" tutorial (cadr language))))
59   (let ((file (expand-file-name tutorial "~")))
60     (delete-other-windows)
61     (let ((buffer (or (get-file-buffer file)
62                       (create-file-buffer file)))
63           (window-configuration (current-window-configuration)))
64       (condition-case error-data
65           (progn
66             (switch-to-buffer buffer)
67             (setq buffer-file-name file)
68             (setq default-directory (expand-file-name "~/"))
69             (setq buffer-auto-save-file-name nil)
70             ;; Because of non-Mule users, TUTORIALs are not coded
71             ;; independently, so we must guess the coding according to
72             ;; the language.
73             (let ((coding-system-for-read (nth 2 language)))
74               (insert-file-contents (locate-data-file tutorial)))
75             (goto-char (point-min))
76             ;; The 'didactic' blank lines: possibly insert blank lines
77             ;; around <<nya nya nya>> and replace << >> with [ ].
78             (if (re-search-forward "^<<.+>>")
79                 (let ((n (- (window-height (selected-window))
80                             (count-lines (point-min) (point-at-bol))
81                             6)))
82                   (if (< n 12)
83                       (progn (beginning-of-line) (kill-line))
84                     ;; Some people get confused by the large gap
85                     (delete-backward-char 2)
86                     (insert "]")
87                     (beginning-of-line)
88                     (save-excursion
89                       (delete-char 2)
90                       (insert "["))
91                     (newline (/ n 2))
92                     (next-line 1)
93                     (newline (- n (/ n 2))))))
94             (goto-char (point-min))
95             (set-buffer-modified-p nil))
96         ;; TUTORIAL was not found: kill the buffer and restore the
97         ;; window configuration.
98         (file-error (kill-buffer buffer)
99                     (set-window-configuration window-configuration)
100                     ;; Now, signal the error
101                     (signal (car error-data) (cdr error-data)))))))
102
103
104 (provide 'help-nomule)
105
106 ;;; help-nomule.el ends here