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, | |
4 | ;; 2004, 2005 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 | |
13 | ;; the Free Software Foundation; either version 2, or (at your option) | |
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 |
06c43cdf | 41 | (if (or (featurep 'xemacs) |
a8151ef7 LMI |
42 | (< emacs-major-version 20)) |
43 | '("--**-" . "-----") | |
44 | '("**" "--"))) | |
eec82323 LMI |
45 | |
46 | (eval-and-compile | |
47 | (autoload 'gnus-xmas-define "gnus-xmas") | |
48 | (autoload 'gnus-xmas-redefine "gnus-xmas") | |
23f87bed MB |
49 | (autoload 'appt-select-lowest-window "appt") |
50 | (autoload 'gnus-get-buffer-create "gnus") | |
51 | (autoload 'nnheader-find-etc-directory "nnheader")) | |
eec82323 | 52 | |
23f87bed MB |
53 | (autoload 'smiley-region "smiley") |
54 | ;; Fixme: shouldn't require message | |
55 | (autoload 'message-text-with-property "message") | |
06c43cdf DL |
56 | |
57 | (defun gnus-kill-all-overlays () | |
58 | "Delete all overlays in the current buffer." | |
59 | (let* ((overlayss (overlay-lists)) | |
60 | (buffer-read-only nil) | |
61 | (overlays (delq nil (nconc (car overlayss) (cdr overlayss))))) | |
62 | (while overlays | |
63 | (delete-overlay (pop overlays))))) | |
2d2f7f3e | 64 | |
eec82323 LMI |
65 | ;;; Mule functions. |
66 | ||
eec82323 | 67 | (defun gnus-mule-max-width-function (el max-width) |
16409b0b GM |
68 | `(let* ((val (eval (, el))) |
69 | (valstr (if (numberp val) | |
70 | (int-to-string val) val))) | |
71 | (if (> (length valstr) ,max-width) | |
72 | (truncate-string-to-width valstr ,max-width) | |
73 | valstr))) | |
6748645f | 74 | |
23f87bed MB |
75 | (eval-and-compile |
76 | (defalias 'gnus-char-width | |
77 | (if (fboundp 'char-width) | |
78 | 'char-width | |
79 | (lambda (ch) 1)))) ;; A simple hack. | |
80 | ||
eec82323 | 81 | (eval-and-compile |
06c43cdf | 82 | (if (featurep 'xemacs) |
16409b0b | 83 | (gnus-xmas-define) |
eec82323 | 84 | (defvar gnus-mouse-face-prop 'mouse-face |
16409b0b | 85 | "Property used for highlighting mouse regions."))) |
eec82323 | 86 | |
23f87bed MB |
87 | (eval-when-compile |
88 | (defvar gnus-tmp-unread) | |
89 | (defvar gnus-tmp-replied) | |
90 | (defvar gnus-tmp-score-char) | |
91 | (defvar gnus-tmp-indentation) | |
92 | (defvar gnus-tmp-opening-bracket) | |
93 | (defvar gnus-tmp-lines) | |
94 | (defvar gnus-tmp-name) | |
95 | (defvar gnus-tmp-closing-bracket) | |
96 | (defvar gnus-tmp-subject-or-nil) | |
97 | (defvar gnus-check-before-posting) | |
98 | (defvar gnus-mouse-face) | |
99 | (defvar gnus-group-buffer)) | |
eec82323 LMI |
100 | |
101 | (defun gnus-ems-redefine () | |
102 | (cond | |
4ddf0e64 | 103 | ((featurep 'xemacs) |
eec82323 LMI |
104 | (gnus-xmas-redefine)) |
105 | ||
106 | ((featurep 'mule) | |
107 | ;; Mule and new Emacs definitions | |
108 | ||
109 | ;; [Note] Now there are three kinds of mule implementations, | |
16409b0b | 110 | ;; original MULE, XEmacs/mule and Emacs 20+ including |
23f87bed MB |
111 | ;; MULE features. Unfortunately these APIs are different. In |
112 | ;; particular, Emacs (including original Mule) and XEmacs are | |
feee6240 | 113 | ;; quite different. However, this version of Gnus doesn't support |
16409b0b GM |
114 | ;; anything other than XEmacs 20+ and Emacs 20.3+. |
115 | ||
eec82323 | 116 | ;; Predicates to check are following: |
23f87bed | 117 | ;; (boundp 'MULE) is t only if Mule (original; anything older than |
eec82323 | 118 | ;; Mule 2.3) is running. |
23f87bed | 119 | ;; (featurep 'mule) is t when other mule variants are running. |
eec82323 | 120 | |
16409b0b | 121 | ;; It is possible to detect XEmacs/mule by (featurep 'mule) and |
23f87bed | 122 | ;; (featurep 'xemacs). In this case, the implementation for |
16409b0b | 123 | ;; XEmacs/mule may be shareable between XEmacs and XEmacs/mule. |
eec82323 LMI |
124 | |
125 | (defvar gnus-summary-display-table nil | |
126 | "Display table used in summary mode buffers.") | |
16409b0b | 127 | (defalias 'gnus-max-width-function 'gnus-mule-max-width-function) |
eec82323 LMI |
128 | |
129 | (when (boundp 'gnus-check-before-posting) | |
130 | (setq gnus-check-before-posting | |
131 | (delq 'long-lines | |
132 | (delq 'control-chars gnus-check-before-posting)))) | |
133 | ||
134 | (defun gnus-summary-line-format-spec () | |
135 | (insert gnus-tmp-unread gnus-tmp-replied | |
136 | gnus-tmp-score-char gnus-tmp-indentation) | |
137 | (put-text-property | |
138 | (point) | |
139 | (progn | |
140 | (insert | |
141 | gnus-tmp-opening-bracket | |
142 | (format "%4d: %-20s" | |
143 | gnus-tmp-lines | |
144 | (if (> (length gnus-tmp-name) 20) | |
16409b0b | 145 | (truncate-string-to-width gnus-tmp-name 20) |
eec82323 LMI |
146 | gnus-tmp-name)) |
147 | gnus-tmp-closing-bracket) | |
148 | (point)) | |
149 | gnus-mouse-face-prop gnus-mouse-face) | |
16409b0b | 150 | (insert " " gnus-tmp-subject-or-nil "\n"))))) |
eec82323 LMI |
151 | |
152 | (defun gnus-region-active-p () | |
153 | "Say whether the region is active." | |
154 | (and (boundp 'transient-mark-mode) | |
155 | transient-mark-mode | |
156 | (boundp 'mark-active) | |
157 | mark-active)) | |
158 | ||
23f87bed MB |
159 | (defun gnus-mark-active-p () |
160 | "Non-nil means the mark and region are currently active in this buffer." | |
161 | mark-active) ; aliased to region-exists-p in XEmacs. | |
162 | ||
16409b0b GM |
163 | (if (fboundp 'add-minor-mode) |
164 | (defalias 'gnus-add-minor-mode 'add-minor-mode) | |
165 | (defun gnus-add-minor-mode (mode name map &rest rest) | |
6748645f | 166 | (set (make-local-variable mode) t) |
a8151ef7 LMI |
167 | (unless (assq mode minor-mode-alist) |
168 | (push `(,mode ,name) minor-mode-alist)) | |
169 | (unless (assq mode minor-mode-map-alist) | |
170 | (push (cons mode map) | |
171 | minor-mode-map-alist)))) | |
172 | ||
6748645f LMI |
173 | (defun gnus-x-splash () |
174 | "Show a splash screen using a pixmap in the current buffer." | |
175 | (let ((dir (nnheader-find-etc-directory "gnus")) | |
176 | pixmap file height beg i) | |
177 | (save-excursion | |
178 | (switch-to-buffer (gnus-get-buffer-create gnus-group-buffer)) | |
5f180e53 DL |
179 | (let ((buffer-read-only nil) |
180 | width height) | |
6748645f LMI |
181 | (erase-buffer) |
182 | (when (and dir | |
16409b0b GM |
183 | (file-exists-p (setq file |
184 | (expand-file-name "x-splash" dir)))) | |
23f87bed MB |
185 | (let ((coding-system-for-read 'raw-text) |
186 | default-enable-multibyte-characters) | |
187 | (with-temp-buffer | |
188 | (insert-file-contents file) | |
189 | (goto-char (point-min)) | |
190 | (ignore-errors | |
191 | (setq pixmap (read (current-buffer))))))) | |
6748645f | 192 | (when pixmap |
16409b0b | 193 | (make-face 'gnus-splash) |
6748645f LMI |
194 | (setq height (/ (car pixmap) (frame-char-height)) |
195 | width (/ (cadr pixmap) (frame-char-width))) | |
16409b0b | 196 | (set-face-foreground 'gnus-splash "Brown") |
6748645f LMI |
197 | (set-face-stipple 'gnus-splash pixmap) |
198 | (insert-char ?\n (* (/ (window-height) 2 height) height)) | |
199 | (setq i height) | |
200 | (while (> i 0) | |
16409b0b | 201 | (insert-char ?\ (* (/ (window-width) 2 width) width)) |
6748645f | 202 | (setq beg (point)) |
16409b0b | 203 | (insert-char ?\ width) |
6748645f | 204 | (set-text-properties beg (point) '(face gnus-splash)) |
16409b0b | 205 | (insert ?\n) |
6748645f LMI |
206 | (decf i)) |
207 | (goto-char (point-min)) | |
208 | (sit-for 0)))))) | |
209 | ||
23f87bed MB |
210 | ;;; Image functions. |
211 | ||
212 | (defun gnus-image-type-available-p (type) | |
213 | (and (fboundp 'image-type-available-p) | |
214 | (image-type-available-p type))) | |
215 | ||
216 | (defun gnus-create-image (file &optional type data-p &rest props) | |
217 | (let ((face (plist-get props :face))) | |
218 | (when 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))) | |
222 | ||
223 | (defun gnus-put-image (glyph &optional string category) | |
224 | (let ((point (point))) | |
225 | (insert-image glyph (or string " ")) | |
226 | (put-text-property point (point) 'gnus-image-category category) | |
227 | (unless string | |
228 | (put-text-property (1- (point)) (point) | |
229 | 'gnus-image-text-deletable t)) | |
230 | glyph)) | |
231 | ||
232 | (defun gnus-remove-image (image &optional category) | |
233 | (dolist (position (message-text-with-property 'display)) | |
234 | (when (and (equal (get-text-property position 'display) image) | |
235 | (equal (get-text-property position 'gnus-image-category) | |
236 | category)) | |
237 | (put-text-property position (1+ position) 'display nil) | |
238 | (when (get-text-property position 'gnus-image-text-deletable) | |
239 | (delete-region position (1+ position)))))) | |
6748645f | 240 | |
eec82323 LMI |
241 | (provide 'gnus-ems) |
242 | ||
ab5796a9 | 243 | ;;; arch-tag: e7360b45-14b5-4171-aa39-69a44aed3cdb |
eec82323 | 244 | ;;; gnus-ems.el ends here |