*** 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-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-to-width 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
105 (eval-and-compile
106   (let ((case-fold-search t))
107     (cond
108      ((string-match "windows-nt\\|os/2\\|emx" (symbol-name system-type))
109       (setq nnheader-file-name-translation-alist
110             (append nnheader-file-name-translation-alist
111                     '((?: . ?_)
112                       (?+ . ?-))))))))
113
114 (defvar gnus-tmp-unread)
115 (defvar gnus-tmp-replied)
116 (defvar gnus-tmp-score-char)
117 (defvar gnus-tmp-indentation)
118 (defvar gnus-tmp-opening-bracket)
119 (defvar gnus-tmp-lines)
120 (defvar gnus-tmp-name)
121 (defvar gnus-tmp-closing-bracket)
122 (defvar gnus-tmp-subject-or-nil)
123
124 (defun gnus-ems-redefine ()
125   (cond
126    ((string-match "XEmacs\\|Lucid" emacs-version)
127     (gnus-xmas-redefine))
128
129    ((featurep 'mule)
130     ;; Mule and new Emacs definitions
131
132     ;; [Note] Now there are three kinds of mule implementations,
133     ;; original MULE, XEmacs/mule and beta version of Emacs including
134     ;; some mule features. Unfortunately these API are different. In
135     ;; particular, Emacs (including original MULE) and XEmacs are
136     ;; quite different.
137     ;; Predicates to check are following:
138     ;; (boundp 'MULE) is t only if MULE (original; anything older than
139     ;;                     Mule 2.3) is running.
140     ;; (featurep 'mule) is t when every mule variants are running.
141
142     ;; These implementations may be able to share between original
143     ;; MULE and beta version of new Emacs. In addition, it is able to
144     ;; detect XEmacs/mule by (featurep 'mule) and to check variable
145     ;; `emacs-version'. In this case, implementation for XEmacs/mule
146     ;; may be able to share between XEmacs and XEmacs/mule.
147
148     (defvar gnus-summary-display-table nil
149       "Display table used in summary mode buffers.")
150     (fset 'gnus-cite-add-face 'gnus-mule-cite-add-face)
151     (fset 'gnus-max-width-function 'gnus-mule-max-width-function)
152     (fset 'gnus-summary-set-display-table (lambda ()))
153     
154     (when (boundp 'gnus-check-before-posting)
155       (setq gnus-check-before-posting
156             (delq 'long-lines
157                   (delq 'control-chars gnus-check-before-posting))))
158
159     (defun gnus-summary-line-format-spec ()
160       (insert gnus-tmp-unread gnus-tmp-replied
161               gnus-tmp-score-char gnus-tmp-indentation)
162       (put-text-property
163        (point)
164        (progn
165          (insert
166           gnus-tmp-opening-bracket
167           (format "%4d: %-20s"
168                   gnus-tmp-lines
169                   (if (> (length gnus-tmp-name) 20)
170                       (truncate-string-to-width gnus-tmp-name 20)
171                     gnus-tmp-name))
172           gnus-tmp-closing-bracket)
173          (point))
174        gnus-mouse-face-prop gnus-mouse-face)
175       (insert " " gnus-tmp-subject-or-nil "\n"))
176     )))
177
178 (defun gnus-region-active-p ()
179   "Say whether the region is active."
180   (and (boundp 'transient-mark-mode)
181        transient-mark-mode
182        (boundp 'mark-active)
183        mark-active))
184
185 (defun gnus-add-minor-mode (mode name map)
186   (if (fboundp 'add-minor-mode)
187       (add-minor-mode mode name map)
188     (set (make-local-variable mode) t)
189     (unless (assq mode minor-mode-alist)
190       (push `(,mode ,name) minor-mode-alist))
191     (unless (assq mode minor-mode-map-alist)
192       (push (cons mode map)
193             minor-mode-map-alist))))
194
195 (defun gnus-x-splash ()
196   "Show a splash screen using a pixmap in the current buffer."
197   (let ((dir (nnheader-find-etc-directory "gnus"))
198         pixmap file height beg i)
199     (save-excursion
200       (switch-to-buffer (gnus-get-buffer-create gnus-group-buffer))
201       (let ((buffer-read-only nil))
202         (erase-buffer)
203         (when (and dir
204                    (file-exists-p (setq file (concat dir "x-splash"))))
205           (with-temp-buffer
206             (insert-file-contents file)
207             (goto-char (point-min))
208             (ignore-errors
209               (setq pixmap (read (current-buffer))))))
210         (when pixmap
211           (erase-buffer)
212           (unless (facep 'gnus-splash)
213             (make-face 'gnus-splash))
214           (setq height (/ (car pixmap) (frame-char-height))
215                 width (/ (cadr pixmap) (frame-char-width)))
216           (set-face-foreground 'gnus-splash "Brown")
217           (set-face-stipple 'gnus-splash pixmap)
218           (insert-char ?\n (* (/ (window-height) 2 height) height))
219           (setq i height)
220           (while (> i 0)
221             (insert-char ?  (* (+ (/ (window-width) 2 width) 1) width))
222             (setq beg (point))
223             (insert-char ?  width)
224             (set-text-properties beg (point) '(face gnus-splash))
225             (insert "\n")
226             (decf i))
227           (goto-char (point-min))
228           (sit-for 0))))))
229
230 (provide 'gnus-ems)
231
232 ;; Local Variables:
233 ;; byte-compile-warnings: '(redefine callargs)
234 ;; End:
235
236 ;;; gnus-ems.el ends here