Commit | Line | Data |
---|---|---|
eec82323 | 1 | ;;; gnus-ems.el --- functions for making Gnus work under different Emacsen |
6748645f | 2 | ;; Copyright (C) 1995,96,97,98 Free Software Foundation, Inc. |
eec82323 | 3 | |
6748645f | 4 | ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org> |
eec82323 LMI |
5 | ;; Keywords: news |
6 | ||
7 | ;; This file is part of GNU Emacs. | |
8 | ||
9 | ;; GNU Emacs is free software; you can redistribute it and/or modify | |
10 | ;; it under the terms of the GNU General Public License as published by | |
11 | ;; the Free Software Foundation; either version 2, or (at your option) | |
12 | ;; any later version. | |
13 | ||
14 | ;; GNU Emacs is distributed in the hope that it will be useful, | |
15 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | ;; GNU General Public License for more details. | |
18 | ||
19 | ;; You should have received a copy of the GNU General Public License | |
20 | ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
21 | ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
22 | ;; Boston, MA 02111-1307, USA. | |
23 | ||
24 | ;;; Commentary: | |
25 | ||
26 | ;;; Code: | |
27 | ||
28 | (eval-when-compile (require 'cl)) | |
29 | ||
30 | ;;; Function aliases later to be redefined for XEmacs usage. | |
31 | ||
32 | (defvar gnus-xemacs (string-match "XEmacs\\|Lucid" emacs-version) | |
33 | "Non-nil if running under XEmacs.") | |
34 | ||
35 | (defvar gnus-mouse-2 [mouse-2]) | |
36 | (defvar gnus-down-mouse-2 [down-mouse-2]) | |
a8151ef7 LMI |
37 | (defvar gnus-mode-line-modified |
38 | (if (or gnus-xemacs | |
39 | (< emacs-major-version 20)) | |
40 | '("--**-" . "-----") | |
41 | '("**" "--"))) | |
eec82323 LMI |
42 | |
43 | (eval-and-compile | |
44 | (autoload 'gnus-xmas-define "gnus-xmas") | |
45 | (autoload 'gnus-xmas-redefine "gnus-xmas") | |
a8151ef7 | 46 | (autoload 'appt-select-lowest-window "appt")) |
eec82323 LMI |
47 | |
48 | (or (fboundp 'mail-file-babyl-p) | |
49 | (fset 'mail-file-babyl-p 'rmail-file-p)) | |
50 | ||
51 | ;;; Mule functions. | |
52 | ||
53 | (defun gnus-mule-cite-add-face (number prefix face) | |
54 | ;; At line NUMBER, ignore PREFIX and add FACE to the rest of the line. | |
55 | (when face | |
56 | (let ((inhibit-point-motion-hooks t) | |
57 | from to) | |
58 | (goto-line number) | |
6748645f LMI |
59 | (unless (eobp) ; Sometimes things become confused (broken). |
60 | (if (boundp 'MULE) | |
61 | (forward-char (chars-in-string prefix)) | |
62 | (forward-char (length prefix))) | |
63 | (skip-chars-forward " \t") | |
64 | (setq from (point)) | |
65 | (end-of-line 1) | |
66 | (skip-chars-backward " \t") | |
67 | (setq to (point)) | |
68 | (when (< from to) | |
69 | (push (setq overlay (gnus-make-overlay from to)) | |
70 | gnus-cite-overlay-list) | |
71 | (gnus-overlay-put (gnus-make-overlay from to) 'face face)))))) | |
eec82323 LMI |
72 | |
73 | (defun gnus-mule-max-width-function (el max-width) | |
74 | (` (let* ((val (eval (, el))) | |
75 | (valstr (if (numberp val) | |
76 | (int-to-string val) val))) | |
77 | (if (> (length valstr) (, max-width)) | |
78 | (truncate-string valstr (, max-width)) | |
79 | valstr)))) | |
80 | ||
a8151ef7 LMI |
81 | (defun gnus-encode-coding-string (string system) |
82 | string) | |
83 | ||
6748645f LMI |
84 | (defun gnus-decode-coding-string (string system) |
85 | string) | |
86 | ||
87 | (defun gnus-encode-coding-string (string system) | |
88 | string) | |
89 | ||
eec82323 LMI |
90 | (eval-and-compile |
91 | (if (string-match "XEmacs\\|Lucid" emacs-version) | |
92 | nil | |
93 | ||
94 | (defvar gnus-mouse-face-prop 'mouse-face | |
a8151ef7 | 95 | "Property used for highlighting mouse regions.")) |
eec82323 LMI |
96 | |
97 | (cond | |
98 | ((string-match "XEmacs\\|Lucid" emacs-version) | |
99 | (gnus-xmas-define)) | |
100 | ||
101 | ((or (not (boundp 'emacs-minor-version)) | |
6748645f LMI |
102 | (and (< emacs-major-version 20) |
103 | (< emacs-minor-version 30))) | |
eec82323 LMI |
104 | ;; Remove the `intangible' prop. |
105 | (let ((props (and (boundp 'gnus-hidden-properties) | |
106 | gnus-hidden-properties))) | |
107 | (while (and props (not (eq (car (cdr props)) 'intangible))) | |
108 | (setq props (cdr props))) | |
109 | (when props | |
110 | (setcdr props (cdr (cdr (cdr props)))))) | |
111 | (unless (fboundp 'buffer-substring-no-properties) | |
112 | (defun buffer-substring-no-properties (beg end) | |
113 | (format "%s" (buffer-substring beg end))))) | |
114 | ||
115 | ((boundp 'MULE) | |
116 | (provide 'gnusutil)))) | |
117 | ||
118 | (eval-and-compile | |
119 | (cond | |
120 | ((not window-system) | |
121 | (defun gnus-dummy-func (&rest args)) | |
122 | (let ((funcs '(mouse-set-point set-face-foreground | |
123 | set-face-background x-popup-menu))) | |
124 | (while funcs | |
125 | (unless (fboundp (car funcs)) | |
126 | (fset (car funcs) 'gnus-dummy-func)) | |
127 | (setq funcs (cdr funcs)))))) | |
128 | (unless (fboundp 'file-regular-p) | |
129 | (defun file-regular-p (file) | |
130 | (and (not (file-directory-p file)) | |
131 | (not (file-symlink-p file)) | |
132 | (file-exists-p file)))) | |
133 | (unless (fboundp 'face-list) | |
134 | (defun face-list (&rest args)))) | |
135 | ||
136 | (eval-and-compile | |
137 | (let ((case-fold-search t)) | |
138 | (cond | |
6748645f LMI |
139 | ((string-match "windows-nt\\|os/2\\|emx\\|cygwin" |
140 | (symbol-name system-type)) | |
eec82323 LMI |
141 | (setq nnheader-file-name-translation-alist |
142 | (append nnheader-file-name-translation-alist | |
143 | '((?: . ?_) | |
144 | (?+ . ?-)))))))) | |
145 | ||
146 | (defvar gnus-tmp-unread) | |
147 | (defvar gnus-tmp-replied) | |
148 | (defvar gnus-tmp-score-char) | |
149 | (defvar gnus-tmp-indentation) | |
150 | (defvar gnus-tmp-opening-bracket) | |
151 | (defvar gnus-tmp-lines) | |
152 | (defvar gnus-tmp-name) | |
153 | (defvar gnus-tmp-closing-bracket) | |
154 | (defvar gnus-tmp-subject-or-nil) | |
155 | ||
156 | (defun gnus-ems-redefine () | |
157 | (cond | |
158 | ((string-match "XEmacs\\|Lucid" emacs-version) | |
159 | (gnus-xmas-redefine)) | |
160 | ||
161 | ((featurep 'mule) | |
162 | ;; Mule and new Emacs definitions | |
163 | ||
164 | ;; [Note] Now there are three kinds of mule implementations, | |
165 | ;; original MULE, XEmacs/mule and beta version of Emacs including | |
166 | ;; some mule features. Unfortunately these API are different. In | |
167 | ;; particular, Emacs (including original MULE) and XEmacs are | |
168 | ;; quite different. | |
169 | ;; Predicates to check are following: | |
170 | ;; (boundp 'MULE) is t only if MULE (original; anything older than | |
171 | ;; Mule 2.3) is running. | |
172 | ;; (featurep 'mule) is t when every mule variants are running. | |
173 | ||
174 | ;; These implementations may be able to share between original | |
175 | ;; MULE and beta version of new Emacs. In addition, it is able to | |
176 | ;; detect XEmacs/mule by (featurep 'mule) and to check variable | |
177 | ;; `emacs-version'. In this case, implementation for XEmacs/mule | |
178 | ;; may be able to share between XEmacs and XEmacs/mule. | |
179 | ||
180 | (defalias 'gnus-truncate-string 'truncate-string) | |
181 | ||
182 | (defvar gnus-summary-display-table nil | |
183 | "Display table used in summary mode buffers.") | |
184 | (fset 'gnus-cite-add-face 'gnus-mule-cite-add-face) | |
185 | (fset 'gnus-max-width-function 'gnus-mule-max-width-function) | |
6748645f | 186 | (fset 'gnus-summary-set-display-table (lambda ())) |
a8151ef7 | 187 | (fset 'gnus-encode-coding-string 'encode-coding-string) |
6748645f | 188 | (fset 'gnus-decode-coding-string 'decode-coding-string) |
eec82323 LMI |
189 | |
190 | (when (boundp 'gnus-check-before-posting) | |
191 | (setq gnus-check-before-posting | |
192 | (delq 'long-lines | |
193 | (delq 'control-chars gnus-check-before-posting)))) | |
194 | ||
195 | (defun gnus-summary-line-format-spec () | |
196 | (insert gnus-tmp-unread gnus-tmp-replied | |
197 | gnus-tmp-score-char gnus-tmp-indentation) | |
198 | (put-text-property | |
199 | (point) | |
200 | (progn | |
201 | (insert | |
202 | gnus-tmp-opening-bracket | |
203 | (format "%4d: %-20s" | |
204 | gnus-tmp-lines | |
205 | (if (> (length gnus-tmp-name) 20) | |
206 | (truncate-string gnus-tmp-name 20) | |
207 | gnus-tmp-name)) | |
208 | gnus-tmp-closing-bracket) | |
209 | (point)) | |
210 | gnus-mouse-face-prop gnus-mouse-face) | |
211 | (insert " " gnus-tmp-subject-or-nil "\n")) | |
3c22558d | 212 | |
40166464 KH |
213 | (when (and (boundp 'enable-multibyte-characters) |
214 | enable-multibyte-characters) | |
215 | (require 'gnus-mule) | |
216 | (gnus-mule-initialize)) | |
eec82323 LMI |
217 | ))) |
218 | ||
219 | (defun gnus-region-active-p () | |
220 | "Say whether the region is active." | |
221 | (and (boundp 'transient-mark-mode) | |
222 | transient-mark-mode | |
223 | (boundp 'mark-active) | |
224 | mark-active)) | |
225 | ||
a8151ef7 LMI |
226 | (defun gnus-add-minor-mode (mode name map) |
227 | (if (fboundp 'add-minor-mode) | |
228 | (add-minor-mode mode name map) | |
6748645f | 229 | (set (make-local-variable mode) t) |
a8151ef7 LMI |
230 | (unless (assq mode minor-mode-alist) |
231 | (push `(,mode ,name) minor-mode-alist)) | |
232 | (unless (assq mode minor-mode-map-alist) | |
233 | (push (cons mode map) | |
234 | minor-mode-map-alist)))) | |
235 | ||
6748645f LMI |
236 | (defun gnus-x-splash () |
237 | "Show a splash screen using a pixmap in the current buffer." | |
238 | (let ((dir (nnheader-find-etc-directory "gnus")) | |
239 | pixmap file height beg i) | |
240 | (save-excursion | |
241 | (switch-to-buffer (gnus-get-buffer-create gnus-group-buffer)) | |
242 | (let ((buffer-read-only nil)) | |
243 | (erase-buffer) | |
244 | (when (and dir | |
245 | (file-exists-p (setq file (concat dir "x-splash")))) | |
246 | (nnheader-temp-write nil | |
247 | (insert-file-contents file) | |
248 | (goto-char (point-min)) | |
249 | (ignore-errors | |
250 | (setq pixmap (read (current-buffer)))))) | |
251 | (when pixmap | |
252 | (erase-buffer) | |
253 | (unless (facep 'gnus-splash) | |
254 | (make-face 'gnus-splash)) | |
255 | (setq height (/ (car pixmap) (frame-char-height)) | |
256 | width (/ (cadr pixmap) (frame-char-width))) | |
257 | (set-face-foreground 'gnus-splash "ForestGreen") | |
258 | (set-face-stipple 'gnus-splash pixmap) | |
259 | (insert-char ?\n (* (/ (window-height) 2 height) height)) | |
260 | (setq i height) | |
261 | (while (> i 0) | |
262 | (insert-char ? (* (+ (/ (window-width) 2 width) 1) width)) | |
263 | (setq beg (point)) | |
264 | (insert-char ? width) | |
265 | (set-text-properties beg (point) '(face gnus-splash)) | |
266 | (insert "\n") | |
267 | (decf i)) | |
268 | (goto-char (point-min)) | |
269 | (sit-for 0)))))) | |
270 | ||
271 | (if (fboundp 'split-string) | |
272 | (fset 'gnus-split-string 'split-string) | |
273 | (defun gnus-split-string (string pattern) | |
274 | "Return a list of substrings of STRING which are separated by PATTERN." | |
275 | (let (parts (start 0)) | |
276 | (while (string-match pattern string start) | |
277 | (setq parts (cons (substring string start (match-beginning 0)) parts) | |
278 | start (match-end 0))) | |
279 | (nreverse (cons (substring string start) parts))))) | |
280 | ||
eec82323 LMI |
281 | (provide 'gnus-ems) |
282 | ||
283 | ;; Local Variables: | |
284 | ;; byte-compile-warnings: '(redefine callargs) | |
285 | ;; End: | |
286 | ||
287 | ;;; gnus-ems.el ends here |