*** 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 (and (not 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 (eval-and-compile
79   (if (string-match "XEmacs\\|Lucid" emacs-version)
80       nil
81
82     (defvar gnus-mouse-face-prop 'mouse-face
83       "Property used for highlighting mouse regions."))
84
85   (cond
86    ((string-match "XEmacs\\|Lucid" emacs-version)
87     (gnus-xmas-define))
88
89    ((or (not (boundp 'emacs-minor-version))
90         (< emacs-minor-version 30))
91     ;; Remove the `intangible' prop.
92     (let ((props (and (boundp 'gnus-hidden-properties)
93                       gnus-hidden-properties)))
94       (while (and props (not (eq (car (cdr props)) 'intangible)))
95         (setq props (cdr props)))
96       (when props
97         (setcdr props (cdr (cdr (cdr props))))))
98     (unless (fboundp 'buffer-substring-no-properties)
99       (defun buffer-substring-no-properties (beg end)
100         (format "%s" (buffer-substring beg end)))))
101
102    ((boundp 'MULE)
103     (provide 'gnusutil))))
104
105 (eval-and-compile
106   (cond
107    ((not window-system)
108     (defun gnus-dummy-func (&rest args))
109     (let ((funcs '(mouse-set-point set-face-foreground
110                                    set-face-background x-popup-menu)))
111       (while funcs
112         (unless (fboundp (car funcs))
113           (fset (car funcs) 'gnus-dummy-func))
114         (setq funcs (cdr funcs))))))
115   (unless (fboundp 'file-regular-p)
116     (defun file-regular-p (file)
117       (and (not (file-directory-p file))
118            (not (file-symlink-p file))
119            (file-exists-p file))))
120   (unless (fboundp 'face-list)
121     (defun face-list (&rest args))))
122
123 (eval-and-compile
124   (let ((case-fold-search t))
125     (cond
126      ((string-match "windows-nt\\|os/2\\|emx" (format "%s" system-type))
127       (setq nnheader-file-name-translation-alist
128             (append nnheader-file-name-translation-alist
129                     '((?: . ?_)
130                       (?+ . ?-))))))))
131
132 (defvar gnus-tmp-unread)
133 (defvar gnus-tmp-replied)
134 (defvar gnus-tmp-score-char)
135 (defvar gnus-tmp-indentation)
136 (defvar gnus-tmp-opening-bracket)
137 (defvar gnus-tmp-lines)
138 (defvar gnus-tmp-name)
139 (defvar gnus-tmp-closing-bracket)
140 (defvar gnus-tmp-subject-or-nil)
141
142 (defun gnus-ems-redefine ()
143   (cond
144    ((string-match "XEmacs\\|Lucid" emacs-version)
145     (gnus-xmas-redefine))
146
147    ((featurep 'mule)
148     ;; Mule and new Emacs definitions
149
150     ;; [Note] Now there are three kinds of mule implementations,
151     ;; original MULE, XEmacs/mule and beta version of Emacs including
152     ;; some mule features. Unfortunately these API are different. In
153     ;; particular, Emacs (including original MULE) and XEmacs are
154     ;; quite different.
155     ;; Predicates to check are following:
156     ;; (boundp 'MULE) is t only if MULE (original; anything older than
157     ;;                     Mule 2.3) is running.
158     ;; (featurep 'mule) is t when every mule variants are running.
159
160     ;; These implementations may be able to share between original
161     ;; MULE and beta version of new Emacs. In addition, it is able to
162     ;; detect XEmacs/mule by (featurep 'mule) and to check variable
163     ;; `emacs-version'. In this case, implementation for XEmacs/mule
164     ;; may be able to share between XEmacs and XEmacs/mule.
165
166     (defalias 'gnus-truncate-string 'truncate-string)
167
168     (defvar gnus-summary-display-table nil
169       "Display table used in summary mode buffers.")
170     (fset 'gnus-cite-add-face 'gnus-mule-cite-add-face)
171     (fset 'gnus-max-width-function 'gnus-mule-max-width-function)
172     (fset 'gnus-summary-set-display-table 'ignore)
173
174     (when (boundp 'gnus-check-before-posting)
175       (setq gnus-check-before-posting
176             (delq 'long-lines
177                   (delq 'control-chars gnus-check-before-posting))))
178
179     (defun gnus-summary-line-format-spec ()
180       (insert gnus-tmp-unread gnus-tmp-replied
181               gnus-tmp-score-char gnus-tmp-indentation)
182       (put-text-property
183        (point)
184        (progn
185          (insert
186           gnus-tmp-opening-bracket
187           (format "%4d: %-20s"
188                   gnus-tmp-lines
189                   (if (> (length gnus-tmp-name) 20)
190                       (truncate-string gnus-tmp-name 20)
191                     gnus-tmp-name))
192           gnus-tmp-closing-bracket)
193          (point))
194        gnus-mouse-face-prop gnus-mouse-face)
195       (insert " " gnus-tmp-subject-or-nil "\n"))
196     )))
197
198 (defun gnus-region-active-p ()
199   "Say whether the region is active."
200   (and (boundp 'transient-mark-mode)
201        transient-mark-mode
202        (boundp 'mark-active)
203        mark-active))
204
205 (defun gnus-add-minor-mode (mode name map)
206   (if (fboundp 'add-minor-mode)
207       (add-minor-mode mode name map)
208     (unless (assq mode minor-mode-alist)
209       (push `(,mode ,name) minor-mode-alist))
210     (unless (assq mode minor-mode-map-alist)
211       (push (cons mode map)
212             minor-mode-map-alist))))
213
214 (provide 'gnus-ems)
215
216 ;; Local Variables:
217 ;; byte-compile-warnings: '(redefine callargs)
218 ;; End:
219
220 ;;; gnus-ems.el ends here