Importing Gnus v5.8.5.
[elisp/gnus.git-] / lisp / gnus-ems.el
1 ;;; gnus-ems.el --- functions for making Gnus work under different Emacsen
2 ;; Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000
3 ;;        Free Software Foundation, Inc.
4
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
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-3 [down-mouse-3])
38 (defvar gnus-down-mouse-2 [down-mouse-2])
39 (defvar gnus-widget-button-keymap nil)
40 (defvar gnus-mode-line-modified
41   (if (or gnus-xemacs
42           (< emacs-major-version 20))
43       '("--**-" . "-----")
44     '("**" "--")))
45
46 (eval-and-compile
47   (autoload 'gnus-xmas-define "gnus-xmas")
48   (autoload 'gnus-xmas-redefine "gnus-xmas")
49   (autoload 'appt-select-lowest-window "appt"))
50
51 ;;; Mule functions.
52
53 (defun gnus-mule-max-width-function (el max-width)
54   `(let* ((val (eval (, el)))
55           (valstr (if (numberp val)
56                       (int-to-string val) val)))
57      (if (> (length valstr) ,max-width)
58          (truncate-string-to-width valstr ,max-width)
59        valstr)))
60
61 (eval-and-compile
62   (if (string-match "XEmacs\\|Lucid" emacs-version)
63       nil
64
65     (defvar gnus-mouse-face-prop 'mouse-face
66       "Property used for highlighting mouse regions."))
67
68   (cond
69    ((string-match "XEmacs\\|Lucid" emacs-version)
70     (gnus-xmas-define))
71
72    ((boundp 'MULE)
73     (provide 'gnusutil))))
74
75 (eval-and-compile
76   (cond
77    ((not window-system)
78     (defun gnus-dummy-func (&rest args))
79     (let ((funcs '(mouse-set-point set-face-foreground
80                                    set-face-background x-popup-menu)))
81       (while funcs
82         (unless (fboundp (car funcs))
83           (fset (car funcs) 'gnus-dummy-func))
84         (setq funcs (cdr funcs)))))))
85
86 (eval-and-compile
87   (let ((case-fold-search t))
88     (cond
89      ((string-match "windows-nt\\|os/2\\|emx\\|cygwin32"
90                     (symbol-name system-type))
91       (setq nnheader-file-name-translation-alist
92             (append nnheader-file-name-translation-alist
93                     (mapcar (lambda (c) (cons c ?_))
94                             '(?: ?* ?\" ?< ?> ??))
95                     '((?+ . ?-))))))))
96
97 (defvar gnus-tmp-unread)
98 (defvar gnus-tmp-replied)
99 (defvar gnus-tmp-score-char)
100 (defvar gnus-tmp-indentation)
101 (defvar gnus-tmp-opening-bracket)
102 (defvar gnus-tmp-lines)
103 (defvar gnus-tmp-name)
104 (defvar gnus-tmp-closing-bracket)
105 (defvar gnus-tmp-subject-or-nil)
106
107 (defun gnus-ems-redefine ()
108   (cond
109    ((string-match "XEmacs\\|Lucid" emacs-version)
110     (gnus-xmas-redefine))
111
112    ((featurep 'mule)
113     ;; Mule and new Emacs definitions
114
115     ;; [Note] Now there are three kinds of mule implementations,
116     ;; original MULE, XEmacs/mule and beta version of Emacs including
117     ;; some mule features.  Unfortunately these API are different.  In
118     ;; particular, Emacs (including original MULE) and XEmacs are
119     ;; quite different.
120     ;; Predicates to check are following:
121     ;; (boundp 'MULE) is t only if MULE (original; anything older than
122     ;;                     Mule 2.3) is running.
123     ;; (featurep 'mule) is t when every mule variants are running.
124
125     ;; These implementations may be able to share between original
126     ;; MULE and beta version of new Emacs.  In addition, it is able to
127     ;; detect XEmacs/mule by (featurep 'mule) and to check variable
128     ;; `emacs-version'.  In this case, implementation for XEmacs/mule
129     ;; may be able to share between XEmacs and XEmacs/mule.
130
131     (defvar gnus-summary-display-table nil
132       "Display table used in summary mode buffers.")
133     (fset 'gnus-max-width-function 'gnus-mule-max-width-function)
134     (fset 'gnus-summary-set-display-table (lambda ()))
135
136     (when (boundp 'gnus-check-before-posting)
137       (setq gnus-check-before-posting
138             (delq 'long-lines
139                   (delq 'control-chars gnus-check-before-posting))))
140
141     (defun gnus-summary-line-format-spec ()
142       (insert gnus-tmp-unread gnus-tmp-replied
143               gnus-tmp-score-char gnus-tmp-indentation)
144       (put-text-property
145        (point)
146        (progn
147          (insert
148           gnus-tmp-opening-bracket
149           (format "%4d: %-20s"
150                   gnus-tmp-lines
151                   (if (> (length gnus-tmp-name) 20)
152                       (truncate-string-to-width gnus-tmp-name 20)
153                     gnus-tmp-name))
154           gnus-tmp-closing-bracket)
155          (point))
156        gnus-mouse-face-prop gnus-mouse-face)
157       (insert " " gnus-tmp-subject-or-nil "\n")))))
158
159 (defun gnus-region-active-p ()
160   "Say whether the region is active."
161   (and (boundp 'transient-mark-mode)
162        transient-mark-mode
163        (boundp 'mark-active)
164        mark-active))
165
166 (defun gnus-add-minor-mode (mode name map)
167   (if (fboundp 'add-minor-mode)
168       (add-minor-mode mode name map)
169     (set (make-local-variable mode) t)
170     (unless (assq mode minor-mode-alist)
171       (push `(,mode ,name) minor-mode-alist))
172     (unless (assq mode minor-mode-map-alist)
173       (push (cons mode map)
174             minor-mode-map-alist))))
175
176 (defun gnus-x-splash ()
177   "Show a splash screen using a pixmap in the current buffer."
178   (let ((dir (nnheader-find-etc-directory "gnus"))
179         pixmap file height beg i)
180     (save-excursion
181       (switch-to-buffer (gnus-get-buffer-create gnus-group-buffer))
182       (let ((buffer-read-only nil))
183         (erase-buffer)
184         (when (and dir
185                    (file-exists-p (setq file (concat dir "x-splash"))))
186           (with-temp-buffer
187             (insert-file-contents file)
188             (goto-char (point-min))
189             (ignore-errors
190               (setq pixmap (read (current-buffer))))))
191         (when pixmap
192           (unless (facep 'gnus-splash)
193             (make-face 'gnus-splash))
194           (setq height (/ (car pixmap) (frame-char-height))
195                 width (/ (cadr pixmap) (frame-char-width)))
196           (set-face-foreground 'gnus-splash "Brown")
197           (set-face-stipple 'gnus-splash pixmap)
198           (insert-char ?\n (* (/ (window-height) 2 height) height))
199           (setq i height)
200           (while (> i 0)
201             (insert-char ?  (* (/ (window-width) 2 width) width))
202             (setq beg (point))
203             (insert-char ?  width)
204             (set-text-properties beg (point) '(face gnus-splash))
205             (insert "\n")
206             (decf i))
207           (goto-char (point-min))
208           (sit-for 0))))))
209
210 (provide 'gnus-ems)
211
212 ;; Local Variables:
213 ;; byte-compile-warnings: '(redefine callargs)
214 ;; End:
215
216 ;;; gnus-ems.el ends here