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