8b9e712b05ea718dd796f2cab253f4cd384da135
[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,99 Free Software Foundation, Inc.
3
4 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
5 ;; Keywords: news
6
7 ;; This file is part of GNU Emacs.
8
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 2, or (at your option)
12 ;; any later version.
13
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 ;; GNU General Public License for more details.
18
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 ;; Boston, MA 02111-1307, USA.
23
24 ;;; Commentary:
25
26 ;;; Code:
27
28 (eval-when-compile (require 'cl))
29
30 ;;; Function aliases later to be redefined for XEmacs usage.
31
32 (defvar gnus-xemacs (string-match "XEmacs\\|Lucid" emacs-version)
33   "Non-nil if running under XEmacs.")
34
35 (defvar gnus-mouse-2 [mouse-2])
36 (defvar gnus-down-mouse-3 [down-mouse-3])
37 (defvar gnus-down-mouse-2 [down-mouse-2])
38 (defvar gnus-widget-button-keymap nil)
39 (defvar gnus-mode-line-modified
40   (if (or gnus-xemacs
41           (< emacs-major-version 20))
42       '("--**-" . "-----")
43     '("**" "--")))
44
45 (eval-and-compile
46   (autoload 'gnus-xmas-define "gnus-xmas")
47   (autoload 'gnus-xmas-redefine "gnus-xmas")
48   (autoload 'appt-select-lowest-window "appt"))
49
50 ;;; Mule functions.
51
52 (defun gnus-mule-max-width-function (el max-width)
53   `(let* ((val (eval (, el)))
54           (valstr (if (numberp val)
55                       (int-to-string val) val)))
56      (if (> (length valstr) ,max-width)
57          (truncate-string-to-width valstr ,max-width)
58        valstr)))
59
60 (eval-and-compile
61   (if (string-match "XEmacs\\|Lucid" emacs-version)
62       nil
63
64     (defvar gnus-mouse-face-prop 'mouse-face
65       "Property used for highlighting mouse regions."))
66
67   (cond
68    ((string-match "XEmacs\\|Lucid" emacs-version)
69     (gnus-xmas-define))
70
71    ((boundp 'MULE)
72     (provide 'gnusutil))))
73
74 (eval-and-compile
75   (cond
76    ((not window-system)
77     (defun gnus-dummy-func (&rest args))
78     (let ((funcs '(mouse-set-point set-face-foreground
79                                    set-face-background x-popup-menu)))
80       (while funcs
81         (unless (fboundp (car funcs))
82           (fset (car funcs) 'gnus-dummy-func))
83         (setq funcs (cdr funcs)))))))
84
85 (eval-and-compile
86   (let ((case-fold-search t))
87     (cond
88      ((string-match "windows-nt\\|os/2\\|emx\\|cygwin32"
89                     (symbol-name system-type))
90       (setq nnheader-file-name-translation-alist
91             (append nnheader-file-name-translation-alist
92                     (mapcar (lambda (c) (cons c ?_))
93                             '(?: ?* ?\" ?< ?> ??))
94                     '((?+ . ?-))))))))
95
96 (defvar gnus-tmp-unread)
97 (defvar gnus-tmp-replied)
98 (defvar gnus-tmp-score-char)
99 (defvar gnus-tmp-indentation)
100 (defvar gnus-tmp-opening-bracket)
101 (defvar gnus-tmp-lines)
102 (defvar gnus-tmp-name)
103 (defvar gnus-tmp-closing-bracket)
104 (defvar gnus-tmp-subject-or-nil)
105
106 (defun gnus-ems-redefine ()
107   (cond
108    ((string-match "XEmacs\\|Lucid" emacs-version)
109     (gnus-xmas-redefine))
110
111    ((featurep 'mule)
112     ;; Mule and new Emacs definitions
113
114     ;; [Note] Now there are three kinds of mule implementations,
115     ;; original MULE, XEmacs/mule and beta version of Emacs including
116     ;; some mule features.  Unfortunately these API are different.  In
117     ;; particular, Emacs (including original MULE) and XEmacs are
118     ;; quite different.
119     ;; Predicates to check are following:
120     ;; (boundp 'MULE) is t only if MULE (original; anything older than
121     ;;                     Mule 2.3) is running.
122     ;; (featurep 'mule) is t when every mule variants are running.
123
124     ;; These implementations may be able to share between original
125     ;; MULE and beta version of new Emacs.  In addition, it is able to
126     ;; detect XEmacs/mule by (featurep 'mule) and to check variable
127     ;; `emacs-version'.  In this case, implementation for XEmacs/mule
128     ;; may be able to share between XEmacs and XEmacs/mule.
129
130     (defvar gnus-summary-display-table nil
131       "Display table used in summary mode buffers.")
132     (fset 'gnus-max-width-function 'gnus-mule-max-width-function)
133     (fset 'gnus-summary-set-display-table (lambda ()))
134
135     (when (boundp 'gnus-check-before-posting)
136       (setq gnus-check-before-posting
137             (delq 'long-lines
138                   (delq 'control-chars gnus-check-before-posting))))
139
140     (defun gnus-summary-line-format-spec ()
141       (insert gnus-tmp-unread gnus-tmp-replied
142               gnus-tmp-score-char gnus-tmp-indentation)
143       (put-text-property
144        (point)
145        (progn
146          (insert
147           gnus-tmp-opening-bracket
148           (format "%4d: %-20s"
149                   gnus-tmp-lines
150                   (if (> (length gnus-tmp-name) 20)
151                       (truncate-string-to-width gnus-tmp-name 20)
152                     gnus-tmp-name))
153           gnus-tmp-closing-bracket)
154          (point))
155        gnus-mouse-face-prop gnus-mouse-face)
156       (insert " " gnus-tmp-subject-or-nil "\n")))))
157
158 (defun gnus-region-active-p ()
159   "Say whether the region is active."
160   (and (boundp 'transient-mark-mode)
161        transient-mark-mode
162        (boundp 'mark-active)
163        mark-active))
164
165 (defun gnus-add-minor-mode (mode name map)
166   (if (fboundp 'add-minor-mode)
167       (add-minor-mode mode name map)
168     (set (make-local-variable mode) t)
169     (unless (assq mode minor-mode-alist)
170       (push `(,mode ,name) minor-mode-alist))
171     (unless (assq mode minor-mode-map-alist)
172       (push (cons mode map)
173             minor-mode-map-alist))))
174
175 (defun gnus-x-splash ()
176   "Show a splash screen using a pixmap in the current buffer."
177   (let ((dir (nnheader-find-etc-directory "gnus"))
178         pixmap file height beg i)
179     (save-excursion
180       (switch-to-buffer (gnus-get-buffer-create gnus-group-buffer))
181       (let ((buffer-read-only nil))
182         (erase-buffer)
183         (when (and dir
184                    (file-exists-p (setq file (concat dir "x-splash"))))
185           (with-temp-buffer
186             (insert-file-contents file)
187             (goto-char (point-min))
188             (ignore-errors
189               (setq pixmap (read (current-buffer))))))
190         (when pixmap
191           (unless (facep 'gnus-splash)
192             (make-face 'gnus-splash))
193           (setq height (/ (car pixmap) (frame-char-height))
194                 width (/ (cadr pixmap) (frame-char-width)))
195           (set-face-foreground 'gnus-splash "Brown")
196           (set-face-stipple 'gnus-splash pixmap)
197           (insert-char ?\n (* (/ (window-height) 2 height) height))
198           (setq i height)
199           (while (> i 0)
200             (insert-char ?  (* (/ (window-width) 2 width) width))
201             (setq beg (point))
202             (insert-char ?  width)
203             (set-text-properties beg (point) '(face gnus-splash))
204             (insert "\n")
205             (decf i))
206           (goto-char (point-min))
207           (sit-for 0))))))
208
209 (provide 'gnus-ems)
210
211 ;; Local Variables:
212 ;; byte-compile-warnings: '(redefine callargs)
213 ;; End:
214
215 ;;; gnus-ems.el ends here