1 ;;; gnus-ems.el --- functions for making Gnus work under different Emacsen
2 ;; Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
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.")))
82 (defvar gnus-tmp-unread)
83 (defvar gnus-tmp-replied)
84 (defvar gnus-tmp-score-char)
85 (defvar gnus-tmp-indentation)
86 (defvar gnus-tmp-opening-bracket)
87 (defvar gnus-tmp-lines)
88 (defvar gnus-tmp-name)
89 (defvar gnus-tmp-closing-bracket)
90 (defvar gnus-tmp-subject-or-nil)
91 (defvar gnus-check-before-posting)
93 (defun gnus-ems-redefine ()
99 ;; Mule and new Emacs definitions
101 ;; [Note] Now there are three kinds of mule implementations,
102 ;; original MULE, XEmacs/mule and Emacs 20+ including
103 ;; MULE features. Unfortunately these API are different. In
104 ;; particular, Emacs (including original MULE) and XEmacs are
105 ;; quite different. However, this version of Gnus doesn't support
106 ;; anything other than XEmacs 20+ and Emacs 20.3+.
108 ;; Predicates to check are following:
109 ;; (boundp 'MULE) is t only if MULE (original; anything older than
110 ;; Mule 2.3) is running.
111 ;; (featurep 'mule) is t when every mule variants are running.
113 ;; It is possible to detect XEmacs/mule by (featurep 'mule) and
114 ;; checking `emacs-version'. In this case, the implementation for
115 ;; XEmacs/mule may be shareable between XEmacs and XEmacs/mule.
117 (defvar gnus-summary-display-table nil
118 "Display table used in summary mode buffers.")
119 (defalias 'gnus-max-width-function 'gnus-mule-max-width-function)
121 (when (boundp 'gnus-check-before-posting)
122 (setq gnus-check-before-posting
124 (delq 'control-chars gnus-check-before-posting))))
126 (defun gnus-summary-line-format-spec ()
127 (insert gnus-tmp-unread gnus-tmp-replied
128 gnus-tmp-score-char gnus-tmp-indentation)
133 gnus-tmp-opening-bracket
136 (if (> (length gnus-tmp-name) 20)
137 (truncate-string-to-width gnus-tmp-name 20)
139 gnus-tmp-closing-bracket)
141 gnus-mouse-face-prop gnus-mouse-face)
142 (insert " " gnus-tmp-subject-or-nil "\n")))))
144 (defun gnus-region-active-p ()
145 "Say whether the region is active."
146 (and (boundp 'transient-mark-mode)
148 (boundp 'mark-active)
151 (defun gnus-mark-active-p ()
152 "Non-nil means the mark and region are currently active in this buffer."
153 mark-active) ; aliased to region-exists-p in XEmacs.
155 (if (fboundp 'add-minor-mode)
156 (defalias 'gnus-add-minor-mode 'add-minor-mode)
157 (defun gnus-add-minor-mode (mode name map &rest rest)
158 (set (make-local-variable mode) t)
159 (unless (assq mode minor-mode-alist)
160 (push `(,mode ,name) minor-mode-alist))
161 (unless (assq mode minor-mode-map-alist)
162 (push (cons mode map)
163 minor-mode-map-alist))))
165 (defun gnus-x-splash ()
166 "Show a splash screen using a pixmap in the current buffer."
167 (let ((dir (nnheader-find-etc-directory "gnus"))
168 pixmap file height beg i)
170 (switch-to-buffer (gnus-get-buffer-create gnus-group-buffer))
171 (let ((buffer-read-only nil)
175 (file-exists-p (setq file
176 (expand-file-name "x-splash" dir))))
177 (let ((coding-system-for-read 'raw-text)
178 default-enable-multibyte-characters)
180 (insert-file-contents file)
181 (goto-char (point-min))
183 (setq pixmap (read (current-buffer)))))))
185 (make-face 'gnus-splash)
186 (setq height (/ (car pixmap) (frame-char-height))
187 width (/ (cadr pixmap) (frame-char-width)))
188 (set-face-foreground 'gnus-splash "Brown")
189 (set-face-stipple 'gnus-splash pixmap)
190 (insert-char ?\n (* (/ (window-height) 2 height) height))
193 (insert-char ?\ (* (/ (window-width) 2 width) width))
195 (insert-char ?\ width)
196 (set-text-properties beg (point) '(face gnus-splash))
199 (goto-char (point-min))
204 (defun gnus-image-type-available-p (type)
205 (and (fboundp 'image-type-available-p)
206 (image-type-available-p type)))
208 (defun gnus-create-image (file &optional type data-p &rest props)
209 (let ((face (plist-get props :face)))
211 (setq props (plist-put props :foreground (face-foreground face)))
212 (setq props (plist-put props :background (face-background face))))
213 (apply 'create-image file type data-p props)))
215 (defun gnus-put-image (glyph &optional string)
216 (insert-image glyph (or string " "))
218 (put-text-property (1- (point)) (point)
219 'gnus-image-text-deletable t))
222 (defun gnus-remove-image (image)
223 (dolist (position (message-text-with-property 'display))
224 (when (equal (get-text-property position 'display) image)
225 (put-text-property position (1+ position) 'display nil)
226 (when (get-text-property position 'gnus-image-text-deletable)
227 (delete-region position (1+ position))))))
231 ;;; gnus-ems.el ends here