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