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