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 | (eval-and-compile |
80 | (let ((case-fold-search t)) | |
81 | (cond | |
16409b0b | 82 | ((string-match "windows-nt\\|os/2\\|emx\\|cygwin32" |
6748645f | 83 | (symbol-name system-type)) |
eec82323 LMI |
84 | (setq nnheader-file-name-translation-alist |
85 | (append nnheader-file-name-translation-alist | |
16409b0b GM |
86 | (mapcar (lambda (c) (cons c ?_)) |
87 | '(?: ?* ?\" ?< ?> ??)) | |
88 | '((?+ . ?-)))))))) | |
eec82323 LMI |
89 | |
90 | (defvar gnus-tmp-unread) | |
91 | (defvar gnus-tmp-replied) | |
92 | (defvar gnus-tmp-score-char) | |
93 | (defvar gnus-tmp-indentation) | |
94 | (defvar gnus-tmp-opening-bracket) | |
95 | (defvar gnus-tmp-lines) | |
96 | (defvar gnus-tmp-name) | |
97 | (defvar gnus-tmp-closing-bracket) | |
98 | (defvar gnus-tmp-subject-or-nil) | |
99 | ||
100 | (defun gnus-ems-redefine () | |
101 | (cond | |
4ddf0e64 | 102 | ((featurep 'xemacs) |
eec82323 LMI |
103 | (gnus-xmas-redefine)) |
104 | ||
105 | ((featurep 'mule) | |
106 | ;; Mule and new Emacs definitions | |
107 | ||
108 | ;; [Note] Now there are three kinds of mule implementations, | |
16409b0b GM |
109 | ;; original MULE, XEmacs/mule and Emacs 20+ including |
110 | ;; MULE features. Unfortunately these API are different. In | |
eec82323 | 111 | ;; particular, Emacs (including original MULE) and XEmacs are |
16409b0b GM |
112 | ;; quite different. Howvere, this version of Gnus doesn't support |
113 | ;; anything other than XEmacs 20+ and Emacs 20.3+. | |
114 | ||
eec82323 LMI |
115 | ;; Predicates to check are following: |
116 | ;; (boundp 'MULE) is t only if MULE (original; anything older than | |
117 | ;; Mule 2.3) is running. | |
118 | ;; (featurep 'mule) is t when every mule variants are running. | |
119 | ||
16409b0b GM |
120 | ;; It is possible to detect XEmacs/mule by (featurep 'mule) and |
121 | ;; checking `emacs-version'. In this case, the implementation for | |
122 | ;; XEmacs/mule may be shareable between XEmacs and XEmacs/mule. | |
eec82323 LMI |
123 | |
124 | (defvar gnus-summary-display-table nil | |
125 | "Display table used in summary mode buffers.") | |
16409b0b | 126 | (defalias 'gnus-max-width-function 'gnus-mule-max-width-function) |
eec82323 LMI |
127 | |
128 | (when (boundp 'gnus-check-before-posting) | |
129 | (setq gnus-check-before-posting | |
130 | (delq 'long-lines | |
131 | (delq 'control-chars gnus-check-before-posting)))) | |
132 | ||
133 | (defun gnus-summary-line-format-spec () | |
134 | (insert gnus-tmp-unread gnus-tmp-replied | |
135 | gnus-tmp-score-char gnus-tmp-indentation) | |
136 | (put-text-property | |
137 | (point) | |
138 | (progn | |
139 | (insert | |
140 | gnus-tmp-opening-bracket | |
141 | (format "%4d: %-20s" | |
142 | gnus-tmp-lines | |
143 | (if (> (length gnus-tmp-name) 20) | |
16409b0b | 144 | (truncate-string-to-width gnus-tmp-name 20) |
eec82323 LMI |
145 | gnus-tmp-name)) |
146 | gnus-tmp-closing-bracket) | |
147 | (point)) | |
148 | gnus-mouse-face-prop gnus-mouse-face) | |
16409b0b | 149 | (insert " " gnus-tmp-subject-or-nil "\n"))))) |
eec82323 LMI |
150 | |
151 | (defun gnus-region-active-p () | |
152 | "Say whether the region is active." | |
153 | (and (boundp 'transient-mark-mode) | |
154 | transient-mark-mode | |
155 | (boundp 'mark-active) | |
156 | mark-active)) | |
157 | ||
16409b0b GM |
158 | (if (fboundp 'add-minor-mode) |
159 | (defalias 'gnus-add-minor-mode 'add-minor-mode) | |
160 | (defun gnus-add-minor-mode (mode name map &rest rest) | |
6748645f | 161 | (set (make-local-variable mode) t) |
a8151ef7 LMI |
162 | (unless (assq mode minor-mode-alist) |
163 | (push `(,mode ,name) minor-mode-alist)) | |
164 | (unless (assq mode minor-mode-map-alist) | |
165 | (push (cons mode map) | |
166 | minor-mode-map-alist)))) | |
167 | ||
6748645f LMI |
168 | (defun gnus-x-splash () |
169 | "Show a splash screen using a pixmap in the current buffer." | |
170 | (let ((dir (nnheader-find-etc-directory "gnus")) | |
171 | pixmap file height beg i) | |
172 | (save-excursion | |
173 | (switch-to-buffer (gnus-get-buffer-create gnus-group-buffer)) | |
5f180e53 DL |
174 | (let ((buffer-read-only nil) |
175 | width height) | |
6748645f LMI |
176 | (erase-buffer) |
177 | (when (and dir | |
16409b0b GM |
178 | (file-exists-p (setq file |
179 | (expand-file-name "x-splash" dir)))) | |
180 | (with-temp-buffer | |
6748645f LMI |
181 | (insert-file-contents file) |
182 | (goto-char (point-min)) | |
183 | (ignore-errors | |
184 | (setq pixmap (read (current-buffer)))))) | |
185 | (when pixmap | |
16409b0b | 186 | (make-face 'gnus-splash) |
6748645f LMI |
187 | (setq height (/ (car pixmap) (frame-char-height)) |
188 | width (/ (cadr pixmap) (frame-char-width))) | |
16409b0b | 189 | (set-face-foreground 'gnus-splash "Brown") |
6748645f LMI |
190 | (set-face-stipple 'gnus-splash pixmap) |
191 | (insert-char ?\n (* (/ (window-height) 2 height) height)) | |
192 | (setq i height) | |
193 | (while (> i 0) | |
16409b0b | 194 | (insert-char ?\ (* (/ (window-width) 2 width) width)) |
6748645f | 195 | (setq beg (point)) |
16409b0b | 196 | (insert-char ?\ width) |
6748645f | 197 | (set-text-properties beg (point) '(face gnus-splash)) |
16409b0b | 198 | (insert ?\n) |
6748645f LMI |
199 | (decf i)) |
200 | (goto-char (point-min)) | |
201 | (sit-for 0)))))) | |
202 | ||
16409b0b GM |
203 | (defvar gnus-article-xface-ring-internal nil |
204 | "Cache for face data.") | |
205 | ||
206 | ;; Worth customizing? | |
207 | (defvar gnus-article-xface-ring-size 6 | |
208 | "Length of the ring used for `gnus-article-xface-ring-internal'.") | |
209 | ||
5f180e53 DL |
210 | (defvar gnus-article-compface-xbm |
211 | (eq 0 (string-match "#define" (shell-command-to-string "uncompface -X"))) | |
212 | "Non-nil means the compface program supports the -X option. | |
213 | That produces XBM output.") | |
214 | ||
16409b0b GM |
215 | (defun gnus-article-display-xface (beg end) |
216 | "Display an XFace header from between BEG and END in the current article. | |
217 | Requires support for images in your Emacs and the external programs | |
7044c058 | 218 | `uncompface', and `icontopbm'. On a GNU/Linux system these |
16409b0b | 219 | might be in packages with names like `compface' or `faces-xface' and |
5f180e53 DL |
220 | `netpbm' or `libgr-progs', for instance. See also |
221 | `gnus-article-compface-xbm'. | |
16409b0b GM |
222 | |
223 | This function is for Emacs 21+. See `gnus-xmas-article-display-xface' | |
224 | for XEmacs." | |
225 | ;; It might be worth converting uncompface's output in Lisp. | |
226 | ||
e7d235f7 DL |
227 | (when (if (fboundp 'display-graphic-p) |
228 | (display-graphic-p)) | |
229 | (unless gnus-article-xface-ring-internal ; Only load ring when needed. | |
230 | (setq gnus-article-xface-ring-internal | |
231 | (make-ring gnus-article-xface-ring-size))) | |
232 | (save-excursion | |
233 | (let* ((cur (current-buffer)) | |
234 | (data (buffer-substring beg end)) | |
235 | (image (cdr-safe (assoc data (ring-elements | |
236 | gnus-article-xface-ring-internal)))) | |
237 | default-enable-multibyte-characters) | |
16409b0b | 238 | (unless image |
e7d235f7 DL |
239 | (with-temp-buffer |
240 | (insert data) | |
5f180e53 DL |
241 | (and (eq 0 (apply #'call-process-region (point-min) (point-max) |
242 | "uncompface" | |
243 | 'delete '(t nil) nil | |
244 | (if gnus-article-compface-xbm | |
245 | '("-X")))) | |
246 | (if gnus-article-compface-xbm | |
247 | t | |
248 | (goto-char (point-min)) | |
249 | (progn (insert "/* Width=48, Height=48 */\n") t) | |
250 | (eq 0 (call-process-region (point-min) (point-max) | |
251 | "icontopbm" | |
252 | 'delete '(t nil)))) | |
e7d235f7 DL |
253 | ;; Miles Bader says that faces don't look right as |
254 | ;; light on dark. | |
255 | (if (eq 'dark (cdr-safe (assq 'background-mode | |
256 | (frame-parameters)))) | |
5f180e53 DL |
257 | (setq image (create-image (buffer-string) |
258 | (if gnus-article-compface-xbm | |
259 | 'xbm | |
260 | 'pbm) | |
261 | t | |
e7d235f7 DL |
262 | :ascent 'center |
263 | :foreground "black" | |
264 | :background "white")) | |
5f180e53 DL |
265 | (setq image (create-image (buffer-string) |
266 | (if gnus-article-compface-xbm | |
267 | 'xbm | |
268 | 'pbm) | |
269 | t | |
e7d235f7 DL |
270 | :ascent 'center))))) |
271 | (ring-insert gnus-article-xface-ring-internal (cons data image))) | |
272 | (when image | |
273 | (goto-char (point-min)) | |
274 | (re-search-forward "^From:" nil 'move) | |
275 | (insert-image image)))))) | |
6748645f | 276 | |
eec82323 LMI |
277 | (provide 'gnus-ems) |
278 | ||
eec82323 | 279 | ;;; gnus-ems.el ends here |