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 ;; We do not byte-compile this file, because error messages are such a
42 (if (string-match "XEmacs\\|Lucid" emacs-version)
44 ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
45 (defvar gnus-display-type
47 (let ((display-resource (x-get-resource ".displayType" "DisplayType")))
48 (cond (display-resource (intern (downcase display-resource)))
49 ((x-display-color-p) 'color)
50 ((x-display-grayscale-p) 'grayscale)
53 "A symbol indicating the display Emacs is running under.
54 The symbol should be one of `color', `grayscale' or `mono'. If Emacs
55 guesses this display attribute wrongly, either set this variable in
56 your `~/.emacs' or set the resource `Emacs.displayType' in your
57 `~/.Xdefaults'. See also `gnus-background-mode'.
59 This is a meta-variable that will affect what default values other
60 variables get. You would normally not change this variable, but
61 pounce directly on the real variables themselves.")
63 (defvar gnus-background-mode
65 (let ((bg-resource (x-get-resource ".backgroundMode"
67 (params (frame-parameters)))
68 (cond (bg-resource (intern (downcase bg-resource)))
69 ((and (cdr (assq 'background-color params))
70 (< (apply '+ (x-color-values
71 (cdr (assq 'background-color params))))
72 (/ (apply '+ (x-color-values "white")) 3)))
76 "A symbol indicating the Emacs background brightness.
77 The symbol should be one of `light' or `dark'.
78 If Emacs guesses this frame attribute wrongly, either set this variable in
79 your `~/.emacs' or set the resource `Emacs.backgroundMode' in your
81 See also `gnus-display-type'.
83 This is a meta-variable that will affect what default values other
84 variables get. You would normally not change this variable, but
85 pounce directly on the real variables themselves."))
88 ((string-match "XEmacs\\|Lucid" emacs-version)
89 ;; XEmacs definitions.
91 (setq gnus-mouse-2 [button2])
92 (setq gnus-easymenu 'auc-menu)
94 (or (memq 'underline (list-faces))
95 (funcall (intern "make-face") 'underline))
96 ;; Must avoid calling set-face-underline-p directly, because it
97 ;; is a defsubst in emacs19, and will make the .elc files non
99 (or (face-differs-from-default-p 'underline)
100 (funcall 'set-face-underline-p 'underline t))
101 (or (fboundp 'set-text-properties)
102 (defun set-text-properties (start end props &optional buffer)
103 (if (or (null buffer) (bufferp buffer))
107 start end (car props) (nth 1 props) buffer)
108 (setq props (nthcdr 2 props)))
109 (remove-text-properties start end ())))))
111 (defalias 'gnus-make-overlay 'make-extent)
112 (defalias 'gnus-overlay-put 'set-extent-property)
113 (defun gnus-move-overlay (extent start end &optional buffer)
114 (set-extent-endpoints extent start end))
116 (or (boundp 'standard-display-table) (setq standard-display-table nil))
117 (or (boundp 'read-event) (fset 'read-event 'next-command-event))
119 ;; Fix by "jeff (j.d.) sparkes" <jsparkes@bnr.ca>.
120 (defvar gnus-display-type (device-class)
121 "A symbol indicating the display Emacs is running under.
122 The symbol should be one of `color', `grayscale' or `mono'. If Emacs
123 guesses this display attribute wrongly, either set this variable in
124 your `~/.emacs' or set the resource `Emacs.displayType' in your
125 `~/.Xdefaults'. See also `gnus-background-mode'.
127 This is a meta-variable that will affect what default values other
128 variables get. You would normally not change this variable, but
129 pounce directly on the real variables themselves.")
132 (or (fboundp 'x-color-values)
133 (fset 'x-color-values
135 (color-instance-rgb-components
136 (make-color-instance color)))))
138 (defvar gnus-background-mode
140 (x-get-resource ".backgroundMode" "BackgroundMode" 'string))
141 (params (frame-parameters)))
142 (cond (bg-resource (intern (downcase bg-resource)))
143 ((and (assq 'background-color params)
144 (< (apply '+ (x-color-values
145 (cdr (assq 'background-color params))))
146 (/ (apply '+ (x-color-values "white")) 3)))
149 "A symbol indicating the Emacs background brightness.
150 The symbol should be one of `light' or `dark'.
151 If Emacs guesses this frame attribute wrongly, either set this variable in
152 your `~/.emacs' or set the resource `Emacs.backgroundMode' in your
154 See also `gnus-display-type'.
156 This is a meta-variable that will affect what default values other
157 variables get. You would normally not change this variable, but
158 pounce directly on the real variables themselves.")
161 (defun gnus-install-mouse-tracker ()
162 (require 'mode-motion)
163 (setq mode-motion-hook 'mode-motion-highlight-line)))
165 ((and (not (string-match "28.9" emacs-version))
166 (not (string-match "29" emacs-version)))
167 (setq gnus-hidden-properties '(invisible t))
168 (or (fboundp 'buffer-substring-no-properties)
169 (defun buffer-substring-no-properties (beg end)
170 (format "%s" (buffer-substring beg end)))))
180 (defun gnus-dummy-func (&rest args))
181 (let ((funcs '(mouse-set-point set-face-foreground
182 set-face-background x-popup-menu)))
184 (or (fboundp (car funcs))
185 (fset (car funcs) 'gnus-dummy-func))
186 (setq funcs (cdr funcs))))))
187 (or (fboundp 'file-regular-p)
188 (defun file-regular-p (file)
189 (and (not (file-directory-p file))
190 (not (file-symlink-p file))
191 (file-exists-p file))))
192 (or (fboundp 'face-list)
193 (defun face-list (&rest args)))
196 (defun gnus-highlight-selected-summary-xemacs ()
197 ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
198 ;; Highlight selected article in summary buffer
199 (if gnus-summary-selected-face
201 (let* ((beg (progn (beginning-of-line) (point)))
202 (end (progn (end-of-line) (point)))
203 (to (max 1 (1- (or (previous-single-property-change
204 end 'mouse-face nil beg) end))))
205 (from (1+ (or (next-single-property-change
206 beg 'mouse-face nil end) beg))))
211 (if gnus-newsgroup-selected-overlay
212 (delete-extent gnus-newsgroup-selected-overlay))
213 (setq gnus-newsgroup-selected-overlay
214 (make-extent from to))
215 (set-extent-face gnus-newsgroup-selected-overlay
216 gnus-summary-selected-face)))))
218 (defun gnus-summary-recenter-xemacs ()
219 (let* ((top (cond ((< (window-height) 4) 0)
220 ((< (window-height) 7) 1)
222 (height (- (window-height) 2))
223 (bottom (save-excursion (goto-char (point-max))
224 (forward-line (- height))
226 (window (get-buffer-window (current-buffer))))
228 ;; The user has to want it,
229 gnus-auto-center-summary
230 ;; the article buffer must be displayed,
231 (get-buffer-window gnus-article-buffer)
232 ;; Set the window start to either `bottom', which is the biggest
233 ;; possible valid number, or the second line from the top,
234 ;; whichever is the least.
236 window (min bottom (save-excursion (forward-line (- top))
239 (defun gnus-group-insert-group-line-info-xemacs (group)
240 (let ((entry (gnus-gethash group gnus-newsrc-hashtb))
245 (setq info (nth 2 entry))
246 (gnus-group-insert-group-line
247 nil group (nth 1 info) (nth 3 info) (car entry) (nth 4 info)))
248 (setq active (gnus-gethash group gnus-active-hashtb))
250 (gnus-group-insert-group-line
251 nil group (if (member group gnus-zombie-list) gnus-level-zombie
253 nil (if active (- (1+ (cdr active)) (car active)) 0) nil))
256 (remove-text-properties
257 (1+ (gnus-point-at-bol)) (1+ (gnus-point-at-eol))
258 '(gnus-group nil)))))
260 (defun gnus-summary-refer-article-xemacs (message-id)
261 "Refer article specified by MESSAGE-ID.
262 NOTE: This command only works with newsgroups that use real or simulated NNTP."
263 (interactive "sMessage-ID: ")
264 (if (or (not (stringp message-id))
265 (zerop (length message-id)))
267 ;; Construct the correct Message-ID if necessary.
268 ;; Suggested by tale@pawl.rpi.edu.
269 (or (string-match "^<" message-id)
270 (setq message-id (concat "<" message-id)))
271 (or (string-match ">$" message-id)
272 (setq message-id (concat message-id ">")))
273 (let ((header (car (gnus-gethash (downcase message-id)
274 gnus-newsgroup-dependencies))))
276 (or (gnus-summary-goto-article (header-number header))
277 ;; The header has been read, but the article had been
278 ;; expunged, so we insert it again.
280 (gnus-summary-insert-line
281 nil header 0 nil gnus-read-mark nil nil
282 (header-subject header))
285 (remove-text-properties
286 (1+ (gnus-point-at-bol)) (1+ (gnus-point-at-eol))
287 '(gnus-number nil gnus-mark nil gnus-level nil)))
289 (header-number header)))
290 (let ((gnus-override-method gnus-refer-article-method)
291 (gnus-ancient-mark gnus-read-mark)
292 (tmp-buf (get-buffer-create " *gnus refer"))
293 (tmp-point (window-start
294 (get-buffer-window gnus-article-buffer)))
296 (and gnus-refer-article-method
297 (or (gnus-server-opened gnus-refer-article-method)
298 (gnus-open-server gnus-refer-article-method)))
299 ;; Save the old article buffer.
302 (buffer-disable-undo (current-buffer))
303 (insert-buffer-substring gnus-article-buffer))
305 (if (gnus-article-prepare
306 message-id nil (gnus-read-header message-id))
308 (setq number (header-number gnus-current-headers))
309 (gnus-rebuild-thread message-id)
310 (gnus-summary-goto-subject number)
311 (gnus-summary-recenter)
312 (gnus-article-set-window-start
313 (cdr (assq number gnus-newsgroup-bookmarks)))
315 ;; We restore the old article buffer.
317 (set-buffer gnus-article-buffer)
318 (let ((buffer-read-only nil))
319 (insert-buffer-substring tmp-buf)
321 (set-window-start (get-buffer-window (current-buffer))
324 (kill-buffer tmp-buf)))))))
326 (defun gnus-summary-insert-pseudos-xemacs (pslist &optional not-view)
327 (let ((buffer-read-only nil)
328 (article (gnus-summary-article-number))
330 (or (gnus-summary-goto-subject article)
331 (error (format "No such article: %d" article)))
332 (or gnus-newsgroup-headers-hashtb-by-number
333 (gnus-make-headers-hashtable-by-number))
334 (gnus-summary-position-cursor)
335 ;; If all commands are to be bunched up on one line, we collect
337 (if gnus-view-pseudos-separately
339 (let ((ps (setq pslist (sort pslist 'gnus-pseudos<)))
342 (setq action (cdr (assq 'action (car ps))))
343 (setq files (list (cdr (assq 'name (car ps)))))
344 (while (and ps (cdr ps)
345 (string= (or action "1")
346 (or (cdr (assq 'action (car (cdr ps)))) "2")))
347 (setq files (cons (cdr (assq 'name (car (cdr ps)))) files))
348 (setcdr ps (cdr (cdr ps))))
351 (if (not (string-match "%s" action))
352 (setq files (cons " " files)))
353 (setq files (cons " " files))
354 (and (assq 'execute (car ps))
355 (setcdr (assq 'execute (car ps))
356 (funcall (if (string-match "%s" action)
359 (mapconcat (lambda (f) f) files " ")))))
360 (setq ps (cdr ps)))))
361 (if (and gnus-view-pseudos (not not-view))
363 (and (assq 'execute (car pslist))
364 (gnus-execute-command (cdr (assq 'execute (car pslist)))
365 (eq gnus-view-pseudos 'not-confirm)))
366 (setq pslist (cdr pslist)))
369 (gnus-summary-goto-subject (or (cdr (assq 'article (car pslist)))
370 (gnus-summary-article-number)))
374 (file-name-nondirectory (cdr (assq 'name (car pslist))))
375 ": " (or (cdr (assq 'execute (car pslist))) "") "\n")
377 b (1+ b) (list 'gnus-number gnus-reffed-article-number
378 'gnus-mark gnus-unread-mark
380 'gnus-pseudo (car pslist)))
381 ;; Fucking XEmacs redisplay bug with truncated lines.
384 ;; Grumble.. Fucking XEmacs stickyness of text properties.
385 (remove-text-properties
386 (1+ b) (1+ (gnus-point-at-eol))
387 '(gnus-number nil gnus-mark nil gnus-level nil))
389 (gnus-sethash (int-to-string gnus-reffed-article-number)
390 (car pslist) gnus-newsgroup-headers-hashtb-by-number)
391 (setq gnus-reffed-article-number (1- gnus-reffed-article-number))
392 (setq pslist (cdr pslist)))))))
395 (defun gnus-copy-article-buffer-xemacs (&optional article-buffer)
396 (setq gnus-article-copy (get-buffer-create " *gnus article copy*"))
397 (buffer-disable-undo gnus-article-copy)
398 (or (memq gnus-article-copy gnus-buffer-list)
399 (setq gnus-buffer-list (cons gnus-article-copy gnus-buffer-list)))
400 (let ((article-buffer (or article-buffer gnus-article-buffer))
402 (if (and (get-buffer article-buffer)
403 (buffer-name (get-buffer article-buffer)))
405 (set-buffer article-buffer)
407 (setq buf (buffer-substring (point-min) (point-max)))
408 (set-buffer gnus-article-copy)
410 (insert (format "%s" buf))))))
412 (defun gnus-article-push-button-xemacs (event)
413 "Check text under the mouse pointer for a callback function.
414 If the text under the mouse pointer has a `gnus-callback' property,
415 call it with the value of the `gnus-data' text property."
417 (set-buffer (window-buffer (event-window event)))
418 (let* ((pos (event-closest-point event))
419 (data (get-text-property pos 'gnus-data))
420 (fun (get-text-property pos 'gnus-callback)))
421 (if fun (funcall fun data))))
423 ;; Re-build the thread containing ID.
424 (defun gnus-rebuild-thread-xemacs (id)
425 (let ((dep gnus-newsgroup-dependencies)
426 (buffer-read-only nil)
427 parent headers refs thread art)
428 (while (and id (setq headers
429 (car (setq art (gnus-gethash (downcase id)
432 (setq id (and (setq refs (header-references headers))
433 (string-match "\\(<[^>]+>\\) *$" refs)
434 (substring refs (match-beginning 1) (match-end 1)))))
435 (setq thread (gnus-make-sub-thread (car parent)))
436 (gnus-rebuild-remove-articles thread)
438 (gnus-summary-prepare-threads (list thread) 0)
440 (while (and (>= (point) beg)
442 (remove-text-properties
443 (1+ (gnus-point-at-bol)) (1+ (gnus-point-at-eol))
444 '(gnus-number nil gnus-mark nil gnus-level nil))
446 (gnus-summary-update-lines beg (point)))))
449 ;; Fixed by Christopher Davis <ckd@loiosh.kei.com>.
450 (defun gnus-article-add-button-xemacs (from to fun &optional data)
451 "Create a button between FROM and TO with callback FUN and data DATA."
452 (and gnus-article-button-face
453 (gnus-overlay-put (gnus-make-overlay from to) 'face gnus-article-button-face))
454 (add-text-properties from to
456 (and gnus-article-mouse-face
457 (list 'mouse-face gnus-article-mouse-face))
458 (list 'gnus-callback fun)
459 (and data (list 'gnus-data data))
460 (list 'highlight t))))
463 (defun gnus-ems-redefine ()
465 ((string-match "XEmacs\\|Lucid" emacs-version)
466 ;; XEmacs definitions.
467 (fset 'gnus-mouse-face-function 'identity)
468 (fset 'gnus-summary-make-display-table (lambda () nil))
469 (fset 'gnus-visual-turn-off-edit-menu 'identity)
470 (fset 'gnus-highlight-selected-summary
471 'gnus-highlight-selected-summary-xemacs)
472 (fset 'gnus-summary-recenter 'gnus-summary-recenter-xemacs)
473 (fset 'gnus-group-insert-group-line-info
474 'gnus-group-insert-group-line-info-xemacs)
475 (fset 'gnus-copy-article-buffer 'gnus-copy-article-buffer-xemacs)
476 (fset 'gnus-summary-refer-article 'gnus-summary-refer-article-xemacs)
477 (fset 'gnus-summary-insert-pseudos 'gnus-summary-insert-pseudos-xemacs)
478 (fset 'gnus-article-push-button 'gnus-article-push-button-xemacs)
479 (fset 'gnus-rebuild-thread 'gnus-rebuild-thread-xemacs)
480 (fset 'gnus-article-add-button 'gnus-article-add-button-xemacs)
482 (if (not gnus-visual)
484 (setq gnus-group-mode-hook
487 (easy-menu-add gnus-group-reading-menu)
488 (easy-menu-add gnus-group-group-menu)
489 (easy-menu-add gnus-group-post-menu)
490 (easy-menu-add gnus-group-misc-menu)
491 (gnus-install-mouse-tracker))
492 gnus-group-mode-hook))
493 (setq gnus-summary-mode-hook
496 (easy-menu-add gnus-summary-mark-menu)
497 (easy-menu-add gnus-summary-move-menu)
498 (easy-menu-add gnus-summary-article-menu)
499 (easy-menu-add gnus-summary-thread-menu)
500 (easy-menu-add gnus-summary-misc-menu)
501 (easy-menu-add gnus-summary-post-menu)
502 (easy-menu-add gnus-summary-kill-menu)
503 (gnus-install-mouse-tracker))
504 gnus-summary-mode-hook))
505 (setq gnus-article-mode-hook
508 (easy-menu-add gnus-article-article-menu)
509 (easy-menu-add gnus-article-treatment-menu))
510 gnus-article-mode-hook)))
512 (defvar gnus-logo (make-glyph (make-specifier 'image)))
514 (defun gnus-group-startup-xmessage (&optional x y)
515 "Insert startup message in current buffer."
516 ;; Insert the message.
520 (set-glyph-property gnus-logo 'image "~/tmp/gnus.xpm")
521 (set-glyph-image gnus-logo "~/tmp/gnus.xpm" 'global 'x)
524 (set-extent-begin-glyph (make-extent (point) (point)) gnus-logo)
526 Gnus * A newsreader for Emacsen
527 A Praxis Release * larsi@ifi.uio.no")
528 (goto-char (point-min))
530 (insert (make-string (/ (max (- (window-width) (or x 35)) 0) 2)
533 (goto-char (point-min))
534 ;; +4 is fuzzy factor.
535 (insert-char ?\n (/ (max (- (window-height) (or y 24)) 0) 2)))
552 ;; 18 is the longest line.
553 (indent-rigidly (point-min) (point-max)
554 (/ (max (- (window-width) (or x 28)) 0) 2))
555 (goto-char (point-min))
556 ;; +4 is fuzzy factor.
557 (insert-char ?\n (/ (max (- (window-height) (or y 12)) 0) 2)))
560 (goto-char (point-min))
561 (search-forward "Praxis")
562 (put-text-property (match-beginning 0) (match-end 0) 'face 'bold)
563 (goto-char (point-min)))
571 (if (not (fboundp 'truncate-string))
572 (defun truncate-string (str width)
573 (let ((w (string-width str))
574 (col 0) (idx 0) (p-idx 0) chr)
578 (setq chr (aref str idx)
579 col (+ col (char-width chr))
581 idx (+ idx (char-bytes chr))
583 (substring str 0 (if (= col width)
588 (defalias 'gnus-truncate-string 'truncate-string)
590 (defun gnus-cite-add-face (number prefix face)
591 ;; At line NUMBER, ignore PREFIX and add FACE to the rest of the line.
593 (let ((inhibit-point-motion-hooks t)
597 (forward-char (chars-in-string prefix))
598 (forward-char (length prefix)))
599 (skip-chars-forward " \t")
602 (skip-chars-backward " \t")
605 (gnus-overlay-put (gnus-make-overlay from to) 'face face)))))
607 (defun gnus-max-width-function (el max-width)
608 (` (let* ((val (eval (, el)))
609 (valstr (if (numberp val)
610 (int-to-string val) val)))
611 (if (> (length valstr) (, max-width))
612 (truncate-string valstr (, max-width))
615 (fset 'gnus-summary-make-display-table (lambda () nil))
617 (if (boundp 'gnus-check-before-posting)
618 (setq gnus-check-before-posting
620 (delq 'control-chars gnus-check-before-posting)))
628 ;; byte-compile-warnings: nil
631 ;;; gnus-ems.el ends here