*** empty log message ***
[gnus] / lisp / gnus-ems.el
1 ;;; gnus-ems.el --- functions for making Gnus work under different Emacsen
2 ;; Copyright (C) 1995 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
21 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
22
23 ;;; Commentary:
24
25 ;;; Code:
26
27 (defvar gnus-mouse-2 [mouse-2])
28
29 (defalias 'gnus-make-overlay 'make-overlay)
30 (defalias 'gnus-overlay-put 'overlay-put)
31 (defalias 'gnus-move-overlay 'move-overlay)
32
33 (eval-and-compile 
34   (autoload 'gnus-xmas-define "gnus-xmas")
35   (autoload 'gnus-xmas-redefine "gnus-xmas"))
36
37 (or (fboundp 'mail-file-babyl-p)
38     (fset 'mail-file-babyl-p 'rmail-file-p))
39
40 ;;; Mule functions.
41
42 (defun gnus-mule-truncate-string (str width)
43   (let ((w (string-width str))
44         (col 0) (idx 0) (p-idx 0) chr)
45     (if (<= w width)
46         str
47       (while (< col width)
48         (setq chr (aref str idx)
49               col (+ col (char-width chr))
50               p-idx idx
51               idx (+ idx (char-bytes chr))
52               ))
53       (substring str 0 (if (= col width)
54                            idx
55                          p-idx)))))
56
57 (defun gnus-mule-cite-add-face (number prefix face)
58   ;; At line NUMBER, ignore PREFIX and add FACE to the rest of the line.
59   (if face
60       (let ((inhibit-point-motion-hooks t)
61             from to)
62         (goto-line number)
63         (if (boundp 'MULE)
64             (forward-char (chars-in-string prefix))
65           (forward-char (length prefix)))
66         (skip-chars-forward " \t")
67         (setq from (point))
68         (end-of-line 1)
69         (skip-chars-backward " \t")
70         (setq to (point))
71         (if (< from to)
72             (gnus-overlay-put (gnus-make-overlay from to) 'face face)))))
73
74 (defun gnus-mule-max-width-function (el max-width)
75   (` (let* ((val (eval (, el)))
76             (valstr (if (numberp val)
77                         (int-to-string val) val)))
78        (if (> (length valstr) (, max-width))
79            (truncate-string valstr (, max-width))
80          valstr))))
81
82
83 (eval
84  '(progn
85     (if (string-match "XEmacs\\|Lucid" emacs-version)
86         ()
87
88       (defvar gnus-mouse-face-prop 'mouse-face)
89
90       ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
91       (defvar gnus-display-type 
92         (condition-case nil
93             (let ((display-resource (x-get-resource ".displayType" "DisplayType")))
94               (cond (display-resource (intern (downcase display-resource)))
95                     ((x-display-color-p) 'color)
96                     ((x-display-grayscale-p) 'grayscale)
97                     (t 'mono)))
98           (error 'mono))
99         "A symbol indicating the display Emacs is running under.
100 The symbol should be one of `color', `grayscale' or `mono'. If Emacs
101 guesses this display attribute wrongly, either set this variable in
102 your `~/.emacs' or set the resource `Emacs.displayType' in your
103 `~/.Xdefaults'. See also `gnus-background-mode'.
104
105 This is a meta-variable that will affect what default values other
106 variables get.  You would normally not change this variable, but
107 pounce directly on the real variables themselves.")
108
109       (defvar gnus-background-mode 
110         (condition-case nil
111             (let ((bg-resource (x-get-resource ".backgroundMode"
112                                                "BackgroundMode"))
113                   (params (frame-parameters)))
114               (cond (bg-resource (intern (downcase bg-resource)))
115                     ((and (cdr (assq 'background-color params))
116                           (< (apply '+ (x-color-values
117                                         (cdr (assq 'background-color params))))
118                              (/ (apply '+ (x-color-values "white")) 3)))
119                      'dark)
120                     (t 'light)))
121           (error 'light))
122         "A symbol indicating the Emacs background brightness.
123 The symbol should be one of `light' or `dark'.
124 If Emacs guesses this frame attribute wrongly, either set this variable in
125 your `~/.emacs' or set the resource `Emacs.backgroundMode' in your
126 `~/.Xdefaults'.
127 See also `gnus-display-type'.
128
129 This is a meta-variable that will affect what default values other
130 variables get.  You would normally not change this variable, but
131 pounce directly on the real variables themselves."))
132
133     (cond 
134      ((string-match "XEmacs\\|Lucid" emacs-version)
135       (gnus-xmas-define))
136
137      ((and (not (string-match "28.9" emacs-version)) 
138            (not (string-match "29" emacs-version)))
139       ;; Remove the `intangible' prop.
140       (let ((props (and (boundp 'gnus-hidden-properties) 
141                         gnus-hidden-properties)))
142         (while (and props (not (eq (car (cdr props)) 'intangible)))
143           (setq props (cdr props)))
144         (and props (setcdr props (cdr (cdr (cdr props))))))
145       (or (fboundp 'buffer-substring-no-properties)
146           (defun buffer-substring-no-properties (beg end)
147             (format "%s" (buffer-substring beg end)))))
148    
149      ((boundp 'MULE)
150       (provide 'gnusutil))
151      )))
152
153 (eval-and-compile
154   (cond
155    ((not window-system)
156     (defun gnus-dummy-func (&rest args))
157     (let ((funcs '(mouse-set-point set-face-foreground
158                                    set-face-background x-popup-menu)))
159       (while funcs
160         (or (fboundp (car funcs))
161             (fset (car funcs) 'gnus-dummy-func))
162         (setq funcs (cdr funcs))))))
163   (or (fboundp 'file-regular-p)
164       (defun file-regular-p (file)
165         (and (not (file-directory-p file))
166              (not (file-symlink-p file))
167              (file-exists-p file))))
168   (or (fboundp 'face-list)
169       (defun face-list (&rest args)))
170   )
171
172 (defun gnus-ems-redefine ()
173   (cond 
174    ((string-match "XEmacs\\|Lucid" emacs-version)
175     (gnus-xmas-redefine))
176
177    ((boundp 'MULE)
178     ;; Mule definitions
179     (or (fboundp 'truncate-string)
180         (fset 'truncate-string 'gnus-mule-truncate-string))
181     (defalias 'gnus-truncate-string 'truncate-string)
182
183     (fset 'gnus-summary-make-display-table (lambda () nil))
184     (fset 'gnus-cite-add-face 'gnus-mule-cite-add-face)
185     (fset 'gnus-max-width-function 'gnus-mule-max-width-function)
186     
187     (if (boundp 'gnus-check-before-posting)
188         (setq gnus-check-before-posting
189               (delq 'long-lines
190                     (delq 'control-chars gnus-check-before-posting))))
191     )
192    ))
193
194 (provide 'gnus-ems)
195
196 ;; Local Variables:
197 ;; byte-compile-warnings: '(redefine callargs)
198 ;; End:
199
200 ;;; gnus-ems.el ends here