Emacs Resources

Tips and Tricks

I am collecting some nifty tips and tricks here for you to use… soon come…

C Indentation Style

There are several built in styles in Emacs for indentation of C code. To select between them you can use the key sequence C-c . and if you double-tab there you will get a list of such styles.

It is pretty easy to write a new style if you disagree with these coding styles. Personally I like the Linux coding style myself, although it took a bit to get used to it is actually very nice. I agree with Linus Torvalds when he says that an 8 char or tab indentation is not too much. When you are in hack mode at 4AM it is pretty nice.

In a later article I will write about this more in depth.

Start files updated

The .emacs and .gnus was updated.

Start file for the Gnus news and mail reader for Emacs

Gnus is an excellent system of reading mail and news in. I especially love it since now I can share my mail and news database and newsrc across different operating systems, in principle there is no difference between Gnus under Linux and Gnus under Windows (with a few exceptions, like pathnames and such).

I just love it. But it wasn’t too easy to set up so I hope other people will benefit from having access to my configuration files. You will need both my .emacs and my .gnus file and then you will have to locate the places in the files where you should enter information apropriate to you, such as server names, email addresses and so on.

Good luck.

My ”.emacs” (start file) for Windows NT

This is the startfile for emacs that I use under Windows NT myself. It works quite well for me. I am using an Microsoft Intellimouse Explorer with the ordinary intellimouse drivers that MS supplies with it and scrolling works fine. I have recently heard of people that uses Logitec mice that they run into certain problems sometimes. I suggest comp.emacs if you have problems with this.

dot-emacs

Folding

A nice thing is the folding capabilities of Emacs. If you are editing a large file but wants to concentrate on one part, say a soubroutine in your code you can use folding as a way of temporarily hiding what you do not want to se.

Go to the first line you want displayed, press C-SPC to mark it, go to the last and run the command

M-x narrow-to-region

now only the region you have selected will now show. The first time you do this Emacs may ask you if you want to enable this command since it is by default disabled in some installations of Emacs. Enable it and leave it enabled by answering y to the questions.

The short-hand key for this is C-x n n.

To unfold everything use C-x n w.

Stopping Emacs from moving past last line

One of the things that seems to irritate a lot of people is that emacs employs a free roaming buffer. It means that it is possible to move past the end of the file you are editing without inserting any characters like pressing RET and similar. This behaviour is not appreciated by all people so there is now a setting you can change to affect this behaviour.

(setq next-line-add-newlines nil)

Making Emacs show a clock in the status bar

Try this, if you don’t like 24 hour formats, you can just change or omit that line.

(setq display-time-24hr-format t)
      (display-time)

A note on emacs key sequences.

 

The sequence to save a file in Emacs is C-x s this means that you should hold down the CTRL key, press ”x” while doing so, release all keys and then hit ”s”. The M-q sequence is often used to align text in various input modes, to execute that sequence means to hold down the META or ALT (on a PC keyboard) key and pressing q at the same time. This can be a bit confusing if you are not used to Emacs, but you will soon learn. If you have not allready, take the Emacs tutorial now, C-h t will take you to it.

.EMACS

;; $Id: .emacs,v 1.3 2003/05/28 19:33:24 ichi Exp ichi $

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; .emacs for Ichimusai
;;
;; There are a lot of people that have helped me with my .emacs
;; knowingly and unknowingly as I have pulled certain pieces from
;; different published .emacses around the world. You are too many to
;; mention. Thanks
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(setq load-path
(append (list (expand-file-name "~/site-lisp/")
(expand-file-name "~/elisp/")
(expand-file-name "c:/cygwin/usr/share/emacs/etc/gnus/"))
load-path))

;; ;; PC bindings mode.
;; (setq pc-bindings-mode t)
;; (setq pc-selection-mode t)

