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