Commit | Line | Data |
---|---|---|
eec82323 | 1 | ;;; gnus-ems.el --- functions for making Gnus work under different Emacsen |
e84b4b86 TTN |
2 | |
3 | ;; Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, | |
e3fe4da0 | 4 | ;; 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc. |
eec82323 | 5 | |
6748645f | 6 | ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org> |
eec82323 LMI |
7 | ;; Keywords: news |
8 | ||
9 | ;; This file is part of GNU Emacs. | |
10 | ||
11 | ;; GNU Emacs is free software; you can redistribute it and/or modify | |
12 | ;; it under the terms of the GNU General Public License as published by | |
5a9dffec | 13 | ;; the Free Software Foundation; either version 3, or (at your option) |
eec82323 LMI |
14 | ;; any later version. |
15 | ||
16 | ;; GNU Emacs is distributed in the hope that it will be useful, | |
17 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 | ;; GNU General Public License for more details. | |
20 | ||
21 | ;; You should have received a copy of the GNU General Public License | |
22 | ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
3a35cf56 LK |
23 | ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
24 | ;; Boston, MA 02110-1301, USA. | |
eec82323 LMI |
25 | |
26 | ;;; Commentary: | |
27 | ||
28 | ;;; Code: | |
29 | ||
4bcf2f05 DL |
30 | (eval-when-compile |
31 | (require 'cl) | |
32 | (require 'ring)) | |
eec82323 LMI |
33 | |
34 | ;;; Function aliases later to be redefined for XEmacs usage. | |
35 | ||
eec82323 | 36 | (defvar gnus-mouse-2 [mouse-2]) |
16409b0b | 37 | (defvar gnus-down-mouse-3 [down-mouse-3]) |
eec82323 | 38 | (defvar gnus-down-mouse-2 [down-mouse-2]) |
16409b0b | 39 | (defvar gnus-widget-button-keymap nil) |
a8151ef7 | 40 | (defvar gnus-mode-line-modified |
01c52d31 | 41 | (if (featurep 'xemacs) |
a8151ef7 LMI |
42 | '("--**-" . "-----") |
43 | '("**" "--"))) | |
eec82323 LMI |
44 | |
45 | (eval-and-compile | |
46 | (autoload 'gnus-xmas-define "gnus-xmas") | |
47 | (autoload 'gnus-xmas-redefine "gnus-xmas") | |
23f87bed MB |
48 | (autoload 'gnus-get-buffer-create "gnus") |
49 | (autoload 'nnheader-find-etc-directory "nnheader")) | |
eec82323 | 50 | |
23f87bed | 51 | (autoload 'smiley-region "smiley") |
06c43cdf DL |
52 | |
53 | (defun gnus-kill-all-overlays () | |
54 | "Delete all overlays in the current buffer." | |
55 | (let* ((overlayss (overlay-lists)) | |
56 | (buffer-read-only nil) | |
57 | (overlays (delq nil (nconc (car overlayss) (cdr overlayss))))) | |
58 | (while overlays | |
59 | (delete-overlay (pop overlays))))) | |
2d2f7f3e | 60 | |
eec82323 LMI |
61 | ;;; Mule functions. |
62 | ||
eec82323 | 63 | (defun gnus-mule-max-width-function (el max-width) |
16409b0b GM |
64 | `(let* ((val (eval (, el))) |
65 | (valstr (if (numberp val) | |
66 | (int-to-string val) val))) | |
67 | (if (> (length valstr) ,max-width) | |
68 | (truncate-string-to-width valstr ,max-width) | |
69 | valstr))) | |
6748645f | 70 | |
eec82323 | 71 | (eval-and-compile |
06c43cdf | 72 | (if (featurep 'xemacs) |
16409b0b | 73 | (gnus-xmas-define) |
eec82323 | 74 | (defvar gnus-mouse-face-prop 'mouse-face |
16409b0b | 75 | "Property used for highlighting mouse regions."))) |
eec82323 | 76 | |
9efa445f DN |
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) | |
eec82323 LMI |
89 | |
90 | (defun gnus-ems-redefine () | |
91 | (cond | |
4ddf0e64 | 92 | ((featurep 'xemacs) |
eec82323 LMI |
93 | (gnus-xmas-redefine)) |
94 | ||
95 | ((featurep 'mule) | |
96 | ;; Mule and new Emacs definitions | |
97 | ||
98 | ;; [Note] Now there are three kinds of mule implementations, | |
16409b0b | 99 | ;; original MULE, XEmacs/mule and Emacs 20+ including |
23f87bed MB |
100 | ;; MULE features. Unfortunately these APIs are different. In |
101 | ;; particular, Emacs (including original Mule) and XEmacs are | |
feee6240 | 102 | ;; quite different. However, this version of Gnus doesn't support |
16409b0b GM |
103 | ;; anything other than XEmacs 20+ and Emacs 20.3+. |
104 | ||
eec82323 | 105 | ;; Predicates to check are following: |
23f87bed | 106 | ;; (boundp 'MULE) is t only if Mule (original; anything older than |
eec82323 | 107 | ;; Mule 2.3) is running. |
23f87bed | 108 | ;; (featurep 'mule) is t when other mule variants are running. |
eec82323 | 109 | |
16409b0b | 110 | ;; It is possible to detect XEmacs/mule by (featurep 'mule) and |
23f87bed | 111 | ;; (featurep 'xemacs). In this case, the implementation for |
16409b0b | 112 | ;; XEmacs/mule may be shareable between XEmacs and XEmacs/mule. |
eec82323 LMI |
113 | |
114 | (defvar gnus-summary-display-table nil | |
115 | "Display table used in summary mode buffers.") | |
16409b0b | 116 | (defalias 'gnus-max-width-function 'gnus-mule-max-width-function) |
eec82323 LMI |
117 | |
118 | (when (boundp 'gnus-check-before-posting) | |
119 | (setq gnus-check-before-posting | |
120 | (delq 'long-lines | |
121 | (delq 'control-chars gnus-check-before-posting)))) | |
122 | ||
123 | (defun gnus-summary-line-format-spec () | |
124 | (insert gnus-tmp-unread gnus-tmp-replied | |
125 | gnus-tmp-score-char gnus-tmp-indentation) | |
126 | (put-text-property | |
127 | (point) | |
128 | (progn | |
129 | (insert | |
130 | gnus-tmp-opening-bracket | |
131 | (format "%4d: %-20s" | |
132 | gnus-tmp-lines | |
133 | (if (> (length gnus-tmp-name) 20) | |
16409b0b | 134 | (truncate-string-to-width gnus-tmp-name 20) |
eec82323 LMI |
135 | gnus-tmp-name)) |
136 | gnus-tmp-closing-bracket) | |
137 | (point)) | |
138 | gnus-mouse-face-prop gnus-mouse-face) | |
16409b0b | 139 | (insert " " gnus-tmp-subject-or-nil "\n"))))) |
eec82323 | 140 | |
01c52d31 MB |
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 | |
150 | lowest-window w))))) | |
151 | (select-window lowest-window))) | |
152 | ||
eec82323 LMI |
153 | (defun gnus-region-active-p () |
154 | "Say whether the region is active." | |
155 | (and (boundp 'transient-mark-mode) | |
156 | transient-mark-mode | |
157 | (boundp 'mark-active) | |
158 | mark-active)) | |
159 | ||
23f87bed MB |
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. | |
163 | ||
db48b197 | 164 | (autoload 'gnus-alive-p "gnus-util") |
407da272 | 165 | (autoload 'mm-disable-multibyte "mm-util") |
db48b197 | 166 | |
6748645f LMI |
167 | (defun gnus-x-splash () |
168 | "Show a splash screen using a pixmap in the current buffer." | |
524705ae MB |
169 | (interactive) |
170 | (unless window-system | |
171 | (error "`gnus-x-splash' requires running on the window system")) | |
172 | (switch-to-buffer (gnus-get-buffer-create (if (or (gnus-alive-p) | |
173 | (interactive-p)) | |
174 | "*gnus-x-splash*" | |
175 | gnus-group-buffer))) | |
37cc095b | 176 | (let ((inhibit-read-only t) |
524705ae MB |
177 | (file (nnheader-find-etc-directory "images/gnus/x-splash" t)) |
178 | pixmap fcw fch width height fringes sbars left yoffset top ls) | |
179 | (erase-buffer) | |
5cedca8d | 180 | (sit-for 0) ;; Necessary for measuring the window size correctly. |
524705ae MB |
181 | (when (and file |
182 | (ignore-errors | |
2b57967e | 183 | (let ((coding-system-for-read 'raw-text)) |
524705ae | 184 | (with-temp-buffer |
2b57967e | 185 | (mm-disable-multibyte) |
524705ae MB |
186 | (insert-file-contents file) |
187 | (goto-char (point-min)) | |
188 | (setq pixmap (read (current-buffer))))))) | |
189 | (setq fcw (float (frame-char-width)) | |
190 | fch (float (frame-char-height)) | |
191 | width (/ (car pixmap) fcw) | |
192 | height (/ (cadr pixmap) fch) | |
193 | fringes (if (fboundp 'window-fringes) | |
194 | (eval '(window-fringes)) | |
195 | '(10 11 nil)) | |
196 | sbars (frame-parameter nil 'vertical-scroll-bars)) | |
197 | (cond ((eq sbars 'right) | |
198 | (setq sbars | |
199 | (cons 0 (/ (or (frame-parameter nil 'scroll-bar-width) 14) | |
200 | fcw)))) | |
201 | (sbars | |
202 | (setq sbars | |
203 | (cons (/ (or (frame-parameter nil 'scroll-bar-width) 14) | |
204 | fcw) | |
60ece9b0 MB |
205 | 0))) |
206 | (t | |
207 | (setq sbars '(0 . 0)))) | |
524705ae MB |
208 | (setq left (- (* (round (/ (1- (/ (+ (window-width) |
209 | (car sbars) (cdr sbars) | |
210 | (/ (+ (or (car fringes) 0) | |
211 | (or (cadr fringes) 0)) | |
212 | fcw)) | |
213 | width)) | |
214 | 2)) | |
215 | width) | |
216 | (car sbars) | |
217 | (/ (or (car fringes) 0) fcw)) | |
218 | yoffset (cadr (window-edges)) | |
219 | top (max 0 (- (* (max (if (and tool-bar-mode | |
220 | (not (featurep 'gtk)) | |
221 | (eq (frame-first-window) | |
222 | (selected-window))) | |
223 | 1 0) | |
224 | (round (/ (1- (/ (+ (1- (window-height)) | |
225 | (* 2 yoffset)) | |
226 | height)) | |
227 | 2))) | |
228 | height) | |
229 | yoffset)) | |
230 | ls (/ (or line-spacing 0) fch) | |
231 | height (max 0 (- height ls))) | |
232 | (cond ((>= (- top ls) 1) | |
233 | (insert | |
234 | (propertize | |
235 | " " | |
236 | 'display `(space :width 0 :ascent 100)) | |
237 | "\n" | |
238 | (propertize | |
239 | " " | |
240 | 'display `(space :width 0 :height ,(- top ls 1) :ascent 100)) | |
241 | "\n")) | |
242 | ((> (- top ls) 0) | |
243 | (insert | |
244 | (propertize | |
245 | " " | |
246 | 'display `(space :width 0 :height ,(- top ls) :ascent 100)) | |
247 | "\n"))) | |
248 | (if (and (> width 0) (> left 0)) | |
249 | (insert (propertize | |
250 | " " | |
251 | 'display `(space :width ,left :height ,height :ascent 0))) | |
252 | (setq width (+ width left))) | |
253 | (when (> width 0) | |
254 | (insert (propertize | |
255 | " " | |
256 | 'display `(space :width ,width :height ,height :ascent 0) | |
257 | 'face `(gnus-splash :stipple ,pixmap)))) | |
258 | (goto-char (if (<= (- top ls) 0) (1- (point)) (point-min))) | |
259 | (redraw-frame (selected-frame)) | |
260 | (sit-for 0)))) | |
6748645f | 261 | |
23f87bed MB |
262 | ;;; Image functions. |
263 | ||
264 | (defun gnus-image-type-available-p (type) | |
265 | (and (fboundp 'image-type-available-p) | |
11e95b02 MB |
266 | (image-type-available-p type) |
267 | (if (fboundp 'display-images-p) | |
268 | (display-images-p) | |
269 | t))) | |
23f87bed MB |
270 | |
271 | (defun gnus-create-image (file &optional type data-p &rest props) | |
272 | (let ((face (plist-get props :face))) | |
273 | (when face | |
274 | (setq props (plist-put props :foreground (face-foreground face))) | |
275 | (setq props (plist-put props :background (face-background face)))) | |
276 | (apply 'create-image file type data-p props))) | |
277 | ||
278 | (defun gnus-put-image (glyph &optional string category) | |
279 | (let ((point (point))) | |
280 | (insert-image glyph (or string " ")) | |
281 | (put-text-property point (point) 'gnus-image-category category) | |
282 | (unless string | |
283 | (put-text-property (1- (point)) (point) | |
284 | 'gnus-image-text-deletable t)) | |
285 | glyph)) | |
286 | ||
287 | (defun gnus-remove-image (image &optional category) | |
01c52d31 MB |
288 | "Remove the image matching IMAGE and CATEGORY found first." |
289 | (let ((start (point-min)) | |
290 | val end) | |
291 | (while (and (not end) | |
292 | (or (setq val (get-text-property start 'display)) | |
293 | (and (setq start | |
294 | (next-single-property-change start 'display)) | |
295 | (setq val (get-text-property start 'display))))) | |
296 | (setq end (or (next-single-property-change start 'display) | |
297 | (point-max))) | |
298 | (if (and (equal val image) | |
299 | (equal (get-text-property start 'gnus-image-category) | |
23f87bed | 300 | category)) |
01c52d31 MB |
301 | (progn |
302 | (put-text-property start end 'display nil) | |
303 | (when (get-text-property start 'gnus-image-text-deletable) | |
304 | (delete-region start end))) | |
305 | (unless (= end (point-max)) | |
306 | (setq start end | |
307 | end nil)))))) | |
6748645f | 308 | |
eec82323 LMI |
309 | (provide 'gnus-ems) |
310 | ||
cbee283d | 311 | ;; arch-tag: e7360b45-14b5-4171-aa39-69a44aed3cdb |
eec82323 | 312 | ;;; gnus-ems.el ends here |