1 ;;; gnus-ems.el --- functions for making Semi-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 ;; Tatsuya Ichikawa <t-ichi@niagara.shiojiri.ne.jp>
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
30 (eval-when-compile (require 'cl))
32 ;;; Function aliases later to be redefined for XEmacs usage.
35 (defvar gnus-xemacs (string-match "XEmacs" emacs-version)
36 "Non-nil if running under XEmacs."))
38 (defvar gnus-mouse-2 [mouse-2])
39 (defvar gnus-down-mouse-3 [down-mouse-3])
40 (defvar gnus-down-mouse-2 [down-mouse-2])
41 (defvar gnus-widget-button-keymap nil)
42 (defvar gnus-mode-line-modified
44 (< emacs-major-version 20))
49 (autoload 'gnus-xmas-define "gnus-xmas")
50 (autoload 'gnus-xmas-redefine "gnus-xmas")
51 (autoload 'appt-select-lowest-window "appt"))
53 (or (fboundp 'mail-file-babyl-p)
54 (fset 'mail-file-babyl-p 'rmail-file-p))
61 (defvar gnus-mouse-face-prop 'mouse-face
62 "Property used for highlighting mouse regions.")))
67 (defun gnus-dummy-func (&rest args))
68 (let ((funcs '(mouse-set-point set-face-foreground
69 set-face-background x-popup-menu)))
71 (unless (fboundp (car funcs))
72 (defalias (car funcs) 'gnus-dummy-func))
73 (setq funcs (cdr funcs)))))))
76 (let ((case-fold-search t))
78 ((string-match "windows-nt\\|os/2\\|emx\\|cygwin32"
79 (symbol-name system-type))
80 (setq nnheader-file-name-translation-alist
81 (append nnheader-file-name-translation-alist
82 (mapcar (lambda (c) (cons c ?_))
83 '(?: ?* ?\" ?< ?> ??))
86 (defvar gnus-tmp-unread)
87 (defvar gnus-tmp-replied)
88 (defvar gnus-tmp-score-char)
89 (defvar gnus-tmp-indentation)
90 (defvar gnus-tmp-opening-bracket)
91 (defvar gnus-tmp-lines)
92 (defvar gnus-tmp-name)
93 (defvar gnus-tmp-closing-bracket)
94 (defvar gnus-tmp-subject-or-nil)
96 (defun gnus-ems-redefine ()
102 ;; Mule and new Emacs definitions
104 ;; [Note] Now there are three kinds of mule implementations,
105 ;; original MULE, XEmacs/mule and Emacs 20+ including
106 ;; MULE features. Unfortunately these API are different. In
107 ;; particular, Emacs (including original MULE) and XEmacs are
108 ;; quite different. However, this version of Gnus doesn't support
109 ;; anything other than XEmacs 20+ and Emacs 20.3+.
111 ;; Predicates to check are following:
112 ;; (boundp 'MULE) is t only if MULE (original; anything older than
113 ;; Mule 2.3) is running.
114 ;; (featurep 'mule) is t when every mule variants are running.
116 ;; It is possible to detect XEmacs/mule by (featurep 'mule) and
117 ;; checking `emacs-version'. In this case, the implementation for
118 ;; XEmacs/mule may be shareable between XEmacs and XEmacs/mule.
120 (defvar gnus-summary-display-table nil
121 "Display table used in summary mode buffers.")
122 (defalias 'gnus-summary-set-display-table (lambda ()))
124 (if (fboundp 'truncate-string-to-width)
125 (fset 'gnus-truncate-string 'truncate-string-to-width)
126 (fset 'gnus-truncate-string 'truncate-string))
128 (when (boundp 'gnus-check-before-posting)
129 (setq gnus-check-before-posting
131 (delq 'control-chars gnus-check-before-posting))))
133 (when (featurep 'mule)
134 (defun gnus-tilde-max-form (el max-width)
135 "Return a form that limits EL to MAX-WIDTH."
136 (let ((max (abs max-width)))
139 `(let ((width (string-width ,el)))
140 (gnus-truncate-string ,el width (- width ,max)))
141 `(gnus-truncate-string ,el ,max))
143 `(let* ((val (eval ,el))
144 (width (string-width val)))
145 (gnus-truncate-string val width (- width ,max)))
146 `(let ((val (eval ,el)))
147 (gnus-truncate-string val ,max))))))
149 (defun gnus-tilde-cut-form (el cut-width)
150 "Return a form that cuts CUT-WIDTH off of EL."
151 (let ((cut (abs cut-width)))
154 `(gnus-truncate-string ,el (- (string-width ,el) ,cut))
155 `(gnus-truncate-string ,el (string-width ,el) ,cut))
157 `(let ((val (eval ,el)))
158 (gnus-truncate-string val (- (string-width val) ,cut)))
159 `(let ((val (eval ,el)))
160 (gnus-truncate-string val (string-width val) ,cut))))))
163 (defun gnus-region-active-p ()
164 "Say whether the region is active."
165 (and (boundp 'transient-mark-mode)
167 (boundp 'mark-active)
170 (defun gnus-add-minor-mode (mode name map)
171 (if (fboundp 'add-minor-mode)
172 (add-minor-mode mode name map)
173 (set (make-local-variable mode) t)
174 (unless (assq mode minor-mode-alist)
175 (push `(,mode ,name) minor-mode-alist))
176 (unless (assq mode minor-mode-map-alist)
177 (push (cons mode map)
178 minor-mode-map-alist))))
180 (defun gnus-x-splash ()
181 "Show a splash screen using a pixmap in the current buffer."
182 (let ((dir (nnheader-find-etc-directory "gnus"))
183 pixmap file height beg i)
185 (switch-to-buffer (gnus-get-buffer-create gnus-group-buffer))
186 (let ((buffer-read-only nil))
189 (file-exists-p (setq file (concat dir "x-splash"))))
191 (insert-file-contents-as-binary file)
192 (goto-char (point-min))
194 (setq pixmap (read (current-buffer))))))
196 (unless (facep 'gnus-splash)
197 (make-face 'gnus-splash))
198 (setq height (/ (car pixmap) (frame-char-height))
199 width (/ (cadr pixmap) (frame-char-width)))
200 (set-face-foreground 'gnus-splash "Brown")
201 (set-face-stipple 'gnus-splash pixmap)
202 (insert-char ?\n (* (/ (window-height) 2 height) height))
205 (insert-char ? (* (/ (window-width) 2 width) width))
207 (insert-char ? width)
208 (set-text-properties beg (point) '(face gnus-splash))
211 (goto-char (point-min))
214 (defvar gnus-article-xface-ring-internal nil
215 "Cache for face data.")
217 ;; Worth customizing?
218 (defvar gnus-article-xface-ring-size 6
219 "Length of the ring used for `gnus-article-xface-ring-internal'.")
221 (defun gnus-article-display-xface (beg end)
222 "Display an XFace header from between BEG and END in the current article.
223 This requires support images in your Emacs and the external programs
224 `uncompface', `icontopbm' and `ppmtoxbm'. On a GNU/Linux system these
225 might be in packages with names like `compface' or `faces-xface' and
226 `netpbm' or `libgr-progs', for instance.
228 This function is for Emacs 21+. See `gnus-xmas-article-display-xface'
230 ;; It might be worth converting uncompface's output in Lisp.
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 (when (if (fboundp 'display-graphic-p)
243 (let ((coding-system-for-read 'binary)
244 (coding-system-for-write 'binary))
247 (and (eq 0 (call-process-region (point-min) (point-max)
250 (goto-char (point-min))
251 (progn (insert "/* Width=48, Height=48 */\n") t)
252 (eq 0 (call-process-region (point-min) (point-max)
255 (eq 0 (call-process-region (point-min) (point-max)
258 (setq image (create-image (buffer-string) 'xbm t)))))
259 (ring-insert gnus-article-xface-ring-internal (cons data image))))
261 (goto-char (point-min))
262 (re-search-forward "^From:" nil 'move)
263 (insert-image image " ")))))
265 (defun-maybe assoc-ignore-case (key alist)
266 "Like `assoc', but assumes KEY is a string and ignores case when comparing."
267 (setq key (downcase key))
269 (while (and alist (not element))
270 (if (equal key (downcase (car (car alist))))
271 (setq element (car alist)))
272 (setq alist (cdr alist)))
276 ;;; Language support staffs.
278 (defvar-maybe current-language-environment "English"
279 "The language environment.")
281 (defvar-maybe language-info-alist nil
282 "Alist of language environment definitions.")
284 (defun-maybe get-language-info (lang-env key)
285 "Return information listed under KEY for language environment LANG-ENV."
286 (if (symbolp lang-env)
287 (setq lang-env (symbol-name lang-env)))
288 (let ((lang-slot (assoc-ignore-case lang-env language-info-alist)))
290 (cdr (assq key (cdr lang-slot))))))
292 (defun-maybe set-language-info (lang-env key info)
293 "Modify part of the definition of language environment LANG-ENV."
294 (if (symbolp lang-env)
295 (setq lang-env (symbol-name lang-env)))
296 (let (lang-slot key-slot)
297 (setq lang-slot (assoc lang-env language-info-alist))
298 (if (null lang-slot) ; If no slot for the language, add it.
299 (setq lang-slot (list lang-env)
300 language-info-alist (cons lang-slot language-info-alist)))
301 (setq key-slot (assq key lang-slot))
302 (if (null key-slot) ; If no slot for the key, add it.
304 (setq key-slot (list key))
305 (setcdr lang-slot (cons key-slot (cdr lang-slot)))))
306 (setcdr key-slot info)))
311 ;; byte-compile-warnings: '(redefine callargs)
314 ;;; gnus-ems.el ends here