1 ;;; gnus-ems.el --- functions for making Semi-gnus work under different Emacsen
2 ;; Copyright (C) 1995,96,97,98 Free Software Foundation, Inc.
4 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
5 ;; Tatsuya Ichikawa <t-ichi@niagara.shiojiri.ne.jp>
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
29 (eval-when-compile (require 'cl))
31 ;;; Function aliases later to be redefined for XEmacs usage.
33 (defvar gnus-xemacs (string-match "XEmacs\\|Lucid" emacs-version)
34 "Non-nil if running under XEmacs.")
36 (defvar gnus-mouse-2 [mouse-2])
37 (defvar gnus-mouse-3 [mouse-3])
38 (defvar gnus-down-mouse-2 [down-mouse-2])
39 (defvar gnus-widget-button-keymap nil)
40 (defvar gnus-mode-line-modified
42 (< emacs-major-version 20))
47 (autoload 'gnus-xmas-define "gnus-xmas")
48 (autoload 'gnus-xmas-redefine "gnus-xmas")
49 (autoload 'appt-select-lowest-window "appt"))
51 (or (fboundp 'mail-file-babyl-p)
52 (fset 'mail-file-babyl-p 'rmail-file-p))
56 (defun gnus-mule-cite-add-face (number prefix face)
57 ;; At line NUMBER, ignore PREFIX and add FACE to the rest of the line.
59 (let ((inhibit-point-motion-hooks t)
62 (unless (eobp) ; Sometimes things become confused (broken).
63 (forward-char (chars-in-string prefix))
64 (skip-chars-forward " \t")
67 (skip-chars-backward " \t")
70 (push (setq overlay (gnus-make-overlay from to))
71 gnus-cite-overlay-list)
72 (gnus-overlay-put (gnus-make-overlay from to) 'face face))))))
74 (defvar gnus-mule-bitmap-image-file nil)
75 (defun gnus-mule-group-startup-message (&optional x y)
76 "Insert startup message in current buffer."
77 ;; Insert the message.
80 (if (featurep 'bitmap)
84 "" (if (and (stringp gnus-mule-bitmap-image-file)
85 (file-exists-p gnus-mule-bitmap-image-file))
86 (insert-file gnus-mule-bitmap-image-file)))
109 (gnus-indent-rigidly (point-min) (point-max)
110 (/ (max (- (window-width) (or x 46)) 0) 2))
111 (goto-char (point-min))
113 (let* ((pheight (count-lines (point-min) (point-max)))
114 (wheight (window-height))
115 (rest (- wheight pheight)))
116 (insert (make-string (max 0 (* 2 (/ rest 3))) ?\n)))
118 (put-text-property (point-min) (point-max) 'face 'gnus-splash-face)
119 (goto-char (point-min))
120 (setq mode-line-buffer-identification (concat " " gnus-version))
121 (setq gnus-simple-splash t)
122 (set-buffer-modified-p t))
124 (defun gnus-encode-coding-string (string system)
127 (defun gnus-decode-coding-string (string system)
131 (if (string-match "XEmacs\\|Lucid" emacs-version)
134 (defvar gnus-mouse-face-prop 'mouse-face
135 "Property used for highlighting mouse regions."))
138 ((string-match "XEmacs\\|Lucid" emacs-version)
141 ((or (not (boundp 'emacs-minor-version))
142 (and (< emacs-major-version 20)
143 (< emacs-minor-version 30)))
144 ;; Remove the `intangible' prop.
145 (let ((props (and (boundp 'gnus-hidden-properties)
146 gnus-hidden-properties)))
147 (while (and props (not (eq (car (cdr props)) 'intangible)))
148 (setq props (cdr props)))
150 (setcdr props (cdr (cdr (cdr props))))))
151 (unless (fboundp 'buffer-substring-no-properties)
152 (defun buffer-substring-no-properties (beg end)
153 (format "%s" (buffer-substring beg end)))))
156 (provide 'gnusutil))))
161 (defun gnus-dummy-func (&rest args))
162 (let ((funcs '(mouse-set-point set-face-foreground
163 set-face-background x-popup-menu)))
165 (unless (fboundp (car funcs))
166 (fset (car funcs) 'gnus-dummy-func))
167 (setq funcs (cdr funcs)))))))
170 (let ((case-fold-search t))
172 ((string-match "windows-nt\\|os/2\\|emx" (symbol-name system-type))
173 (setq nnheader-file-name-translation-alist
174 (append nnheader-file-name-translation-alist
178 (defvar gnus-tmp-unread)
179 (defvar gnus-tmp-replied)
180 (defvar gnus-tmp-score-char)
181 (defvar gnus-tmp-indentation)
182 (defvar gnus-tmp-opening-bracket)
183 (defvar gnus-tmp-lines)
184 (defvar gnus-tmp-name)
185 (defvar gnus-tmp-closing-bracket)
186 (defvar gnus-tmp-subject-or-nil)
188 (defun gnus-ems-redefine ()
190 ((string-match "XEmacs\\|Lucid" emacs-version)
191 (gnus-xmas-redefine))
194 ;; Mule and new Emacs definitions
196 ;; [Note] Now there are three kinds of mule implementations,
197 ;; original MULE, XEmacs/mule and beta version of Emacs including
198 ;; some mule features. Unfortunately these API are different. In
199 ;; particular, Emacs (including original MULE) and XEmacs are
201 ;; Predicates to check are following:
202 ;; (boundp 'MULE) is t only if MULE (original; anything older than
203 ;; Mule 2.3) is running.
204 ;; (featurep 'mule) is t when every mule variants are running.
206 ;; These implementations may be able to share between original
207 ;; MULE and beta version of new Emacs. In addition, it is able to
208 ;; detect XEmacs/mule by (featurep 'mule) and to check variable
209 ;; `emacs-version'. In this case, implementation for XEmacs/mule
210 ;; may be able to share between XEmacs and XEmacs/mule.
212 (defvar gnus-summary-display-table nil
213 "Display table used in summary mode buffers.")
214 (fset 'gnus-summary-set-display-table (lambda ()))
215 (fset 'gnus-encode-coding-string 'encode-coding-string)
216 (fset 'gnus-decode-coding-string 'decode-coding-string)
218 (if (fboundp 'truncate-string-to-width)
219 (fset 'gnus-truncate-string 'truncate-string-to-width)
220 (fset 'gnus-truncate-string 'truncate-string))
222 (defun gnus-tilde-max-form (el max-width)
223 "Return a form that limits EL to MAX-WIDTH."
224 (let ((max (abs max-width)))
226 `(if (> (string-width ,el) ,max)
228 `(gnus-truncate-string
229 ,el (string-width ,el)
230 (- (string-width ,el) ,max))
231 `(gnus-truncate-string ,el ,max))
233 `(let ((val (eval ,el)))
234 (if (> (string-width val) ,max)
236 `(gnus-truncate-string
237 val (string-width val)
238 (- (string-width val) ,max))
239 `(gnus-truncate-string val ,max))
242 (defun gnus-tilde-cut-form (el cut-width)
243 "Return a form that cuts CUT-WIDTH off of EL."
244 (let ((cut (abs cut-width)))
246 `(if (> (string-width ,el) ,cut)
248 `(gnus-truncate-string
249 ,el (- (string-width ,el) ,cut))
250 `(gnus-truncate-string
251 ,el (- (string-width ,el) ,cut) ,cut))
253 `(let ((val (eval ,el)))
254 (if (> (string-width val) ,cut)
256 `(gnus-truncate-string
257 val (- (string-width val) ,cut))
258 `(gnus-truncate-string
259 val (- (string-width val) ,cut) ,cut))
264 (if (module-installed-p 'bitmap)
265 (fset 'gnus-group-startup-message 'gnus-mule-group-startup-message)
268 (when (boundp 'gnus-check-before-posting)
269 (setq gnus-check-before-posting
271 (delq 'control-chars gnus-check-before-posting))))
273 (when (fboundp 'chars-in-string)
274 (fset 'gnus-cite-add-face 'gnus-mule-cite-add-face))
278 (defun gnus-region-active-p ()
279 "Say whether the region is active."
280 (and (boundp 'transient-mark-mode)
282 (boundp 'mark-active)
285 (defun gnus-add-minor-mode (mode name map)
286 (if (fboundp 'add-minor-mode)
287 (add-minor-mode mode name map)
288 (set (make-local-variable mode) t)
289 (unless (assq mode minor-mode-alist)
290 (push `(,mode ,name) minor-mode-alist))
291 (unless (assq mode minor-mode-map-alist)
292 (push (cons mode map)
293 minor-mode-map-alist))))
295 (defun gnus-x-splash ()
296 "Show a splash screen using a pixmap in the current buffer."
297 (let ((dir (nnheader-find-etc-directory "gnus"))
298 pixmap file height beg i)
300 (switch-to-buffer (gnus-get-buffer-create gnus-group-buffer))
301 (let ((buffer-read-only nil))
304 (file-exists-p (setq file (concat dir "x-splash"))))
306 (insert-file-contents file)
307 (goto-char (point-min))
309 (setq pixmap (read (current-buffer))))))
312 (unless (facep 'gnus-splash)
313 (make-face 'gnus-splash))
314 (setq height (/ (car pixmap) (frame-char-height))
315 width (/ (cadr pixmap) (frame-char-width)))
316 (set-face-foreground 'gnus-splash "ForestGreen")
317 (set-face-stipple 'gnus-splash pixmap)
318 (insert-char ?\n (* (/ (window-height) 2 height) height))
321 (insert-char ? (* (+ (/ (window-width) 2 width) 1) width))
323 (insert-char ? width)
324 (set-text-properties beg (point) '(face gnus-splash))
327 (goto-char (point-min))
330 (if (fboundp 'split-string)
331 (fset 'gnus-split-string 'split-string)
332 (defun gnus-split-string (string pattern)
333 "Return a list of substrings of STRING which are separated by PATTERN."
334 (let (parts (start 0))
335 (while (string-match pattern string start)
336 (setq parts (cons (substring string start (match-beginning 0)) parts)
337 start (match-end 0)))
338 (nreverse (cons (substring string start) parts)))))
343 ;; byte-compile-warnings: '(redefine callargs)
346 ;;; gnus-ems.el ends here