1 ;;; gnus-ems.el --- functions for making Gnus work under different Emacsen
2 ;; Copyright (C) 1995 Free Software Foundation, Inc.
4 ;; Author: Lars Magne Ingebrigtsen <larsi@ifi.uio.no>
7 ;; This file is part of GNU Emacs.
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)
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.
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
21 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
27 (defvar gnus-mouse-2 [mouse-2])
28 (defvar gnus-easymenu 'easymenu)
29 (defvar gnus-group-mode-hook ())
30 (defvar gnus-summary-mode-hook ())
31 (defvar gnus-article-mode-hook ())
33 (defalias 'gnus-make-overlay 'make-overlay)
34 (defalias 'gnus-overlay-put 'overlay-put)
35 (defalias 'gnus-move-overlay 'move-overlay)
37 ;; Don't warn about these undefined variables.
39 (defvar gnus-active-hashtb)
40 (defvar gnus-article-buffer)
41 (defvar gnus-auto-center-summary)
42 (defvar gnus-buffer-list)
43 (defvar gnus-current-headers)
44 (defvar gnus-level-killed)
45 (defvar gnus-level-zombie)
46 (defvar gnus-newsgroup-bookmarks)
47 (defvar gnus-newsgroup-dependencies)
48 (defvar gnus-newsgroup-headers-hashtb-by-number)
49 (defvar gnus-newsgroup-selected-overlay)
50 (defvar gnus-newsrc-hashtb)
51 (defvar gnus-read-mark)
52 (defvar gnus-refer-article-method)
53 (defvar gnus-reffed-article-number)
54 (defvar gnus-unread-mark)
56 (defvar gnus-view-pseudos)
57 (defvar gnus-view-pseudos-separately)
59 (defvar gnus-zombie-list)
60 ;defined in gnus-msg.el
61 (defvar gnus-article-copy)
62 (defvar gnus-check-before-posting)
63 ;defined in gnus-vis.el
64 (defvar gnus-article-button-face)
65 (defvar gnus-article-mouse-face)
66 (defvar gnus-summary-selected-face)
69 ;; We do not byte-compile this file, because error messages are such a
74 (if (string-match "XEmacs\\|Lucid" emacs-version)
76 ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
77 (defvar gnus-display-type
79 (let ((display-resource (x-get-resource ".displayType" "DisplayType")))
80 (cond (display-resource (intern (downcase display-resource)))
81 ((x-display-color-p) 'color)
82 ((x-display-grayscale-p) 'grayscale)
85 "A symbol indicating the display Emacs is running under.
86 The symbol should be one of `color', `grayscale' or `mono'. If Emacs
87 guesses this display attribute wrongly, either set this variable in
88 your `~/.emacs' or set the resource `Emacs.displayType' in your
89 `~/.Xdefaults'. See also `gnus-background-mode'.
91 This is a meta-variable that will affect what default values other
92 variables get. You would normally not change this variable, but
93 pounce directly on the real variables themselves.")
95 (defvar gnus-background-mode
97 (let ((bg-resource (x-get-resource ".backgroundMode"
99 (params (frame-parameters)))
100 (cond (bg-resource (intern (downcase bg-resource)))
101 ((and (cdr (assq 'background-color params))
102 (< (apply '+ (x-color-values
103 (cdr (assq 'background-color params))))
104 (/ (apply '+ (x-color-values "white")) 3)))
108 "A symbol indicating the Emacs background brightness.
109 The symbol should be one of `light' or `dark'.
110 If Emacs guesses this frame attribute wrongly, either set this variable in
111 your `~/.emacs' or set the resource `Emacs.backgroundMode' in your
113 See also `gnus-display-type'.
115 This is a meta-variable that will affect what default values other
116 variables get. You would normally not change this variable, but
117 pounce directly on the real variables themselves."))
120 ((string-match "XEmacs\\|Lucid" emacs-version)
121 ;; XEmacs definitions.
123 (setq gnus-mouse-2 [button2])
124 (setq gnus-easymenu 'auc-menu)
126 (or (memq 'underline (list-faces))
127 (funcall (intern "make-face") 'underline))
128 ;; Must avoid calling set-face-underline-p directly, because it
129 ;; is a defsubst in emacs19, and will make the .elc files non
131 (or (face-differs-from-default-p 'underline)
132 (funcall 'set-face-underline-p 'underline t))
133 (or (fboundp 'set-text-properties)
134 (defun set-text-properties (start end props &optional buffer)
135 (if (or (null buffer) (bufferp buffer))
139 start end (car props) (nth 1 props) buffer)
140 (setq props (nthcdr 2 props)))
141 (remove-text-properties start end ())))))
143 (defalias 'gnus-make-overlay 'make-extent)
144 (defalias 'gnus-overlay-put 'set-extent-property)
145 (defun gnus-move-overlay (extent start end &optional buffer)
146 (set-extent-endpoints extent start end))
148 (or (boundp 'standard-display-table) (setq standard-display-table nil))
149 (or (boundp 'read-event) (fset 'read-event 'next-command-event))
151 ;; Fix by "jeff (j.d.) sparkes" <jsparkes@bnr.ca>.
152 (defvar gnus-display-type (device-class)
153 "A symbol indicating the display Emacs is running under.
154 The symbol should be one of `color', `grayscale' or `mono'. If Emacs
155 guesses this display attribute wrongly, either set this variable in
156 your `~/.emacs' or set the resource `Emacs.displayType' in your
157 `~/.Xdefaults'. See also `gnus-background-mode'.
159 This is a meta-variable that will affect what default values other
160 variables get. You would normally not change this variable, but
161 pounce directly on the real variables themselves.")
164 (or (fboundp 'x-color-values)
165 (fset 'x-color-values
167 (color-instance-rgb-components
168 (make-color-instance color)))))
170 (defvar gnus-background-mode
172 (x-get-resource ".backgroundMode" "BackgroundMode" 'string))
173 (params (frame-parameters)))
174 (cond (bg-resource (intern (downcase bg-resource)))
175 ((and (assq 'background-color params)
176 (< (apply '+ (x-color-values
177 (cdr (assq 'background-color params))))
178 (/ (apply '+ (x-color-values "white")) 3)))
181 "A symbol indicating the Emacs background brightness.
182 The symbol should be one of `light' or `dark'.
183 If Emacs guesses this frame attribute wrongly, either set this variable in
184 your `~/.emacs' or set the resource `Emacs.backgroundMode' in your
186 See also `gnus-display-type'.
188 This is a meta-variable that will affect what default values other
189 variables get. You would normally not change this variable, but
190 pounce directly on the real variables themselves.")
193 (defun gnus-install-mouse-tracker ()
194 (require 'mode-motion)
195 (setq mode-motion-hook 'mode-motion-highlight-line)))
197 ((and (not (string-match "28.9" emacs-version))
198 (not (string-match "29" emacs-version)))
199 ;; Remove the `intangible' prop.
200 (let ((props gnus-hidden-properties))
201 (while (and props (not (eq (car (cdr props)) 'intangible)))
202 (setq props (cdr props)))
203 (and props (setcdr props (cdr (cdr (cdr props))))))
204 (or (fboundp 'buffer-substring-no-properties)
205 (defun buffer-substring-no-properties (beg end)
206 (format "%s" (buffer-substring beg end)))))
216 (defun gnus-dummy-func (&rest args))
217 (let ((funcs '(mouse-set-point set-face-foreground
218 set-face-background x-popup-menu)))
220 (or (fboundp (car funcs))
221 (fset (car funcs) 'gnus-dummy-func))
222 (setq funcs (cdr funcs))))))
223 (or (fboundp 'file-regular-p)
224 (defun file-regular-p (file)
225 (and (not (file-directory-p file))
226 (not (file-symlink-p file))
227 (file-exists-p file))))
228 (or (fboundp 'face-list)
229 (defun face-list (&rest args)))
232 (defun gnus-highlight-selected-summary-xemacs ()
233 ;; Highlight selected article in summary buffer
234 (if gnus-summary-selected-face
236 (if gnus-newsgroup-selected-overlay
237 (delete-extent gnus-newsgroup-selected-overlay))
238 (setq gnus-newsgroup-selected-overlay
239 (make-extent (gnus-point-at-bol) (gnus-point-at-eol)))
240 (set-extent-face gnus-newsgroup-selected-overlay
241 gnus-summary-selected-face))))
243 (defun gnus-summary-recenter-xemacs ()
244 (let* ((top (cond ((< (window-height) 4) 0)
245 ((< (window-height) 7) 1)
247 (height (- (window-height) 2))
248 (bottom (save-excursion (goto-char (point-max))
249 (forward-line (- height))
251 (window (get-buffer-window (current-buffer))))
253 ;; The user has to want it,
254 gnus-auto-center-summary
255 ;; the article buffer must be displayed,
256 (get-buffer-window gnus-article-buffer)
257 ;; Set the window start to either `bottom', which is the biggest
258 ;; possible valid number, or the second line from the top,
259 ;; whichever is the least.
261 window (min bottom (save-excursion (forward-line (- top))
264 (defun gnus-group-insert-group-line-info-xemacs (group)
265 (let ((entry (gnus-gethash group gnus-newsrc-hashtb))
270 (setq info (nth 2 entry))
271 (gnus-group-insert-group-line
272 nil group (nth 1 info) (nth 3 info) (car entry) (nth 4 info)))
273 (setq active (gnus-gethash group gnus-active-hashtb))
275 (gnus-group-insert-group-line
276 nil group (if (member group gnus-zombie-list) gnus-level-zombie
278 nil (if active (- (1+ (cdr active)) (car active)) 0) nil))
281 (remove-text-properties
282 (1+ (gnus-point-at-bol)) (1+ (gnus-point-at-eol))
283 '(gnus-group nil)))))
285 (defun gnus-summary-refer-article-xemacs (message-id)
286 "Refer article specified by MESSAGE-ID.
287 NOTE: This command only works with newsgroups that use real or simulated NNTP."
288 (interactive "sMessage-ID: ")
289 (if (or (not (stringp message-id))
290 (zerop (length message-id)))
292 ;; Construct the correct Message-ID if necessary.
293 ;; Suggested by tale@pawl.rpi.edu.
294 (or (string-match "^<" message-id)
295 (setq message-id (concat "<" message-id)))
296 (or (string-match ">$" message-id)
297 (setq message-id (concat message-id ">")))
298 (let ((header (car (gnus-gethash (downcase message-id)
299 gnus-newsgroup-dependencies))))
301 (or (gnus-summary-goto-article (header-number header))
302 ;; The header has been read, but the article had been
303 ;; expunged, so we insert it again.
305 (gnus-summary-insert-line
306 nil header 0 nil gnus-read-mark nil nil
307 (header-subject header))
310 (remove-text-properties
311 (1+ (gnus-point-at-bol)) (1+ (gnus-point-at-eol))
312 '(gnus-number nil gnus-mark nil gnus-level nil)))
314 (header-number header)))
315 (let ((gnus-override-method gnus-refer-article-method)
316 (gnus-ancient-mark gnus-read-mark)
317 (tmp-buf (get-buffer-create " *gnus refer"))
318 (tmp-point (window-start
319 (get-buffer-window gnus-article-buffer)))
321 (and gnus-refer-article-method
322 (or (gnus-server-opened gnus-refer-article-method)
323 (gnus-open-server gnus-refer-article-method)))
324 ;; Save the old article buffer.
327 (buffer-disable-undo (current-buffer))
328 (insert-buffer-substring gnus-article-buffer))
330 (if (gnus-article-prepare
331 message-id nil (gnus-read-header message-id))
333 (setq number (header-number gnus-current-headers))
334 (gnus-rebuild-thread message-id)
335 (gnus-summary-goto-subject number)
336 (gnus-summary-recenter)
337 (gnus-article-set-window-start
338 (cdr (assq number gnus-newsgroup-bookmarks)))
340 ;; We restore the old article buffer.
342 (set-buffer gnus-article-buffer)
343 (let ((buffer-read-only nil))
344 (insert-buffer-substring tmp-buf)
346 (set-window-start (get-buffer-window (current-buffer))
349 (kill-buffer tmp-buf)))))))
351 (defun gnus-summary-insert-pseudos-xemacs (pslist &optional not-view)
352 (let ((buffer-read-only nil)
353 (article (gnus-summary-article-number))
355 (or (gnus-summary-goto-subject article)
356 (error (format "No such article: %d" article)))
357 (or gnus-newsgroup-headers-hashtb-by-number
358 (gnus-make-headers-hashtable-by-number))
359 (gnus-summary-position-cursor)
360 ;; If all commands are to be bunched up on one line, we collect
362 (if gnus-view-pseudos-separately
364 (let ((ps (setq pslist (sort pslist 'gnus-pseudos<)))
367 (setq action (cdr (assq 'action (car ps))))
368 (setq files (list (cdr (assq 'name (car ps)))))
369 (while (and ps (cdr ps)
370 (string= (or action "1")
371 (or (cdr (assq 'action (car (cdr ps)))) "2")))
372 (setq files (cons (cdr (assq 'name (car (cdr ps)))) files))
373 (setcdr ps (cdr (cdr ps))))
376 (if (not (string-match "%s" action))
377 (setq files (cons " " files)))
378 (setq files (cons " " files))
379 (and (assq 'execute (car ps))
380 (setcdr (assq 'execute (car ps))
381 (funcall (if (string-match "%s" action)
384 (mapconcat (lambda (f) f) files " ")))))
385 (setq ps (cdr ps)))))
386 (if (and gnus-view-pseudos (not not-view))
388 (and (assq 'execute (car pslist))
389 (gnus-execute-command (cdr (assq 'execute (car pslist)))
390 (eq gnus-view-pseudos 'not-confirm)))
391 (setq pslist (cdr pslist)))
394 (gnus-summary-goto-subject (or (cdr (assq 'article (car pslist)))
395 (gnus-summary-article-number)))
399 (file-name-nondirectory (cdr (assq 'name (car pslist))))
400 ": " (or (cdr (assq 'execute (car pslist))) "") "\n")
402 b (1+ b) (list 'gnus-number gnus-reffed-article-number
403 'gnus-mark gnus-unread-mark
405 'gnus-pseudo (car pslist)))
406 ;; Fucking XEmacs redisplay bug with truncated lines.
409 ;; Grumble.. Fucking XEmacs stickyness of text properties.
410 (remove-text-properties
411 (1+ b) (1+ (gnus-point-at-eol))
412 '(gnus-number nil gnus-mark nil gnus-level nil))
414 (gnus-sethash (int-to-string gnus-reffed-article-number)
415 (car pslist) gnus-newsgroup-headers-hashtb-by-number)
416 (setq gnus-reffed-article-number (1- gnus-reffed-article-number))
417 (setq pslist (cdr pslist)))))))
420 (defun gnus-copy-article-buffer-xemacs (&optional article-buffer)
421 (setq gnus-article-copy (get-buffer-create " *gnus article copy*"))
422 (buffer-disable-undo gnus-article-copy)
423 (or (memq gnus-article-copy gnus-buffer-list)
424 (setq gnus-buffer-list (cons gnus-article-copy gnus-buffer-list)))
425 (let ((article-buffer (or article-buffer gnus-article-buffer))
427 (if (and (get-buffer article-buffer)
428 (buffer-name (get-buffer article-buffer)))
430 (set-buffer article-buffer)
432 (setq buf (buffer-substring (point-min) (point-max)))
433 (set-buffer gnus-article-copy)
435 (insert (format "%s" buf))))))
437 (defun gnus-article-push-button-xemacs (event)
438 "Check text under the mouse pointer for a callback function.
439 If the text under the mouse pointer has a `gnus-callback' property,
440 call it with the value of the `gnus-data' text property."
442 (set-buffer (window-buffer (event-window event)))
443 (let* ((pos (event-closest-point event))
444 (data (get-text-property pos 'gnus-data))
445 (fun (get-text-property pos 'gnus-callback)))
446 (if fun (funcall fun data))))
448 ;; Re-build the thread containing ID.
449 (defun gnus-rebuild-thread-xemacs (id)
450 (let ((dep gnus-newsgroup-dependencies)
451 (buffer-read-only nil)
452 parent headers refs thread art)
453 (while (and id (setq headers
454 (car (setq art (gnus-gethash (downcase id)
457 (setq id (and (setq refs (header-references headers))
458 (string-match "\\(<[^>]+>\\) *$" refs)
459 (substring refs (match-beginning 1) (match-end 1)))))
460 (setq thread (gnus-make-sub-thread (car parent)))
461 (gnus-rebuild-remove-articles thread)
463 (gnus-summary-prepare-threads (list thread) 0)
465 (while (and (>= (point) beg)
467 (remove-text-properties
468 (1+ (gnus-point-at-bol)) (1+ (gnus-point-at-eol))
469 '(gnus-number nil gnus-mark nil gnus-level nil))
471 (gnus-summary-update-lines beg (point)))))
474 ;; Fixed by Christopher Davis <ckd@loiosh.kei.com>.
475 (defun gnus-article-add-button-xemacs (from to fun &optional data)
476 "Create a button between FROM and TO with callback FUN and data DATA."
477 (and gnus-article-button-face
478 (gnus-overlay-put (gnus-make-overlay from to) 'face gnus-article-button-face))
479 (add-text-properties from to
481 (and gnus-article-mouse-face
482 (list 'mouse-face gnus-article-mouse-face))
483 (list 'gnus-callback fun)
484 (and data (list 'gnus-data data))
485 (list 'highlight t))))
487 (defun gnus-window-left-corner-xemacs (&optional window)
488 (nth 1 (window-pixel-edges window)))
490 (defun gnus-ems-redefine ()
492 ((string-match "XEmacs\\|Lucid" emacs-version)
493 ;; XEmacs definitions.
494 (fset 'gnus-mouse-face-function 'identity)
495 (fset 'gnus-summary-make-display-table (lambda () nil))
496 (fset 'gnus-visual-turn-off-edit-menu 'identity)
497 (fset 'gnus-highlight-selected-summary
498 'gnus-highlight-selected-summary-xemacs)
499 (fset 'gnus-summary-recenter 'gnus-summary-recenter-xemacs)
500 (fset 'gnus-group-insert-group-line-info
501 'gnus-group-insert-group-line-info-xemacs)
502 (fset 'gnus-copy-article-buffer 'gnus-copy-article-buffer-xemacs)
503 (fset 'gnus-summary-refer-article 'gnus-summary-refer-article-xemacs)
504 (fset 'gnus-summary-insert-pseudos 'gnus-summary-insert-pseudos-xemacs)
505 (fset 'gnus-article-push-button 'gnus-article-push-button-xemacs)
506 (fset 'gnus-rebuild-thread 'gnus-rebuild-thread-xemacs)
507 (fset 'gnus-article-add-button 'gnus-article-add-button-xemacs)
508 (fset 'gnus-window-left-corner 'gnus-window-left-corner-xemacs)
510 (if (not gnus-visual)
512 (setq gnus-group-mode-hook
515 (easy-menu-add gnus-group-reading-menu)
516 (easy-menu-add gnus-group-group-menu)
517 (easy-menu-add gnus-group-misc-menu)
518 (gnus-install-mouse-tracker))
519 gnus-group-mode-hook))
520 (setq gnus-summary-mode-hook
523 (easy-menu-add gnus-summary-mark-menu)
524 (easy-menu-add gnus-summary-move-menu)
525 (easy-menu-add gnus-summary-article-menu)
526 (easy-menu-add gnus-summary-thread-menu)
527 (easy-menu-add gnus-summary-misc-menu)
528 (easy-menu-add gnus-summary-post-menu)
529 (easy-menu-add gnus-summary-kill-menu)
530 (gnus-install-mouse-tracker))
531 gnus-summary-mode-hook))
532 (setq gnus-article-mode-hook
535 (easy-menu-add gnus-article-article-menu)
536 (easy-menu-add gnus-article-treatment-menu))
537 gnus-article-mode-hook)))
539 (defvar gnus-logo (make-glyph (make-specifier 'image)))
541 (defun gnus-group-startup-xmessage (&optional x y)
542 "Insert startup message in current buffer."
543 ;; Insert the message.
547 (set-glyph-property gnus-logo 'image "~/tmp/gnus.xpm")
548 (set-glyph-image gnus-logo "~/tmp/gnus.xpm" 'global 'x)
551 (set-extent-begin-glyph (make-extent (point) (point)) gnus-logo)
553 Gnus * A newsreader for Emacsen
554 A Praxis Release * larsi@ifi.uio.no")
555 (goto-char (point-min))
557 (insert (make-string (/ (max (- (window-width) (or x 35)) 0) 2)
560 (goto-char (point-min))
561 ;; +4 is fuzzy factor.
562 (insert-char ?\n (/ (max (- (window-height) (or y 24)) 0) 2)))
579 ;; 18 is the longest line.
580 (indent-rigidly (point-min) (point-max)
581 (/ (max (- (window-width) (or x 28)) 0) 2))
582 (goto-char (point-min))
583 ;; +4 is fuzzy factor.
584 (insert-char ?\n (/ (max (- (window-height) (or y 12)) 0) 2)))
587 (goto-char (point-min))
588 (search-forward "Praxis")
589 (put-text-property (match-beginning 0) (match-end 0) 'face 'bold)
590 (goto-char (point-min)))
598 (if (not (fboundp 'truncate-string))
599 (defun truncate-string (str width)
600 (let ((w (string-width str))
601 (col 0) (idx 0) (p-idx 0) chr)
605 (setq chr (aref str idx)
606 col (+ col (char-width chr))
608 idx (+ idx (char-bytes chr))
610 (substring str 0 (if (= col width)
615 (defalias 'gnus-truncate-string 'truncate-string)
617 (defun gnus-cite-add-face (number prefix face)
618 ;; At line NUMBER, ignore PREFIX and add FACE to the rest of the line.
620 (let ((inhibit-point-motion-hooks t)
624 (forward-char (chars-in-string prefix))
625 (forward-char (length prefix)))
626 (skip-chars-forward " \t")
629 (skip-chars-backward " \t")
632 (gnus-overlay-put (gnus-make-overlay from to) 'face face)))))
634 (defun gnus-max-width-function (el max-width)
635 (` (let* ((val (eval (, el)))
636 (valstr (if (numberp val)
637 (int-to-string val) val)))
638 (if (> (length valstr) (, max-width))
639 (truncate-string valstr (, max-width))
642 (fset 'gnus-summary-make-display-table (lambda () nil))
644 (if (boundp 'gnus-check-before-posting)
645 (setq gnus-check-before-posting
647 (delq 'control-chars gnus-check-before-posting)))
655 ;; byte-compile-warnings: '(redefine callargs)
658 ;;; gnus-ems.el ends here