(require 'gnus)
(eval-after-load "gnus"
'(progn
(setq gnus-init-file (expand-file-name ".gnus" gnus-directory))
(require 'spam)
(require 'message-x)
(require 'mailcrypt)
(load-library "spook")
))
(setq gnus-directory (expand-file-name "~/News/"))
(defun switch-to-gnus ()
(interactive)
(if (or (not (fboundp 'gnus-alive-p))
(not (gnus-alive-p)))
(gnus)
(let (candidate priority in-gnus (tests '(("\\*Group" . 3))))
(when (not (member mode-name '("Message" "Summary")))
(setq tests (cons '("^\\*\\(mail\\|\\(wide \\)?reply\\)" . 1)
tests)))
(when (not (string= mode-name "Summary"))
(setq tests (cons '("\\*Summary" . 2) tests)))
(dolist (buf (buffer-list))
(dolist (test tests)
(when (and (string-match (car test) (buffer-name buf))
(or (not priority) (< (cdr test) priority))
(> (buffer-size buf) 0))
(setq candidate buf
priority (cdr test)))))
(if (buffer-live-p candidate)
(if (eq candidate (current-buffer))
(gnus-group-get-new-news)
(switch-to-buffer candidate))
(error "unlive buffer!")))))
(defadvice save-buffers-kill-emacs (before quit-gnus (&rest args) activate)
(let (buf)
(when (and (fboundp 'gnus-alive-p)
(gnus-alive-p)
(bufferp (setq buf (get-buffer "*Group*"))))
(with-current-buffer buf
(gnus-group-exit)))))
(add-hook 'gnus-group-mode-hook
(lambda ()
(local-set-key (kbd "q") 'gnus-group-suspend)
(local-set-key (kbd "Q") 'gnus-group-exit)))
(define-key goto-keymap [?g] 'switch-to-gnus)
(require 'gnus-dired)
(add-hook 'dired-mode-hook 'turn-on-gnus-dired-mode)