The very unofficial .emacs home DaveGallucci.emacs
emacs
Sections
home
what is this all about ?
customization basics
special topics
local dotfiles
dotfiles on the web
new and updated pages
useful sites and pages
search locally
EMacro
OS/2 Emacs
Latest Additions
local files:
John J. Glynn
David Jolley

linked files:


articles:


links:
The Emacs wiki
ODP search for Emacs


dmoz.org
;; =====================================================================
;; =====================================================================
;; Filename: .emacs
;; Emacs initialization file
;; Dave Gallucci
;; work email galluccd@nasd.com
;; home email dgall812@concentric.net
;; =====================================================================
;; This .emacs initialization file has evolved over many months, and
;; you'll often see code or even comments that I stole from other
;; sample .emacs files, dejanews posts, lisp files, or the GNU
;; pages. I am convinced that Emacs can be made to do anything I will
;; ever need. ( or any other programmer for that matter ) If you think
;; Emacs is just an editor, you don't yet understand what Emacs is all
;; about. At one time, I used to get caught up in the Emacs vs. VI
;; thing, then decided to really learn Emacs.  Though it edits, it is
;; a total coding environment, fully extensible and able to do
;; practically anything, include amusing diversions we all need after
;; banging out a few thousand lines of code. If you see anything in
;; this file that I can improve on, please let me know. Learning Emacs
;; is a journey that doesn't end.
;; =====================================================================
;; =====================================================================

;; =====================================================================
;; BEGIN CUSTOMIZATIONS
;; =====================================================================
;; STUFF THAT HAS TO BE FIRST ACCORDING TO NOTES
;; =====================================================================

;; SET THIS FIRST!! EVERYTHING ELSE DEPENDS ON THIS VARIABLE!
(setenv "HOME" "c:/emacs")

;; =====================================================================
;; Append additional directories to load-path. For my own directory
;; tree, I have added a directory under the emacs/lisp directory
;; called elisp, and the oo-browser tree is under that one. The elisp
;; directory contains all the add-ons I use that are *not* [ yet ]
;; part of the emacs distribution. The oo-browser tree contains
;; ... what else? See entry for oo-browser below.
(setq load-path (append
                 '("~/lisp/elisp"
                   "~/lisp/elisp/oo-browser"
                   "~/lisp/elisp/oo-browser/hypb")
                 load-path))

;; =====================================================================

;; which-func-mode ( From gnu emacs FAQ ) If you set
;; which-func-mode-global via customize, which-func-mode will not turn
;; on automatically. You need to add the following to your startup
;; file BEFORE the call to custom-set-variables:
(which-func-mode 1)

;; =====================================================================
;; Emacs auto customize section. Emacs will add to this section when
;; you use the customize tool available on the help menu
;; =====================================================================

(custom-set-variables
 '(rmail-mail-new-frame t t)
 '(inhibit-startup-message t)
 '(transient-mark-mode t)
 '(which-func-mode-global t nil (which-func))
 '(scroll-step 1)
 '(scroll-conservatively 1 t)
 '(find-file-run-dired t)
 '(tab-width 4)
 '(fast-lock-save-events nil)
 '(global-font-lock-mode t nil (font-lock))
 '(global-auto-revert-mode t nil (autorevert))
 '(c-font-lock-extra-types (quote ("FILE" "\\sw+_t" "LPCTSTR" "WORD" "DWORD" "BYTE" "FIXME")))
 '(c++-font-lock-extra-types (quote ("\\sw+_t" "\\([iof]\\|str\\)+stream\\(buf\\)?" "ios" "string" "rope" "list" "slist" "deque" "vector" "bit_vector" "set" "multiset" "map" "multimap" "hash\\(_\\(m\\(ap\\|ulti\\(map\\|set\\)\\)\\|set\\)\\)?" "stack" "queue" "priority_queue" "iterator" "const_iterator" "reverse_iterator" "const_reverse_iterator" "reference" "const_reference" "LPCTSTR" "BYTE" "WORD" "DWORD" "FIXME" "true" "false" "private" "protected" "public" "__forceinline")))
 '(font-lock-global-modes t))
(custom-set-faces
 '(vhdl-font-lock-attribute-face ((((class color) (background light)) nil)))
;; '(font-lock-comment-face ((t (:foreground "blue" :background "cornsilk"))))
 '(font-lock-comment-face ((t (:foreground "ForestGreen" (background light)))))
 '(font-lock-string-face ((((class color) (background light)) (:bold nil :foreground "magenta"))))
 '(font-lock-keyword-face ((((class color) (background light)) (:bold nil :foreground "Blue"))))
 '(vhdl-font-lock-value-face ((((class color) (background light)) (:bold nil :foreground "Blue"))))
 '(font-lock-warning-face ((((class color) (background light)) (:bold nil :foreground "Black"))))
 '(font-lock-constant-face ((((class color) (background light)) (:bold nil :foreground "Black"))))
 '(vhdl-font-lock-control-signal-face ((((class color) (background light)) (:foreground "Blue"))))
 '(vhdl-font-lock-data-signal-face ((((class color) (background light)) (:foreground "Blue"))))
 '(font-lock-type-face ((((class color) (background light)) (:bold nil :foreground "Blue"))))
 '(vhdl-font-lock-clock-signal-face ((((class color) (background light)) (:foreground "Blue"))))
 '(vhdl-font-lock-reset-signal-face ((((class color) (background light)) (:foreground "Blue"))))
 '(font-lock-variable-name-face ((((class color) (background light)) (:bold nil))))
 '(vhdl-font-lock-prompt-face ((((class color) (background light)) (:foreground "Blue"))))
 '(font-lock-function-name-face ((((class color) (background light)) (:bold nil :foreground "Black"))))
 '(vhdl-font-lock-test-signal-face ((((class color) (background light)) (:foreground "Blue"))))
 '(font-lock-builtin-face ((((class color) (background light)) (:bold nil :foreground "Blue")))))

;; =====================================================================
;; EMACS SETTINGS AFFECTING ALL MODES
;; =====================================================================

;; Load gnuserv. This is required for things such as running emacs as
;; the default MSVC editor. I usually start emacs once in the morning,
;; then keep it running all day as my only editor
(require 'gnuserv)
(gnuserv-start)
(setq gnuserv-frame (selected-frame))

;; Frame title bar formatting to show full path of file
(setq-default
 frame-title-format
 (list '((buffer-file-name " %f" (dired-directory
                                                                  dired-directory
                                                                  (revert-buffer-function " %b"
                                                                                                                  ("%b - Dir:  " default-directory)))))))

