(Finteractive_form): Doc fix.
[emacs.git] / lisp / gnus / gnus-ems.el
blob10fdb2dc7be5a307f6d84ff99f925b3fadef532e
1 ;;; gnus-ems.el --- functions for making Gnus work under different Emacsen
2 ;; Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000
3 ;; Free Software Foundation, Inc.
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
6 ;; Keywords: news
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)
13 ;; any later version.
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.
25 ;;; Commentary:
27 ;;; Code:
29 (eval-when-compile
30 (require 'cl)
31 (require 'ring))
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 (or (featurep 'xemacs)
41 (< emacs-major-version 20))
42 '("--**-" . "-----")
43 '("**" "--")))
45 (eval-and-compile
46 (autoload 'gnus-xmas-define "gnus-xmas")
47 (autoload 'gnus-xmas-redefine "gnus-xmas")
48 (autoload 'appt-select-lowest-window "appt"))
50 (if (featurep 'xemacs)
51 (autoload 'gnus-smiley-display "smiley")
52 (autoload 'gnus-smiley-display "smiley-ems") ; override XEmacs version
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)))))
63 ;;; Mule functions.
65 (defun gnus-mule-max-width-function (el max-width)
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)))
73 (eval-and-compile
74 (if (featurep 'xemacs)
75 (gnus-xmas-define)
76 (defvar gnus-mouse-face-prop 'mouse-face
77 "Property used for highlighting mouse regions.")))
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)
89 (defun gnus-ems-redefine ()
90 (cond
91 ((featurep 'xemacs)
92 (gnus-xmas-redefine))
94 ((featurep 'mule)
95 ;; Mule and new Emacs definitions
97 ;; [Note] Now there are three kinds of mule implementations,
98 ;; original MULE, XEmacs/mule and Emacs 20+ including
99 ;; MULE features. Unfortunately these API are different. In
100 ;; particular, Emacs (including original MULE) and XEmacs are
101 ;; quite different. However, this version of Gnus doesn't support
102 ;; anything other than XEmacs 20+ and Emacs 20.3+.
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.
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.
113 (defvar gnus-summary-display-table nil
114 "Display table used in summary mode buffers.")
115 (defalias 'gnus-max-width-function 'gnus-mule-max-width-function)
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))))
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)
133 (truncate-string-to-width gnus-tmp-name 20)
134 gnus-tmp-name))
135 gnus-tmp-closing-bracket)
136 (point))
137 gnus-mouse-face-prop gnus-mouse-face)
138 (insert " " gnus-tmp-subject-or-nil "\n")))))
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))
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)
150 (set (make-local-variable mode) t)
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))))
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))
163 (let ((buffer-read-only nil)
164 width height)
165 (erase-buffer)
166 (when (and dir
167 (file-exists-p (setq file
168 (expand-file-name "x-splash" dir))))
169 (with-temp-buffer
170 (insert-file-contents file)
171 (goto-char (point-min))
172 (ignore-errors
173 (setq pixmap (read (current-buffer))))))
174 (when pixmap
175 (make-face 'gnus-splash)
176 (setq height (/ (car pixmap) (frame-char-height))
177 width (/ (cadr pixmap) (frame-char-width)))
178 (set-face-foreground 'gnus-splash "Brown")
179 (set-face-stipple 'gnus-splash pixmap)
180 (insert-char ?\n (* (/ (window-height) 2 height) height))
181 (setq i height)
182 (while (> i 0)
183 (insert-char ?\ (* (/ (window-width) 2 width) width))
184 (setq beg (point))
185 (insert-char ?\ width)
186 (set-text-properties beg (point) '(face gnus-splash))
187 (insert ?\n)
188 (decf i))
189 (goto-char (point-min))
190 (sit-for 0))))))
192 (defvar gnus-article-xface-ring-internal nil
193 "Cache for face data.")
195 ;; Worth customizing?
196 (defvar gnus-article-xface-ring-size 6
197 "Length of the ring used for `gnus-article-xface-ring-internal'.")
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.")
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
207 `uncompface', and `icontopbm'. On a GNU/Linux system these
208 might be in packages with names like `compface' or `faces-xface' and
209 `netpbm' or `libgr-progs', for instance. See also
210 `gnus-article-compface-xbm'.
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.
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)
227 (unless image
228 (with-temp-buffer
229 (insert data)
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
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))))
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))))
246 (setq image (create-image (buffer-string)
247 (if gnus-article-compface-xbm
248 'xbm
249 'pbm)
251 :ascent 'center
252 :foreground "black"
253 :background "white"))
254 (setq image (create-image (buffer-string)
255 (if gnus-article-compface-xbm
256 'xbm
257 'pbm)
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)
264 (while (get-text-property (point) 'display)
265 (goto-char (next-single-property-change (point) 'display)))
266 (insert-image image))))))
268 (provide 'gnus-ems)
270 ;;; arch-tag: e7360b45-14b5-4171-aa39-69a44aed3cdb
271 ;;; gnus-ems.el ends here