Initial git import
[sxemacs] / 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: SXEmacs Development Team
6 ;; Keywords: help, internal, dumped
7
8 ;; This file is part of SXEmacs.
9
10 ;; SXEmacs is free software: you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation, either version 3 of the License, or
13 ;; (at your option) any later version.
14
15 ;; SXEmacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 ;; GNU General Public License for more details.
19
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with this program.  If not, see <http://www.gnu.org/licenses/>.
22
23 ;;; Synched up with: Not in FSF
24
25 ;;; Commentary:
26
27 ;; This file is dumped with SXEmacs.
28
29 ;;; Code:
30
31 (defconst tutorial-supported-languages
32   '(
33     ("Croatian" hr iso-8859-2)
34     ("French" fr iso-8859-1)
35     ("German" de iso-8859-1)
36     ("Norwegian" no iso-8859-1)
37     ("Polish" pl iso-8859-2)
38     ("Romanian" ro iso-8859-2)
39     ("Swedish" se iso-8859-1)
40     )
41   "Alist of supported languages in TUTORIAL files.
42 Add languages here, as more are translated.")
43
44 ;; TUTORIAL arg is XEmacs addition
45 (defun help-with-tutorial (&optional tutorial language)
46   "Select the XEmacs learn-by-doing tutorial.
47 Optional arg TUTORIAL specifies the tutorial file; default is \"TUTORIAL\".
48 With a prefix argument, choose the language."
49   (interactive "i\nP")
50   (or tutorial
51       (setq tutorial "TUTORIAL"))
52   (when (and language (consp language))
53     (let ((completion-ignore-case t))
54       (setq language (assoc (completing-read "Language: "
55                                              tutorial-supported-languages
56                                              nil t)
57                             tutorial-supported-languages))))
58   (when language
59     (setq tutorial (format "%s.%s" tutorial (cadr language))))
60   (let ((file (expand-file-name tutorial "~")))
61     (delete-other-windows)
62     (let ((buffer (or (get-file-buffer file)
63                       (create-file-buffer file)))
64           (window-configuration (current-window-configuration)))
65       (condition-case error-data
66           (progn
67             (switch-to-buffer buffer)
68             (setq buffer-file-name file)
69             (setq default-directory (expand-file-name "~/"))
70             (setq buffer-auto-save-file-name nil)
71             ;; Because of non-Mule users, TUTORIALs are not coded
72             ;; independently, so we must guess the coding according to
73             ;; the language.
74             (let ((coding-system-for-read (nth 2 language)))
75               (insert-file-contents (locate-data-file tutorial)))
76             (goto-char (point-min))
77             ;; The 'didactic' blank lines: possibly insert blank lines
78             ;; around <<nya nya nya>> and replace << >> with [ ].
79             (if (re-search-forward "^<<.+>>")
80                 (let ((n (- (window-height (selected-window))
81                             (count-lines (point-min) (point-at-bol))
82                             6)))
83                   (if (< n 12)
84                       (progn (beginning-of-line) (kill-line))
85                     ;; Some people get confused by the large gap
86                     (delete-backward-char 2)
87                     (insert "]")
88                     (beginning-of-line)
89                     (save-excursion
90                       (delete-char 2)
91                       (insert "["))
92                     (newline (/ n 2))
93                     (next-line 1)
94                     (newline (- n (/ n 2))))))
95             (goto-char (point-min))
96             (set-buffer-modified-p nil))
97         ;; TUTORIAL was not found: kill the buffer and restore the
98         ;; window configuration.
99         (file-error (kill-buffer buffer)
100                     (set-window-configuration window-configuration)
101                     ;; Now, signal the error
102                     (signal (car error-data) (cdr error-data)))))))
103
104 ;; General Mule-compatibility stuffs
105 (define-function 'string-width 'length)
106
107 ;; The following was originally in subr.el
108 (unless (featurep 'mule)
109   (defun make-char (charset &optional arg1 arg2)
110     "Make a character from CHARSET and octets ARG1 and ARG2.
111 This function is available for compatibility with Mule-enabled XEmacsen.
112 When CHARSET is `ascii', return (int-char ARG1).  Otherwise, return
113 that value with the high bit set.  ARG2 is always ignored."
114     (int-char (if (eq charset 'ascii)
115                   arg1
116                 (logior arg1 #x80)))))
117
118
119 (provide 'help-nomule)
120
121 ;;; help-nomule.el ends here