From d9cae60fa5048abd3528f96a285109329639fda6 Mon Sep 17 00:00:00 2001 From: Kyle Meyer Date: Fri, 23 Jan 2015 23:23:05 -0500 Subject: Improve organization and consistency of files - Add pages and more headings for large files. - Try to use consistent order for file (or page) structure. * Loading * Settings * Hooks * Any mode activation or function calls * My functions * Key bindings --- lisp/init-gnus.el | 295 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 154 insertions(+), 141 deletions(-) (limited to 'lisp/init-gnus.el') diff --git a/lisp/init-gnus.el b/lisp/init-gnus.el index 8fdc85a..5acde06 100644 --- a/lisp/init-gnus.el +++ b/lisp/init-gnus.el @@ -1,52 +1,34 @@ (require 'gnus) +(autoload 'gnus-group-topic "gnus-topic") + +(require 'org-gnus) + +(setq gnus-home-directory "~/.gnus.d/" + gnus-directory gnus-home-directory + gnus-article-save-directory (expand-file-name "saved/" gnus-directory) + gnus-kill-files-directory (expand-file-name "scores/" gnus-directory)) + +(setq gnus-startup-file (expand-file-name "newsrc" gnus-home-directory) + gnus-init-file (expand-file-name "gnus" gnus-home-directory) + gnus-save-newsrc-file nil + gnus-read-newsrc-file nil) + +(setq sendmail-program "/usr/bin/msmtp" + gnus-gcc-mark-as-read t + gnus-visible-headers '("^From" "^Subject" "^Date" "^To" "^Cc" "^User-Agent") + gnus-confirm-mail-reply-to-news t) + +(setq imap-shell-program "/usr/lib/dovecot/imap -c ~/.dovecotrc" + gnus-select-method '(nnimap "dov" (nnimap-stream shell)) + gnus-secondary-select-methods '((nntp "news.gmane.org"))) -(setq - ;; Locations - gnus-home-directory "~/.gnus.d/" - gnus-directory gnus-home-directory - gnus-article-save-directory (expand-file-name "saved/" gnus-directory) - gnus-kill-files-directory (expand-file-name "scores/" gnus-directory) - ;; Startup files - gnus-startup-file (expand-file-name "newsrc" gnus-home-directory) - gnus-init-file (expand-file-name "gnus" gnus-home-directory) - gnus-save-newsrc-file nil - gnus-read-newsrc-file nil - ;; Select methods - imap-shell-program "/usr/lib/dovecot/imap -c ~/.dovecotrc" - gnus-select-method '(nnimap "dov" (nnimap-stream shell)) - gnus-secondary-select-methods '((nntp "news.gmane.org")) - ;; Groups - gnus-topic-display-empty-topics nil - gnus-group-list-inactive-groups nil - ;; Messages - message-send-mail-function 'message-send-mail-with-sendmail - sendmail-program "/usr/bin/msmtp" - message-sendmail-envelope-from 'header - gnus-gcc-mark-as-read t - message-citation-line-function 'message-insert-formatted-citation-line - message-citation-line-format "%f wrote:" - message-kill-buffer-on-exit t - gnus-visible-headers '("^From" "^Subject" "^Date" "^To" "^Cc" "^User-Agent") - gnus-confirm-mail-reply-to-news t - footnote-section-tag "" - ;; Threading - gnus-thread-hide-subtree t - gnus-thread-sort-functions '(gnus-thread-sort-by-most-recent-number) - gnus-summary-line-format "%U%R %&user-date;%-20= %-15,15f %B %S \n" - gnus-sum-thread-tree-indent " " - gnus-sum-thread-tree-root "." - gnus-sum-thread-tree-false-root "o " - gnus-sum-thread-tree-single-indent "" - gnus-sum-thread-tree-leaf-with-other "+-> " - gnus-sum-thread-tree-vertical "| " - gnus-sum-thread-tree-single-leaf "`-> " - ;; Agent - gnus-agent-go-online t - gnus-agent-synchronize-flags t - ;; Miscellaneous - gnus-auto-select-next 'quietly - mm-discouraged-alternatives '("text/html" "text/richtext") - gnus-interactive-exit nil) +(setq gnus-agent-go-online t + gnus-agent-synchronize-flags t) + +(setq mm-discouraged-alternatives '("text/html" "text/richtext")) +(setq gnus-interactive-exit nil) + +(add-hook 'kill-emacs-hook 'gnus-grace-exit-before-kill-emacs) (defun km/sync-mail () (interactive) @@ -70,17 +52,23 @@ (gnus-alive-p)) (let ((noninteractive t)) (gnus-group-exit)))) -(add-hook 'kill-emacs-hook 'gnus-grace-exit-before-kill-emacs) -(defun km/message-confirm-sender () - "Stop sending message from the wrong address." - (unless (yes-or-no-p (format "Send message from %s?" - (message-field-value "From"))) - (user-error "Not sending message"))) +(define-prefix-command 'km/mail-map) +(global-set-key (kbd "C-x m") 'km/mail-map) -(add-hook 'message-send-hook 'km/message-confirm-sender) +(define-key km/mail-map "g" 'gnus) +(define-key km/mail-map "p" 'gnus-plugged) +(define-key km/mail-map "u" 'gnus-unplugged) +(define-key km/mail-map "s" 'km/sync-mail) -(autoload 'gnus-group-topic "gnus-topic") + +;;; Gnus group buffer + +(setq gnus-topic-display-empty-topics nil + gnus-group-list-inactive-groups nil) + +(setq gnus-group-sort-function '(km/gnus-group-sort-by-topic + gnus-group-sort-by-level)) (defun km/gnus-group-sort-by-topic (info1 info2) "Sort alphabetically by group topic. @@ -89,11 +77,30 @@ is off." (string< (gnus-group-topic (gnus-info-group info1)) (gnus-group-topic (gnus-info-group info2)))) -(setq gnus-group-sort-function '(km/gnus-group-sort-by-topic - gnus-group-sort-by-level)) +(define-key gnus-group-mode-map "e" 'gnus-group-select-group) -(add-hook 'message-mode-hook - (lambda () (flyspell-mode 1))) + +;;; Gnus summary and article buffer + +(setq gnus-summary-line-format "%U%R %&user-date;%-20= %-15,15f %B %S \n" + gnus-sum-thread-tree-indent " " + gnus-sum-thread-tree-root "." + gnus-sum-thread-tree-false-root "o " + gnus-sum-thread-tree-single-indent "" + gnus-sum-thread-tree-leaf-with-other "+-> " + gnus-sum-thread-tree-vertical "| " + gnus-sum-thread-tree-single-leaf "`-> ") + +(setq gnus-auto-select-next 'quietly) + +(setq gnus-thread-hide-subtree t + gnus-thread-sort-functions '(gnus-thread-sort-by-most-recent-number)) + +(add-hook 'gnus-summary-mode-hook 'km/gnus-setup-local-ace-jump) + +(defun km/gnus-setup-local-ace-jump () + (add-hook 'ace-jump-mode-end-hook (lambda () (gnus-summary-scroll-up 0)) + nil t)) (defun km/gnus-follow-last-message-link (arg) "Follow link at bottom of message. @@ -106,11 +113,6 @@ follow it." (shr-copy-url) (widget-button-press (point)))) -(define-key gnus-summary-mode-map - (kbd "C-c j") 'km/gnus-follow-last-message-link) -(define-key gnus-article-mode-map - (kbd "C-c j") 'km/gnus-follow-last-message-link) - (defun km/gnus-open-github-patch () "Open patch from github email. A new buffer with the patch contents is opened in another window." @@ -132,57 +134,55 @@ A new buffer with the patch contents is opened in another window." (select-window (gnus-get-buffer-window gnus-article-buffer)) (goto-char (point-max))) -(require 'notmuch) -(require 'org-gnus) -(require 'org-notmuch) -(setq org-gnus-prefer-web-links t) +;; From http://ivan.kanis.fr/ivan-gnus.el +(defun km/gnus-catchup-and-goto-next-group (&optional all) + "Mark all articles in this group as read and select the next group. +If given a prefix, mark all articles, unread as well as ticked, as +read. Don't ask to confirm." + (interactive "P") + (save-excursion + (gnus-summary-catchup all t)) + (gnus-summary-next-group)) -(define-key gnus-group-mode-map "GG" 'notmuch-search) -;; http://roland.entierement.nu/blog/2010/09/08/gnus-dovecot-offlineimap-search-a-howto.html -(defun km/notmuch-shortcut () - (define-key gnus-group-mode-map "GG" 'notmuch-search)) +;; From http://ivan.kanis.fr/ivan-gnus.el +(defadvice gnus-summary-next-group (before km/gnus-next-group activate) + "Go to next group without selecting the first article." + (ad-set-arg 0 t)) -(defun km/notmuch-file-to-group (file) - "Calculate the Gnus group name from the given file name." - (let ((group (file-name-directory (directory-file-name (file-name-directory file))))) - (setq group (replace-regexp-in-string ".*/mail/" "nnimap+dov:" group)) - (setq group (replace-regexp-in-string "/$" "" group)) - (if (string-match ":$" group) - (concat group "INBOX") - (replace-regexp-in-string ":\\." ":" group)))) +(define-key gnus-summary-mode-map + (kbd "C-c j") 'km/gnus-follow-last-message-link) +(define-key gnus-summary-mode-map ";" 'gnus-summary-universal-argument) +;; This overrides `gnus-summary-post-news', which is also bound to +;; 'S p'. +(define-key gnus-summary-mode-map "a" 'ace-jump-mode) +(define-key gnus-summary-mode-map "c" 'km/gnus-catchup-and-goto-next-group) +(define-key gnus-summary-mode-map "e" 'gnus-summary-scroll-up) +(define-key gnus-summary-mode-map "j" 'ace-jump-mode) -(defun km/notmuch-goto-message-in-gnus () - "Open a summary buffer containing the current notmuch article." - (interactive) - (let ((group (km/notmuch-file-to-group (notmuch-show-get-filename))) - (message-id (replace-regexp-in-string - "^id:" "" (notmuch-show-get-message-id)))) - (setq message-id (replace-regexp-in-string "\"" "" message-id)) - (if (and group message-id) - (progn - (switch-to-buffer "*Group*") - (org-gnus-follow-link group message-id)) - (message "Couldn't get relevant infos for switching to Gnus.")))) +(define-key gnus-article-mode-map + (kbd "C-c j") 'km/gnus-follow-last-message-link) +(define-key gnus-article-mode-map "e" 'shr-browse-url) -(defun km/gnus-goto-message-in-notmuch () - "Show message in notmuch." - (interactive) - (when (and (memq major-mode '(gnus-summary-mode gnus-article-mode)) - (string= (cadr (gnus-find-method-for-group gnus-newsgroup-name)) - "dov")) - (let* ((header (with-current-buffer gnus-summary-buffer - (gnus-summary-article-header))) - (message-id (org-remove-angle-brackets (mail-header-id header)))) - (notmuch-show (concat "id:" message-id))))) + +;;; Message mode -(add-hook 'km/org-store-link-hook 'km/gnus-goto-message-in-notmuch) +(setq message-send-mail-function 'message-send-mail-with-sendmail + message-sendmail-envelope-from 'header + message-citation-line-function 'message-insert-formatted-citation-line + message-citation-line-format "%f wrote:" + message-kill-buffer-on-exit t + footnote-section-tag "") -(define-key notmuch-show-mode-map (kbd "C-c C-c") 'km/notmuch-goto-message-in-gnus) -(add-hook 'gnus-group-mode-hook 'km/notmuch-shortcut) +(add-hook 'message-send-hook 'km/message-confirm-sender) +(add-hook 'message-mode-hook + (lambda () (flyspell-mode 1))) -(setq notmuch-fcc-dirs nil - notmuch-search-oldest-first nil) +(defun km/message-confirm-sender () + "Stop sending message from the wrong address." + (unless (yes-or-no-p (format "Send message from %s?" + (message-field-value "From"))) + (user-error "Not sending message"))) ;; Modified from ;; http://emacs-fu.blogspot.com/2008/12/some-simple-tricks-boxquote-footnote.html. @@ -211,12 +211,8 @@ paragraph." (define-key message-mode-map (kbd "C-c m s") 'km/snip-mail-quote) -(define-key gnus-summary-mode-map "c" 'km/gnus-catchup-and-goto-next-group) -(define-key gnus-summary-mode-map ";" 'gnus-summary-universal-argument) -(define-key gnus-summary-mode-map "e" 'gnus-summary-scroll-up) - -(define-key gnus-group-mode-map "e" 'gnus-group-select-group) -(define-key gnus-article-mode-map "e" 'shr-browse-url) + +;;; Select and bury ;; Modified from http://www.xsteve.at/prg/gnus/ @@ -261,40 +257,57 @@ paragraph." (bury-buffer) (bury-buffer buf)))))) -;; From http://ivan.kanis.fr/ivan-gnus.el -(defun km/gnus-catchup-and-goto-next-group (&optional all) - "Mark all articles in this group as read and select the next group. -If given a prefix, mark all articles, unread as well as ticked, as -read. Don't ask to confirm." - (interactive "P") - (save-excursion - (gnus-summary-catchup all t)) - (gnus-summary-next-group)) +(define-key km/mail-map "b" 'km/gnus-select-or-bury) -;; From http://ivan.kanis.fr/ivan-gnus.el -(defadvice gnus-summary-next-group (before km/gnus-next-group activate) - "Go to next group without selecting the first article." - (ad-set-arg 0 t)) + +;;; Notmuch -(defun km/gnus-setup-local-ace-jump () - (add-hook 'ace-jump-mode-end-hook (lambda () (gnus-summary-scroll-up 0)) - nil t)) -(add-hook 'gnus-summary-mode-hook 'km/gnus-setup-local-ace-jump) +(require 'notmuch) +(require 'org-notmuch) -;; This overrides `gnus-summary-post-news', which is also bound to -;; 'S p'. -(define-key gnus-summary-mode-map "a" 'ace-jump-mode) +(setq org-gnus-prefer-web-links t) -(define-key gnus-summary-mode-map "j" 'ace-jump-mode) +(setq notmuch-fcc-dirs nil + notmuch-search-oldest-first nil) -(define-prefix-command 'km/mail-map) -(global-set-key (kbd "C-x m") 'km/mail-map) +(add-hook 'km/org-store-link-hook 'km/gnus-goto-message-in-notmuch) + +(defun km/notmuch-file-to-group (file) + "Calculate the Gnus group name from the given file name." + (let ((group (file-name-directory (directory-file-name (file-name-directory file))))) + (setq group (replace-regexp-in-string ".*/mail/" "nnimap+dov:" group)) + (setq group (replace-regexp-in-string "/$" "" group)) + (if (string-match ":$" group) + (concat group "INBOX") + (replace-regexp-in-string ":\\." ":" group)))) + +(defun km/notmuch-goto-message-in-gnus () + "Open a summary buffer containing the current notmuch article." + (interactive) + (let ((group (km/notmuch-file-to-group (notmuch-show-get-filename))) + (message-id (replace-regexp-in-string + "^id:" "" (notmuch-show-get-message-id)))) + (setq message-id (replace-regexp-in-string "\"" "" message-id)) + (if (and group message-id) + (progn + (switch-to-buffer "*Group*") + (org-gnus-follow-link group message-id)) + (message "Couldn't get relevant infos for switching to Gnus.")))) + +(defun km/gnus-goto-message-in-notmuch () + "Show message in notmuch." + (interactive) + (when (and (memq major-mode '(gnus-summary-mode gnus-article-mode)) + (string= (cadr (gnus-find-method-for-group gnus-newsgroup-name)) + "dov")) + (let* ((header (with-current-buffer gnus-summary-buffer + (gnus-summary-article-header))) + (message-id (org-remove-angle-brackets (mail-header-id header)))) + (notmuch-show (concat "id:" message-id))))) + +(define-key notmuch-show-mode-map (kbd "C-c C-c") 'km/notmuch-goto-message-in-gnus) +(define-key gnus-group-mode-map "GG" 'notmuch-search) -(define-key km/mail-map "g" 'gnus) -(define-key km/mail-map "b" 'km/gnus-select-or-bury) -(define-key km/mail-map "p" 'gnus-plugged) -(define-key km/mail-map "u" 'gnus-unplugged) -(define-key km/mail-map "s" 'km/sync-mail) (define-key km/mail-map "n" 'notmuch-search) (provide 'init-gnus) -- cgit v1.2.3