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