1 ;;; gnus-ems.el --- functions for making Gnus work under different Emacsen
2 ;; Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002
3 ;; Free Software Foundation, Inc.
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
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.
33 ;;; Function aliases later to be redefined for XEmacs usage.
35 (defvar gnus-mouse-2 [mouse-2])
36 (defvar gnus-down-mouse-3 [down-mouse-3])
37 (defvar gnus-down-mouse-2 [down-mouse-2])
38 (defvar gnus-widget-button-keymap nil)
39 (defvar gnus-mode-line-modified
40 (if (or (featurep 'xemacs)
41 (< emacs-major-version 20))
46 (autoload 'gnus-xmas-define "gnus-xmas")
47 (autoload 'gnus-xmas-redefine "gnus-xmas")
48 (autoload 'appt-select-lowest-window "appt"))
50 (autoload 'smiley-region "smiley")
52 (defun gnus-kill-all-overlays ()
53 "Delete all overlays in the current buffer."
54 (let* ((overlayss (overlay-lists))
55 (buffer-read-only nil)
56 (overlays (delq nil (nconc (car overlayss) (cdr overlayss)))))
58 (delete-overlay (pop overlays)))))
62 (defun gnus-mule-max-width-function (el max-width)
63 `(let* ((val (eval (, el)))
64 (valstr (if (numberp val)
65 (int-to-string val) val)))
66 (if (> (length valstr) ,max-width)
67 (truncate-string-to-width valstr ,max-width)
71 (defalias 'gnus-char-width
72 (if (fboundp 'char-width)
74 (lambda (ch) 1)))) ;; A simple hack.
77 (if (featurep 'xemacs)
79 (defvar gnus-mouse-face-prop 'mouse-face
80 "Property used for highlighting mouse regions.")))
83 (let ((case-fold-search t))
85 ((string-match "windows-nt\\|os/2\\|emx\\|cygwin32"
86 (symbol-name system-type))
87 (setq nnheader-file-name-translation-alist
88 (append nnheader-file-name-translation-alist
89 (mapcar (lambda (c) (cons c ?_))
90 '(?: ?* ?\" ?< ?> ??))
91 (if (string-match "windows-nt\\|cygwin32"
92 (symbol-name system-type))
96 (defvar gnus-tmp-unread)
97 (defvar gnus-tmp-replied)
98 (defvar gnus-tmp-score-char)
99 (defvar gnus-tmp-indentation)
100 (defvar gnus-tmp-opening-bracket)
101 (defvar gnus-tmp-lines)
102 (defvar gnus-tmp-name)
103 (defvar gnus-tmp-closing-bracket)
104 (defvar gnus-tmp-subject-or-nil)
105 (defvar gnus-check-before-posting)
107 (defun gnus-ems-redefine ()
110 (gnus-xmas-redefine))
113 ;; Mule and new Emacs definitions
115 ;; [Note] Now there are three kinds of mule implementations,
116 ;; original MULE, XEmacs/mule and Emacs 20+ including
117 ;; MULE features. Unfortunately these API are different. In
118 ;; particular, Emacs (including original MULE) and XEmacs are
119 ;; quite different. Howvere, this version of Gnus doesn't support
120 ;; anything other than XEmacs 20+ and Emacs 20.3+.
122 ;; Predicates to check are following:
123 ;; (boundp 'MULE) is t only if MULE (original; anything older than
124 ;; Mule 2.3) is running.
125 ;; (featurep 'mule) is t when every mule variants are running.
127 ;; It is possible to detect XEmacs/mule by (featurep 'mule) and
128 ;; checking `emacs-version'. In this case, the implementation for
129 ;; XEmacs/mule may be shareable between XEmacs and XEmacs/mule.
131 (defvar gnus-summary-display-table nil
132 "Display table used in summary mode buffers.")
133 (defalias 'gnus-max-width-function 'gnus-mule-max-width-function)
135 (when (boundp 'gnus-check-before-posting)
136 (setq gnus-check-before-posting
138 (delq 'control-chars gnus-check-before-posting))))
140 (defun gnus-summary-line-format-spec ()
141 (insert gnus-tmp-unread gnus-tmp-replied
142 gnus-tmp-score-char gnus-tmp-indentation)
147 gnus-tmp-opening-bracket
150 (if (> (length gnus-tmp-name) 20)
151 (truncate-string-to-width gnus-tmp-name 20)
153 gnus-tmp-closing-bracket)
155 gnus-mouse-face-prop gnus-mouse-face)
156 (insert " " gnus-tmp-subject-or-nil "\n")))))
158 (defun gnus-region-active-p ()
159 "Say whether the region is active."
160 (and (boundp 'transient-mark-mode)
162 (boundp 'mark-active)
165 (if (fboundp 'add-minor-mode)
166 (defalias 'gnus-add-minor-mode 'add-minor-mode)
167 (defun gnus-add-minor-mode (mode name map &rest rest)
168 (set (make-local-variable mode) t)
169 (unless (assq mode minor-mode-alist)
170 (push `(,mode ,name) minor-mode-alist))
171 (unless (assq mode minor-mode-map-alist)
172 (push (cons mode map)
173 minor-mode-map-alist))))
175 (defun gnus-x-splash ()
176 "Show a splash screen using a pixmap in the current buffer."
177 (let ((dir (nnheader-find-etc-directory "gnus"))
178 pixmap file height beg i)
180 (switch-to-buffer (gnus-get-buffer-create gnus-group-buffer))
181 (let ((buffer-read-only nil)
185 (file-exists-p (setq file
186 (expand-file-name "x-splash" dir))))
188 (insert-file-contents file)
189 (goto-char (point-min))
191 (setq pixmap (read (current-buffer))))))
193 (make-face 'gnus-splash)
194 (setq height (/ (car pixmap) (frame-char-height))
195 width (/ (cadr pixmap) (frame-char-width)))
196 (set-face-foreground 'gnus-splash "Brown")
197 (set-face-stipple 'gnus-splash pixmap)
198 (insert-char ?\n (* (/ (window-height) 2 height) height))
201 (insert-char ?\ (* (/ (window-width) 2 width) width))
203 (insert-char ?\ width)
204 (set-text-properties beg (point) '(face gnus-splash))
207 (goto-char (point-min))
212 (defun gnus-image-type-available-p (type)
213 (and (fboundp 'image-type-available-p)
214 (image-type-available-p type)))
216 (defun gnus-create-image (file &optional type data-p &rest props)
217 (let ((face (plist-get props :face)))
219 (setq props (plist-put props :foreground (face-foreground face)))
220 (setq props (plist-put props :background (face-background face))))
221 (apply 'create-image file type data-p props)))
223 (defun gnus-put-image (glyph &optional string)
224 (insert-image glyph (or string " "))
226 (put-text-property (1- (point)) (point)
227 'gnus-image-text-deletable t))
230 (defun gnus-remove-image (image)
231 (dolist (position (message-text-with-property 'display))
232 (when (equal (get-text-property position 'display) image)
233 (put-text-property position (1+ position) 'display nil)
234 (when (get-text-property position 'gnus-image-text-deletable)
235 (delete-region position (1+ position))))))
239 ;;; gnus-ems.el ends here