36bf70b9a38be52eea78b09b4d093416ad60041a
[gnus] / lisp / gnus-ems.el
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.
4
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
6 ;; Keywords: news
7
8 ;; This file is part of GNU Emacs.
9
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)
13 ;; any later version.
14
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.
19
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.
24
25 ;;; Commentary:
26
27 ;;; Code:
28
29 (eval-when-compile (require 'cl))
30
31 ;;; Function aliases later to be redefined for XEmacs usage.
32
33 (eval-and-compile
34   (defvar gnus-xemacs (featurep 'xemacs)
35     "Non-nil if running under XEmacs."))
36
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
42   (if (or gnus-xemacs
43           (< emacs-major-version 20))
44       '("--**-" . "-----")
45     '("**" "--")))
46
47 (eval-and-compile
48   (autoload 'gnus-xmas-define "gnus-xmas")
49   (autoload 'gnus-xmas-redefine "gnus-xmas")
50   (autoload 'appt-select-lowest-window "appt"))
51
52 (autoload 'gnus-smiley-display "smiley-ems") ; override XEmacs version
53
54 ;;; Mule functions.
55
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)
62        valstr)))
63
64 (eval-and-compile
65   (if gnus-xemacs
66       (gnus-xmas-define)
67     (defvar gnus-mouse-face-prop 'mouse-face
68       "Property used for highlighting mouse regions.")))
69
70 (eval-and-compile
71   (let ((case-fold-search t))
72     (cond
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                             '(?: ?* ?\" ?< ?> ??))
79                     '((?+ . ?-))))))))
80
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)
90
91 (defun gnus-ems-redefine ()
92   (cond
93    (gnus-xemacs
94     (gnus-xmas-redefine))
95
96    ((featurep 'mule)
97     ;; Mule and new Emacs definitions
98
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+.
105
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.
110
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.
114
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)
118
119     (when (boundp 'gnus-check-before-posting)
120       (setq gnus-check-before-posting
121             (delq 'long-lines
122                   (delq 'control-chars gnus-check-before-posting))))
123
124     (defun gnus-summary-line-format-spec ()
125       (insert gnus-tmp-unread gnus-tmp-replied
126               gnus-tmp-score-char gnus-tmp-indentation)
127       (put-text-property
128        (point)
129        (progn
130          (insert
131           gnus-tmp-opening-bracket
132           (format "%4d: %-20s"
133                   gnus-tmp-lines
134                   (if (> (length gnus-tmp-name) 20)
135                       (truncate-string-to-width gnus-tmp-name 20)
136                     gnus-tmp-name))