1 ;;; gnus-ems.el --- functions for making Gnus work under different Emacsen
2 ;; Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004
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 (featurep 'xemacs)
45 (autoload 'gnus-xmas-define "gnus-xmas")
46 (autoload 'gnus-xmas-redefine "gnus-xmas")
47 (autoload 'gnus-get-buffer-create "gnus")
48 (autoload 'nnheader-find-etc-directory "nnheader"))
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 (if (featurep 'xemacs)
73 (defvar gnus-mouse-face-prop 'mouse-face
74 "Property used for highlighting mouse regions.")))
77 (defvar gnus-tmp-unread)
78 (defvar gnus-tmp-replied)
79 (defvar gnus-tmp-score-char)
80 (defvar gnus-tmp-indentation)
81 (defvar gnus-tmp-opening-bracket)
82 (defvar gnus-tmp-lines)
83 (defvar gnus-tmp-name)
84 (defvar gnus-tmp-closing-bracket)
85 (defvar gnus-tmp-subject-or-nil)
86 (defvar gnus-check-before-posting)
87 (defvar gnus-mouse-face)
88 (defvar gnus-group-buffer))
90 (defun gnus-ems-redefine ()
96 ;; Mule and new Emacs definitions
98 ;; [Note] Now there are three kinds of mule implementations,
99 ;; original MULE, XEmacs/mule and Emacs 20+ including
100 ;; MULE features. Unfortunately these APIs are different. In
101 ;; particular, Emacs (including original Mule) and XEmacs are
102 ;; quite different. However, this version of Gnus doesn't support
103 ;; anything other than XEmacs 20+ and Emacs 20.3+.
105 ;; Predicates to check are following:
106 ;; (boundp 'MULE) is t only if Mule (original; anything older than
107 ;; Mule 2.3) is running.
108 ;; (featurep 'mule) is t when other mule variants are running.
110 ;; It is possible to detect XEmacs/mule by (featurep 'mule) and
111 ;; (featurep 'xemacs). In this case, the implementation for
112 ;; XEmacs/mule may be shareable between XEmacs and XEmacs/mule.
114 (defvar gnus-summary-display-table nil
115 "Display table used in summary mode buffers.")
116 (defalias 'gnus-max-width-function 'gnus-mule-max-width-function)
118 (when (boundp 'gnus-check-before-posting)
119 (setq gnus-check-before-posting
121 (delq 'control-chars gnus-check-before-posting))))
123 (defun gnus-summary-line-format-spec ()
124 (insert gnus-tmp-unread gnus-tmp-replied
125 gnus-tmp-score-char gnus-tmp-indentation)
130 gnus-tmp-opening-bracket
133 (if (> (length gnus-tmp-name) 20)
134 (truncate-string-to-width gnus-tmp-name 20)
136 gnus-tmp-closing-bracket)
138 gnus-mouse-face-prop gnus-mouse-face)
139 (insert " " gnus-tmp-subject-or-nil "\n")))))
141 ;; Clone of `appt-select-lowest-window' in appt.el.
142 (defun gnus-select-lowest-window ()
143 "Select the lowest window on the frame."
144 (let ((lowest-window (selected-window))
145 (bottom-edge (nth 3 (window-edges))))
146 (walk-windows (lambda (w)
147 (let ((next-bottom-edge (nth 3 (window-edges w))))
148 (when (< bottom-edge next-bottom-edge)
149 (setq bottom-edge next-bottom-edge
151 (select-window lowest-window)))
153 (defun gnus-region-active-p ()
154 "Say whether the region is active."
155 (and (boundp 'transient-mark-mode)
157 (boundp 'mark-active)
160 (defun gnus-mark-active-p ()
161 "Non-nil means the mark and region are currently active in this buffer."
162 mark-active) ; aliased to region-exists-p in XEmacs.
164 (defun gnus-x-splash ()
165 "Show a splash screen using a pixmap in the current buffer."
166 (let ((dir (nnheader-find-etc-directory "gnus"))
167 pixmap file height beg i)
169 (switch-to-buffer (gnus-get-buffer-create gnus-group-buffer))
170 (let ((buffer-read-only nil)
174 (file-exists-p (setq file
175 (expand-file-name "x-splash" dir))))
176 (let ((coding-system-for-read 'raw-text)
177 default-enable-multibyte-characters)
179 (insert-file-contents file)
180 (goto-char (point-min))
182 (setq pixmap (read (current-buffer)))))))
184 (make-face 'gnus-splash)
185 (setq height (/ (car pixmap) (frame-char-height))
186 width (/ (cadr pixmap) (frame-char-width)))
187 (set-face-foreground 'gnus-splash "Brown")
188 (set-face-stipple 'gnus-splash pixmap)
189 (insert-char ?\n (* (/ (window-height) 2 height) height))
192 (insert-char ?\ (* (/ (window-width) 2 width) width))
194 (insert-char ?\ width)
195 (set-text-properties beg (point) '(face gnus-splash))
198 (goto-char (point-min))
203 (defun gnus-image-type-available-p (type)
204 (and (fboundp 'image-type-available-p)
205 (image-type-available-p type)))
207 (defun gnus-create-image (file &optional type data-p &rest props)
208 (let ((face (plist-get props :face)))
210 (setq props (plist-put props :foreground (face-foreground face)))
211 (setq props (plist-put props :background (face-background face))))
212 (apply 'create-image file type data-p props)))
214 (defun gnus-put-image (glyph &optional string category)
215 (let ((point (point)))
216 (insert-image glyph (or string " "))
217 (put-text-property point (point) 'gnus-image-category category)
219 (put-text-property (1- (point)) (point)
220 'gnus-image-text-deletable t))
223 (defun gnus-remove-image (image &optional category)
224 "Remove the image matching IMAGE and CATEGORY found first."
225 (let ((start (point-min))
227 (while (and (not end)
228 (or (setq val (get-text-property start 'display))
230 (next-single-property-change start 'display))
231 (setq val (get-text-property start 'display)))))
232 (setq end (or (next-single-property-change start 'display)
234 (if (and (equal val image)
235 (equal (get-text-property start 'gnus-image-category)
238 (put-text-property start end 'display nil)
239 (when (get-text-property start 'gnus-image-text-deletable)
240 (delete-region start end)))
241 (unless (= end (point-max))
247 ;;; arch-tag: e7360b45-14b5-4171-aa39-69a44aed3cdb
248 ;;; gnus-ems.el ends here