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 (and (fboundp 'make-face)
128 (funcall (intern "make-face") 'underline)))
129 ;; Must avoid calling set-face-underline-p directly, because it
130 ;; is a defsubst in emacs19, and will make the .elc files non
132 (or (face-differs-from-default-p 'underline)
133 (funcall 'set-face-underline-p 'underline t))
134 (or (fboundp 'set-text-properties)
135 (defun set-text-properties (start end props &optional buffer)
136 (if (or (null buffer) (bufferp buffer))
140 start end (car props) (nth 1 props) buffer)
141 (setq props (nthcdr 2 props)))
142 (remove-text-properties start end ())))))
144 (defalias 'gnus-make-overlay 'make-extent)
145 (defalias 'gnus-overlay-put 'set-extent-property)
146 (defun gnus-move-overlay (extent start end &optional buffer)
147 (set-extent-endpoints extent start end))
149 (or (boundp 'standard-display-table) (setq standard-display-table nil))
150 (or (boundp 'read-event) (fset 'read-event 'next-command-event))
152 ;; Fix by "jeff (j.d.) sparkes" <jsparkes@bnr.ca>.
153 (defvar gnus-display-type (device-class)
154 "A symbol indicating the display Emacs is running under.
155 The symbol should be one of `color', `grayscale' or `mono'. If Emacs
156 guesses this display attribute wrongly, either set this variable in
157 your `~/.emacs' or set the resource `Emacs.displayType' in your
158 `~/.Xdefaults'. See also `gnus-background-mode'.
160 This is a meta-variable that will affect what default values other
161 variables get. You would normally not change this variable, but
162 pounce directly on the real variables themselves.")
165 (or (fboundp 'x-color-values)
166 (fset 'x-color-values
168 (color-instance-rgb-components
169 (make-color-instance color)))))
171 (defvar gnus-background-mode
174 (x-get-resource ".backgroundMode" "BackgroundMode" 'string)
176 (params (frame-parameters)))
177 (cond (bg-resource (intern (downcase bg-resource)))
178 ((and (assq 'background-color params)
179 (< (apply '+ (x-color-values
180 (cdr (assq 'background-color params))))
181 (/ (apply '+ (x-color-values "white")) 3)))
184 "A symbol indicating the Emacs background brightness.
185 The symbol should be one of `light' or `dark'.
186 If Emacs guesses this frame attribute wrongly, either set this variable in
187 your `~/.emacs' or set the resource `Emacs.backgroundMode' in your
189 See also `gnus-display-type'.
191 This is a meta-variable that will affect what default values other
192 variables get. You would normally not change this variable, but
193 pounce directly on the real variables themselves.")
196 (defun gnus-install-mouse-tracker ()
197 (require 'mode-motion)
198 (setq mode-motion-hook 'mode-motion-highlight-line)))
200 ((and (not (string-match "28.9" emacs-version))
201 (not (string-match "29" emacs-version)))
202 ;; Remove the `intangible' prop.
203 (let ((props (and (boundp 'gnus-hidden-properties)
204 gnus-hidden-properties)))
205 (while (and props (not (eq (car (cdr props)) 'intangible)))
206 (setq props (cdr props)))
207 (and props (setcdr props (cdr (cdr (cdr props))))))
208 (or (fboundp 'buffer-substring-no-properties)
209 (defun buffer-substring-no-properties (beg end)
210 (format "%s" (buffer-substring beg end)))))
220 (defun gnus-dummy-func (&rest args))
221 (let ((funcs '(mouse-set-point set-face-foreground
222 set-face-background x-popup-menu)))
224 (or (fboundp (car funcs))
225 (fset (car funcs) 'gnus-dummy-func))
226 (setq funcs (cdr funcs))))))
227 (or (fboundp 'file-regular-p)
228 (defun file-regular-p (file)
229 (and (not (file-directory-p file))
230 (not (file-symlink-p file))
231 (file-exists-p file))))
232 (or (fboundp 'face-list)
233 (defun face-list (&rest args)))
236 (defun gnus-highlight-selected-summary-xemacs ()
237 ;; Highlight selected article in summary buffer
238 (if gnus-summary-selected-face
240 (if gnus-newsgroup-selected-overlay
241 (delete-extent gnus-newsgroup-selected-overlay))
242 (setq gnus-newsgroup-selected-overlay
243 (make-extent (gnus-point-at-bol) (gnus-point-at-eol)))
244 (set-extent-face gnus-newsgroup-selected-overlay
245 gnus-summary-selected-face))))
247 (defun gnus-summary-recenter-xemacs ()
248 (let* ((top (cond ((< (window-height) 4) 0)
249 ((< (window-height) 7) 1)
251 (height (- (window-height) 2))
252 (bottom (save-excursion (goto-char (point-max))
253 (forward-line (- height))
255 (window (get-buffer-window (current-buffer))))
257 ;; The user has to want it,
258 gnus-auto-center-summary
259 ;; the article buffer must be displayed,
260 (get-buffer-window gnus-article-buffer)
261 ;; Set the window start to either `bottom', which is the biggest
262 ;; possible valid number, or the second line from the top,
263 ;; whichever is the least.
265 window (min bottom (save-excursion (forward-line (- top))
268 (defun gnus-group-insert-group-line-info-xemacs (group)
269 (let ((entry (gnus-gethash group gnus-newsrc-hashtb))
274 (setq info (nth 2 entry))
275 (gnus-group-insert-group-line
276 nil group (nth 1 info) (nth 3 info) (car entry) (nth 4 info)))
277 (setq active (gnus-gethash group gnus-active-hashtb))
279 (gnus-group-insert-group-line
280 nil group (if (member group gnus-zombie-list) gnus-level-zombie
282 nil (if active (- (1+ (cdr active)) (car active)) 0) nil))
285 (remove-text-properties
286 (1+ (gnus-point-at-bol)) (1+ (gnus-point-at-eol))
287 '(gnus-group nil)))))
289 (defun gnus-summary-refer-article-xemacs (message-id)
290 "Refer article specified by MESSAGE-ID.
291 NOTE: This command only works with newsgroups that use real or simulated NNTP."
292 (interactive "sMessage-ID: ")
293 (if (or (not (stringp message-id))
294 (zerop (length message-id)))
296 ;; Construct the correct Message-ID if necessary.
297 ;; Suggested by tale@pawl.rpi.edu.
298 (or (string-match "^<" message-id)
299 (setq message-id (concat "<" message-id)))
300 (or (string-match ">$" message-id)
301 (setq message-id (concat message-id ">")))
302 (let ((header (car (gnus-gethash (downcase message-id)
303 gnus-newsgroup-dependencies))))
305 (or (gnus-summary-goto-article (mail-header-number header))
306 ;; The header has been read, but the article had been
307 ;; expunged, so we insert it again.
309 (gnus-summary-insert-line
310 nil header 0 nil gnus-read-mark nil nil
311 (mail-header-subject header))
314 (remove-text-properties
315 (1+ (gnus-point-at-bol)) (1+ (gnus-point-at-eol))
316 '(gnus-number nil gnus-mark nil gnus-level nil)))
318 (mail-header-number header)))
319 (let ((gnus-override-method gnus-refer-article-method)
320 (gnus-ancient-mark gnus-read-mark)
321 (tmp-point (window-start
322 (get-buffer-window gnus-article-buffer)))
324 (and gnus-refer-article-method
325 (gnus-check-server gnus-refer-article-method))
326 ;; Save the old article buffer.
328 (set-buffer gnus-article-buffer)
329 (gnus-kill-buffer " *temp Article*")
330 (setq tmp-buf (rename-buffer " *temp Article*")))
332 (if (gnus-article-prepare
333 message-id nil (gnus-read-header message-id))
335 (setq number (mail-header-number gnus-current-headers))
336 (gnus-rebuild-thread message-id)
337 (gnus-summary-goto-subject number)
338 (gnus-summary-recenter)
339 (gnus-article-set-window-start
340 (cdr (assq number gnus-newsgroup-bookmarks)))
342 ;; We restore the old article buffer.
344 (kill-buffer gnus-article-buffer)
346 (rename-buffer gnus-article-buffer)
347 (let ((buffer-read-only nil))
349 (set-window-start (get-buffer-window (current-buffer))
352 (defun gnus-summary-insert-pseudos-xemacs (pslist &optional not-view)
353 (let ((buffer-read-only nil)
354 (article (gnus-summary-article-number))
356 (or (gnus-summary-goto-subject article)
357 (error (format "No such article: %d" article)))
358 (or gnus-newsgroup-headers-hashtb-by-number
359 (gnus-make-headers-hashtable-by-number))
360 (gnus-summary-position-cursor)
361 ;; If all commands are to be bunched up on one line, we collect
363 (if gnus-view-pseudos-separately
365 (let ((ps (setq pslist (sort pslist 'gnus-pseudos<)))
368 (setq action (cdr (assq 'action (car ps))))
369 (setq files (list (cdr (assq 'name (car ps)))))
370 (while (and ps (cdr ps)
371 (string= (or action "1")
372 (or (cdr (assq 'action (car (cdr ps)))) "2")))
373 (setq files (cons (cdr (assq 'name (car (cdr ps)))) files))
374 (setcdr ps (cdr (cdr ps))))
377 (if (not (string-match "%s" action))
378 (setq files (cons " " files)))
379 (setq files (cons " " files))
380 (and (assq 'execute (car ps))
381 (setcdr (assq 'execute (car ps))
382 (funcall (if (string-match "%s" action)
385 (mapconcat (lambda (f) f) files " ")))))
386 (setq ps (cdr ps)))))
387 (if (and gnus-view-pseudos (not not-view))
389 (and (assq 'execute (car pslist))
390 (gnus-execute-command (cdr (assq 'execute (car pslist)))
391 (eq gnus-view-pseudos 'not-confirm)))
392 (setq pslist (cdr pslist)))
395 (gnus-summary-goto-subject (or (cdr (assq 'article (car pslist)))
396 (gnus-summary-article-number)))
400 (file-name-nondirectory (cdr (assq 'name (car pslist))))
401 ": " (or (cdr (assq 'execute (car pslist))) "") "\n")
403 b (1+ b) (list 'gnus-number gnus-reffed-article-number
404 'gnus-mark gnus-unread-mark
406 'gnus-pseudo (car pslist)))
407 ;; Fucking XEmacs redisplay bug with truncated lines.
410 ;; Grumble.. Fucking XEmacs stickyness of text properties.
411 (remove-text-properties
412 (1+ b) (1+ (gnus-point-at-eol))
413 '(gnus-number nil gnus-mark nil gnus-level nil))
415 (gnus-sethash (int-to-string gnus-reffed-article-number)
416 (car pslist) gnus-newsgroup-headers-hashtb-by-number)
417 (setq gnus-reffed-article-number (1- gnus-reffed-article-number))
418 (setq pslist (cdr pslist)))))))
421 (defun gnus-copy-article-buffer-xemacs (&optional article-buffer)
422 (setq gnus-article-copy (get-buffer-create " *gnus article copy*"))
423 (buffer-disable-undo gnus-article-copy)
424 (or (memq gnus-article-copy gnus-buffer-list)
425 (setq gnus-buffer-list (cons gnus-article-copy gnus-buffer-list)))
426 (let ((article-buffer (or article-buffer gnus-article-buffer))
428 (if (and (get-buffer article-buffer)
429 (buffer-name (get-buffer article-buffer)))
431 (set-buffer article-buffer)
433 (setq buf (buffer-substring (point-min) (point-max)))
434 (set-buffer gnus-article-copy)
436 (insert (format "%s" buf))))))
438 (defun gnus-article-push-button-xemacs (event)
439 "Check text under the mouse pointer for a callback function.
440 If the text under the mouse pointer has a `gnus-callback' property,
441 call it with the value of the `gnus-data' text property."
443 (set-buffer (window-buffer (event-window event)))
444 (let* ((pos (event-closest-point event))
445 (data (get-text-property pos 'gnus-data))
446 (fun (get-text-property pos 'gnus-callback)))
447 (if fun (funcall fun data))))
449 ;; Re-build the thread containing ID.
450 (defun gnus-rebuild-thread-xemacs (id)
451 (let ((dep gnus-newsgroup-dependencies)
452 (buffer-read-only nil)
453 parent headers refs thread art)
454 (while (and id (setq headers
455 (car (setq art (gnus-gethash (downcase id)
458 (setq id (and (setq refs (mail-header-references headers))
459 (string-match "\\(<[^>]+>\\) *$" refs)
460 (substring refs (match-beginning 1) (match-end 1)))))
461 (setq thread (gnus-make-sub-thread (car parent)))
462 (gnus-rebuild-remove-articles thread)
464 (gnus-summary-prepare-threads (list thread) 0)
466 (while (and (>= (point) beg)
469 (remove-text-properties
470 (1+ (gnus-point-at-bol)) (1+ (gnus-point-at-eol))
471 '(gnus-number nil gnus-mark nil gnus-level nil)))
473 (gnus-summary-update-lines beg (point)))))
476 ;; Fixed by Christopher Davis <ckd@loiosh.kei.com>.
477 (defun gnus-article-add-button-xemacs (from to fun &optional data)
478 "Create a button between FROM and TO with callback FUN and data DATA."
479 (and gnus-article-button-face
480 (gnus-overlay-put (gnus-make-overlay from to) 'face gnus-article-button-face))
481 (add-text-properties from to
483 (and gnus-article-mouse-face
484 (list 'mouse-face gnus-article-mouse-face))
485 (list 'gnus-callback fun)
486 (and data (list 'gnus-data data))
487 (list 'highlight t))))
489 (defun gnus-window-top-edge-xemacs (&optional window)
490 (nth 1 (window-pixel-edges window)))
492 ;; Select the lowest window on the frame.
493 (defun gnus-appt-select-lowest-window-xemacs ()
494 (let* ((lowest-window (selected-window))
495 (bottom-edge (car (cdr (cdr (cdr (window-pixel-edges))))))
496 (last-window (previous-window))
499 (let* ((this-window (next-window))
500 (next-bottom-edge (car (cdr (cdr (cdr
503 (if (< bottom-edge next-bottom-edge)
505 (setq bottom-edge next-bottom-edge)
506 (setq lowest-window this-window)))
508 (select-window this-window)
509 (if (eq last-window this-window)
511 (select-window lowest-window)
512 (setq window-search nil)))))))
515 (defun gnus-ems-redefine ()
517 ((string-match "XEmacs\\|Lucid" emacs-version)
518 ;; XEmacs definitions.
519 (fset 'gnus-mouse-face-function 'identity)
520 (fset 'gnus-summary-make-display-table (lambda () nil))
521 (fset 'gnus-visual-turn-off-edit-menu 'identity)
522 (fset 'gnus-highlight-selected-summary
523 'gnus-highlight-selected-summary-xemacs)
524 (fset 'gnus-summary-recenter 'gnus-summary-recenter-xemacs)
525 (fset 'gnus-group-insert-group-line-info
526 'gnus-group-insert-group-line-info-xemacs)
527 (fset 'gnus-copy-article-buffer 'gnus-copy-article-buffer-xemacs)
528 (fset 'gnus-summary-refer-article 'gnus-summary-refer-article-xemacs)
529 (fset 'gnus-summary-insert-pseudos 'gnus-summary-insert-pseudos-xemacs)
530 (fset 'gnus-article-push-button 'gnus-article-push-button-xemacs)
531 (fset 'gnus-rebuild-thread 'gnus-rebuild-thread-xemacs)
532 (fset 'gnus-article-add-button 'gnus-article-add-button-xemacs)
533 (fset 'gnus-window-top-edge 'gnus-window-top-edge-xemacs)
535 (or (fboundp 'appt-select-lowest-window)
536 (fset 'appt-select-lowest-window
537 'gnus-appt-select-lowest-window-xemacs))
539 (if (not gnus-visual)
541 (setq gnus-group-mode-hook
544 (easy-menu-add gnus-group-reading-menu)
545 (easy-menu-add gnus-group-group-menu)
546 (easy-menu-add gnus-group-misc-menu)
547 (gnus-install-mouse-tracker))
548 gnus-group-mode-hook))
549 (setq gnus-summary-mode-hook
552 (easy-menu-add gnus-summary-article-menu)
553 (easy-menu-add gnus-summary-thread-menu)
554 (easy-menu-add gnus-summary-misc-menu)
555 (easy-menu-add gnus-summary-post-menu)
556 (easy-menu-add gnus-summary-kill-menu)
557 (gnus-install-mouse-tracker))
558 gnus-summary-mode-hook))
559 (setq gnus-article-mode-hook
562 (easy-menu-add gnus-article-article-menu)
563 (easy-menu-add gnus-article-treatment-menu))
564 gnus-article-mode-hook)))
566 (defvar gnus-logo (make-glyph (make-specifier 'image)))
568 (defun gnus-group-startup-xmessage (&optional x y)
569 "Insert startup message in current buffer."
570 ;; Insert the message.
574 (set-glyph-property gnus-logo 'image "~/tmp/gnus.xpm")
575 (set-glyph-image gnus-logo "~/tmp/gnus.xpm" 'global 'x)
578 (set-extent-begin-glyph (make-extent (point) (point)) gnus-logo)
580 Gnus * A newsreader for Emacsen
581 A Praxis Release * larsi@ifi.uio.no")
582 (goto-char (point-min))
584 (insert (make-string (/ (max (- (window-width) (or x 35)) 0) 2)
587 (goto-char (point-min))
588 ;; +4 is fuzzy factor.
589 (insert-char ?\n (/ (max (- (window-height) (or y 24)) 0) 2)))
606 ;; 18 is the longest line.
607 (indent-rigidly (point-min) (point-max)
608 (/ (max (- (window-width) (or x 28)) 0) 2))
609 (goto-char (point-min))
610 ;; +4 is fuzzy factor.
611 (insert-char ?\n (/ (max (- (window-height) (or y 12)) 0) 2)))
614 (goto-char (point-min))
615 (search-forward "Praxis")
616 (put-text-property (match-beginning 0) (match-end 0) 'face 'bold)
617 (goto-char (point-min)))
625 (if (not (fboundp 'truncate-string))
626 (defun truncate-string (str width)
627 (let ((w (string-width str))
628 (col 0) (idx 0) (p-idx 0) chr)
632 (setq chr (aref str idx)
633 col (+ col (char-width chr))
635 idx (+ idx (char-bytes chr))
637 (substring str 0 (if (= col width)
642 (defalias 'gnus-truncate-string 'truncate-string)
644 (defun gnus-cite-add-face (number prefix face)
645 ;; At line NUMBER, ignore PREFIX and add FACE to the rest of the line.
647 (let ((inhibit-point-motion-hooks t)
651 (forward-char (chars-in-string prefix))
652 (forward-char (length prefix)))
653 (skip-chars-forward " \t")
656 (skip-chars-backward " \t")
659 (gnus-overlay-put (gnus-make-overlay from to) 'face face)))))
661 (defun gnus-max-width-function (el max-width)
662 (` (let* ((val (eval (, el)))
663 (valstr (if (numberp val)
664 (int-to-string val) val)))
665 (if (> (length valstr) (, max-width))
666 (truncate-string valstr (, max-width))
669 (fset 'gnus-summary-make-display-table (lambda () nil))
671 (if (boundp 'gnus-check-before-posting)
672 (setq gnus-check-before-posting
674 (delq 'control-chars gnus-check-before-posting)))
682 ;; byte-compile-warnings: '(redefine callargs)
685 ;;; gnus-ems.el ends here