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"))
52 (autoload 'gnus-smiley-display "smiley-ems") ; override XEmacs version
56 (defun gnus-mule-max-width-function (el max-width)
57 `(let* ((val (eval (, el)))
58 (valstr (if (numberp val)
59 (int-to-string val) val)))
60 (if (> (length valstr) ,max-width)
61 (truncate-string-to-width valstr ,max-width)
67 (defvar gnus-mouse-face-prop 'mouse-face
68 "Property used for highlighting mouse regions.")))
71 (let ((case-fold-search t))
73 ((string-match "windows-nt\\|os/2\\|emx\\|cygwin32"
74 (symbol-name system-type))
75 (setq nnheader-file-name-translation-alist
76 (append nnheader-file-name-translation-alist
77 (mapcar (lambda (c) (cons c ?_))
78 '(?: ?* ?\" ?< ?> ??))
81 (defvar gnus-tmp-unread)
82 (defvar gnus-tmp-replied)
83 (defvar gnus-tmp-score-char)
84 (defvar gnus-tmp-indentation)
85 (defvar gnus-tmp-opening-bracket)
86 (defvar gnus-tmp-lines)
87 (defvar gnus-tmp-name)
88 (defvar gnus-tmp-closing-bracket)
89 (defvar gnus-tmp-subject-or-nil)
91 (defun gnus-ems-redefine ()
97 ;; Mule and new Emacs definitions
99 ;; [Note] Now there are three kinds of mule implementations,
100 ;; original MULE, XEmacs/mule and Emacs 20+ including
101 ;; MULE features. Unfortunately these API are different. In
102 ;; particular, Emacs (including original MULE) and XEmacs are
103 ;; quite different. Howvere, this version of Gnus doesn't support
104 ;; anything other than XEmacs 20+ and Emacs 20.3+.
106 ;; Predicates to check are following:
107 ;; (boundp 'MULE) is t only if MULE (original; anything older than
108 ;; Mule 2.3) is running.
109 ;; (featurep 'mule) is t when every mule variants are running.
111 ;; It is possible to detect XEmacs/mule by (featurep 'mule) and
112 ;; checking `emacs-version'. In this case, the implementation for
113 ;; XEmacs/mule may be shareable between XEmacs and XEmacs/mule.
115 (defvar gnus-summary-display-table nil
116 "Display table used in summary mode buffers.")
117 (defalias 'gnus-max-width-function 'gnus-mule-max-width-function)
119 (when (boundp 'gnus-check-before-posting)
120 (setq gnus-check-before-posting
122 (delq 'control-chars gnus-check-before-posting))))
124 (defun gnus-summary-line-format-spec ()
125 (insert gnus-tmp-unread gnus-tmp-replied
126 gnus-tmp-score-char gnus-tmp-indentation)
131 gnus-tmp-opening-bracket
134 (if (> (length gnus-tmp-name) 20)
135 (truncate-string-to-width gnus-tmp-name 20)
137 gnus-tmp-closing-bracket)
139 gnus-mouse-face-prop gnus-mouse-face)
140 (insert " " gnus-tmp-subject-or-nil "\n")))))
142 (defun gnus-region-active-p ()
143 "Say whether the region is active."
144 (and (boundp 'transient-mark-mode)
146 (boundp 'mark-active)
149 (if (fboundp 'add-minor-mode)
150 (defalias 'gnus-add-minor-mode 'add-minor-mode)
151 (defun gnus-add-minor-mode (mode name map &rest rest)
152 (set (make-local-variable mode) t)
153 (unless (assq mode minor-mode-alist)
154 (push `(,mode ,name) minor-mode-alist))
155 (unless (assq mode minor-mode-map-alist)
156 (push (cons mode map)
157 minor-mode-map-alist))))
159 (defun gnus-x-splash ()
160 "Show a splash screen using a pixmap in the current buffer."
161 (let ((dir (nnheader-find-etc-directory "gnus"))
162 pixmap file height beg i)
164 (switch-to-buffer (gnus-get-buffer-create gnus-group-buffer))
165 (let ((buffer-read-only nil))
168 (file-exists-p (setq file
169 (expand-file-name "x-splash" dir))))
171 (insert-file-contents file)
172 (goto-char (point-min))
174 (setq pixmap (read (current-buffer))))))
176 (make-face 'gnus-splash)
177 (setq height (/ (car pixmap) (frame-char-height))
178 width (/ (cadr pixmap) (frame-char-width)))
179 (set-face-foreground 'gnus-splash "Brown")
180 (set-face-stipple 'gnus-splash pixmap)
181 (insert-char ?\n (* (/ (window-height) 2 height) height))
184 (insert-char ?\ (* (/ (window-width) 2 width) width))
186 (insert-char ?\ width)
187 (set-text-properties beg (point) '(face gnus-splash))
190 (goto-char (point-min))
193 (defvar gnus-article-xface-ring-internal nil
194 "Cache for face data.")
196 ;; Worth customizing?
197 (defvar gnus-article-xface-ring-size 6
198 "Length of the ring used for `gnus-article-xface-ring-internal'.")
200 (defvar gnus-article-compface-xbm
201 (eq 0 (string-match "#define" (shell-command-to-string "uncompface -X")))
202 "Non-nil means the compface program supports the -X option.
203 That produces XBM output.")
205 (defun gnus-article-display-xface (beg end)
206 "Display an XFace header from between BEG and END in the current article.
207 Requires support for images in your Emacs and the external programs
208 `uncompface', and `icontopbm'. On a GNU/Linux system these
209 might be in packages with names like `compface' or `faces-xface' and
210 `netpbm' or `libgr-progs', for instance. See also
211 `gnus-article-compface-xbm'.
213 This function is for Emacs 21+. See `gnus-xmas-article-display-xface'
215 ;; It might be worth converting uncompface's output in Lisp.
217 (when (if (fboundp 'display-graphic-p)
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 default-enable-multibyte-characters)
231 (and (eq 0 (apply #'call-process-region (point-min) (point-max)
234 (if gnus-article-compface-xbm
236 (unless 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)
242 ;; Miles Bader says that faces don't look right as
244 (if (eq 'dark (cdr-safe (assq 'background-mode
245 (frame-parameters))))
246 (setq image (create-image (buffer-string) 'pbm t
249 :background "white"))
250 (setq image (create-image (buffer-string) 'pbm t
252 (ring-insert gnus-article-xface-ring-internal (cons data image)))
254 (goto-char (point-min))
255 (re-search-forward "^From:" nil 'move)
256 (insert-image image))))))
261 ;; byte-compile-warnings: '(redefine callargs)
264 ;;; gnus-ems.el ends here