(gnus-bdf-image-file): New variable; moved from gnus.el.
[elisp/gnus.git-] / lisp / gnus-ems.el
1 ;;; gnus-ems.el --- functions for making Gnus work under different Emacsen
2 ;; Copyright (C) 1995,96,97,98 Free Software Foundation, Inc.
3
4 ;; Author: Lars Magne Ingebrigtsen <larsi@ifi.uio.no>
5 ;;         Tatsuya Ichikawa <t-ichi@niagara.shiojiri.ne.jp>
6 ;; Keywords: news
7
8 ;; This file is part of GNU Emacs.
9
10 ;; GNU Emacs 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 2, or (at your option)
13 ;; any later version.
14
15 ;; GNU Emacs 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 GNU Emacs; see the file COPYING.  If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
24
25 ;;; Commentary:
26
27 ;;; Code:
28
29 (eval-when-compile (require 'cl))
30
31 ;;; Function aliases later to be redefined for XEmacs usage.
32
33 (defvar gnus-xemacs (string-match "XEmacs\\|Lucid" emacs-version)
34   "Non-nil if running under XEmacs.")
35
36 (defvar gnus-mouse-2 [mouse-2])
37 (defvar gnus-down-mouse-2 [down-mouse-2])
38 (defvar gnus-mode-line-modified
39   (if (or gnus-xemacs
40           (< emacs-major-version 20))
41       '("--**-" . "-----")
42     '("**" "--")))
43
44 (eval-and-compile
45   (autoload 'gnus-xmas-define "gnus-xmas")
46   (autoload 'gnus-xmas-redefine "gnus-xmas")
47   (autoload 'appt-select-lowest-window "appt"))
48
49 (or (fboundp 'mail-file-babyl-p)
50     (fset 'mail-file-babyl-p 'rmail-file-p))
51
52 ;;; Mule functions.
53
54 (defun gnus-mule-cite-add-face (number prefix face)
55   ;; At line NUMBER, ignore PREFIX and add FACE to the rest of the line.
56   (when face
57     (let ((inhibit-point-motion-hooks t)
58           from to)
59       (goto-line number)
60       (unless (eobp)            ; Sometimes things become confused (broken).
61         (if (boundp 'MULE)
62             (forward-char (chars-in-string prefix))
63           (forward-char (length prefix)))
64         (skip-chars-forward " \t")
65         (setq from (point))
66         (end-of-line 1)
67         (skip-chars-backward " \t")
68         (setq to (point))
69         (when (< from to)
70           (push (setq overlay (gnus-make-overlay from to))
71                 gnus-cite-overlay-list)
72           (gnus-overlay-put (gnus-make-overlay from to) 'face face))))))
73
74 (defun gnus-mule-max-width-function (el max-width)
75   (` (let* ((val (eval (, el)))
76             (valstr (if (numberp val)
77                         (int-to-string val) val)))
78        (if (> (length valstr) (, max-width))
79            (truncate-string valstr (, max-width))
80          valstr))))
81
82 (defvar gnus-bdf-image-file nil)
83 (defun gnus-mule-group-startup-message (&optional x y)
84   "Insert startup message in current buffer."
85   ;; Insert the message.
86   (erase-buffer)
87   (insert
88    (if (featurep 'bitmap)
89      (format "              %s
90
91 "
92              "" (if (and (stringp gnus-bdf-image-file)
93                          (file-exists-p gnus-bdf-image-file))
94                     (insert-file gnus-image-file)))
95      (format "              %s
96           _    ___ _             _
97           _ ___ __ ___  __    _ ___
98           __   _     ___    __  ___
99               _           ___     _
100              _  _ __             _
101              ___   __            _
102                    __           _
103                     _      _   _
104                    _      _    _
105                       _  _    _
106                   __  ___
107                  _   _ _     _
108                 _   _
109               _    _
110              _    _
111             _
112           __
113
114 "
115              "")))
116   ;; And then hack it.
117   (gnus-indent-rigidly (point-min) (point-max)
118                        (/ (max (- (window-width) (or x 46)) 0) 2))
119   (goto-char (point-min))
120   (forward-line 1)
121   (let* ((pheight (count-lines (point-min) (point-max)))
122          (wheight (window-height))
123          (rest (- wheight pheight)))
124     (insert (make-string (max 0 (* 2 (/ rest 3))) ?\n)))
125   ;; Fontify some.
126   (put-text-property (point-min) (point-max) 'face 'gnus-splash-face)
127   (goto-char (point-min))
128   (setq mode-line-buffer-identification (concat " " gnus-version))
129   (setq gnus-simple-splash t)
130   (set-buffer-modified-p t))
131
132 (defun gnus-encode-coding-string (string system)
133   string)
134
135 (defun gnus-decode-coding-string (string system)
136   string)
137
138 (eval-and-compile
139   (if (string-match "XEmacs\\|Lucid" emacs-version)
140       nil
141
142     (defvar gnus-mouse-face-prop 'mouse-face
143       "Property used for highlighting mouse regions."))
144
145   (cond
146    ((string-match "XEmacs\\|Lucid" emacs-version)
147     (gnus-xmas-define))
148
149    ((or (not (boundp 'emacs-minor-version))
150         (and (< emacs-major-version 20)
151              (< emacs-minor-version 30)))
152     ;; Remove the `intangible' prop.
153     (let ((props (and (boundp 'gnus-hidden-properties)
154                       gnus-hidden-properties)))
155       (while (and props (not (eq (car (cdr props)) 'intangible)))
156         (setq props (cdr props)))
157       (when props
158         (setcdr props (cdr (cdr (cdr props))))))
159     (unless (fboundp 'buffer-substring-no-properties)
160       (defun buffer-substring-no-properties (beg end)
161         (format "%s" (buffer-substring beg end)))))
162
163    ((boundp 'MULE)
164     (provide 'gnusutil))))
165
166 (eval-and-compile
167   (cond
168    ((not window-system)
169     (defun gnus-dummy-func (&rest args))
170     (let ((funcs '(mouse-set-point set-face-foreground
171                                    set-face-background x-popup-menu)))
172       (while funcs
173         (unless (fboundp (car funcs))
174           (fset (car funcs) 'gnus-dummy-func))
175         (setq funcs (cdr funcs))))))
176   (unless (fboundp 'file-regular-p)
177     (defun file-regular-p (file)
178       (and (not (file-directory-p file))
179            (not (file-symlink-p file))
180            (file-exists-p file))))
181   (unless (fboundp 'face-list)
182     (defun face-list (&rest args))))
183
184 (eval-and-compile
185   (let ((case-fold-search t))
186     (cond
187      ((string-match "windows-nt\\|os/2\\|emx" (format "%s" system-type))
188       (setq nnheader-file-name-translation-alist
189             (append nnheader-file-name-translation-alist
190                     '((?: . ?_)
191                       (?+ . ?-))))))))
192
193 (defvar gnus-tmp-unread)
194 (defvar gnus-tmp-replied)
195 (defvar gnus-tmp-score-char)
196 (defvar gnus-tmp-indentation)
197 (defvar gnus-tmp-opening-bracket)
198 (defvar gnus-tmp-lines)
199 (defvar gnus-tmp-name)
200 (defvar gnus-tmp-closing-bracket)
201 (defvar gnus-tmp-subject-or-nil)
202
203 (defun gnus-ems-redefine ()
204   (cond
205    ((string-match "XEmacs\\|Lucid" emacs-version)
206     (gnus-xmas-redefine))
207
208    ((featurep 'mule)
209     ;; Mule and new Emacs definitions
210
211     ;; [Note] Now there are three kinds of mule implementations,
212     ;; original MULE, XEmacs/mule and beta version of Emacs including
213     ;; some mule features. Unfortunately these API are different. In
214     ;; particular, Emacs (including original MULE) and XEmacs are
215     ;; quite different.
216     ;; Predicates to check are following:
217     ;; (boundp 'MULE) is t only if MULE (original; anything older than
218     ;;                     Mule 2.3) is running.
219     ;; (featurep 'mule) is t when every mule variants are running.
220
221     ;; These implementations may be able to share between original
222     ;; MULE and beta version of new Emacs. In addition, it is able to
223     ;; detect XEmacs/mule by (featurep 'mule) and to check variable
224     ;; `emacs-version'. In this case, implementation for XEmacs/mule
225     ;; may be able to share between XEmacs and XEmacs/mule.
226
227     (defalias 'gnus-truncate-string 'truncate-string)
228
229     (defvar gnus-summary-display-table nil
230       "Display table used in summary mode buffers.")
231     (fset 'gnus-cite-add-face 'gnus-mule-cite-add-face)
232     (fset 'gnus-max-width-function 'gnus-mule-max-width-function)
233     (fset 'gnus-summary-set-display-table (lambda ()))
234     (fset 'gnus-encode-coding-string 'encode-coding-string)
235     (fset 'gnus-decode-coding-string 'decode-coding-string)
236
237     (and window-system
238          (module-installed-p 'bitmap)
239          (fset 'gnus-group-startup-message 'gnus-mule-group-startup-message))
240
241     (when (boundp 'gnus-check-before-posting)
242       (setq gnus-check-before-posting
243             (delq 'long-lines
244                   (delq 'control-chars gnus-check-before-posting))))
245
246     (defun gnus-summary-line-format-spec ()
247       (insert gnus-tmp-unread gnus-tmp-replied
248               gnus-tmp-score-char gnus-tmp-indentation)
249       (put-text-property
250        (point)
251        (progn
252          (insert
253           gnus-tmp-opening-bracket
254           (format "%4d: %-20s"
255                   gnus-tmp-lines
256                   (if (> (length gnus-tmp-name) 20)
257                       (truncate-string gnus-tmp-name 20)
258                     gnus-tmp-name))
259           gnus-tmp-closing-bracket)
260          (point))
261        gnus-mouse-face-prop gnus-mouse-face)
262       (insert " " gnus-tmp-subject-or-nil "\n"))
263     )))
264
265 (defun gnus-region-active-p ()
266   "Say whether the region is active."
267   (and (boundp 'transient-mark-mode)
268        transient-mark-mode
269        (boundp 'mark-active)
270        mark-active))
271
272 (defun gnus-add-minor-mode (mode name map)
273   (if (fboundp 'add-minor-mode)
274       (add-minor-mode mode name map)
275     (unless (assq mode minor-mode-alist)
276       (push `(,mode ,name) minor-mode-alist))
277     (unless (assq mode minor-mode-map-alist)
278       (push (cons mode map)
279             minor-mode-map-alist))))
280
281 (defun gnus-x-splash ()
282   "Show a splash screen using a pixmap in the current buffer."
283   (let ((dir (nnheader-find-etc-directory "gnus"))
284         pixmap file height beg i)
285     (save-excursion
286       (switch-to-buffer (get-buffer-create gnus-group-buffer))
287       (let ((buffer-read-only nil))
288         (erase-buffer)
289         (when (and dir
290                    (file-exists-p (setq file (concat dir "x-splash"))))
291           (nnheader-temp-write nil
292             (insert-file-contents file)
293             (goto-char (point-min))
294             (ignore-errors
295               (setq pixmap (read (current-buffer))))))
296         (when pixmap
297           (erase-buffer)
298           (unless (facep 'gnus-splash)
299             (make-face 'gnus-splash))
300           (setq height (/ (car pixmap) (frame-char-height))
301                 width (/ (cadr pixmap) (frame-char-width)))
302           (set-face-foreground 'gnus-splash "ForestGreen")
303           (set-face-stipple 'gnus-splash pixmap)
304           (insert-char ?\n (* (/ (window-height) 2 height) height))
305           (setq i height)
306           (while (> i 0)
307             (insert-char ?  (* (+ (/ (window-width) 2 width) 1) width))
308             (setq beg (point))
309             (insert-char ?  width)
310             (set-text-properties beg (point) '(face gnus-splash))
311             (insert "\n")
312             (decf i))
313           (goto-char (point-min))
314           (sit-for 0))))))
315
316 (provide 'gnus-ems)
317
318 ;; Local Variables:
319 ;; byte-compile-warnings: '(redefine callargs)
320 ;; End:
321
322 ;;; gnus-ems.el ends here