compare symbol names with `equal'
[bpt/emacs.git] / lisp / gnus / gnus-ems.el
CommitLineData
eec82323 1;;; gnus-ems.el --- functions for making Gnus work under different Emacsen
e84b4b86 2
ba318903 3;; Copyright (C) 1995-2014 Free Software Foundation, Inc.
eec82323 4
6748645f 5;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
eec82323
LMI
6;; Keywords: news
7
8;; This file is part of GNU Emacs.
9
5e809f55 10;; GNU Emacs is free software: you can redistribute it and/or modify
eec82323 11;; it under the terms of the GNU General Public License as published by
5e809f55
GM
12;; the Free Software Foundation, either version 3 of the License, or
13;; (at your option) any later version.
eec82323
LMI
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
5e809f55 21;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
eec82323
LMI
22
23;;; Commentary:
24
25;;; Code:
26
4bcf2f05
DL
27(eval-when-compile
28 (require 'cl)
29 (require 'ring))
eec82323
LMI
30
31;;; Function aliases later to be redefined for XEmacs usage.
32
eec82323 33(defvar gnus-mouse-2 [mouse-2])
16409b0b 34(defvar gnus-down-mouse-3 [down-mouse-3])
eec82323 35(defvar gnus-down-mouse-2 [down-mouse-2])
16409b0b 36(defvar gnus-widget-button-keymap nil)
a8151ef7 37(defvar gnus-mode-line-modified
01c52d31 38 (if (featurep 'xemacs)
a8151ef7
LMI
39 '("--**-" . "-----")
40 '("**" "--")))
eec82323
LMI
41
42(eval-and-compile
43 (autoload 'gnus-xmas-define "gnus-xmas")
1e957e64 44 (autoload 'gnus-xmas-redefine "gnus-xmas"))
eec82323 45
1e957e64
GM
46(autoload 'gnus-get-buffer-create "gnus")
47(autoload 'nnheader-find-etc-directory "nnheader")
23f87bed 48(autoload 'smiley-region "smiley")
06c43cdf
DL
49
50(defun gnus-kill-all-overlays ()
51 "Delete all overlays in the current buffer."
52 (let* ((overlayss (overlay-lists))
53 (buffer-read-only nil)
54 (overlays (delq nil (nconc (car overlayss) (cdr overlayss)))))
55 (while overlays
56 (delete-overlay (pop overlays)))))
2d2f7f3e 57
eec82323
LMI
58;;; Mule functions.
59
eec82323 60(defun gnus-mule-max-width-function (el max-width)
16409b0b
GM
61 `(let* ((val (eval (, el)))
62 (valstr (if (numberp val)
63 (int-to-string val) val)))
64 (if (> (length valstr) ,max-width)
65 (truncate-string-to-width valstr ,max-width)
66 valstr)))
6748645f 67
eec82323 68(eval-and-compile
06c43cdf 69 (if (featurep 'xemacs)
16409b0b 70 (gnus-xmas-define)
eec82323 71 (defvar gnus-mouse-face-prop 'mouse-face
16409b0b 72 "Property used for highlighting mouse regions.")))
eec82323 73
9efa445f
DN
74(defvar gnus-tmp-unread)
75(defvar gnus-tmp-replied)
76(defvar gnus-tmp-score-char)
77(defvar gnus-tmp-indentation)
78(defvar gnus-tmp-opening-bracket)
79(defvar gnus-tmp-lines)
80(defvar gnus-tmp-name)
81(defvar gnus-tmp-closing-bracket)
82(defvar gnus-tmp-subject-or-nil)
83(defvar gnus-check-before-posting)
84(defvar gnus-mouse-face)
85(defvar gnus-group-buffer)
eec82323
LMI
86
87(defun gnus-ems-redefine ()
88 (cond
4ddf0e64 89 ((featurep 'xemacs)
eec82323
LMI
90 (gnus-xmas-redefine))
91
92 ((featurep 'mule)
93 ;; Mule and new Emacs definitions
94
95 ;; [Note] Now there are three kinds of mule implementations,
16409b0b 96 ;; original MULE, XEmacs/mule and Emacs 20+ including
23f87bed
MB
97 ;; MULE features. Unfortunately these APIs are different. In
98 ;; particular, Emacs (including original Mule) and XEmacs are
feee6240 99 ;; quite different. However, this version of Gnus doesn't support
16409b0b
GM
100 ;; anything other than XEmacs 20+ and Emacs 20.3+.
101
eec82323 102 ;; Predicates to check are following:
23f87bed 103 ;; (boundp 'MULE) is t only if Mule (original; anything older than
eec82323 104 ;; Mule 2.3) is running.
23f87bed 105 ;; (featurep 'mule) is t when other mule variants are running.
eec82323 106
16409b0b 107 ;; It is possible to detect XEmacs/mule by (featurep 'mule) and
23f87bed 108 ;; (featurep 'xemacs). In this case, the implementation for
16409b0b 109 ;; XEmacs/mule may be shareable between XEmacs and XEmacs/mule.
eec82323
LMI
110
111 (defvar gnus-summary-display-table nil
112 "Display table used in summary mode buffers.")
16409b0b 113 (defalias 'gnus-max-width-function 'gnus-mule-max-width-function)
eec82323
LMI
114
115 (when (boundp 'gnus-check-before-posting)
116 (setq gnus-check-before-posting
117 (delq 'long-lines
118 (delq 'control-chars gnus-check-before-posting))))
119
120 (defun gnus-summary-line-format-spec ()
121 (insert gnus-tmp-unread gnus-tmp-replied
122 gnus-tmp-score-char gnus-tmp-indentation)
123 (put-text-property
124 (point)
125 (progn
126 (insert
127 gnus-tmp-opening-bracket
128 (format "%4d: %-20s"
129 gnus-tmp-lines
130 (if (> (length gnus-tmp-name) 20)
16409b0b 131 (truncate-string-to-width gnus-tmp-name 20)
eec82323
LMI
132 gnus-tmp-name))
133 gnus-tmp-closing-bracket)
134 (point))
135 gnus-mouse-face-prop gnus-mouse-face)
16409b0b 136 (insert " " gnus-tmp-subject-or-nil "\n")))))
eec82323 137
01c52d31
MB
138;; Clone of `appt-select-lowest-window' in appt.el.
139(defun gnus-select-lowest-window ()
140"Select the lowest window on the frame."
141 (let ((lowest-window (selected-window))
142 (bottom-edge (nth 3 (window-edges))))
143 (walk-windows (lambda (w)
144 (let ((next-bottom-edge (nth 3 (window-edges w))))
145 (when (< bottom-edge next-bottom-edge)
146 (setq bottom-edge next-bottom-edge
147 lowest-window w)))))
148 (select-window lowest-window)))
149
eec82323
LMI
150(defun gnus-region-active-p ()
151 "Say whether the region is active."
152 (and (boundp 'transient-mark-mode)
153 transient-mark-mode
154 (boundp 'mark-active)
155 mark-active))
156
23f87bed
MB
157(defun gnus-mark-active-p ()
158 "Non-nil means the mark and region are currently active in this buffer."
159 mark-active) ; aliased to region-exists-p in XEmacs.
160
db48b197 161(autoload 'gnus-alive-p "gnus-util")
407da272 162(autoload 'mm-disable-multibyte "mm-util")
db48b197 163
23f87bed
MB
164;;; Image functions.
165
166(defun gnus-image-type-available-p (type)
167 (and (fboundp 'image-type-available-p)
11e95b02
MB
168 (if (fboundp 'display-images-p)
169 (display-images-p)
ebada6e0
TZ
170 t)
171 (image-type-available-p type)))
23f87bed
MB
172
173(defun gnus-create-image (file &optional type data-p &rest props)
174 (let ((face (plist-get props :face)))
175 (when face
176 (setq props (plist-put props :foreground (face-foreground face)))
177 (setq props (plist-put props :background (face-background face))))
4478e074
G
178 (ignore-errors
179 (apply 'create-image file type data-p props))))
23f87bed 180
0c32d782
KY
181(defun gnus-put-image (glyph &optional string category)
182 (let ((point (point)))
4ddab346 183 (insert-image glyph (or string " "))
0c32d782
KY
184 (put-text-property point (point) 'gnus-image-category category)
185 (unless string
186 (put-text-property (1- (point)) (point)
187 'gnus-image-text-deletable t))
23f87bed
MB
188 glyph))
189
190(defun gnus-remove-image (image &optional category)
01c52d31
MB
191 "Remove the image matching IMAGE and CATEGORY found first."
192 (let ((start (point-min))
193 val end)
194 (while (and (not end)
195 (or (setq val (get-text-property start 'display))
196 (and (setq start
197 (next-single-property-change start 'display))
198 (setq val (get-text-property start 'display)))))
199 (setq end (or (next-single-property-change start 'display)
200 (point-max)))
201 (if (and (equal val image)
202 (equal (get-text-property start 'gnus-image-category)
23f87bed 203 category))
01c52d31
MB
204 (progn
205 (put-text-property start end 'display nil)
206 (when (get-text-property start 'gnus-image-text-deletable)
207 (delete-region start end)))
208 (unless (= end (point-max))
209 (setq start end
210 end nil))))))
6748645f 211
c7b98a1c 212(defmacro gnus-string-mark-left-to-right (string)
e21bac42
G
213 (if (fboundp 'bidi-string-mark-left-to-right)
214 `(bidi-string-mark-left-to-right ,string)
c7b98a1c
G
215 string))
216
a14b3417 217(eval-and-compile
a41c2e6d
G
218 ;; XEmacs does not have window-inside-pixel-edges
219 (defalias 'gnus-window-inside-pixel-edges
220 (if (fboundp 'window-inside-pixel-edges)
221 'window-inside-pixel-edges
222 'window-pixel-edges))
223
cf6a9685
GM
224 (if (or (featurep 'emacs) (fboundp 'set-process-plist))
225 (progn ; these exist since Emacs 22.1
a14b3417
KY
226 (defalias 'gnus-set-process-plist 'set-process-plist)
227 (defalias 'gnus-process-plist 'process-plist)
228 (defalias 'gnus-process-get 'process-get)
229 (defalias 'gnus-process-put 'process-put))
230 (defun gnus-set-process-plist (process plist)
231 "Replace the plist of PROCESS with PLIST. Returns PLIST."
3fb8f8a1
KY
232 (put 'gnus-process-plist-internal process plist))
233
a14b3417
KY
234 (defun gnus-process-plist (process)
235 "Return the plist of PROCESS."
3fb8f8a1
KY
236 ;; This form works but can't prevent the plist data from
237 ;; growing infinitely.
238 ;;(get 'gnus-process-plist-internal process)
239 (let* ((plist (symbol-plist 'gnus-process-plist-internal))
240 (tem (memq process plist)))
241 (prog1
242 (cadr tem)
243 ;; Remove it from the plist data.
244 (when tem
245 (if (eq plist tem)
246 (progn
247 (setcar plist (caddr plist))
248 (setcdr plist (or (cdddr plist) '(nil))))
249 (setcdr (nthcdr (- (length plist) (length tem) 1) plist)
250 (cddr tem)))))))
251
a14b3417
KY
252 (defun gnus-process-get (process propname)
253 "Return the value of PROCESS' PROPNAME property.
254This is the last value stored with `(gnus-process-put PROCESS PROPNAME VALUE)'."
255 (plist-get (gnus-process-plist process) propname))
3fb8f8a1 256
a14b3417
KY
257 (defun gnus-process-put (process propname value)
258 "Change PROCESS' PROPNAME property to VALUE.
259It can be retrieved with `(gnus-process-get PROCESS PROPNAME)'."
260 (gnus-set-process-plist process
b89666af 261 (plist-put (gnus-process-plist process)
a14b3417 262 propname value)))))
2cdd366f 263
eec82323
LMI
264(provide 'gnus-ems)
265
eec82323 266;;; gnus-ems.el ends here