(mm-uu-copy-to-buffer): buffer-file-coding-system
[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, 2001, 2002, 2003
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
30   (require 'cl)
31   (require 'ring))
32
33 ;;; Function aliases later to be redefined for XEmacs usage.
34
35 (defvar gnus-mouse-2 [mouse-2])
36 (defvar gnus-down-mouse-3 [down-mouse-3])
37 (defvar gnus-down-mouse-2 [down-mouse-2])
38 (defvar gnus-widget-button-keymap nil)
39 (defvar gnus-mode-line-modified
40   (if (or (featurep 'xemacs)
41           (< emacs-major-version 20))
42       '("--**-" . "-----")
43     '("**" "--")))
44
45 (eval-and-compile
46   (autoload 'gnus-xmas-define "gnus-xmas")
47   (autoload 'gnus-xmas-redefine "gnus-xmas")
48   (autoload 'appt-select-lowest-window "appt"))
49
50 (autoload 'smiley-region "smiley")
51
52 (defun gnus-kill-all-overlays ()
53   "Delete all overlays in the current buffer."
54   (let* ((overlayss (overlay-lists))
55          (buffer-read-only nil)
56          (overlays (delq nil (nconc (car overlayss) (cdr overlayss)))))
57     (while overlays
58       (delete-overlay (pop overlays)))))
59
60 ;;; Mule functions.
61
62 (defun gnus-mule-max-width-function (el max-width)
63   `(let* ((val (eval (, el)))
64           (valstr (if (numberp val)
65                       (int-to-string val) val)))
66      (if (> (length valstr) ,max-width)
67          (truncate-string-to-width valstr ,max-width)
68        valstr)))
69
70 (eval-and-compile
71   (defalias 'gnus-char-width
72     (if (fboundp 'char-width)
73         'char-width
74       (lambda (ch) 1)))) ;; A simple hack.
75
76 (eval-and-compile
77   (if (featurep 'xemacs)
78       (gnus-xmas-define)
79     (defvar gnus-mouse-face-prop 'mouse-face
80       "Property used for highlighting mouse regions.")))
81
82 (defvar gnus-tmp-unread)
83 (defvar gnus-tmp-replied)
84 (defvar gnus-tmp-score-char)
85 (defvar gnus-tmp-indentation)
86 (defvar gnus-tmp-opening-bracket)
87 (defvar gnus-tmp-lines)
88 (defvar gnus-tmp-name)
89 (defvar gnus-tmp-closing-bracket)
90 (defvar gnus-tmp-subject-or-nil)
91 (defvar gnus-check-before-posting)
92
93 (defun gnus-ems-redefine ()
94   (cond
95    ((featurep 'xemacs)
96     (gnus-xmas-redefine))
97
98    ((featurep 'mule)
99     ;; Mule and new Emacs definitions
100
101     ;; [Note] Now there are three kinds of mule implementations,
102     ;; original MULE, XEmacs/mule and Emacs 20+ including
103     ;; MULE features.  Unfortunately these API are different.  In
104     ;; particular, Emacs (including original MULE) and XEmacs are
105     ;; quite different.  However, this version of Gnus doesn't support
106     ;; anything other than XEmacs 20+ and Emacs 20.3+.
107
108     ;; Predicates to check are following:
109     ;; (boundp 'MULE) is t only if MULE (original; anything older than
110     ;;                     Mule 2.3) is running.
111     ;; (featurep 'mule) is t when every mule variants are running.
112
113     ;; It is possible to detect XEmacs/mule by (featurep 'mule) and
114     ;; checking `emacs-version'.  In this case, the implementation for
115     ;; XEmacs/mule may be shareable between XEmacs and XEmacs/mule.
116
117     (defvar gnus-summary-display-table nil
118       "Display table used in summary mode buffers.")
119     (defalias 'gnus-max-width-function 'gnus-mule-max-width-function)
120
121     (when (boundp 'gnus-check-before-posting)
122       (setq gnus-check-before-posting
123             (delq 'long-lines
124                   (delq 'control-chars gnus-check-before-posting))))
125
126     (defun gnus-summary-line-format-spec ()
127       (insert gnus-tmp-unread gnus-tmp-replied
128               gnus-tmp-score-char gnus-tmp-indentation)
129       (put-text-property
130        (point)
131        (progn
132          (insert
133           gnus-tmp-opening-bracket
134           (format "%4d: %-20s"
135                   gnus-tmp-lines
136                   (if (> (length gnus-tmp-name) 20)
137                       (truncate-string-to-width gnus-tmp-name 20)
138                     gnus-tmp-name))
139           gnus-tmp-closing-bracket)
140          (point))
141        gnus-mouse-face-prop gnus-mouse-face)
142       (insert " " gnus-tmp-subject-or-nil "\n")))))
143
144 (defun gnus-region-active-p ()
145   "Say whether the region is active."
146   (and (boundp 'transient-mark-mode)
147        transient-mark-mode
148        (boundp 'mark-active)
149        mark-active))
150
151 (defun gnus-mark-active-p ()
152   "Non-nil means the mark and region are currently active in this buffer."
153