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