This commit was generated by cvs2svn to compensate for changes in r5444,
[elisp/gnus.git-] / lisp / gnus-ems.el
1 ;;; gnus-ems.el --- functions for making Semi-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 ;;         Tatsuya Ichikawa <t-ichi@niagara.shiojiri.ne.jp>
6 ;; Keywords: news
7
8 ;; This file is part of GNU Emacs.
9
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
13 ;; any later version.
14
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 ;; GNU General Public License for more details.
19
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
24
25 ;;; Commentary:
26
27 ;;; Code:
28
29 (eval-when-compile (require 'cl))
30
31 ;;; Function aliases later to be redefined for XEmacs usage.
32
33 (defvar gnus-xemacs (string-match "XEmacs\\|Lucid" emacs-version)
34   "Non-nil if running under XEmacs.")
35
36 (defvar gnus-mouse-2 [mouse-2])
37 (defvar gnus-down-mouse-2 [down-mouse-2])
38 (defvar gnus-mode-line-modified
39   (if (or gnus-xemacs
40           (< emacs-major-version 20))
41       '("--**-" . "-----")
42     '("**" "--")))
43
44 (eval-and-compile
45   (autoload 'gnus-xmas-define "gnus-xmas")
46   (autoload 'gnus-xmas-redefine "gnus-xmas")
47   (autoload 'appt-select-lowest-window "appt"))
48
49 (or (fboundp 'mail-file-babyl-p)
50     (fset 'mail-file-babyl-p 'rmail-file-p))
51
52 ;;; Mule functions.
53
54 (defun gnus-mule-cite-add-face (number prefix face)
55   ;; At line NUMBER, ignore PREFIX and add FACE to the rest of the line.
56   (when face
57     (let ((inhibit-point-motion-hooks t)
58           from to)
59       (goto-line number)
60       (unless (eobp)            ; Sometimes things become confused (broken).
61         (forward-char (chars-in-string 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 (defvar gnus-mule-bitmap-image-file nil)
73 (defun gnus-mule-group-startup-message (&optional x y)
74   "Insert startup message in current buffer."
75   ;; Insert the message.
76   (erase-buffer)
77   (insert
78    (if (featurep 'bitmap)
79      (format "              %s
80
81 "
82              "" (if (and (stringp gnus-mule-bitmap-image-file)
83                          (file-exists-p gnus-mule-bitmap-image-file))
84                     (insert-file gnus-mule-bitmap-image-file)))
85      (format "              %s
86           _    ___ _             _
87           _ ___ __ ___  __    _ ___
88           __   _     ___    __  ___
89               _           ___     _
90              _  _ __             _
91              ___   __            _
92                    __           _
93                     _      _   _
94                    _      _    _
95                       _  _    _
96                   __  ___
97                  _   _ _     _
98                 _   _
99               _    _
100              _    _
101             _
102           __
103
104 "
105              "")))
106   ;; And then hack it.
107   (gnus-indent-rigidly (point-min) (point-max)
108                        (/ (max (- (window-width) (or x 46)) 0) 2))
109   (goto-char (point-min))
110   (forward-line 1)
111   (let* ((pheight (count-lines (point-min) (point-max)))
112          (wheight (window-height))
113          (rest (- wheight pheight)))
114     (insert (make-string (max 0 (* 2 (/ rest 3))) ?\n)))
115   ;; Fontify some.
116   (put-text-property (point-min) (point-max) 'face 'gnus-splash-face)
117   (goto-char (point-min))
118   (setq mode-line-buffer-identification (concat " " gnus-version))
119   (setq gnus-simple-splash t)
120   (set-buffer-modified-p t))
121
122 (defun gnus-encode-coding-string (string system)
123   string)
124
125 (defun gnus-decode-coding-string (string system)
126   string)
127
128 (eval-and-compile
129   (if (string-match "XEmacs\\|Lucid" emacs-version)
130       nil
131
132     (defvar gnus-mouse-face-prop 'mouse-face
133       "Property used for highlighting mouse regions."))
134
135   (cond
136    ((string-match "XEmacs\\|Lucid" emacs-version)
137     (gnus-xmas-define))
138
139    ((or (not (boundp 'emacs-minor-version))
140         (and (< emacs-major-version 20)
141              (< emacs-minor-version 30)))
142     ;; Remove the `intangible' prop.
143     (let ((props (and (boundp 'gnus-hidden-properties)
144                       gnus-hidden-properties)))
145       (while (and props (not (eq (car (cdr props)) 'intangible)))
146         (setq props (cdr props)))
147       (when props
148         (setcdr props (cdr (cdr (cdr props))))))
149     (unless (fboundp 'buffer-substring-no-properties)
150       (defun buffer-substring-no-properties (beg end)
151         (format "%s" (buffer-substring beg end)))))
152
153    ((boundp 'MULE)
154     (provide 'gnusutil))))
155
156 (eval-and-compile
157   (cond
158    ((not window-system)
159     (defun gnus-dummy-func (&rest args))
160     (let ((funcs '(mouse-set-point set-face-foreground
161                                    set-face-background x-popup-menu)))
162       (while funcs
163         (unless (fboundp (car funcs))
164           (fset (car funcs) 'gnus-dummy-func))
165         (setq funcs (cdr funcs))))))
166   (unless (fboundp 'file-regular-p)
167     (defun file-regular-p (file)
168       (and (not (file-directory-p file))
169            (not (file-symlink-p file))
170            (file-exists-p file))))
171   (unless (fboundp 'face-list)
172     (defun face-list (&rest args))))
173
174 (eval-and-compile
175   (let ((case-fold-search t))
176     (cond
177      ((string-match "windows-nt\\|os/2\\|emx" (symbol-name system-type))
178       (setq nnheader-file-name-translation-alist
179             (append nnheader-file-name-translation-alist
180                     '((?: . ?_)
181                       (?+ . ?-))))))))
182
183 (defvar gnus-tmp-unread)
184 (defvar gnus-tmp-replied)
185 (defvar gnus-tmp-score-char)
186 (defvar gnus-tmp-indentation)
187 (defvar gnus-tmp-opening-bracket)
188 (defvar gnus-tmp-lines)
189 (defvar gnus-tmp-name)
190 (defvar gnus-tmp-closing-bracket)
191 (defvar gnus-tmp-subject-or-nil)
192
193 (defun gnus-ems-redefine ()
194   (cond
195    ((string-match "XEmacs\\|Lucid" emacs-version)
196     (gnus-xmas-redefine))
197
198    ((featurep 'mule)
199     ;; Mule and new Emacs definitions
200
201     ;; [Note] Now there are three kinds of mule implementations,
202     ;; original MULE, XEmacs/mule and beta version of Emacs including
203     ;; some mule features. Unfortunately these API are different. In
204     ;; particular, Emacs (including original MULE) and XEmacs are
205     ;; quite different.
206     ;; Predicates to check are following:
207     ;; (boundp 'MULE) is t only if MULE (original; anything older than
208     ;;                     Mule 2.3) is running.
209     ;; (featurep 'mule) is t when every mule variants are running.
210
211     ;; These implementations may be able to share between original
212     ;; MULE and beta version of new Emacs. In addition, it is able to
213     ;; detect XEmacs/mule by (featurep 'mule) and to check variable
214     ;; `emacs-version'. In this case, implementation for XEmacs/mule
215     ;; may be able to share between XEmacs and XEmacs/mule.
216
217     (defvar gnus-summary-display-table nil
218       "Display table used in summary mode buffers.")
219     (fset 'gnus-summary-set-display-table (lambda ()))
220     (fset 'gnus-encode-coding-string 'encode-coding-string)
221     (fset 'gnus-decode-coding-string 'decode-coding-string)
222
223     (if (fboundp 'truncate-string-to-width)
224         (fset 'gnus-truncate-string 'truncate-string-to-width)
225       (fset 'gnus-truncate-string 'truncate-string))
226
227     (defun gnus-tilde-max-form (el max-width)
228       "Return a form that limits EL to MAX-WIDTH."
229       (let ((max (abs max-width)))
230         (if (symbolp el)
231             `(if (> (string-width ,el) ,max)
232                  ,(if (< max-width 0)
233                       `(gnus-truncate-string
234                         ,el (string-width ,el)
235                         (- (string-width ,el) ,max))
236                     `(gnus-truncate-string ,el ,max))
237                ,el)
238           `(let ((val (eval ,el)))
239              (if (> (string-width val) ,max)
240                  ,(if (< max-width 0)
241                       `(gnus-truncate-string
242                         val (string-width val)
243                         (- (string-width val) ,max))
244                     `(gnus-truncate-string val ,max))
245                val)))))
246
247     (defun gnus-tilde-cut-form (el cut-width)
248       "Return a form that cuts CUT-WIDTH off of EL."
249       (let ((cut (abs cut-width)))
250         (if (symbolp el)
251             `(if (> (string-width ,el) ,cut)
252                  ,(if (< cut-width 0)
253                       `(gnus-truncate-string
254                         ,el (- (string-width ,el) ,cut))
255                     `(gnus-truncate-string
256                       ,el (- (string-width ,el) ,cut) ,cut))
257                ,el)
258           `(let ((val (eval ,el)))
259              (if (> (string-width val) ,cut)
260                  ,(if (< cut-width 0)
261                       `(gnus-truncate-string
262                         val (- (string-width val) ,cut))
263                     `(gnus-truncate-string
264                       val (- (string-width val) ,cut) ,cut))
265                val)))))
266
267     (when window-system
268       (require 'path-util)
269       (if (module-installed-p 'bitmap)
270           (fset 'gnus-group-startup-message 'gnus-mule-group-startup-message)
271         ))
272
273     (when (boundp 'gnus-check-before-posting)
274       (setq gnus-check-before-posting
275             (delq 'long-lines
276                   (delq 'control-chars gnus-check-before-posting))))
277
278     (when (fboundp 'chars-in-string)
279       (fset 'gnus-cite-add-face 'gnus-mule-cite-add-face))
280
281     )))
282
283 (defun gnus-region-active-p ()
284   "Say whether the region is active."
285   (and (boundp 'transient-mark-mode)
286        transient-mark-mode
287        (boundp 'mark-active)
288        mark-active))
289
290 (defun gnus-add-minor-mode (mode name map)
291   (if (fboundp 'add-minor-mode)
292       (add-minor-mode mode name map)
293     (set (make-local-variable mode) t)
294     (unless (assq mode minor-mode-alist)
295       (push `(,mode ,name) minor-mode-alist))
296     (unless (assq mode minor-mode-map-alist)
297       (push (cons mode map)
298             minor-mode-map-alist))))
299
300 (defun gnus-x-splash ()
301   "Show a splash screen using a pixmap in the current buffer."
302   (let ((dir (nnheader-find-etc-directory "gnus"))
303         pixmap file height beg i)
304     (save-excursion
305       (switch-to-buffer (gnus-get-buffer-create gnus-group-buffer))
306       (let ((buffer-read-only nil))
307         (erase-buffer)
308         (when (and dir
309                    (file-exists-p (setq file (concat dir "x-splash"))))
310           (nnheader-temp-write nil
311             (insert-file-contents file)
312             (goto-char (point-min))
313             (ignore-errors
314               (setq pixmap (read (current-buffer))))))
315         (when pixmap
316           (erase-buffer)
317           (unless (facep 'gnus-splash)
318             (make-face 'gnus-splash))
319           (setq height (/ (car pixmap) (frame-char-height))
320                 width (/ (cadr pixmap) (frame-char-width)))
321           (set-face-foreground 'gnus-splash "ForestGreen")
322           (set-face-stipple 'gnus-splash pixmap)
323           (insert-char ?\n (* (/ (window-height) 2 height) height))
324           (setq i height)
325           (while (> i 0)
326             (insert-char ?  (* (+ (/ (window-width) 2 width) 1) width))
327             (setq beg (point))
328             (insert-char ?  width)
329             (set-text-properties beg (point) '(face gnus-splash))
330             (insert "\n")
331             (decf i))
332           (goto-char (point-min))
333           (sit-for 0))))))
334
335 (if (fboundp 'split-string)
336     (fset 'gnus-split-string 'split-string)
337   (defun gnus-split-string (string pattern)
338     "Return a list of substrings of STRING which are separated by PATTERN."
339     (let (parts (start 0))
340       (while (string-match pattern string start)
341         (setq parts (cons (substring string start (match-beginning 0)) parts)
342               start (match-end 0)))
343       (nreverse (cons (substring string start) parts)))))
344
345 (provide 'gnus-ems)
346
347 ;; Local Variables:
348 ;; byte-compile-warnings: '(redefine callargs)
349 ;; End:
350
351 ;;; gnus-ems.el ends here