*** 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 (defvar gnus-easymenu 'easymenu)
29 (defvar gnus-group-mode-hook ())
30 (defvar gnus-summary-mode-hook ())
31 (defvar gnus-article-mode-hook ())
32
33 ;; We do not byte-compile this file, because error messages are such a
34 ;; bore.  
35
36 (eval
37  '(cond 
38    ((string-match "XEmacs\\|Lucid" emacs-version)
39     ;; XEmacs definitions.
40
41     (setq gnus-mouse-2 [button2])
42     (setq gnus-easymenu 'auc-menu)
43
44     (or (memq 'underline (list-faces))
45         (funcall (intern "make-face") 'underline))
46     ;; Must avoid calling set-face-underline-p directly, because it
47     ;; is a defsubst in emacs19, and will make the .elc files non
48     ;; portable!
49     (or (face-differs-from-default-p 'underline)
50         (funcall 'set-face-underline-p 'underline t))
51     (or (fboundp 'set-text-properties)
52         (defun set-text-properties (start end props &optional buffer)
53           (if props
54               (put-text-property start end (car props) (cadr props) buffer)
55             (remove-text-properties start end ()))))
56     
57     (or (fboundp 'make-overlay) (fset 'make-overlay 'make-extent))
58     (or (fboundp 'overlay-put) (fset 'overlay-put 'set-extent-property))
59     (or (fboundp 'move-overlay) 
60         (defun move-overlay (extent start end &optional buffer)
61           (set-extent-endpoints extent start end)))
62     (or (boundp 'standard-display-table) (setq standard-display-table nil))
63     (or (boundp 'read-event) (fset 'read-event 'next-command-event))
64
65     (if (not gnus-visual)
66         ()
67       (setq gnus-group-mode-hook
68             (cons
69              (lambda ()
70                (easy-menu-add gnus-group-reading-menu)
71                (easy-menu-add gnus-group-group-menu)
72                (easy-menu-add gnus-group-post-menu)
73                (easy-menu-add gnus-group-misc-menu)
74                (gnus-install-mouse-tracker)) 
75              gnus-group-mode-hook))
76       (setq gnus-summary-mode-hook
77             (cons
78              (lambda ()
79                (easy-menu-add gnus-summary-mark-menu)
80                (easy-menu-add gnus-summary-move-menu)
81                (easy-menu-add gnus-summary-article-menu)
82                (easy-menu-add gnus-summary-thread-menu)
83                (easy-menu-add gnus-summary-misc-menu)
84                (easy-menu-add gnus-summary-post-menu)
85                (easy-menu-add gnus-summary-kill-menu)
86                (gnus-install-mouse-tracker)) 
87              gnus-summary-mode-hook))
88       (setq gnus-article-mode-hook
89             (cons
90              (lambda ()
91                (easy-menu-add gnus-article-article-menu)
92                (easy-menu-add gnus-article-treatment-menu))
93              gnus-article-mode-hook)))
94
95     (defun gnus-install-mouse-tracker ()
96       (require 'mode-motion)
97       (setq mode-motion-hook 'mode-motion-highlight-line)))
98
99    ((and (not (string-match "28.9" emacs-version)) 
100          (not (string-match "29" emacs-version)))
101     (setq gnus-hidden-properties '(invisible t))
102     (or (fboundp 'buffer-substring-no-properties)
103         (defun buffer-substring-no-properties (beg end)
104           (format "%s" (buffer-substring beg end)))))
105    
106    ((boundp 'MULE)
107     (provide 'gnusutil))
108    
109    ))
110
111 (eval-and-compile
112   (cond
113    ((not window-system)
114     (defun gnus-dummy-func (&rest args))
115     (let ((funcs '(mouse-set-point set-face-foreground
116                                    set-face-background x-popup-menu)))
117       (while funcs
118         (or (fboundp (car funcs))
119             (fset (car funcs) 'gnus-dummy-func))
120         (setq funcs (cdr funcs))))))
121   (or (fboundp 'file-regular-p)
122       (defun file-regular-p (file)
123         (and (not (file-directory-p file))
124              (not (file-symlink-p file))
125              (file-exists-p file))))
126   (or (fboundp 'face-list)
127       (defun face-list (&rest args)))
128   )
129
130 (defun gnus-ems-redefine ()
131   (cond 
132    ((string-match "XEmacs\\|Lucid" emacs-version)
133     ;; XEmacs definitions.
134     (fset 'gnus-set-mouse-face (lambda (string) string))
135
136     (defun gnus-summary-make-display-table ()
137       ;; We start from the standard display table, if any.
138       (let* ((table (window-display-table)))
139         (and (not table)
140              (setq table (make-vector 261 ())))
141         ;; Nix out all the control chars...
142         (let ((i 32))
143           (while (>= (setq i (1- i)) 0)
144             (aset table i [??])))
145         ;; ... but not newline, of course.
146         (aset table ?\n nil)
147         ;; We nix out any glyphs over 126 that are not set already.  
148         (let ((i 256))
149           (while (>= (setq i (1- i)) 127)
150             (or (aref table i)
151                 (aset table i [??]))))
152         (set-window-display-table (get-buffer-window (current-buffer)) table)))
153
154     (defun gnus-highlight-selected-summary ()
155       ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
156       ;; Highlight selected article in summary buffer
157       (if gnus-summary-selected-face
158           (save-excursion
159             (let* ((beg (progn (beginning-of-line) (point)))
160                    (end (progn (end-of-line) (point)))
161                    (to (max 1 (1- (or (previous-single-property-change
162                                        end 'mouse-face nil beg) end))))
163                    (from (1+ (or (next-single-property-change 
164                                   beg 'mouse-face nil end) beg))))
165               (if (< to beg)
166                   (progn
167                     (setq from beg)
168                     (setq to end)))
169               (if gnus-newsgroup-selected-overlay
170                   (delete-extent gnus-newsgroup-selected-overlay))
171               (setq gnus-newsgroup-selected-overlay
172                     (make-extent from to))
173               (set-extent-face gnus-newsgroup-selected-overlay
174                                gnus-summary-selected-face)))))
175
176     )
177    ((boundp 'MULE)
178     ;; Mule definitions
179     (defun top-short-string (str width)
180       "Return a substring of STRING, starting at top and its length is
181 equal or smaller than WIDTH. This function doesn't split in the middle
182 of multi-octet character. [tl-str]"
183       (substring str 0
184                  (let ((i 0) (w 0) chr (len (length str)))
185                    (catch 'label
186                      (while (< i len)
187                        (setq chr (elt str i))
188                        (setq w (+ w (char-width chr)))
189                        (if (> w width)
190                            (throw 'label i))
191                        (setq i (+ i (char-bytes chr)))
192                        )
193                      i))
194                  ))
195     
196     (defun gnus-format-max-width (form length)
197       (let* ((val (eval form))
198              (valstr (if (numberp val) (int-to-string val) val)))
199         (if (> (length valstr) length)
200             (top-short-string valstr length)
201           valstr)))
202     
203     (defun gnus-summary-make-display-table ())
204     )
205    ))
206
207 (provide 'gnus-ems)
208
209 ;; Local Variables:
210 ;; byte-compile-warnings: nil
211 ;; End:
212
213 ;;; gnus-ems.el ends here