Merge remote-tracking branch 'origin/master' into for-steve
[sxemacs] / lisp / mule / mule-help.el
1 ;;; mule-help.el --- Mule-ized Help functions
2
3 ;; Copyright (C) 1997 by Free Software Foundation, Inc.
4
5 ;; Author: SL Baur <steve@xemacs.org>
6 ;; Keywords: help, internal, mule
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: Emacs 20.1
24
25 ;;; Commentary:
26
27 ;;
28
29 ;;; Code:
30
31 ;; TUTORIAL arg is XEmacs addition
32 (defun help-with-tutorial (&optional arg tutorial)
33   "Select the XEmacs learn-by-doing tutorial.
34 If there is a tutorial version written in the language
35 of the selected language environment, that version is used.
36 If there's no tutorial in that language, `TUTORIAL' is selected.
37 With arg, you are asked to select which language."
38   (interactive "P")
39   (let (lang filename file)
40     (if arg
41         (or (setq lang (read-language-name 'tutorial "Language: "))
42             (error "No tutorial file of the specified language"))
43       (setq lang current-language-environment))
44     ;; The menubar buttons call this function like this:
45     ;; (help-with-tutorial nil "tutorial.lang")
46     (setq filename (if (and (not arg) tutorial)
47                        tutorial
48                      (or (get-language-info lang 'tutorial)
49                          (or tutorial "TUTORIAL"))))
50     (setq file (expand-file-name (concat "~/" filename)))
51     (delete-other-windows)
52     (if (get-file-buffer file)
53         (switch-to-buffer (get-file-buffer file))
54       (switch-to-buffer (create-file-buffer file))
55       (setq buffer-file-name file)
56       (setq default-directory (expand-file-name "~/"))
57       (setq buffer-auto-save-file-name nil)
58       (let ((coding-system-for-read
59              (get-language-info lang 'tutorial-coding-system)))
60         (insert-file-contents (locate-data-file filename)))
61       (goto-char (point-min))
62       ;; The 'didactic' blank lines: Possibly insert blank lines
63       ;; around <<nya nya nya>>, and change << >> to [ ].
64       (if (re-search-forward "^<<.+>>" nil t)
65           (let ((n (- (window-height (selected-window))
66                       (count-lines (point-min) (point-at-bol))
67                       6)))
68             (if (< n 12)
69                 (progn (beginning-of-line) (kill-line))
70               ;; Some people get confused by the large gap
71               (delete-backward-char 2)
72               (insert "]")
73               (beginning-of-line)
74               (save-excursion
75                 (delete-char 2)
76                 (insert "["))
77               (newline (/ n 2))
78               (next-line 1)
79               (newline (- n (/ n 2))))))
80       (goto-char (point-min))
81       (set-buffer-modified-p nil))))
82
83
84 (provide 'mule-help)
85
86 ;;; mule-help.el ends here