Commit | Line | Data |
---|---|---|
eec82323 | 1 | ;;; gnus-ems.el --- functions for making Gnus work under different Emacsen |
16409b0b GM |
2 | ;; Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000 |
3 | ;; Free Software Foundation, Inc. | |
eec82323 | 4 | |
6748645f | 5 | ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org> |
eec82323 LMI |
6 | ;; Keywords: news |
7 | ||
8 | ;; This file is part of GNU Emacs. | |
9 | ||
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) | |
13 | ;; any later version. | |
14 | ||
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. | |
19 | ||
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. | |
24 | ||
25 | ;;; Commentary: | |
26 | ||
27 | ;;; Code: | |
28 | ||
4bcf2f05 DL |
29 | (eval-when-compile |
30 | (require 'cl) | |
31 | (require 'ring)) | |
eec82323 LMI |
32 | |
33 | ;;; Function aliases later to be redefined for XEmacs usage. | |
34 | ||
eec82323 | 35 | (defvar gnus-mouse-2 [mouse-2]) |
16409b0b | 36 | (defvar gnus-down-mouse-3 [down-mouse-3]) |
eec82323 | 37 | (defvar gnus-down-mouse-2 [down-mouse-2]) |
16409b0b | 38 | (defvar gnus-widget-button-keymap nil) |
a8151ef7 | 39 | (defvar gnus-mode-line-modified |
06c43cdf | 40 | (if (or (featurep 'xemacs) |
a8151ef7 LMI |
41 | (< emacs-major-version 20)) |
42 | '("--**-" . "-----") | |
43 | '("**" "--"))) | |
eec82323 LMI |
44 | |
45 | (eval-and-compile | |
46 | (autoload 'gnus-xmas-define "gnus-xmas") | |
47 | (autoload 'gnus-xmas-redefine "gnus-xmas") | |
a8151ef7 | 48 | (autoload 'appt-select-lowest-window "appt")) |
eec82323 | 49 | |
06c43cdf DL |
50 | (if (featurep 'xemacs) |
51 | (autoload 'gnus-smiley-display "smiley") | |
52 | (autoload 'gnus-smiley-display "smiley-ems") ; override XEmacs version | |
53 | ) | |
54 | ||
55 | (defun gnus-kill-all-overlays () | |
56 | "Delete all overlays in the current buffer." | |
57 | (let* ((overlayss (overlay-lists)) | |
58 | (buffer-read-only nil) | |
59 | (overlays (delq nil (nconc (car overlayss) (cdr overlayss))))) | |
60 | (while overlays | |
61 | (delete-overlay (pop overlays))))) | |
2d2f7f3e | 62 | |
eec82323 LMI |
63 | ;;; Mule functions. |
64 | ||
eec82323 | 65 | (defun gnus-mule-max-width-function (el max-width) |
16409b0b GM |
66 | `(let* ((val (eval (, el))) |
67 | (valstr (if (numberp val) | |
68 | (int-to-string val) val))) | |
69 | (if (> (length valstr) ,max-width) | |
70 | (truncate-string-to-width valstr ,max-width) | |
71 | valstr))) | |
6748645f | 72 | |
eec82323 | 73 | (eval-and-compile |
06c43cdf | 74 | (if (featurep 'xemacs) |
16409b0b | 75 | (gnus-xmas-define) |
eec82323 | 76 | (defvar gnus-mouse-face-prop 'mouse-face |
16409b0b | 77 | "Property used for highlighting mouse regions."))) |
eec82323 | 78 | |
eec82323 LMI |
79 | (defvar gnus-tmp-unread) |
80 | (defvar gnus-tmp-replied) | |
81 | (defvar gnus-tmp-score-char) | |
82 | (defvar gnus-tmp-indentation) | |
83 | (defvar gnus-tmp-opening-bracket) | |
84 | (defvar gnus-tmp-lines) | |
85 | (defvar gnus-tmp-name) | |
86 | (defvar gnus-tmp-closing-bracket) | |
87 | (defvar gnus-tmp-subject-or-nil) | |
88 | ||
89 | (defun gnus-ems-redefine () | |
90 | (cond | |
4ddf0e64 | 91 | ((featurep 'xemacs) |
eec82323 LMI |
92 | (gnus-xmas-redefine)) |
93 | ||
94 | ((featurep 'mule) | |
95 | ;; Mule and new Emacs definitions | |
96 | ||
97 | ;; [Note] Now there are three kinds of mule implementations, | |
16409b0b GM |
98 | ;; original MULE, XEmacs/mule and Emacs 20+ including |
99 | ;; MULE features. Unfortunately these API are different. In | |
eec82323 | 100 | ;; particular, Emacs (including original MULE) and XEmacs are |
feee6240 | 101 | ;; quite different. However, this version of Gnus doesn't support |
16409b0b GM |
102 | ;; anything other than XEmacs 20+ and Emacs 20.3+. |
103 | ||
eec82323 LMI |
104 | ;; Predicates to check are following: |
105 | ;; (boundp 'MULE) is t only if MULE (original; anything older than | |
106 | ;; Mule 2.3) is running. | |
107 | ;; (featurep 'mule) is t when every mule variants are running. | |
108 | ||
16409b0b GM |
109 | ;; It is possible to detect XEmacs/mule by (featurep 'mule) and |
110 | ;; checking `emacs-version'. In this case, the implementation for | |
111 | ;; XEmacs/mule may be shareable between XEmacs and XEmacs/mule. | |
eec82323 LMI |
112 | |
113 | (defvar gnus-summary-display-table nil | |
114 | "Display table used in summary mode buffers.") | |
16409b0b | 115 | (defalias 'gnus-max-width-function 'gnus-mule-max-width-function) |
eec82323 LMI |
116 | |
117 | (when (boundp 'gnus-check-before-posting) | |
118 | (setq gnus-check-before-posting | |
119 | (delq 'long-lines | |
120 | (delq 'control-chars gnus-check-before-posting)))) | |
121 | ||
122 | (defun gnus-summary-line-format-spec () | |
123 | (insert gnus-tmp-unread gnus-tmp-replied | |
124 | gnus-tmp-score-char gnus-tmp-indentation) | |
125 | (put-text-property | |
126 | (point) | |
127 | (progn | |
128 | (insert | |
129 | gnus-tmp-opening-bracket | |
130 | (format "%4d: %-20s" | |
131 | gnus-tmp-lines | |
132 | (if (> (length gnus-tmp-name) 20) | |
16409b0b | 133 | (truncate-string-to-width gnus-tmp-name 20) |
eec82323 LMI |
134 | gnus-tmp-name)) |
135 | gnus-tmp-closing-bracket) | |
136 | (point)) | |
137 | gnus-mouse-face-prop gnus-mouse-face) | |
16409b0b | 138 | (insert " " gnus-tmp-subject-or-nil "\n"))))) |
eec82323 LMI |
139 | |
140 | (defun gnus-region-active-p () | |
141 | "Say whether the region is active." | |
142 | (and (boundp 'transient-mark-mode) | |
143 | transient-mark-mode | |
144 | (boundp 'mark-active) | |
145 | mark-active)) | |
146 | ||
16409b0b GM |
147 | (if (fboundp 'add-minor-mode) |
148 | (defalias 'gnus-add-minor-mode 'add-minor-mode) | |
149 | (defun gnus-add-minor-mode (mode name map &rest rest) | |
6748645f | 150 | (set (make-local-variable mode) t) |
a8151ef7 LMI |
151 | (unless (assq mode minor-mode-alist) |
152 | (push `(,mode ,name) minor-mode-alist)) | |
153 | (unless (assq mode minor-mode-map-alist) | |
154 | (push (cons mode map) | |
155 | minor-mode-map-alist)))) | |
156 | ||
6748645f LMI |
157 | (defun gnus-x-splash () |
158 | "Show a splash screen using a pixmap in the current buffer." | |
159 | (let ((dir (nnheader-find-etc-directory "gnus")) | |
160 | pixmap file height beg i) | |
161 | (save-excursion | |
162 | (switch-to-buffer (gnus-get-buffer-create gnus-group-buffer)) | |
5f180e53 DL |
163 | (let ((buffer-read-only nil) |
164 | width height) | |
6748645f LMI |
165 | (erase-buffer) |
166 | (when (and dir | |
16409b0b GM |
167 | (file-exists-p (setq file |
168 | (expand-file-name "x-splash" dir)))) | |
169 | (with-temp-buffer | |
6748645f LMI |
170 | (insert-file-contents file) |
171 | (goto-char (point-min)) | |
172 | (ignore-errors | |
173 | (setq pixmap (read (current-buffer)))))) | |
174 | (when pixmap | |
16409b0b | 175 | (make-face 'gnus-splash) |
6748645f LMI |
176 | (setq height (/ (car pixmap) (frame-char-height)) |
177 | width (/ (cadr pixmap) (frame-char-width))) | |
16409b0b | 178 | (set-face-foreground 'gnus-splash "Brown") |
6748645f LMI |
179 | (set-face-stipple 'gnus-splash pixmap) |
180 | (insert-char ?\n (* (/ (window-height) 2 height) height)) | |
181 | (setq i height) | |
182 | (while (> i 0) | |
16409b0b | 183 | (insert-char ?\ (* (/ (window-width) 2 width) width)) |
6748645f | 184 | (setq beg (point)) |
16409b0b | 185 | (insert-char ?\ width) |
6748645f | 186 | (set-text-properties beg (point) '(face gnus-splash)) |
16409b0b | 187 | (insert ?\n) |
6748645f LMI |
188 | (decf i)) |
189 | (goto-char (point-min)) | |
190 | (sit-for 0)))))) | |
191 | ||
16409b0b GM |
192 | (defvar gnus-article-xface-ring-internal nil |
193 | "Cache for face data.") | |
194 | ||
195 | ;; Worth customizing? | |
196 | (defvar gnus-article-xface-ring-size 6 | |
197 | "Length of the ring used for `gnus-article-xface-ring-internal'.") | |
198 | ||
5f180e53 DL |
199 | (defvar gnus-article-compface-xbm |
200 | (eq 0 (string-match "#define" (shell-command-to-string "uncompface -X"))) | |
201 | "Non-nil means the compface program supports the -X option. | |
202 | That produces XBM output.") | |
203 | ||
16409b0b GM |
204 | (defun gnus-article-display-xface (beg end) |
205 | "Display an XFace header from between BEG and END in the current article. | |
206 | Requires support for images in your Emacs and the external programs | |
7044c058 | 207 | `uncompface', and `icontopbm'. On a GNU/Linux system these |
16409b0b | 208 | might be in packages with names like `compface' or `faces-xface' and |
5f180e53 DL |
209 | `netpbm' or `libgr-progs', for instance. See also |
210 | `gnus-article-compface-xbm'. | |
16409b0b GM |
211 | |
212 | This function is for Emacs 21+. See `gnus-xmas-article-display-xface' | |
213 | for XEmacs." | |
214 | ;; It might be worth converting uncompface's output in Lisp. | |
215 | ||
e7d235f7 DL |
216 | (when (if (fboundp 'display-graphic-p) |
217 | (display-graphic-p)) | |
218 | (unless gnus-article-xface-ring-internal ; Only load ring when needed. | |
219 | (setq gnus-article-xface-ring-internal | |
220 | (make-ring gnus-article-xface-ring-size))) | |
221 | (save-excursion | |
222 | (let* ((cur (current-buffer)) | |
223 | (data (buffer-substring beg end)) | |
224 | (image (cdr-safe (assoc data (ring-elements | |
225 | gnus-article-xface-ring-internal)))) | |
226 | default-enable-multibyte-characters) | |
16409b0b | 227 | (unless image |
e7d235f7 DL |
228 | (with-temp-buffer |
229 | (insert data) | |
5f180e53 DL |
230 | (and (eq 0 (apply #'call-process-region (point-min) (point-max) |
231 | "uncompface" | |
232 | 'delete '(t nil) nil | |
233 | (if gnus-article-compface-xbm | |
234 | '("-X")))) | |
235 | (if gnus-article-compface-xbm | |
236 | t | |
237 | (goto-char (point-min)) | |
238 | (progn (insert "/* Width=48, Height=48 */\n") t) | |
239 | (eq 0 (call-process-region (point-min) (point-max) | |
240 | "icontopbm" | |
241 | 'delete '(t nil)))) | |
e7d235f7 DL |
242 | ;; Miles Bader says that faces don't look right as |
243 | ;; light on dark. | |
244 | (if (eq 'dark (cdr-safe (assq 'background-mode | |
245 | (frame-parameters)))) | |
5f180e53 DL |
246 | (setq image (create-image (buffer-string) |
247 | (if gnus-article-compface-xbm | |
248 | 'xbm | |
249 | 'pbm) | |
250 | t | |
e7d235f7 DL |
251 | :ascent 'center |
252 | :foreground "black" | |
253 | :background "white")) | |
5f180e53 DL |
254 | (setq image (create-image (buffer-string) |
255 | (if gnus-article-compface-xbm | |
256 | 'xbm | |
257 | 'pbm) | |
258 | t | |
e7d235f7 DL |
259 | :ascent 'center))))) |
260 | (ring-insert gnus-article-xface-ring-internal (cons data image))) | |
261 | (when image | |
262 | (goto-char (point-min)) | |
263 | (re-search-forward "^From:" nil 'move) | |
bd2bc09f GM |
264 | (while (get-text-property (point) 'display) |
265 | (goto-char (next-single-property-change (point) 'display))) | |
e7d235f7 | 266 | (insert-image image)))))) |
6748645f | 267 | |
eec82323 LMI |
268 | (provide 'gnus-ems) |
269 | ||
eec82323 | 270 | ;;; gnus-ems.el ends here |