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