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.
33 (defvar gnus-mouse-2
[mouse-2
])
34 (defvar gnus-down-mouse-3
[down-mouse-3
])
35 (defvar gnus-down-mouse-2
[down-mouse-2
])
36 (defvar gnus-widget-button-keymap nil
)
37 (defvar gnus-mode-line-modified
38 (if (or (featurep 'xemacs
)
39 (< emacs-major-version
20))
44 (autoload 'gnus-xmas-define
"gnus-xmas")
45 (autoload 'gnus-xmas-redefine
"gnus-xmas")
46 (autoload 'appt-select-lowest-window
"appt"))
48 (if (featurep 'xemacs
)
49 (autoload 'gnus-smiley-display
"smiley")
50 (autoload 'gnus-smiley-display
"smiley-ems") ; override XEmacs version
53 (defun gnus-kill-all-overlays ()
54 "Delete all overlays in the current buffer."
55 (let* ((overlayss (overlay-lists))
56 (buffer-read-only nil
)
57 (overlays (delq nil
(nconc (car overlayss
) (cdr overlayss
)))))
59 (delete-overlay (pop overlays
)))))
63 (defun gnus-mule-max-width-function (el max-width
)
64 `(let* ((val (eval (, el
)))
65 (valstr (if (numberp val
)
66 (int-to-string val
) val
)))
67 (if (> (length valstr
) ,max-width
)
68 (truncate-string-to-width valstr
,max-width
)
72 (if (featurep 'xemacs
)
74 (defvar gnus-mouse-face-prop
'mouse-face
75 "Property used for highlighting mouse regions.")))
78 (let ((case-fold-search t
))
80 ((string-match "windows-nt\\|os/2\\|emx\\|cygwin32"
81 (symbol-name system-type
))
82 (setq nnheader-file-name-translation-alist
83 (append nnheader-file-name-translation-alist
84 (mapcar (lambda (c) (cons c ?_
))
85 '(?
: ?
* ?
\" ?
< ?
> ??
))
88 (defvar gnus-tmp-unread
)
89 (defvar gnus-tmp-replied
)
90 (defvar gnus-tmp-score-char
)
91 (defvar gnus-tmp-indentation
)
92 (defvar gnus-tmp-opening-bracket
)
93 (defvar gnus-tmp-lines
)
94 (defvar gnus-tmp-name
)
95 (defvar gnus-tmp-closing-bracket
)
96 (defvar gnus-tmp-subject-or-nil
)
98 (defun gnus-ems-redefine ()
101 (gnus-xmas-redefine))
104 ;; Mule and new Emacs definitions
106 ;; [Note] Now there are three kinds of mule implementations,
107 ;; original MULE, XEmacs/mule and Emacs 20+ including
108 ;; MULE features. Unfortunately these API are different. In
109 ;; particular, Emacs (including original MULE) and XEmacs are
110 ;; quite different. Howvere, this version of Gnus doesn't support
111 ;; anything other than XEmacs 20+ and Emacs 20.3+.
113 ;; Predicates to check are following:
114 ;; (boundp 'MULE) is t only if MULE (original; anything older than
115 ;; Mule 2.3) is running.
116 ;; (featurep 'mule) is t when every mule variants are running.
118 ;; It is possible to detect XEmacs/mule by (featurep 'mule) and
119 ;; checking `emacs-version'. In this case, the implementation for
120 ;; XEmacs/mule may be shareable between XEmacs and XEmacs/mule.
122 (defvar gnus-summary-display-table nil
123 "Display table used in summary mode buffers.")
124 (defalias 'gnus-max-width-function
'gnus-mule-max-width-function
)
126 (when (boundp 'gnus-check-before-posting
)
127 (setq gnus-check-before-posting
129 (delq 'control-chars gnus-check-before-posting
))))
131 (defun gnus-summary-line-format-spec ()
132 (insert gnus-tmp-unread gnus-tmp-replied
133 gnus-tmp-score-char gnus-tmp-indentation
)
138 gnus-tmp-opening-bracket
141 (if (> (length gnus-tmp-name
) 20)
142 (truncate-string-to-width gnus-tmp-name
20)
144 gnus-tmp-closing-bracket
)
146 gnus-mouse-face-prop gnus-mouse-face
)
147 (insert " " gnus-tmp-subject-or-nil
"\n")))))
149 (defun gnus-region-active-p ()
150 "Say whether the region is active."
151 (and (boundp 'transient-mark-mode
)
153 (boundp 'mark-active
)
156 (if (fboundp 'add-minor-mode
)
157 (defalias 'gnus-add-minor-mode
'add-minor-mode
)
158 (defun gnus-add-minor-mode (mode name map
&rest rest
)
159 (set (make-local-variable mode
) t
)
160 (unless (assq mode minor-mode-alist
)
161 (push `(,mode
,name
) minor-mode-alist
))
162 (unless (assq mode minor-mode-map-alist
)
163 (push (cons mode map
)
164 minor-mode-map-alist
))))
166 (defun gnus-x-splash ()
167 "Show a splash screen using a pixmap in the current buffer."
168 (let ((dir (nnheader-find-etc-directory "gnus"))
169 pixmap file height beg i
)
171 (switch-to-buffer (gnus-get-buffer-create gnus-group-buffer
))
172 (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 (defvar gnus-article-compface-xbm
209 (eq 0 (string-match "#define" (shell-command-to-string "uncompface -X")))
210 "Non-nil means the compface program supports the -X option.
211 That produces XBM output.")
213 (defun gnus-article-display-xface (beg end
)
214 "Display an XFace header from between BEG and END in the current article.
215 Requires support for images in your Emacs and the external programs
216 `uncompface', and `icontopbm'. On a GNU/Linux system these
217 might be in packages with names like `compface' or `faces-xface' and
218 `netpbm' or `libgr-progs', for instance. See also
219 `gnus-article-compface-xbm'.
221 This function is for Emacs 21+. See `gnus-xmas-article-display-xface'
223 ;; It might be worth converting uncompface's output in Lisp.
225 (when (if (fboundp 'display-graphic-p
)
227 (unless gnus-article-xface-ring-internal
; Only load ring when needed.
228 (setq gnus-article-xface-ring-internal
229 (make-ring gnus-article-xface-ring-size
)))
231 (let* ((cur (current-buffer))
232 (data (buffer-substring beg end
))
233 (image (cdr-safe (assoc data
(ring-elements
234 gnus-article-xface-ring-internal
))))
235 default-enable-multibyte-characters
)
239 (and (eq 0 (apply #'call-process-region
(point-min) (point-max)
242 (if gnus-article-compface-xbm
244 (if gnus-article-compface-xbm
246 (goto-char (point-min))
247 (progn (insert "/* Width=48, Height=48 */\n") t
)
248 (eq 0 (call-process-region (point-min) (point-max)
251 ;; Miles Bader says that faces don't look right as
253 (if (eq 'dark
(cdr-safe (assq 'background-mode
254 (frame-parameters))))
255 (setq image
(create-image (buffer-string)
256 (if gnus-article-compface-xbm
262 :background
"white"))
263 (setq image
(create-image (buffer-string)
264 (if gnus-article-compface-xbm
269 (ring-insert gnus-article-xface-ring-internal
(cons data image
)))
271 (goto-char (point-min))
272 (re-search-forward "^From:" nil
'move
)
273 (insert-image image
))))))
277 ;;; gnus-ems.el ends here