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