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-ems-redefine ()
198 ((string-match "XEmacs\\|Lucid" emacs-version)
199 ;; XEmacs definitions.
200 (fset 'gnus-mouse-face-function 'identity)
201 (fset 'gnus-summary-make-display-table (lambda () nil))
202 (fset 'gnus-visual-turn-off-edit-menu 'identity)
204 (defun gnus-highlight-selected-summary ()
205 ;; Added by Per Abrahamsen <amanda@iesd.auc.dk>.
206 ;; Highlight selected article in summary buffer
207 (if gnus-summary-selected-face
209 (let* ((beg (progn (beginning-of-line) (point)))
210 (end (progn (end-of-line) (point)))
211 (to (max 1 (1- (or (previous-single-property-change
212 end 'mouse-face nil beg) end))))
213 (from (1+ (or (next-single-property-change
214 beg 'mouse-face nil end) beg))))
219 (if gnus-newsgroup-selected-overlay
220 (delete-extent gnus-newsgroup-selected-overlay))
221 (setq gnus-newsgroup-selected-overlay
222 (make-extent from to))
223 (set-extent-face gnus-newsgroup-selected-overlay
224 gnus-summary-selected-face)))))
227 (defun gnus-summary-recenter ()
228 (let* ((top (cond ((< (window-height) 4) 0)
229 ((< (window-height) 7) 1)
231 (height (- (window-height) 2))
232 (bottom (save-excursion (goto-char (point-max))
233 (forward-line (- height))
235 (window (get-buffer-window (current-buffer))))
237 ;; The user has to want it,
238 gnus-auto-center-summary
239 ;; the article buffer must be displayed,
240 (get-buffer-window gnus-article-buffer)
241 ;; Set the window start to either `bottom', which is the biggest
242 ;; possible valid number, or the second line from the top,
243 ;; whichever is the least.
245 window (min bottom (save-excursion (forward-line (- top))
248 (defun gnus-group-insert-group-line-info (group)
249 (let ((entry (gnus-gethash group gnus-newsrc-hashtb))
254 (setq info (nth 2 entry))
255 (gnus-group-insert-group-line
256 nil group (nth 1 info) (nth 3 info) (car entry) (nth 4 info)))
257 (setq active (gnus-gethash group gnus-active-hashtb))
259 (gnus-group-insert-group-line
260 nil group (if (member group gnus-zombie-list) gnus-level-zombie
262 nil (if active (- (1+ (cdr active)) (car active)) 0) nil))
265 (remove-text-properties
266 (1+ (gnus-point-at-bol)) (1+ (gnus-point-at-eol))
267 '(gnus-group nil)))))
269 (defun gnus-copy-article-buffer (&optional article-buffer)
270 (setq gnus-article-copy (get-buffer-create " *gnus article copy*"))
271 (buffer-disable-undo gnus-article-copy)
272 (or (memq gnus-article-copy gnus-buffer-list)
273 (setq gnus-buffer-list (cons gnus-article-copy gnus-buffer-list)))
274 (let ((article-buffer (or article-buffer gnus-article-buffer))
276 (if (and (get-buffer article-buffer)
277 (buffer-name (get-buffer article-buffer)))
279 (set-buffer article-buffer)
281 (setq buf (buffer-substring (point-min) (point-max)))
282 (set-buffer gnus-article-copy)
284 (insert (format "%s" buf))))))
286 (defun gnus-summary-refer-article (message-id)
287 "Refer article specified by MESSAGE-ID.
288 NOTE: This command only works with newsgroups that use real or simulated NNTP."
289 (interactive "sMessage-ID: ")
290 (if (or (not (stringp message-id))
291 (zerop (length message-id)))
293 ;; Construct the correct Message-ID if necessary.
294 ;; Suggested by tale@pawl.rpi.edu.
295 (or (string-match "^<" message-id)
296 (setq message-id (concat "<" message-id)))
297 (or (string-match ">$" message-id)
298 (setq message-id (concat message-id ">")))
299 (let ((header (car (gnus-gethash (downcase message-id)
300 gnus-newsgroup-dependencies))))
302 (or (gnus-summary-goto-article (header-number header))
303 ;; The header has been read, but the article had been
304 ;; expunged, so we insert it again.
306 (gnus-summary-insert-line
307 nil header 0 nil gnus-read-mark nil nil
308 (header-subject header))
311 (remove-text-properties
312 (1+ (gnus-point-at-bol)) (1+ (gnus-point-at-eol))
313 '(gnus-number nil gnus-mark nil gnus-level nil)))
315 (header-number header)))
316 (let ((gnus-override-method gnus-refer-article-method)
317 (gnus-ancient-mark gnus-read-mark)
318 (tmp-buf (get-buffer-create " *gnus refer"))
319 (tmp-point (window-start
320 (get-buffer-window gnus-article-buffer)))
322 (and gnus-refer-article-method
323 (or (gnus-server-opened gnus-refer-article-method)
324 (gnus-open-server gnus-refer-article-method)))
325 ;; Save the old article buffer.
328 (buffer-disable-undo (current-buffer))
329 (insert-buffer-substring gnus-article-buffer))
331 (if (gnus-article-prepare
332 message-id nil (gnus-read-header message-id))
334 (setq number (header-number gnus-current-headers))
335 (gnus-rebuild-thread message-id)
336 (gnus-summary-goto-subject number)
337 (gnus-summary-recenter)
338 (gnus-article-set-window-start
339 (cdr (assq number gnus-newsgroup-bookmarks)))
341 ;; We restore the old article buffer.
343 (set-buffer gnus-article-buffer)
344 (let ((buffer-read-only nil))
345 (insert-buffer-substring tmp-buf)
347 (set-window-start (get-buffer-window (current-buffer))
350 (kill-buffer tmp-buf)))))))
352 (defun gnus-summary-insert-pseudos (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)))
399 (insert " " (file-name-nondirectory
400 (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 (remove-text-properties
408 (1+ b) (1+ (gnus-point-at-eol))
409 '(gnus-number nil gnus-mark nil gnus-level nil))
411 (gnus-sethash (int-to-string gnus-reffed-article-number)
412 (car pslist) gnus-newsgroup-headers-hashtb-by-number)
413 (setq gnus-reffed-article-number (1- gnus-reffed-article-number))
414 (setq pslist (cdr pslist)))))))
417 (defun gnus-article-push-button (event)
418 "Check text under the mouse pointer for a callback function.
419 If the text under the mouse pointer has a `gnus-callback' property,
420 call it with the value of the `gnus-data' text property."
422 (set-buffer (window-buffer (event-window event)))
423 (let* ((pos (event-closest-point event))
424 (data (get-text-property pos 'gnus-data))
425 (fun (get-text-property pos 'gnus-callback)))
426 (if fun (funcall fun data))))
428 ;; Re-build the thread containing ID.
429 (defun gnus-rebuild-thread (id)
430 (let ((dep gnus-newsgroup-dependencies)
431 (buffer-read-only nil)
432 parent headers refs thread art)
433 (while (and id (setq headers
434 (car (setq art (gnus-gethash (downcase id)
437 (setq id (and (setq refs (header-references headers))
438 (string-match "\\(<[^>]+>\\) *$" refs)
439 (substring refs (match-beginning 1) (match-end 1)))))
440 (setq thread (gnus-make-sub-thread (car parent)))
441 (gnus-rebuild-remove-articles thread)
443 (gnus-summary-prepare-threads (list thread) 0)
445 (while (and (>= (point) beg)
447 (remove-text-properties
448 (1+ (gnus-point-at-bol)) (1+ (gnus-point-at-eol))
449 '(gnus-number nil gnus-mark nil gnus-level nil))
451 (gnus-summary-update-lines beg (point)))))
453 ;; Fixed by Christopher Davis <ckd@loiosh.kei.com>.
454 (defun gnus-article-add-button (from to fun &optional data)
455 "Create a button between FROM and TO with callback FUN and data DATA."
456 (and gnus-article-button-face
457 (gnus-overlay-put (gnus-make-overlay from to) 'face gnus-article-button-face))
458 (add-text-properties from to
460 (and gnus-article-mouse-face
461 (list 'mouse-face gnus-article-mouse-face))
462 (list 'gnus-callback fun)
463 (and data (list 'gnus-data data))
464 (list 'highlight t))))
466 (if (not gnus-visual)
468 (setq gnus-group-mode-hook
471 (easy-menu-add gnus-group-reading-menu)
472 (easy-menu-add gnus-group-group-menu)
473 (easy-menu-add gnus-group-post-menu)
474 (easy-menu-add gnus-group-misc-menu)
475 (gnus-install-mouse-tracker))
476 gnus-group-mode-hook))
477 (setq gnus-summary-mode-hook
480 (easy-menu-add gnus-summary-mark-menu)
481 (easy-menu-add gnus-summary-move-menu)
482 (easy-menu-add gnus-summary-article-menu)
483 (easy-menu-add gnus-summary-thread-menu)
484 (easy-menu-add gnus-summary-misc-menu)
485 (easy-menu-add gnus-summary-post-menu)
486 (easy-menu-add gnus-summary-kill-menu)
487 (gnus-install-mouse-tracker))
488 gnus-summary-mode-hook))
489 (setq gnus-article-mode-hook
492 (easy-menu-add gnus-article-article-menu)
493 (easy-menu-add gnus-article-treatment-menu))
494 gnus-article-mode-hook)))
496 (defvar gnus-logo (make-glyph (make-specifier 'image)))
498 (defun gnus-group-startup-xmessage (&optional x y)
499 "Insert startup message in current buffer."
500 ;; Insert the message.
504 (set-glyph-property gnus-logo 'image "~/tmp/gnus.xpm")
505 (set-glyph-image gnus-logo "~/tmp/gnus.xpm" 'global 'x)
508 (set-extent-begin-glyph (make-extent (point) (point)) gnus-logo)
510 Gnus * A newsreader for Emacsen
511 A Praxis Release * larsi@ifi.uio.no")
512 (goto-char (point-min))
514 (insert (make-string (/ (max (- (window-width) (or x 35)) 0) 2)
517 (goto-char (point-min))
518 ;; +4 is fuzzy factor.
519 (insert-char ?\n (/ (max (- (window-height) (or y 24)) 0) 2)))
536 ;; 18 is the longest line.
537 (indent-rigidly (point-min) (point-max)
538 (/ (max (- (window-width) (or x 28)) 0) 2))
539 (goto-char (point-min))
540 ;; +4 is fuzzy factor.
541 (insert-char ?\n (/ (max (- (window-height) (or y 12)) 0) 2)))
544 (goto-char (point-min))
545 (search-forward "Praxis")
546 (put-text-property (match-beginning 0) (match-end 0) 'face 'bold)
547 (goto-char (point-min)))
555 (if (not (fboundp 'truncate-string))
556 (defun truncate-string (str width)
557 (let ((w (string-width str))
558 (col 0) (idx 0) (p-idx 0) chr)
562 (setq chr (aref str idx)
563 col (+ col (char-width chr))
565 idx (+ idx (char-bytes chr))
567 (substring str 0 (if (= col width)
572 (defalias 'gnus-truncate-string 'truncate-string)
574 (defun gnus-cite-add-face (number prefix face)
575 ;; At line NUMBER, ignore PREFIX and add FACE to the rest of the line.
577 (let ((inhibit-point-motion-hooks t)
581 (forward-char (chars-in-string prefix))
582 (forward-char (length prefix)))
583 (skip-chars-forward " \t")
586 (skip-chars-backward " \t")
589 (gnus-overlay-put (gnus-make-overlay from to) 'face face)))))
591 (defun gnus-max-width-function (el max-width)
592 (` (let* ((val (eval (, el)))
593 (valstr (if (numberp val)
594 (int-to-string val) val)))
595 (if (> (length valstr) (, max-width))
596 (truncate-string valstr (, max-width))
599 (fset 'gnus-summary-make-display-table (lambda () nil))
601 (if (boundp 'gnus-check-before-posting)
602 (setq gnus-check-before-posting
604 (delq 'control-chars gnus-check-before-posting)))
612 ;; byte-compile-warnings: nil
615 ;;; gnus-ems.el ends here