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>
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)
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.
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))
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
54 (defun gnus-kill-all-overlays ()
55 "Delete all overlays in the current buffer."
56 (let* ((overlayss (overlay-lists))
57 (buffer-read-only nil)
58 (overlays (delq nil (nconc (car overlayss) (cdr overlayss)))))
60 (delete-overlay (pop overlays)))))
64 (defun gnus-mule-max-width-function (el max-width)
65 `(let* ((val (eval (, el)))
66 (valstr (if (numberp val)
67 (int-to-string val) val)))
68 (if (> (length valstr) ,max-width)
69 (truncate-string-to-width valstr ,max-width)
73 (if (featurep 'xemacs)
75 (defvar gnus-mouse-face-prop 'mouse-face
76 "Property used for highlighting mouse regions.")))
79 (let ((case-fold-search t))
81 ((string-match "windows-nt\\|os/2\\|emx\\|cygwin32"
82 (symbol-name system-type))
83 (setq nnheader-file-name-translation-alist
84 (append nnheader-file-name-translation-alist
85 (mapcar (lambda (c) (cons c ?_))
86 '(?: ?* ?\" ?< ?> ??))
89 (defvar gnus-tmp-unread)
90 (defvar gnus-tmp-replied)
91 (defvar gnus-tmp-score-char)
92 (defvar gnus-tmp-indentation)
93 (defvar gnus-tmp-opening-bracket)
94 (defvar gnus-tmp-lines)
95 (defvar gnus-tmp-name)
96 (defvar gnus-tmp-closing-bracket)
97 (defvar gnus-tmp-subject-or-nil)
98 (defvar gnus-check-before-posting)
100 (defun gnus-ems-redefine ()
103 (gnus-xmas-redefine))
106 ;; Mule and new Emacs definitions
108 ;; [Note] Now there are three kinds of mule implementations,
109 ;; original MULE, XEmacs/mule and Emacs 20+ including
110 ;; MULE features. Unfortunately these API are different. In
111 ;; particular, Emacs (including original MULE) and XEmacs are
112 ;; quite different. Howvere, this version of Gnus doesn't support
113 ;; anything other than XEmacs 20+ and Emacs 20.3+.
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.
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.
124 (defvar gnus-summary-display-table nil
125 "Display table used in summary mode buffers.")
126 (defalias 'gnus-max-width-function 'gnus-mule-max-width-function)
128 (when (boundp 'gnus-check-before-posting)
129 (setq gnus-check-before-posting
131 (delq 'control-chars gnus-check-before-posting))))
133 (defun gnus-summary-line-format-spec ()
134 (insert gnus-tmp-unread gnus-tmp-replied
135 gnus-tmp-score-char gnus-tmp-indentation)
140 gnus-tmp-opening-bracket
143 (if (> (length gnus-tmp-name) 20)
144 (truncate-string-to-width gnus-tmp-name 20)
146 gnus-tmp-closing-bracket)
148 gnus-mouse-face-prop gnus-mouse-face)
149 (insert " " gnus-tmp-subject-or-nil "\n")))))
151 (defun gnus-region-active-p ()
152 "Say whether the region is active."
153 (and (boundp 'transient-mark-mode)
155 (boundp 'mark-active)
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)
161 (set (make-local-variable mode) t)
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))))
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)
173 (switch-to-buffer (gnus-get-buffer-create gnus-group-buffer))
174 (let ((buffer-read-only nil)
178 (file-exists-p (setq file
179 (expand-file-name "x-splash" dir))))
181 (insert-file-contents file)
182 (goto-char (point-min))
184 (setq pixmap (read (current-buffer))))))
186 (make-face 'gnus-splash)
187 (setq height (/ (car pixmap) (frame-char-height))
188 width (/ (cadr pixmap) (frame-char-width)))
189 (set-face-foreground 'gnus-splash "Brown")
190 (set-face-stipple 'gnus-splash pixmap)
191 (insert-char ?\n (* (/ (window-height) 2 height) height))
194 (insert-char ?\ (* (/ (window-width) 2 width) width))
196 (insert-char ?\ width)
197 (set-text-properties beg (point) '(face gnus-splash))
200 (goto-char (point-min))
203 (defvar gnus-article-xface-ring-internal nil
204 "Cache for face data.")
206 ;; Worth customizing?
207 (defvar gnus-article-xface-ring-size 6
208 "Length of the ring used for `gnus-article-xface-ring-internal'.")
210 (defvar gnus-article-compface-xbm
212 (eq 0 (string-match "#define"
213 (shell-command-to-string "uncompface -X")))
215 "Non-nil means the compface program supports the -X option.
216 That produces XBM output.")
218 (defun gnus-article-display-xface (beg end)
219 "Display an XFace header from between BEG and END in the current article.
220 Requires support for images in your Emacs and the external programs
221 `uncompface', and `icontopbm'. On a GNU/Linux system these
222 might be in packages with names like `compface' or `faces-xface' and
223 `netpbm' or `libgr-progs', for instance. See also
224 `gnus-article-compface-xbm'.
226 This function is for Emacs 21+. See `gnus-xmas-article-display-xface'
228 ;; It might be worth converting uncompface's output in Lisp.
230 (when (if (fboundp 'display-graphic-p)
232 (unless gnus-article-xface-ring-internal ; Only load ring when needed.
233 (setq gnus-article-xface-ring-internal
234 (make-ring gnus-article-xface-ring-size)))
236 (let* ((cur (current-buffer))
237 (data (buffer-substring beg end))
238 (image (cdr-safe (assoc data (ring-elements
239 gnus-article-xface-ring-internal))))
240 default-enable-multibyte-characters)
244 (and (eq 0 (apply #'call-process-region (point-min) (point-max)
247 (if gnus-article-compface-xbm
249 (if gnus-article-compface-xbm
251 (goto-char (point-min))
252 (progn (insert "/* Width=48, Height=48 */\n") t)
253 (eq 0 (call-process-region (point-min) (point-max)
256 ;; Miles Bader says that faces don't look right as
258 (if (eq 'dark (cdr-safe (assq 'background-mode
259 (frame-parameters))))
260 (setq image (create-image (buffer-string)
261 (if gnus-article-compface-xbm
267 :background "white"))
268 (setq image (create-image (buffer-string)
269 (if gnus-article-compface-xbm
274 (ring-insert gnus-article-xface-ring-internal (cons data image)))
276 (goto-char (point-min))
277 (re-search-forward "^From:" nil 'move)
278 (insert-image image))))))
282 ;;; gnus-ems.el ends here