Importing pgnus-0.79
[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" (symbol-name system-type))
89       (setq nnheader-file-name-translation-alist
90             (append nnheader-file-name-translation-alist
91                     '((?: . ?_)
92                       (?+ . ?-))))))))
93
94 (defvar gnus-tmp-unread)
95 (defvar gnus-tmp-replied)
96 (defvar gnus-tmp-score-char)
97 (defvar gnus-tmp-indentation)
98 (defvar gnus-tmp-opening-bracket)
99 (defvar gnus-tmp-lines)
100 (defvar gnus-tmp-name)
101 (defvar gnus-tmp-closing-bracket)
102 (defvar gnus-tmp-subject-or-nil)
103
104 (defun gnus-ems-redefine ()
105   (cond
106    ((string-match "XEmacs\\|Lucid" emacs-version)
107     (gnus-xmas-redefine))
108
109    ((featurep 'mule)
110     ;; Mule and new Emacs definitions
111
112     ;; [Note] Now there are three kinds of mule implementations,
113     ;; original MULE, XEmacs/mule and beta version of Emacs including
114     ;; some mule features. Unfortunately these API are different. In
115     ;; particular, Emacs (including original MULE) and XEmacs are
116     ;; quite different.
117     ;; Predicates to check are following:
118     ;; (boundp 'MULE) is t only if MULE (original; anything older than
119     ;;                     Mule 2.3) is running.
120     ;; (featurep 'mule) is t when every mule variants are running.
121
122     ;; These implementations may be able to share between original
123     ;; MULE and beta version of new Emacs. In addition, it is able to
124     ;; detect XEmacs/mule by (featurep 'mule) and to check variable
125     ;; `emacs-version'. In this case, implementation for XEmacs/mule
126     ;; may be able to share between XEmacs and XEmacs/mule.
127
128     (defvar gnus-summary-display-table nil
129       "Display table used in summary mode buffers.")
130     (fset 'gnus-max-width-function 'gnus-mule-max-width-function)
131     (fset 'gnus-summary-set-display-table (lambda ()))
132
133     (when (boundp 'gnus-check-before-posting)
134       (setq gnus-check-before-posting
135             (delq 'long-lines
136                   (delq 'control-chars gnus-check-before-posting))))
137
138     (defun gnus-summary-line-format-spec ()
139       (insert gnus-tmp-unread gnus-tmp-replied
140               gnus-tmp-score-char gnus-tmp-indentation)
141       (put-text-property
142        (point)
143        (progn
144          (insert
145           gnus-tmp-opening-bracket
146           (format "%4d: %-20s"
147                   gnus-tmp-lines
148                   (if (> (length gnus-tmp-name) 20)
149                       (truncate-string-to-width gnus-tmp-name 20)
150                     gnus-tmp-name))
151           gnus-tmp-closing-bracket)
152          (point))
153        gnus-mouse-face-prop gnus-mouse-face)
154       (insert " " gnus-tmp-subject-or-nil "\n"))
155     )))
156
157 (defun gnus-region-active-p ()
158   "Say whether the region is active."
159   (and (boundp 'transient-mark-mode)
160        transient-mark-mode
161        (boundp 'mark-active)
162        mark-active))
163
164 (defun gnus-add-minor-mode (mode name map)
165   (if (fboundp 'add-minor-mode)
166       (add-minor-mode mode name map)
167     (set (make-local-variable mode) t)
168     (unless (assq mode minor-mode-alist)
169       (push `(,mode ,name) minor-mode-alist))
170     (unless (assq mode minor-mode-map-alist)
171       (push (cons mode map)
172             minor-mode-map-alist))))
173
174 (defun gnus-x-splash ()
175   "Show a splash screen using a pixmap in the current buffer."
176   (let ((dir (nnheader-find-etc-directory "gnus"))
177         pixmap file height beg i)
178     (save-excursion
179       (switch-to-buffer (gnus-get-buffer-create gnus-group-buffer))
180       (let ((buffer-read-only nil))
181         (erase-buffer)
182         (when (and dir
183                    (file-exists-p (setq file (concat dir "x-splash"))))
184           (with-temp-buffer
185             (insert-file-contents file)
186             (goto-char (point-min))
187             (ignore-errors
188               (setq pixmap (read (current-buffer))))))
189         (when pixmap
190           (erase-buffer)
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) 1) 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