(setq-default
 icon-title-format
 (list '((buffer-file-name " %f" (dired-directory
                                  dired-directory
                                  (revert-buffer-function " %b"
                                  ("%b - Dir:  " default-directory)))))))

;; Shut off annoying beep
(set-message-beep 'silent)

;; Nice alternative to c-x c-b buffer selection
;; Author: Olaf Sylvester <Olaf.Sylvester@kiel.netsurf.de>
;; Web site: http://homes.cls.net/~Olaf.Sylvester/emacs
(require 'bs)
;; (define-key function-key-map [S-tab] [backtab])
;; (define-key function-key-map [C-S-tab] [C-backtab])
;; (global-set-key [C-tab]      'bs-cycle-next)
;; (global-set-key [C-backtab] 'bs-cycle-previous)

;; do NOT add newlines if I cursor past last line in file
(setq next-line-add-newlines nil)

;; This maps edit keys to standard Windows keystokes. It requires the
;; library cua-mode.el from Kim Storm at the following URL:
;; http://eolicom.olicom.dk/~storm/cua-mode.el Good if you are used to
;; Windows key mapping and are just learning Emacs
;; (load "cua-mode")
;; (CUA-mode t)

;; Enable uppercase or lowercase conversions
(put 'downcase-region 'disabled nil)
(put 'upcase-region 'disabled nil)

;; Tell emacs where my diary file is
(setq diary-file "~/diary/.diary")

;; Replace "yes or no" with y or n
(defun yes-or-no-p (arg)
  "An alias for y-or-n-p, because I hate having to type 'yes' or 'no'."
  (y-or-n-p arg))

;; Tell emacs where central backup directory is, and turn it on
(setq backup-directory "~/backups")
(require 'backups)
(move-backups t)

;; Don't wrap long lines when viewing
(hscroll-global-mode t)

;; Load whitespace.el library. Nukes trailing whitespace from the ends
;; of lines, and deletes excess newlines from the ends of buffers,
;; every time you save.
;; Author: Noah Friedman <friedman@splode.com>
(autoload 'nuke-trailing-whitespace "whitespace" nil t)
(add-hook 'mail-send-hook 'nuke-trailing-whitespace)
(add-hook 'write-file-hooks 'nuke-trailing-whitespace)

;; These are my settings for 17 inch monitor running 1024 x 768
;; resolution. If you change font sizes, you'll probably have to tweak
;; this.
(set-frame-height (selected-frame) 45)
(set-frame-width (selected-frame) 120)

;; If you want to have comments displayed in italics, uncomment the
;; following lines. Note that this must be done before font settings!
;; (Emacs 20)
;; (setq w32-enable-italics t)
;; (make-face-italic 'font-lock-comment-face)

;; To obtain new font string, place this string:
;; (insert(prin1-to-string(w32-select-font))) in the scratch buffer
;; and hit M-x eval-buffer This will give you the font string you
;; need.

;; Defaults for all frames
(setq default-frame-alist
      '((font . "-*-Courier New-normal-r-*-*-11-82-96-96-c-*-iso8859-1")
        ;(background-color . "wheat")
        ;(foreground-color . "black")
        ))

;; Add Emacs close confirmation
(setq kill-emacs-query-functions
      (cons (lambda () (yes-or-no-p "Really kill Emacs?"))
     kill-emacs-query-functions))

;; Get rid of old versions of files
(setq delete-old-versions t)

;; Shut off warning messages when using system shell
(setq w32-allow-system-shell t)

;; Stop ^M's from displaying in system shell window
(add-hook 'comint-output-filter-functions 'shell-strip-ctrl-m nil t)

;; This prevents shell commands from being echoed
(defun my-comint-init ()
  (setq comint-process-echoes t))
(add-hook 'comint-mode-hook 'my-comint-init)

;; Shut off message buffer. Note - if you need to debug emacs,
;; comment these out so you can see what's going on.
;; (setq message-log-max nil)
;; (kill-buffer "*Messages*")

;;; Go into proper mode according to file extension
(setq auto-mode-alist
      (append '(("\\.C$"    . c++-mode)
        ("\\.cc$"   . c++-mode)
        ("\\.cpp$"  . c++-mode)
        ("\\.cxx$"  . c++-mode)
        ("\\.hxx$"  . c++-mode)
        ("\\.h$"    . c++-mode)
        ("\\.hh$"   . c++-mode)
        ("\\.idl$"  . c++-mode)
        ("\\.ipp$"  . c++-mode)
        ("\\.c$"    . c-mode)
        ("\\.pl$"   . perl-mode)
        ("\\.pm$"   . perl-mode)
        ("\\.java$" . java-mode)
        ("\\.txt$"  . text-mode))
          auto-mode-alist))

;; Automatically turn on auto-fill-mode when editing text files
(add-hook 'text-mode-hook 'turn-on-auto-fill)

;; If you want to change the word wrap column, change this number
;; (setq-default fill-column 65)

;; =====================================================================
;; MODE LINE
;; =====================================================================

;; I like to know what time it is. These lines show the clock in the
;; status bar. Comment out first line if you prefer to show time in 12
;; hour format
(setq display-time-24hr-format t)
(setq display-time-day-and-date t)
(display-time)

;; show column number in status bar
(setq column-number-mode t)

;; =====================================================================
;; FONT LOCK STUFF ( AKA SYNTAX COLORIZATION )
;; =====================================================================

;; This block makes tabs, trailing whitespace and "hardspaces" ( aka
;; &nbsp; or Alt-0160 ...) show up in gold color. Thanks to Peter
;; Steiner <unistein@isbe.ch> This, in combination with whitespace.el
;; above, makes sure my source code files are free from trailing
;; whitespace.

; (require 'font-lock)

; (if (memq (framep (selected-frame)) '(x pc win32 w32))
;     (progn
;       (make-face 'pesche-tab-face)
;       (make-face 'pesche-space-face)
;       (make-face 'pesche-hardspace-face)
;       (set-face-background 'pesche-tab-face        "LemonChiffon")
;       (set-face-background 'pesche-space-face      "Gold")
;       (set-face-background 'pesche-hardspace-face  "PaleGreen")
;       ))

; (defvar pesche-tab-face 'pesche-tab-face
;   "Face to use for highlighting tab characters in Font-Lock mode.")
; (defvar pesche-space-face 'pesche-space-face
;   "Face to use for highlighting trailing spaces in Font-Lock mode.")
; (defvar pesche-hardspace-face 'pesche-hardspace-face
;   "Face to use for highlighting hard spaces in Font-Lock mode.")

; (add-hook 'font-lock-mode-hook
;           '(lambda()
;              (setq font-lock-keywords
;                    (append font-lock-keywords
;                            '(("[\t]+" (0 'pesche-tab-face t))
;                              ("[\240]+" (0 'pesche-hardspace-face t))
;                              ("[\040\t]+$" (0 'pesche-space-face t)))))))

;; =====================================================================

;; This loads file to highlite current line
;; Author:  Dave Love <fx@gnu.org>
(load "hl-line")
;;(setq hl-line-mode t)

;; Written by Kyle Jones
;; kyle@wonderworks.com
(load "setnu")

;; =====================================================================
;; PRINT CONFIGURATION
;; =====================================================================

;; This requires GhostScript which is available at this URL:
;; http://www.cs.wisc.edu/~ghost/aladdin To print, just hit C-cp. This
;; produces a file called printme.ps in the spool directory. Open this
;; in GhostView and print from there. This works even on
;; non-postscript printers.
(setq ps-printer-name "~/spool/printme.ps")
(define-key global-map "\C-cp" 'ps-print-buffer)

;; Puts line numbers in printed pages
;;(setq ps-line-number t)

;; =====================================================================
;; COMPILING WITH MS VISUAL STUDIO
;; =====================================================================

;; Note that the lib and include environment variables must be set,
;; and they must point to all directories containing headers and
;; static libs required for your build

;; (setq compile-command "NMAKE /f \"datetimepp.mak\" CFG=\"datetimepp - Win32 Debug\"")
(setq compile-command "NMAKE /f \"datetimepp.mak\" CFG=\"datetimepp - Win32 Release\"")
;; (setq compile-command "NMAKE /f \"SCTS.mak\" \"SCTS\" - Win32 Debug\"")
;; (setq compile-command "NMAKE /f \"SCTS.mak\" \"SCTS\" - Win32 Release\"")
;; (setq compile-command "NMAKE /f \"nqds_compare.mak\" \"nqds_compare\" - Win32 Debug\"")
;; (setq compile-command "NMAKE /f \"nqds_compare.mak\" \"nqds_compare\" - Win32 Release\"")


;; =====================================================================
;; JARI AALTO'S TINY LIBRARY
;; =====================================================================

;; Defines everything, publishes interface for tiny library. This
;; library has a LOT of useful things and is available at
;; ftp://cs.uta.fi/pub/ssjaaa/ema-tiny.html
(require 'tinylibm)

;; search fwd or bkwd for word under cursor
(autoload 'tisw-search-word-forward "tinysword" t t)
(autoload 'tisw-search-word-backward "tinysword" t t)
(global-set-key [f2]   'tisw-search-word-forward)
(global-set-key [S-f2] 'tisw-search-word-backward)

(autoload 'c-comment-edit "c-comment-edit2"
  "No information available. See lisp file c-comment-edit2 for full documentation" t)
(autoload 'c-comment-edit-end "c-comment-edit2"
  "No information available. See lisp file c-comment-edit2 for full documentation" t)

;; =====================================================================
;; DIRED STUFF
;; =====================================================================

;; Hit capital X to execute file at point
(defun dired-execute-file (&optional arg)
  (interactive "P")
  (mapcar #'(lambda (file) (w32-shell-execute "open" file))
          (dired-get-marked-files nil arg)))

(defun dired-mouse-execute-file (event)
  "In dired, execute the file or goto directory name you click on."
  (interactive "e")
  (set-buffer (window-buffer (posn-window (event-end event))))
  (goto-char (posn-point (event-end event)))
  (if (dired-is-dir)
      (dired-find-file)
    (dired-execute-file)))

(defun my-dired-mode-hook ()
  "Hook run when entering dired-mode."
    (define-key dired-mode-map "X" 'dired-execute-file)
    (define-key dired-mode-map [double-down-mouse-1] 'dired-mouse-execute-file))

(add-hook 'dired-mode-hook 'my-dired-mode-hook)

;; =====================================================================
;; SEARCHING
;; =====================================================================

;; make searches case-INsensitive
(set-default 'case-fold-search t)

;; =====================================================================
;; GREP STUFF
;; =====================================================================

;; Note - requires latest grep, find, and xargs to be in emacs/bin
;; directory. It is available from the follwing URL:
;; http://www.cygnus.com/misc/gnu-win32. Once grep is completed, you
;; can visit each hit in order with C-x` ( that's a back tic )

;; this is required for igrep.el version 2.7 and later.
(defvar grep-null-device null-device)

(setq igrep-expression-quote-char ?')
(setq igrep-parenthesis-escape-char ?\\)

(autoload (function igrep) "igrep"
  "*Run `grep` PROGRAM to match EXPRESSION in FILES..." t)
(autoload (function igrep-find) "igrep"
  "*Run `grep` via `find`..." t)
(autoload (function dired-do-igrep) "igrep"
  "*Run `grep` on the marked (or next prefix ARG) files." t)
(autoload (function dired-do-igrep-find) "igrep"
  "*Run `grep` via `find` on the marked (or next prefix ARG) directories." t)

;; Ignore case by default:
(setq igrep-options "-i")
;; To search subdirectories by default:
(setq igrep-find t)

;; =====================================================================
;; CODE RELATED SETTINGS
;; =====================================================================

;; Hit f9 to force a re-fontify
(global-set-key (quote [f9]) (quote font-lock-fontify-buffer))

;; Add OO-Browser library - way cool! Fantastic tool available at
;; http://www.beopen.com. Formerly known as Altrasoft.
(load "br-start")
(global-set-key "\C-c\C-o" 'oo-browser)
(load "hmouse-tag")

;; These setting are written in the order as described in the Emacs
;; info pages. ( Hit C-hi, then go to Emacs | Programs | Program
;; Indent | Custom C Indent | Syntactic Symbols for a description of
;; each. I found it easier to open one of my own source files, and hit
;; tab on a particular line to find the name of the syntactic
;; symbol. This assumes that the setting for
;; c-echo-syntactic-information-p is not nil. )

(defconst my-c-style
  '(
    (c-echo-syntactic-information-p . t)
    (c-basic-offset                 . 4)
    (c-toggle-auto-state            . t)
    (c-offsets-alist .
             ((string                . +)
              (c                     . +)
              (defun-open            . 0)
              (defun-close           . 0)
              (defun-block-intro     . +)
              (class-open            . 0)
              (class-close           . 0)
              (inline-open           . 0)
              (inline-close          . 0)
              (extern-lang-open      . 0)
              (extern-lang-close     . 0)
              (func-decl-cont        . +)
              (knr-argdecl-intro     . +)
              (knr-argdecl           . +)
              (topmost-intro         . 0)
              (topmost-intro-cont    . +)
              (member-init-intro     . +)
              (member-init-cont      . +)
              (inher-intro           . +)
              (inher-cont            . +)
              (block-open            . 0)
              (block-close           . 0)
              (brace-list-open       . 0)
              (brace-list-close      . 0)
              (brace-list-intro      . +)
              (brace-list-entry      . 0)
              (statement             . 0)
              (statement-cont        . +)
              (statement-block-intro . +)
              (statement-case-intro  . +)
              (statement-case-open   . 0)
              (substatement          . +)
              (substatement-open     . 0)
              (case-label            . +)
              (access-label          . -)
              (label                 . 0)
              (do-while-closure      . 0)
              (else-clause           . 0)
              (catch-clause          . 0)
              (comment-intro         . 0)
              (arglist-intro         . c-lineup-arglist-intro-after-paren)
              (arglist-cont          . c-lineup-arglist)
;              (arglist-cont-nonempty . +)
              (arglist-cont-nonempty . c-lineup-arglist-intro-after-paren)
              (arglist-close         . c-lineup-arglist)
              (stream-op             . +)
              (inclass               . +)
              (inextern-lang         . +)
              (cpp-macro             . 0)
              (friend                . 0)
              (objc-method-intro     . +)
              (objc-method-args-cont . +)
              (objc-method-call-cont . +)
              ))

    (c-comment-only-line-offset . (0 . -1000))
    (c-hanging-braces-alist     . ((substatement-open after)
                   (brace-list-open)))
    (c-hanging-colons-alist     . ((member-init-intro before)
                   (inher-intro)
                   (case-label after)
                   (label after)
                   (access-label after)))
    (c-cleanup-list             . ((scope-operator
                    empty-defun-braces
                    defun-close-semi)))
    )
  "Gallucci C++ Programming Style")

(defun my-c-mode-common-hook ()
  (c-add-style "gallucci" my-c-style t)
  (c-set-offset 'member-init-intro '+)
  (setq tab-width 4
        indent-tabs-mode nil)
  (c-toggle-auto-hungry-state t)
  (define-key c-mode-base-map "\C-m" 'newline-and-indent)
  (modify-syntax-entry ?_ "w" c++-mode-syntax-table)
  (modify-syntax-entry ?_ "w" c-mode-syntax-table)
  )

(add-hook 'c-mode-common-hook 'my-c-mode-common-hook)

(setq speedbar-frame-parameters (quote
                 ((minibuffer)
                  (width          . 45)
                  (border-width   . 0)
                  (menu-bar-lines . 0)
                  (unsplittable   . t))))

;; Turn on paren mode - this highlight matching under point
(show-paren-mode 1)

;; Make the % key jump to the matching {}[]() if on another, like VI
(global-set-key "%" 'match-paren)

(defun match-paren (arg)
  "Go to the matching parenthesis if on parenthesis otherwise insert %."
  (interactive "p")
  (cond ((looking-at "\\s\(") (forward-list 1) (backward-char 1))
        ((looking-at "\\s\)") (forward-char 1) (backward-list 1))
        (t (self-insert-command (or arg 1)))))

;; This allows you to keep a tags stack and push and pop your way
;; around the source code. This feature is present in both XEmacs and
;; VI. Pop tag is mapped to M-*.
(global-set-key (read-kbd-macro "M-*") 'tags-return)

(defvar tags-stack nil)

(defun tags-stack-push (el)
  (setq tags-stack (cons el tags-stack)))

(defun tags-stack-pop ()
  (let ((el (car tags-stack)))
    (setq tags-stack (cdr tags-stack))
    el))

(defadvice find-tag (before push-tag activate)
  (or (ad-get-arg 1)
      (tags-stack-push (cons (current-buffer) (point)))))

(defadvice tags-search (before push-tag activate)
  (tags-stack-push (cons (current-buffer) (point))))

(defun tags-return ()
  (interactive)
  (let* ((el (tags-stack-pop))
         (buffer (car el))
         (point  (cdr el)))
    (if buffer (switch-to-buffer buffer))
    (if point (goto-char point))))


;; Use lazy lock for syntax coloring, otherwise large files will not
;; be colored. Also allows large files to load faster. Thanks Andrew
;; Innes
(setq font-lock-support-mode 'lazy-lock-mode)
(setq lazy-lock-defer-on-scrolling nil)
(setq lazy-lock-defer-time 1)
(setq lazy-lock-stealth-time 20)
(setq lazy-lock-stealth-lines 25)
(setq lazy-lock-stealth-verbose nil)
(require 'font-lock)
(require 'lazy-lock)

; =================================================================
;; SMTP OUTGOING MAIL SETTINGS
;; =====================================================================

;; Use signature file. Defaults to ~/.signature
;; (setq mail-signature t)

;; Work Settings
;; (setq user-mail-address "galluccd@nasd.com")
;; (setq smtpmail-default-smtp-server "TRM_SRV_EXCH1")
;; (setq mail-host-address "TRM_SRV_EXCH1")
;; (setq smtpmail-smtp-service "smtp")
;; (setq smtpmail-local-domain "nasdaq.com")
;; (setq smtpmail-debug-info t)

;; Home settings
(setq user-mail-address "dgall812@concentric.net")
(setq smtpmail-default-smtp-server "smtp.concentric.net")
(setq smtpmail-local-domain nil)

;; Common Settings
(setq user-full-name "David Gallucci")
(setq send-mail-function 'smtpmail-send-it)
(load-library "smtpmail")
(load-library "supercite")
(setq sc-nested-citation-p t)

;; =====================================================================
;; POP3 INCOMING MAIL SETTINGS
;; =====================================================================

;; Requires epop3.el by Franklin Lee. You can get it at:
;; http://www.cs.washington.edu/homes/voelker/ntemacs.html#mail-leave-rmail

;; Uncomment these lines if NOT using epop3...
;; (setenv "MAILHOST" "pop3.concentric.net")
;; (setq rmail-pop-password-required t)

;; Sample for checking numerous pop3 servers
;;    (setq rmail-primary-inbox-list
;;          '("po:me@mypopserver.domain.com"
;;            "po:m3@anotherserver.elsewhere.com"
;;            . . . ))

;; (setq rmail-primary-inbox-list
;;       '("po:dgall812@pop3.concentric.net"
;;  ))

;; ... and comment out all this stuff
;; up to and including the require line

;; Tell me when there's new mail. epop3-mail also allows you to leave
;; mail on server
;; (autoload 'epop3-mail "epop3mail"
;;   "Get mail from pop server for PO:USER@HOST and put it in TOFILE." t)

;; (autoload 'start-biff "epop3mail" "pop3 biff, unleashed" t)
;; (autoload 'stop-biff "epop3mail" "pop3 biff, muzzled" t)
;; (autoload 'restart-biff "epop3mail" "pop3 biff, RE-unleashed" t)
;; (autoload 'flush-pop-passwords "epop3mail" "flush passwords" t)
;; (autoload 'biffs-current-language "epop3mail" "what is biff talking?" t)
;; (autoload 'biffs-last-check "epop3mail" "when did biff last check?" t)
;; (autoload 'speak-biff! "biff-mode" "make biff speak" t)

;; (require 'epop3mail)

;; epop3 options

;;  Set this to non-nil for 'biff' to display the # of unread messages.
;; (setq epop3-biff-show-numbers t)

;; Set this to non-nil for 'biff' to show '[Mail:  ]' in the modeline
;; (setq epop3-biff-show-mail-string t)

;; Tell biff to start checking mail now, and do so every 15 minutes
;; (start-biff 15 t)

;; =====================================================================
;; GNUS STUFF
;; =====================================================================

(setq gnus-cache-directory "~/news/cache/")
(setq gnus-home-directory "~/news/")
(setq gnus-startup-file "~/news/.newsrc")
(setq gnus-default-nntp-server "news.concentric.net")
(setq gnus-user-full-name "David Gallucci")
(setq gnus-user-from-line "dgall812@concentric.net")
(setq gnus-use-generic-from "David Gallucci")
(setq mail-host-address "concentric.net")
(setq gnus-local-organization "Not Listed")
(setq gnus-secondary-select-methods '((nnml "")))
(setq nnmail-pop-password-required t)
(setq gnus-use-cache t)
(setq message-yank-prefix ">")

;; =====================================================================
;; MY PREFERRED KEY BINDINGS
;; =====================================================================

;; This allows c-tab and c-s-tab switching
;; Author: Igor Boukanov <boukanov@fi.uib.no>
;; Go to http://www.fi.uib.no/~boukanov/emacs/index.html
(require 'pc-bufsw)
(pc-bufsw::bind-keys [C-tab] [C-S-tab])

;; go to specific line in current buffer
(global-set-key "\C-cg" 'goto-line)

;; Eat space at point up to non-space
(global-set-key "\C-ce" 'fixup-whitespace)

;; Remap Home and End keys to move within current line, and C-Home and
;; C-End keys to beginning and end of buffer
(global-set-key [home] 'beginning-of-line)
(global-set-key [end] 'end-of-line)
(global-set-key [\C-home] 'beginning-of-buffer)
(global-set-key [\C-end] 'end-of-buffer)

;; Use hotkey to toggle speedbar. Speedbar URL is
;; http://www.ultranet.com/~zappo/speedbar.shtml
(global-set-key [f4] 'speedbar-get-focus)

;; =====================================================================
;; MINI-FUNCTIONS, MACROS, AND OTHER PERSONAL HACKS
;; =====================================================================

;; kill current buffer without confirmation
(global-set-key "\C-xk" 'kill-current-buffer)

(defun kill-current-buffer ()
  "Kill the current buffer, without confirmation."
  (interactive)
  (kill-buffer (current-buffer)))

;; =====================================================================
;; =====================================================================

;; kill-buffer-other-window
(global-set-key [f12] 'kill-buffer-other-window)

(defun kill-buffer-other-window (arg)
  "Kill the buffer in the other window, and make the current buffer full size. If no
other window, kills current buffer."
  (interactive "p")
  (let ((buf (save-window-excursion
        (other-window arg)
        (current-buffer))))
    (delete-windows-on buf)
    (kill-buffer buf))  )

;; =====================================================================
;; =====================================================================

;; kill-buffer-jump-other-window
(global-set-key [f11] 'kill-buffer-jump-other-window)

(defun kill-buffer-jump-other-window (arg)
  "Kill this buffer and jump to other window."
  (interactive "p")
    (other-window arg)
    (kill-buffer-other-window arg)  )

;; =====================================================================
;; =====================================================================

;; Good for opening header file under cursor
(global-set-key "\C-cf" 'open-file-under-cursor)

(fset 'open-file-under-cursor
   [?\C-\M-b ?\C-  ?\C-\M-f ?\C-\M-f ?\M-w ?\C-x ?\C-f ?\C-y return])

;; =====================================================================
;; =====================================================================

;; Move current line to top of window
(global-set-key "\C-ct" 'scroll-cursor-to-top)

(fset 'scroll-cursor-to-top
   "\C-u1\C-l")

;; =====================================================================
;; =====================================================================

;; Build comment box out of highlighted region
(global-set-key "\C-cx" 'box-region)

(fset 'box-region
   [?\C-u ?\M-| ?c ?o ?m ?m ?e ?n ?t return])

;; =====================================================================
;; =====================================================================

;; Copy sexp under cursor into register. Somewhat of a hack since
;; marked region remains active following copy. Macro will call
;; unmark-region. If there's a better way, show me!
(global-set-key "\C-cc" 'copy-word-under-cursor)

(fset 'copy-word-under-cursor
   [?\C-\M-b ?\C-  ?\C-\M-f ?\C-x ?r ?s ?l ?\M-x ?t ?i ?: ?: ?t ?- ?u ?n ?m ?a ?r ?k ?- ?r ?e ?g ?i ?o ?n return])

;; =====================================================================
;; =====================================================================

;; Define function to insert current date followed by
;; user-full-name. This code thanks to Douglas Gray Stephens
;; gray@cambridge.scr.slb.com
(defun stamp (arg)
  "Insert current date followed \"user-full-name\".

 This function assumes that the emacs variable \"user-full-name\" is defined
 by ones .emacs file.

 With non-nil argument omit the time from the date.
 "
  (interactive "*P")
  (set-mark-command nil)
  (let (my-time (current-time-string))
        (if arg
                (insert (concat
                                 (format-time-string "%a %d-%b-%Y %T  ")
                                 user-full-name
                                 )
                                )
          (insert (concat
                           (format-time-string "%a %d-%b-%Y %T  ")
                           user-full-name
                           )
                          )

          )
        )
  (setq last-command "")
  )

;; Bind the key Ctrl-C Ctrl-D to the command `stamp'
;; Ctrl-U Ctrl-C Ctrl-D will omit time from `stamp'
(global-set-key "\C-cd" 'stamp)

;; =====================================================================
;; =====================================================================

;; When I yank a piece of code ( known as paste in Windows lingo )
;; into an existing function, I like to have it indent itself to the
;; proper level automatically. This simple macro runs yank ( C-y )
;; followed by an indent current function. ( C-c C-q )
(global-set-key "\C-cy" 'do-smart-yank)

(fset 'do-smart-yank
   "\C-y\C-c\C-q")

;; =====================================================================
;; =====================================================================

;; Replace sexp under cursor with sexp previously copied into register
;; with above function "copy-word-under-cursor". I needed this so I
;; could do same paste operation without having first kill replace
;; what I wanted to paste
(global-set-key "\C-cv" 'replace-word-under-cursor)

(fset 'replace-word-under-cursor
   [?\C-\M-b ?\C-  ?\C-\M-f ?\C-w ?\C-x ?r ?i ?l])

;; =====================================================================
;; =====================================================================

;; Move current line to bottom of window
(global-set-key "\C-cb" 'scroll-cursor-to-bottom)

(fset 'scroll-cursor-to-bottom
   "\C-u-1\C-l")

;; =====================================================================
;; =====================================================================

;;   "Open the currently selected file / directory in the same buffer
;;   as this one."

(global-set-key "\C-co" 'dired-open-in-current-buffer)

(defun dired-open-in-current-buffer ()
  "Open the currently selected file / directory in
the same buffer as this one."
  (interactive)
  (find-alternate-file (dired-get-filename)))

;; =====================================================================
;; =====================================================================

;; Insert header file template from ~/templates directory
(defun insert-header-skeleton ()
  "Insert skeleton header file"
  (interactive)
  (insert-file-contents "~/templates/header.h"))
(global-set-key [f5] 'insert-header-skeleton)

;; =====================================================================
;; =====================================================================

;; Insert implementation file template from ~/templates directory
(defun insert-cpp-skeleton ()
  "Insert skeleton cpp file"
  (interactive)
  (insert-file-contents "~/templates/cpp.cpp"))
(global-set-key [f6] 'insert-cpp-skeleton)

;; =====================================================================
;; =====================================================================

;; Insert function comment file template from ~/templates directory
(defun insert-function-comment ()
  "Insert function comment"
  (interactive)
  (insert-file-contents "~/templates/function.cpp"))
(global-set-key [f7] 'insert-function-comment)

;; =====================================================================
;; =====================================================================

;; If point is in a class definition, return the name of the
;; class. Otherwise, return nil. Thanks to Elijah Daniel for this one.

(defun ewd-classname ()
  "If the point is in a class definition, gets the name of the class.
Return nil otherwise."
  (save-excursion
    (let ((brace (assoc 'inclass (c-guess-basic-syntax))))
      (if (null brace) '()
        (goto-char (cdr brace))
        (let ((class-open (assoc 'class-open (c-guess-basic-syntax))))
          (if class-open (goto-char (cdr class-open)))
          (if (looking-at "^class[ \t]+\\([A-Za-z_][^ \t:{]*\\)")
              (buffer-substring (match-beginning 1) (match-end 1))
            (error "Error parsing class definition!")))))))

;; Insert function prototype in current header file and matching
;; function body in implementation file.
(defun ewd-insert-new-method (rettype proto)
  "Insert a function declaration into the current class header file at
point, along with matching function definition in the corresponding
implementation file, complete with class name and scope resolution
operator.  This function expects the implementation file to be named
foo.cpp and in the same directory as the current header file, foo.h."
  (interactive "sReturn type:\nsPrototype: ")
  (let ((classname (ewd-classname))
        (c-tab-always-indent t))
    (if (null classname) (message "Not in class definition!")
      (unless (string-equal rettype "") (setq rettype (concat rettype " ")))
      (insert rettype proto ";")
      (c-indent-command)
      (save-window-excursion
        (find-file (concat (file-name-sans-extension (buffer-file-name))
                           ".cpp"))
        (end-of-buffer)
        (insert "\n\n")
        (insert-function-comment)
        (end-of-buffer)
        (insert rettype classname "::" proto "\n{\n}\n")))))

(global-set-key "\C-ci" 'ewd-insert-new-method)

;; =====================================================================
;; =====================================================================

;; If the *scratch* buffer is killed, recreate it automatically
    (save-excursion
      (set-buffer (get-buffer-create "*scratch*"))
      (lisp-interaction-mode)
      (make-local-variable 'kill-buffer-query-functions)
      (add-hook 'kill-buffer-query-functions 'kill-scratch-buffer))

    (defun kill-scratch-buffer ()
      ;; Kill the current (*scratch*) buffer
      (remove-hook 'kill-buffer-query-functions 'kill-scratch-buffer)
      (kill-buffer (current-buffer))

      ;; Make a brand new *scratch* buffer
      (set-buffer (get-buffer-create "*scratch*"))
      (lisp-interaction-mode)
      (make-local-variable 'kill-buffer-query-functions)
      (add-hook 'kill-buffer-query-functions 'kill-scratch-buffer)

      ;; Since we killed it, don't let caller do that.
      nil)

;; =====================================================================
;; =====================================================================

;; If the *Messages* buffer is killed, recreate it automatically
    (save-excursion
      (set-buffer (get-buffer-create "*Messages*"))
      (lisp-interaction-mode)
      (make-local-variable 'kill-buffer-query-functions)
      (add-hook 'kill-buffer-query-functions 'kill-scratch-buffer))

    (defun kill-scratch-buffer ()
      ;; Kill the current (*Messages*) buffer
      (remove-hook 'kill-buffer-query-functions 'kill-scratch-buffer)
      (kill-buffer (current-buffer))

      ;; Make a brand new *Messages* buffer
      (set-buffer (get-buffer-create "*Messages*"))
      (lisp-interaction-mode)
      (make-local-variable 'kill-buffer-query-functions)
      (add-hook 'kill-buffer-query-functions 'kill-scratch-buffer)

      ;; Since we killed it, don't let caller do that.
      nil)

;; =====================================================================
;; =====================================================================
;; Saving Emacs Sessions - Useful when you have a bunch of source
;; files open and you don't want to go and manually open each one,
;; especially when they are in various directories. Page 377 of the
;; GNU Emacs Manual says: "The first time you save the state of the
;; Emacs session, you must do it manually, with the command M-x
;; desktop-save. Once you have dome that, exiting Emacs will save the
;; state again -- not only the present Emacs session, but also
;; subsequent sessions. You can also save the state at any time,
;; without exiting Emacs, by typing M-x desktop-save again.
;; =====================================================================

(load "desktop")
(desktop-load-default)
(desktop-read)

;; =====================================================================
;; =====================================================================
;; USEFUL NOTES AND OTHER STUFF
;; =====================================================================

;; How to record and display a keyboard macro

;; Just open a buffer and type C-x ( Then start typing in your macro.
;; Once you are finished defining your macro type C-x ) Then type M-x
;; name-last-kbd-macro. This will allow you to call your macro
;; whatever you want. Next open up your .emacs file and position your
;; cursor where you want the code for the macro to appear.  Type M-x
;; insert-kbd-macro and type in the name.  The code will automatically
;; be generated.

;; =====================================================================
;; =====================================================================

;; Use shell-command-on-region M-| to send region to external
;; process. If you use a prefix argument , C-u M-| this will replace
;; the region with the output of the external process. Good for
;; sending something to stdin and reading from stdout.

;; =====================================================================
;; =====================================================================

;; To copy to named register: C-x r s a - Where a is the name of the
;; register ( a - z ) to save the text to.

;; To paste from named register: C-x r i a - Where a is the name of
;; the register ( a - z ) to paste the saved text from.

;; To remember current point: C-x r spc a - Where a is the name of the
;; register to save point to.

;; To jump to named point: C-x r j a - Where a is the name of the
;; register holding desired point to jump to

;; =====================================================================
;; SOME GOOD URL's FOR EMACS SOURCES
;; =====================================================================

;; http://www.splode.com/users/friedman/software/emacs-lisp/
;; http://www.anc.ed.ac.uk/~stephen/emacs/ell.html

;; =====================================================================
;; =====================================================================

All content copyright by the contributors. Website maintained with Emacs , wsmake and html-helper-mode
Emacs community logo by Daniel Lundin Last updated on Sat Jan 22 14:49:24 2005 by Ingo Koch