;; ;; Set up the scroll wheel on my Microsoft Intellimouse Explorer to do
;; ;; what I need.
;; (defun up-slightly () (interactive) (scroll-up 5))
;; (defun down-slightly () (interactive) (scroll-down 5))
;; (global-set-key [mouse-4] 'down-slightly)
;; (global-set-key [mouse-5] 'up-slightly)

;; (defun up-one () (interactive) (scroll-up 1))
;; (defun down-one () (interactive) (scroll-down 1))
;; (global-set-key [S-mouse-4] 'down-one)
;; (global-set-key [S-mouse-5] 'up-one)

;; (defun up-a-lot () (interactive) (scroll-up 15))
;; (defun down-a-lot () (interactive) (scroll-down 15))
;; (global-set-key [C-mouse-4] 'down-a-lot)
;; (global-set-key [C-mouse-5] 'up-a-lot)

;; (defun crsr-up () (interactive) (previous-line 1))
;; (defun crsr-down () (interactive) (next-line 1))
;; (global-set-key [C-S-mouse-4] 'crsr-up)
;; (global-set-key [C-S-mouse-5] 'crsr-down)

;; I want 8 bit and ISO 8859-1 charset, so that I can use european
;; chars without a hassle.
;(standard-display-european t)
;(set-input-mode (car (current-input-mode))
;  (nth 1 (current-input-mode))
;  0)

(require 'ucs-tables)
(unify-8859-on-encoding-mode 1)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; WINDOWS DIMENSIONS
;;
;; Setup the window, fonts and stuff so that emacs looks and feels
;; okay on my display. Checks weither we are in Windows or X and
;; selects the apropriate font. Uncommented because I now run emacs in
;; so many configurations that this is just becoming disturbing
;; actually.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; (setq default-frame-alist
;;       '((top . 0)
;;         (left . 0)
;;         (width . 100)
;;         (height . 72)
;;         (menu-bar-lines . 0)
;;         (background-color . "linen")
;;         (foreground-color . "black")
;;     (cursor-color . "firebrick")))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; FONT SELECTION
;;
;; Checks what platform we are on and selects my preferred font
;; respectively. Works reasonably well.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(if (not (null window-system))
(progn
(if (eq window-system 'x)
(set-default-font "-adobe-courier-medium-r-normal-*-*-120-*-*-m-*-ISO8859-15"))
(if (eq window-system 'w32)
(set-default-font "-*-Courier New-normal-r-*-*-12-90-96-96-c-*-iso8859-1"))
(show-paren-mode t)
(global-font-lock-mode t)
(setq font-lock-maximum-decoration t))
(progn
(menu-bar-mode 1)))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; MISCELLANEOUS SETTINGS
;;
;; The stuff that don't fint anywhere else in the config file :-)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; Make my Emacs look like a fruit sallad
(global-font-lock-mode t)
(setq font-lock-maximum-decoration t)

;; Enable narrow-to-region
(put 'narrow-to-region 'disabled nil)

;; I use this function pretty often
(put 'upcase-region 'disabled nil)

;; Do not create new lines beyond the edit buffer please
(setq next-line-add-newlines nil)

;; Display a clock in the status bar
(setq display-time-24hr-format t)
(display-time)

;; No backup files please
;(setq make-backup-files nil)

;; Back up my files please
(setq make-backup-files t)

;; My own keybindings
(global-set-key "\C-\M-g" 'goto-line)
(global-set-key "\C-\M-z" 'message-caesar-region)
(global-set-key "\C-b" 'bbdb)
(global-set-key [delete] "\C-d")

;; ERC - Emacs IRC Client setup
;(require 'erc)

;; TeX Stuff
(setq tex-command 'latex
latex-command 'latex
tex-dvi-view-command "xdvi")

;; If there is a saved dekstop we would like to revive it now, load
;; all the ring buffers and restore all edit buffers and so on.
;(desktop-load-default)
;(desktop-read)

;; Sentence endings are off, in america they use ".  " we want to use
;; ". " so we have to modify this a bit.
(setq sentence-end-double-space nil)

;; The browser I prefer
;(setq browse-url-netscape-program "/usr/local/mozilla/mozilla")
(setq browse-url-netscape-program "/usr/bin/opera")

(if (not (null window-system))
(progn
(if (eq window-system 'x)
(setq browse-url-netscape-program "/usr/bin/opera"))
(if (eq window-system 'w32)
(setq browse-url-netscape-program "c:\program files\opera\opera.exe"))))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; CUSTOM SET VARIABLES. DO NOT HAND EDID THESE. USE M-x customise RET
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(custom-set-variables
;; custom-set-variables was added by Custom -- don't edit or cut/paste it!
;; Your init file should contain only one such instance.
'(all-christian-calendar-holidays t t)
'(bbdb-always-add-addresses t)
'(bbdb-check-zip-codes-p nil)
'(bbdb-complete-name-allow-cycling t)
'(bbdb-complete-name-full-completion t)
'(bbdb-completion-display-record t)
'(bbdb-completion-type nil)
'(bbdb-default-label-list (quote ("Home" "Office" "Mobile" "Other" "Work")))
'(bbdb-hashtable-size 168037)
'(bbdb-new-nets-always-primary t)
'(bbdb-north-american-phone-numbers-p nil)
'(bbdb-notice-auto-save-file t)
'(bbdb-notice-hook (quote bbdb-auto-notes-hook))
'(bbdb-offer-save (quote justdoit))
'(bbdb-phones-label-list (quote ("Home" "Office" "Mobile" "Other" "Work")))
'(bbdb-pop-up-display-layout (quote full-multi-line))
'(bbdb-pop-up-target-lines 2)
'(bbdb-quiet-about-name-mismatches t)
'(bbdb-silent-running t)
'(bbdb-use-alternate-names nil)
'(bbdb-user-mail-names "\\bAdministrator\\b")
'(bbdb/mail-auto-create-p t)
'(bbdb/news-auto-create-p t)
'(canlock-password "7411a54024168d07c0e8744be5d5c590097cb504")
'(case-fold-search t)
'(current-language-environment "Latin-1")
'(default-input-method "latin-1-prefix")
'(enable-multibyte-characters nil)
'(global-font-lock-mode t nil (font-lock))
'(gnus-global-score-files (quote ("~/News/GLOBAL.SCORE")))
'(gnus-large-newsgroup 5000)
; '(gnus-local-domain "ichimusai.org")
; '(gnus-local-organization "I have a geometric memory. Now you understand." t)
'(gnus-select-method (quote (nntp "localhost")))
'(holidays-in-diary-buffer t t)
'(mark-holidays-in-calendar t t)
'(mm-text-html-renderer (quote links))
'(nntp-address "localhost" t)
'(show-paren-mode t nil (paren))
'(text-mode-hook (quote (turn-on-auto-fill text-mode-hook-identify)))
'(transient-mark-mode t)
'(uniquify-buffer-name-style nil nil (uniquify))
'(view-calendar-holidays-initially nil t))
(custom-set-faces
;; custom-set-faces was added by Custom -- don't edit or cut/paste it!
;; Your init file should contain only one such instance.
)

.GNUS

;; -*- mode: lisp -*-

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; GNUS                                                             ;;
;; "A god in herself."                                              ;;
;; -- Unknown                                                       ;;
;;                                                                  ;;
;; Dedicated to Jeff Minter (YAK)                                   ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Customized .gnus file for Ichimusai - feel free to enhance and   ;;
;; expand on this as you see fit. Please mail me a copy if you find ;;
;; something useful that you think should go in here.               ;;
;;                                                                  ;;
;; <ichi@ichimusai.org>                  <http://www.ichimusai.org> ;;
;;                                                                  ;;
;; "No news is like GNUS!"                                          ;;
;; -- Ichimusai @ 4.30 AM last sunday...                            ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Credits to David Mason at Red Hat for helping me out by          ;;
;; publishing his own .gnus file from which I Nicked Quite A Lot!   ;;
;;                                                                  ;;
;; And some more credits goes to Torsten Hilbrich for his nice page ;;
;; on GNUS although it is in German, and I have never learned that  ;;
;; language I was able to make out some quirks of the .gnus with it ;;
;; thanks!                                                          ;;
;;                                                                  ;;
;; Sorry mates, your .gnus files were an  excellent help for me.    ;;
;;                                                                  ;;
;; Last but not least, thanks to all the guys in various newsgroups ;;
;; that have spent time trying to sort me out when I have run into  ;;
;; problems. I wish that by publishing this file I will help some   ;;
;; other people to get Gnus working!                                ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; $Id: .gnus,v 1.12 2003/05/29 10:11:12 ichi Exp ichi $
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; General Settings
;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(custom-set-variables
'(gnus-select-method
'(nntp "localhost"))
'(nntp-address "localhost")
'(gnus-local-domain "ichimusai.org")
'(gnus-large-newsgroup 5000)
)

(setq message-from-style 'angles
user-full-name "Ichimusai"

user-mail-address "ichi@ichimusai.org"
mail-host-address "ichimusai.org"
message-kill-buffer-on-exit t
message-syntax-checks '((sender . disabled))
)

(setq gnus-expert-user t)

;; Hide threads initially don't show the first article upon entering a
;; group
(setq gnus-auto-select-first t
gnus-auto-select-subject 'first
;; show collapsed threads
gnus-thread-hide-subtree t)

;; Check for new newsgroups
(setq gnus-check-new-newsgroups t)

;; Set the place where MIME stuff will go
(setq mm-default-directory "~/mime")

;;speed it up gnus!
(setq gnus-read-active-file 'some)
(setq gnus-check-bogus-newsgroup nil)

;; Fetch articles asynchronously this will prefetch articles when you
;; are reading more then one in series
(setq gnus-asynchronous t)

;;archive better :)
(setq gnus-message-archive-group
'((if (message-news-p)
(format-time-string "news.%G.%V")
(format-time-string "mail.%G.%V"))))

;;grab older messages in the thread
(setq gnus-fetch-old-headers 500)
;(setq gnus-fetch-old-headers t)
;(setq gnus-fetch-old-headers nil)
;(setq gnus-fetch-old-headers 'some)
;(setq gnus-fetch-old-headers 100)
;(setq gnus-fetch-old-headers 250)
;(setq gnus-fetch-old-headers 100)

;;abbrevs
(if (file-exists-p abbrev-file-name)
(read-abbrev-file))

;;dont ask just quit
(setq gnus-interactive-exit nil)

;;; TESTING
;; discouraged formats
(setq mm-discouraged-alternatives
'("text/html" "text/richtext"))

;;x-headers
(setq gnus-visible-headers
'(
"^Cc:"
"^Date:"
"^Followup-To:"
"^From:"
"^Keywords:"
"^Newsgroups:"
"^Mailing-List:"
"^Organization:"
"^Posted-To:"
"^Reply-To:"
"^Subject:"
"^Summary:"
"^To:"
"^X-Newsreader:"
"^X-Url:"
;    "^X-"    ; Show all X-headers
)
)

;;group separation
;;too many lists not to do this ;)
(add-hook 'gnus-group-mode-hook 'gnus-topic-mode)

;;appearance
(setq gnus-group-line-format "%M%S%5y:  %(%-65,65g%)\n")
(setq gnus-topic-line-format "%i %A: %(%{%n%}%) %v\n")

;;sort groups
(setq gnus-group-sort-functions 'gnus-group-sort-by-level)

;;Set Group Level movement
(setq gnus-keep-same-level 'best)

;;I dont want to use other newsreaders EVER! or do I?
(setq gnus-save-newsrc-file nil)

;;number of days before expiry
(setq nnmail-expiry-wait 3)

;;All Vcards be ignored,
(setq gnus-ignored-mime-types
'("text/x-vcard"))

;;View all the MIME parts in the current article
(setq gnus-mime-view-all-parts t)

;;Determine chartype in header 'Content-Type'
(setq gnus-article-decode-charset 1)

;;Decode RFC2047-encoded words in the article headers
(setq  gnus-article-decode-mime-words t)

;;Use ssh instead of rsh
;(setq nntp-rlogin-command "ssh")

;;Activate foreign newsgroups
(setq gnus-activate-foreign-newsgroups t)

;;Automatically get new mail and news every n minutes
(gnus-demon-add-handler 'gnus-group-get-new-news 15 t)

;;Paul Fisher's Gnus Stuff! Thanks Paul!
(setq gnus-treat-date-lapsed 'head
gnus-treat-emphasize t
gnus-treat-strip-pgp t
gnus-treat-strip-trailing-blank-lines t
gnus-treat-strip-leading-blank-lines nil
gnus-treat-overstrike t
gnus-treat-emphasize t
gnus-treat-highlight-signature t)

(gnus-start-date-timer)

(setq gnus-uncacheable-groups "^nnml")

;;Hierarchical subscription
(setq gnus-subscribe-hierararchical-interactive t)

;;Add gnus topic mode hook
(setq gnus-subscribe-newsgroup-method 'gnus-subscribe-topics)
(add-hook 'gnus-group-mode-hook 'gnus-topic-mode)

;; The following options are to avoid mail duplicates ...
(setq nnmail-treat-duplicates 'delete)

;; ... and crosspostings within several nnml folders If this is not
;; set - then articles will be delivered to all the folders that rules
;; match, not just the first one. Horribubble - innit?
(setq nnmail-crosspost nil)

;;; POSTING STYLES

(setq gnus-posting-styles
'((".*"
(signature-file "~/.signature")
("Face" "iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAHlBMVEVpVlPq8O+ahoJpZGWI
aF+0rbDP2t77+/tXRkMWGBYnxDeqAAACZUlEQVR4nG2Tv0/jMBTHn44OZvRAsxY3QbBVBE69
LSqp1NugnMOcSjW3drjLGrUMzoYOTrL/W77PTksHnio3eR9/n98Ph56ar40emib5GshoXwBj
hjIJqk1yDIYASSMjkQdElTGmhscE3+YQMwC4jK5qCTas5SaCC4CmGWqtl0ov9VrXwEmzYVAn
8gzuYNkyq5GLlKShGJpqlZawwFDZZigpA1jptSqDzVRaZknz11Rk1rpK+T2aUsX8uWkQCgKN
13SvUOm385BVbczyE/ApgyyAJymXIRLtJYV6DgXKs9FMTQhW8G+mRrPzUGC9ms5E571rhe2w
qvE2C2DzqxWezbn4d9NyLHr4s+h20WN9NIsa0ZKVcPcKofyr6IG/Pm8kXTzCmedYXii63Y/X
74kkN+HdHgtRePJvl26OyqeTrotH3xTC5/w0dRm3ZOqvwsYtiuyC9s1fAzz9dsuUrB0oNFhw
Yk51W4Ds/h1Dwu7Ry8ItrLWo/fRffUYnN1utsZsu34UTlgZo1883Vug5j7ssLAnez228csbg
lmQBlGXBJIBLpzUALghiqVQMuMXc+REq/gQF2bYHY3cAmeKUQQqe4nh3AFrxMLxlxQGs+RYW
SMvazjKYLU7GB4DDcYANoDzd5eoTIN2YFVpm7ZGiJNuDwvr2GAgk1TLAXHZTvruxkBSFBwXG
4lpLt/sK00K0aGEQMPCu6sFEhMoLjJ676f3/Pt1C8OF3JPbA34bPKY3p0hHwAZR5DyyuHsDu
+rFXlPlJzrCLIKu0iV8mSJ5PCBccfkG3BkBHcBcBBJAyWAeg4Eco0e0mIB+zpGgBt4EqDwAA
AABJRU5ErkJggg==")
("X-Home-Page" "http://www.ichimusai.org/")
(organization "Rikskrem"))
((message-news-p)
(address "ichi@ichimusai.org"))
((message-mail-p)
(name "Anders 'P1' Pettersson (Ichimusai)"))
("se.hobby.amatorradio"
(name "SM0UEI (Ichimusai)")
(signature-file "~/.signature-sm0uei"))
("nnml:list.*"
(name "Ichimusai"))
("alt.folklore.urban"
(signature "Ichimusai"))
("algonet.*"
(name "Anders 'P1' Pettersson (Ichimusai)"))))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; WASH HTML
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun wash-ugly-html ()
"Remove ugly HTML tags"
(interactive)
(toggle-read-only -1)
(save-excursion
(beginning-of-buffer)
(while (re-search-forward "<[^<\\.@>]*>" nil t)
(replace-match "" nil nil))
(beginning-of-buffer)
(while (re-search-forward "&gt;" nil t)
(replace-match ">" nil nil))
(beginning-of-buffer)
(while (re-search-forward "&lt;" nil t)
(replace-match "<" nil nil))
(beginning-of-buffer)
(while (re-search-forward "&.*;" nil t)
(replace-match "" nil nil))))

(global-set-key "\C-\M-H" 'wash-ugly-html)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; ADAPTIVE SCORING
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(setq gnus-use-adaptive-scoring t)
(setq gnus-default-adaptive-score-alist
'((gnus-killed-mark (subject -25) (author -1))
(gnus-replied-mark (subject +5) (author +1))
(gnus-ticked-mark (subject +5))
(gnus-saved-mark (subject +5))
(gnus-cached-mark (subject +1))
(gnus-catchup-mark (subject -1))
(gnus-read-mark (subject +5))
(gnus-kill-file-mark (subject -5) (author -1))
(gnus-forwarded-mark (subject +15) (author +15))))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; IFILE SPAM CLASSIFIER
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Full classification takes too much time!
;(require 'ifile-gnus)
;(setq ifile-classification-mode 'full-classification)
;(setq ifile-spam-groups '("spam"))
;(setq ifile-primary-spam-group "spam")

; Spam classification is easier on the CPU!
(require 'ifile-gnus)
(setq ifile-classification-mode 'spam-filter-only)
(setq ifile-spam-groups '("spam" "spam-swedish" "delivery"))
(setq ifile-primary-spam-group "spam")

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; BBDB Stuff
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;
; BBDB setup.
;
(require 'bbdb)
(require 'bbdb-hooks)
(require 'message)
;(require 'message-x)    ; Kai's wunnerful TAB-based completer.

;; Should be set to a large enough prime number Much larger then the
;; number of records in the database.
(setq bbdb-hashtable-size 168037)

(setq gnus-select-group-hook
(function
(lambda ()
;; Enable BBDB activities in mail groups.
(setq bbdb/news-auto-create-p t))))

; Add functionality to save BBDB addresses from the people you REPLY
; to.
(defun my-bbdb-add-recipients-to-bbdb ()
(mapcar
(lambda (address)
(let* ((parsed (mail-header-parse-address (bbdb-string-trim address)))
(net (car parsed))
(name (cdr parsed)))
(when (not (bbdb-search-simple name net))
(bbdb-create-internal (cdr parsed) nil (car parsed) nil nil nil))))
(append (message-tokenize-header (message-fetch-field "to"))
(message-tokenize-header (message-fetch-field "cc"))
(message-tokenize-header (message-fetch-field "bcc")))))
(add-hook 'message-send-mail-hook 'my-bbdb-add-recipients-to-bbdb)

(add-hook 'gnus-startup-hook 'bbdb-insinuate-gnus)
(add-hook 'message-setup-hook 'bbdb-define-all-aliases)
(bbdb-initialize 'gnus 'message)
;(setq bbdb-canonicalize-net-hook 'karl:bbdb-canonicalize-net-hook
(setq
bbdb-auto-notes-alist
'(("user-agent" (".*" interface 0 t))
("x-mailer" (".*" interface 0 t))
("organisation" (".*" organisation 0 t))
("organization" (".*" organisation 0 t))
("x-newsreader" (".*" interface 0 t))
("x-now-playing" (".*" playlist 0))
("xref" ("\\b[^ ]+:[0-9]+.*" seen-in 0))
("newsgroups" ("\\([^,]*\\),?" posted-to "\\1" t))))
(put 'seen-in 'field-separator "; ")
(define-key bbdb-mode-map "<" 'beginning-of-buffer)
(define-key bbdb-mode-map ">" 'end-of-buffer)
(define-key bbdb-mode-map "\r"
(lambda ()
(interactive)
(scroll-up-command 1)))
(define-key bbdb-mode-map "\177"
(lambda ()
(interactive)
(scroll-down-command 1)))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; SUPER CITE
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; (autoload 'sc-cite-original     "supercite" "Supercite 3.1" t)
;; (autoload 'sc-submit-bug-report "supercite" "Supercite 3.1" t)
;; (add-hook 'mail-citation-hook 'sc-cite-original)

;; (require 'bbdb)
;; (bbdb-initialize 'supercite)
;; (bbdb-insinuate-sc)

;; (require 'supercite)
;; (add-hook 'mail-citation-hook 'sc-cite-original)

;; ; Get rid of the leading spaces before quoted block
;; (setq sc-citation-leader "")

;; ; Remove the >>>> for the header line
;; (setq sc-reference-tag-string "")

;; ; Don't ask so many questions
;; (setq sc-confirm-always-p nil)

;; ; Where to get the attribution from
;; (setq sc-preferred-attribution-list '(
;;                       "x-attribution"
;;                       "initials"
;;                       "sc-consult"
;;                       "firstname"
;;                       "lastname")

;;     sc-attrib-selection-list
;;     '(("sc-from-address"
;;        ((".*" . (bbdb/sc-consult-attr
;;              (sc-mail-field "sc-from-address"))))))

;;     sc-mail-glom-frame
;;     '((begin (setq sc-mail-headers-start (point)))
;;       ("^x-attribution:[ \t]+.*$" (sc-mail-fetch-field t) nil t)
;;       ("^\\S +:.*$" (sc-mail-fetch-field) nil t)
;;       ("^$" (list (quote abort) (quote (step . 0))))
;;       ("^$"  (progn (bbdb/sc-default) (list 'abort '(step . 0))))
;;       ("^[ \t]+" (sc-mail-append-field))
;;       (sc-mail-warn-if-non-rfc822-p (sc-mail-error-in-mail-field))
;;       (end (setq sc-mail-headers-end (point)))))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; MAILCRYPT STUFF
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(load-library "mailcrypt")
(mc-setversion "gpg")
(autoload 'mc-install-write-mode "mailcrypt" nil t)
(autoload 'mc-install-read-mode "mailcrypt" nil t)
(add-hook 'gnus-summary-mode-hook 'mc-install-read-mode)
(add-hook 'message-mode-hook 'mc-install-write-mode)
(add-hook 'news-reply-mode-hook 'mc-install-write-mode)

;;; Custom variables

;; Use the pgp2 compatibility wrapper
;(setq mc-gpg-path "/usr/bin/gpg-compat")
;; If you have more than one key, specify the one to use
(setq mc-gpg-user-id "0x1EBEB8F2")
;; Always sign encrypted messages
(setq mc-pgp-always-sign t)
;; How long should mailcrypt remember your passphrase
(setq mc-passwd-timeout 600)

; This will auto sign all outgoing mails and articles
;(add-hook 'message-send-hook 'mc-sign)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; Ispell stuff
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;check spelling on outgoing messages
(add-hook 'message-send-hook 'ispell-message)

;; Different word lists for different groups
(add-hook 'message-mode-hook
'(lambda ()
(when (stringp gnus-newsgroup-name)
; Some groups I want in Swedish
(cond ((string-match
"^\\(se\\|telia\\|dk\\|swnet\\|algonet\\|nnml:list.moosemail\\|nnml:list.fagdevel\\)\\."
gnus-newsgroup-name)
(ispell-change-dictionary "svenska"))
(t
(ispell-change-dictionary "british"))))))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; Summary buffer options
;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; Print the currently displayed article
(define-key gnus-summary-mode-map (read-kbd-macro "C-c p")
'gnus-summary-print-article)

;;Keybinding for wide reply with original
(global-set-key "\C-R" 'gnus-summary-wide-reply-with-original)

;;make new messages bold?
(setq gnus-summary-*-face 'bold)

;;summary window
;I don't like to see much of the summary window!
(gnus-add-configuration
'(article (vertical 1.0
(summary 0.20 point)
(article 1.0))))
(gnus-add-configuration
'(reply-yank
(vertical 1.0
(summary 0.2 point)
(message 1.0 point))))

;(gnus-add-configuration
; '(article
;   (horizontal 1.0
;           (vertical 40 (group 1.0))
;           (vertical 1.0
;             (summary 0.2 point)
;         (article 1.0)))))

;(gnus-add-configuration
; '(summary
;   (horizontal 1.0
;           (vertical 40 (group 1.0))
;           (vertical 1.0 (summary 1.0 point)))))

;;new window for messages?
;(Define-key gnus-summary-mode-map "m" 'gnus-summary-mail-other-window)

;; The line format for the summary buffer
;; (%U) status of this article (read, killed, ...)
;; (%R) 'A' if I already replied to this article
;; (%z) article score as a character ('+', ' ', '-')
;; (%I) some indentation according to the thread level
;; (%( %)) highlighted and mouse-clickable
;; (%[ %]) brackets [ ] or < >
;; (%-20,20n) name of the poster, left justified in a 20 character wide field
;; (%e) wheather the thread is empty or not (an '=')
;; (%s) subject line of the article
;; (\n) newline
(setq gnus-summary-line-format
"%U%R%z%e%~(cut-left 2)~(max-right 6)o %~(cut-left 9)~(max-right
2)o:%~(cut-left 11)~(max-right 2)o%I %[%-15,15n%] %s\n")

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; Article buffer and displaying articles
;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; This hook is executed while the article is displayed.
;; Here some fancy functions are enabled.
(setq gnus-article-prepare-hook
'(gnus-article-maybe-hide-headers

;; Hide headers that are not usually interesting
gnus-article-hide-boring-headers

;; Translate overstrikes using ^H into bold text
gnus-article-treat-overstrike

;; Remove blank lines at the beginning of the article
gnus-article-strip-leading-blank-lines

;; Remove blank lines at the end of the article
gnus-article-remove-trailing-blank-lines

;; Replace consective blank lines with a single one
gnus-article-strip-multiple-blank-lines

;; Highlight the current article
gnus-article-highlight

;; Emphasize the article to translate /kursiv/, *bold*, and
;; _underlined_ text
gnus-article-emphasize

;; Displays the little faces of the sender
gnus-article-display-x-face

;; Convert textual smileys (;-) to some little icons
;    gnus-smiley-display

;; Add buttons to the from header to reply
gnus-article-add-buttons-to-head

;; Convert the Date header to a X-Sent header which displays
;; the time difference from the sending time to now.
gnus-article-date-lapsed
))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; Colors and the beautiful side of Gnus
;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; These colors are used for the different citation levels
;(copy-face 'default 'gnus-cite-face-1)
;(set-face-foreground 'gnus-cite-face-1 "orangered1")

;(copy-face 'default 'gnus-cite-face-2)
;(set-face-foreground 'gnus-cite-face-2 "saddle brown")

;(copy-face 'default 'gnus-cite-face-3)
;(set-face-foreground 'gnus-cite-face-3 "blue")

;(copy-face 'default 'gnus-cite-face-4)
;(set-face-foreground 'gnus-cite-face-4 "turquoise4")

;(copy-face 'default 'gnus-cite-face-5)
;(set-face-foreground 'gnus-cite-face-5 "forest green")

;(copy-face 'default 'gnus-cite-face-6)
;(set-face-foreground 'gnus-cite-face-6 "magenta4")

;(copy-face 'default 'gnus-cite-face-7)
;(set-face-foreground 'gnus-cite-face-7 "purple1")

;(copy-face 'default 'gnus-cite-face-8)
;(set-face-foreground 'gnus-cite-face-8 "burlywood4")

;(copy-face 'default 'gnus-cite-face-9)
;(set-face-foreground 'gnus-cite-face-9 "burlywood4")

;(copy-face 'default 'gnus-cite-face-10)
;(set-face-foreground 'gnus-cite-face-10 "burlywood4")

;; Faces for headers in the article buffer
(setq gnus-header-face-alist
'(
;; Format the more important headers as bold
;    ("\\(from\\|to\\|sender\\|newsgroups\\|subject\\):" bold bold)

;; Underline the subject
;    ("subject:" bold underline)

;; Warning messages are specially treated
("gnus-warning:" font-lock-emphasized-face bold)

;; Date header (at the moment not used) is formatted like a comment
;    ("date:" font-lock-comment-face font-lock-comment-face)

;; The same is true for any x- header
;    ("x-.*:" font-lock-comment-face font-lock-comment-face)
))

;; Face for the signature
(setq gnus-signature-face font-lock-comment-face)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; Scoring and things
;;;
;;; Scoring is pretty neat. This sets a few parameters such as a
;;; global score file and such.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; This is the global scorefile to keep some people out of my sight in
;; every group they might post into
;; Set the score file to a global file
(setq gnus-home-score-file '("~/Score/Iago.SCORE"))
(setq gnus-global-score-files '("~/Score/GLOBAL.SCORE"))
(setq gnus-kill-files-directory "~/Score/")

;; Save manual scores between sessions
(setq gnus-save-score t)

;; Score replies to myself
(add-hook 'message-sent-hook 'gnus-score-followup-article)
(add-hook 'message-sent-hook 'gnus-score-followup-thread)

;; Set expiry on temporary scores
(setq gnus-score-expiry-days 30)

;; Sort threads in the summary buffer the way I want them
(setq gnus-thread-sort-functions '(gnus-thread-sort-by-total-score))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; STATISTICS FUNCTION
;;
;; Select from summary buffer and run M-x stat RET
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun stat (beg end)
(interactive "r")
(let (header from-list subject-list from subject (n 0) (chars 0))
(save-excursion
(goto-char beg)
(while (< (point) end)
(setq header (gnus-summary-article-header))
(incf n)
(incf chars (mail-header-chars header))
(setq from (gnus-extract-address-components (mail-header-from header)))
(setq from (or (car from) (cadr from)))
(if (assoc from from-list)
(incf (cdr (assoc from from-list)))
(push (cons from 1) from-list))
(setq subject (gnus-simplify-subject (mail-header-subject header)))
(if (assoc subject subject-list)
(incf (cdr (assoc subject subject-list)))
(push (cons subject 1) subject-list))
(forward-line)))
(setq from-list (sort from-list (lambda (a b) (> (cdr a) (cdr b)))))
(setq subject-list (sort subject-list (lambda (a b) (> (cdr a) (cdr b)))))
(switch-to-buffer-other-window (get-buffer-create "*stat*"))
(insert (format "Total number of posts: %i\n" n))
(insert (format "Average bytes/post: %f\n" (/ (float chars) n)))
(insert (format "Total number of posters: %i\n" (length from-list)))
(insert (format "Average posts/poster: %f\n\n" (stat-mean from-list)))
(stat-top from-list 20)
(insert (format "\nTotal number of subjects: %i\n" (length subject-list)))
(insert (format "Average posts/subject: %f\n\n" (stat-mean subject-list)))
(stat-top subject-list 20)))

(defun stat-mean (alist)
(let ((mean 0))
(dolist (x alist)
(incf mean (cdr x)))
(/ (float mean) (length alist))))

(defun stat-top (alist &optional n)
(dotimes (i (if (integerp n)
(min n (length alist))
(length alist)))
(insert (format "%4i %s\n"
(cdr (nth i alist))
(car (nth i alist))))))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; SETTING UP LINKS FOR RENDERING HTML
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(setq mm-text-html-renderer-alist
'((links mm-inline-render-with-file
mm-links-remove-leading-blank
"links" "-dump" file)))
;"-assume-codepage" "iso-8859-1"

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; Miscellean
;;;
;;; That which goes nowhere else
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; Gnus verbosity
(setq gnus-verbose 10)

;; To allow for slightly broken signatures
(setq gnus-signature-separator
'("^-- $"         ; The standard
"^-- *$"        ; A common mangling
))

;; Jump into next group quietly when the first one is finished
;(setq gnus-auto-select-next 'quietly)

;; Auto fill mode enabled
;; (add-hook 'gnus-article-mode-hook
;;   '(lambda () (refill-mode 1)))

;; (add-hook 'gnus-article-mode-hook
;;   '(lambda () (auto-fill-mode 1)))

;; Use long filenames (based on the group name) for saving articles
(setq gnus-use-long-file-name t)

;; Don't save the newsrc file, Gnus is my one and only (newsreader of course)
;(setq gnus-save-newsrc-file nil)

;; Pseudo articles (e.g., created by decoding an uudecoded message)
;; are viewed asyncronously.
(setq gnus-view-pseudo-asynchronously t)

;; Default charset, should not be used but I do it anyway :->
;(setq mail-parse-charset 'iso-8859-1)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; Mail server settings
;;;
;;; Individual settings for one or more mail servers, and some common
:;; stuff necessary to speak to the servers and to get mail.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(setq gnus-secondary-select-methods  '((nnml ""))    ; nnml seems sensible
nnmail-mbox-file "~/Mail/Incoming"        ; Spool to this file
nnmail-get-new-mail t                ; Get new mail automatically
mail-source-delete-incoming t            ; Delete incoming mailbox)
)

;; This only works in newer version 5.8 or later.  If you want to you
;; can add ":password "xxxxx" to the construct - otherwise Gnus will
;; ask you.

(setq imap-log "*IMAP-log*")

(setq mail-sources
'(
(file :path "/var/spool/mail/ichi")
(pop :server "your.server"
:user "username"
:pass "passWoRd")
(pop :server "pop3.another.server"
:user "blahblah"
:pass "PaSSWord")
)
)

;; Gnus 5.7 or earlier versions use this
;(setenv "MAILHOST" "pop.algonet.se")    ; Post Office address
;(setq
;    nnmail-spool-file "po:krikkit"    ; Post Office account name (username)
;    nnmail-pop-password ""    ; Post Office password
;)

(require 'smtpmail)
(setq
;       smtpmail-default-smtp-server "mail1.telia.com"    ; SMTP server name
;       smtpmail-smtp-server "mail1.telia.com"        ; SMTP server name
;       smtpmail-local-domain "telia.com"        ; Your domain
smtpmail-default-smtp-server "localhost"    ; SMTP server name
smtpmail-smtp-server "localhost"        ; SMTP server name
smtpmail-local-domain "localhost"        ; Your domain
send-mail-function 'smtpmail-send-it             ; for `mail'
message-send-mail-function 'smtpmail-send-it     ; for `message-mail'
smtpmail-debug-info nil                ; Don't debug
)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; Split Methods
;;;
;;; This goes last in the file so that it is easy to find and add
;;; to. It should be pretty self-explanatory what happens here.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(setq nnmail-split-methods 'nnmail-split-fancy
nnmail-split-fancy
'(|
(: ifile-spam-filter
'(|

;; MAILINGLISTS

("List-Id" "bugtraq.list-id.securityfocus.com" "list.comp.security.bugtraq")
("List-Id" "plucker-list.rubberchicken.org" "list.ebook.plucker")
"misc"))))

Photos and other rants