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.
29 (eval-when-compile (require 'cl))
31 ;;; Function aliases later to be redefined for XEmacs usage.
34 (defvar gnus-xemacs (featurep 'xemacs)
35 "Non-nil if running under XEmacs."))
37 (defvar gnus-mouse-2 [mouse-2])
38 (defvar gnus-down-mouse-3 [down-mouse-3])
39 (defvar gnus-down-mouse-2 [down-mouse-2])
40 (defvar gnus-widget-button-keymap nil)
41 (defvar gnus-mode-line-modified
43 (< emacs-major-version 20))
48 (autoload 'gnus-xmas-define "gnus-xmas")
49 (autoload 'gnus-xmas-redefine "gnus-xmas")
50 (autoload 'appt-select-lowest-window "appt"))
54 (defun gnus-mule-max-width-function (el max-width)
55 `(let* ((val (eval (, el)))
56 (valstr (if (numberp val)
57 (int-to-string val) val)))
58 (if (> (length valstr) ,max-width)
59 (truncate-string-to-width valstr ,max-width)
65 (defvar gnus-mouse-face-prop 'mouse-face
66 "Property used for highlighting mouse regions.")))
71 (let ((funcs '(mouse-set-point set-face-foreground
72 set-face-background x-popup-menu)))
74 (unless (fboundp (car funcs))
75 (defalias (car funcs) 'ignore))
76 (setq funcs (cdr funcs)))))))
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)
99 (defun gnus-ems-redefine ()
102 (gnus-xmas-redefine))
105 ;; Mule and new Emacs definitions
107 ;; [Note] Now there are three kinds of mule implementations,
108 ;; original MULE, XEmacs/mule and Emacs 20+ including
109 ;; MULE features. Unfortunately these API are different. In
110 ;; particular, Emacs (including original MULE) and XEmacs are
111 ;; quite different. Howvere, this version of Gnus doesn't support
112 ;; anything other than XEmacs 20+ and Emacs 20.3+.
114 ;; Predicates to check are following:
115 ;; (boundp 'MULE) is t only if MULE (original; anything older than
116 ;; Mule 2.3) is running.
117 ;; (featurep 'mule) is t when every mule variants are running.
119 ;; It is possible to detect XEmacs/mule by (featurep 'mule) and
120 ;; checking `emacs-version'. In this case, the implementation for
121 ;; XEmacs/mule may be shareable between XEmacs and XEmacs/mule.
123 (defvar gnus-summary-display-table nil
124 "Display table used in summary mode buffers.")
125 (defalias 'gnus-max-width-function 'gnus-mule-max-width-function)
127 (when (boundp 'gnus-check-before-posting)
128 (setq gnus-check-before-posting
130 (delq 'control-chars gnus-check-before-posting))))
132 (defun gnus-summary-line-format-spec ()
133 (insert gnus-tmp-unread gnus-tmp-replied
134 gnus-tmp-score-char gnus-tmp-indentation)
139 gnus-tmp-opening-bracket
142 (if (> (length gnus-tmp-name) 20)
143 (truncate-string-to-width gnus-tmp-name 20)
145 gnus-tmp-closing-bracket)
147 gnus-mouse-face-prop gnus-mouse-face)
148 (insert " " gnus-tmp-subject-or-nil "\n")))))
150 (defun gnus-region-active-p ()
151 "Say whether the region is active."
152 (and (boundp 'transient-mark-mode)
154 (boundp 'mark-active)
157 (if (fboundp 'add-minor-mode)
158 (defalias 'gnus-add-minor-mode 'add-minor-mode)
159 (defun gnus-add-minor-mode (mode name map &rest rest)
160 (set (make-local-variable mode) t)
161 (unless (assq mode minor-mode-alist)
162 (push `(,mode ,name) minor-mode-alist))
163 (unless (assq mode minor-mode-map-alist)
164 (push (cons mode map)
165 minor-mode-map-alist))))
167 (defun gnus-x-splash ()
168 "Show a splash screen using a pixmap in the current buffer."
169 (let ((dir (nnheader-find-etc-directory "gnus"))
170 pixmap file height beg i)
172 (switch-to-buffer (gnus-get-buffer-create gnus-group-buffer))
173 (let ((buffer-read-only nil))
176 (file-exists-p (setq file
177 (expand-file-name "x-splash" dir))))
179 (insert-file-contents file)
180 (goto-char (point-min))
182 (setq pixmap (read (current-buffer))))))
184 (make-face 'gnus-splash)
185 (setq height (/ (car pixmap) (frame-char-height))
186 width (/ (cadr pixmap) (frame-char-width)))
187 (set-face-foreground 'gnus-splash "Brown")
188 (set-face-stipple 'gnus-splash pixmap)
189 (insert-char ?\n (* (/ (window-height) 2 height) height))
192 (insert-char ?\ (* (/ (window-width) 2 width) width))
194 (insert-char ?\ width)
195 (set-text-properties beg (point) '(face gnus-splash))
198 (goto-char (point-min))
201 (defvar gnus-article-xface-ring-internal nil
202 "Cache for face data.")
204 ;; Worth customizing?
205 (defvar gnus-article-xface-ring-size 6
206 "Length of the ring used for `gnus-article-xface-ring-internal'.")
208 (defun gnus-article-display-xface (beg end)
209 "Display an XFace header from between BEG and END in the current article.
210 Requires support for images in your Emacs and the external programs
211 `uncompface', `icontopbm' and `ppmtoxbm'. On a GNU/Linux system these
212 might be in packages with names like `compface' or `faces-xface' and
213 `netpbm' or `libgr-progs', for instance.
215 This function is for Emacs 21+. See `gnus-xmas-article-display-xface'
217 ;; It might be worth converting uncompface's output in Lisp.
219 (unless gnus-article-xface-ring-internal ; Only load ring when needed.
220 (setq gnus-article-xface-ring-internal
221 (make-ring gnus-article-xface-ring-size)))
223 (let* ((cur (current-buffer))
224 (data (buffer-substring beg end))
225 (image (cdr-safe (assoc data (ring-elements
226 gnus-article-xface-ring-internal)))))
227 (when (if (fboundp 'display-graphic-p)
230 (let ((coding-system-for-read 'binary)
231 (coding-system-for-write 'binary))
234 (and (eq 0 (call-process-region (point-min) (point-max)
237 (goto-char (point-min))
238 (progn (insert "/* Width=48, Height=48 */\n") t)
239 (eq 0 (call-process-region (point-min) (point-max)
242 (eq 0 (call-process-region (point-min) (point-max)
245 ;; Miles Bader says that faces don't look right as
247 (if (eq 'dark (cdr-safe (assq 'background-mode
248 (frame-parameters))))
249 (setq image (create-image (buffer-string) 'xbm t
252 :background "white"))
253 (setq image (create-image (buffer-string) 'xbm t
254 :ascent 'center))))))
255 (ring-insert gnus-article-xface-ring-internal (cons data image))))
257 (goto-char (point-min))
258 (re-search-forward "^From:" nil 'move)
259 (insert-image image)))))
264 ;; byte-compile-warnings: '(redefine callargs)
267 ;;; gnus-ems.el ends here