The very unofficial .emacs home DavidJolley.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
;; It seems that the system default setq max-specpdl-size isn't big enough.
;; it works on my emacs-20.6 at work, though...
(setq max-specpdl-size 1000)

;; Add my directories to load-path.
(setq load-path (append
		 '("~/lisp/elisp" "~/lisp/elisp/cc-mode-5.26")
		 load-path))

;; And prettify all frames.
(setq default-frame-alist
	'(
;;	(width . 120) (height . 86)
	(background-color . "white")
	(foreground-color . "black")
	(cursor-color . "blue")
	(cursor-type . box)
	(font . "-*-Lucida Console-normal-r-*-*-11-97-96-96-c-*-iso8859-1")
     ))

;; Add in GnuServ support.
(require 'gnuserv)
(gnuserv-start)

;; make GNUServ default to using the startup frame for it's frames.
(setq gnuserv-frame (selected-frame))

;; Just cos I'm lazy, set up selection & keys like Windows.
(delete-selection-mode)

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

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

;; And I'm too used to the uEmacs M-g binding to goto-line
(global-set-key [?\M-g] 'goto-line)

;; Tell emacs to save backups in the global backups directory...
(defun make-backup-file-name(file)
  (concat "~/backups/" (file-name-nondirectory file) "~"))

;; make cc-mode available.
(require 'cc-mode)

;; 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))

;; Phases of the moon, and sunrise and sunset times should
;; be fairly accurate, I reckon.
(setq calendar-latitude [51 30 north])
(setq calendar-longitude [0 5 west])
(setq calendar-location-name "Northampton, UK")

;;; 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)
		("\\.hpp$"  . 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))

;; And make text mode have auto-filling at column 72
(set-fill-column 72)
(defun my-text-mode-hook ()
  (auto-fill-mode)
)

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

;; I Like to know the time.  24 hour, preferably.
(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)

;; Load whitespace.el library. Nukes trailing whitespace from the ends
;; of lines, and deletes excess newlines from the ends of buffers.
;;
;; get it from: http://www.dsmit.com/lisp/
(require 'whitespace)
(setq whitespace-auto-cleanup t)
(whitespace-global-mode 1)

;; Folding mode.
;; This is only just barely useful for me. I suppose it'll become more
;; relevant as soon as I start to rely on it...

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

(defun my-folding-mode-hook ()
  (interactive)
  (setq fold-behave-table
	'((close	fold-hide)
	  (open	fold-enter)
	  (up		fold-exit)
	  (other	fold-mouse-call-original)))
	 (define-key folding-mode-map [mouse-3] 'fold-mouse-context-sensitive))

;;; I like the keys the way they used to be...
(setq fold-default-keys-function 'fold-bind-backward-compatible-keys)

(load "folding.el" 'nomessage 'noerror)
(folding-mode-add-find-file-hook)

;; Follow mode.
;; Dead useful for wider-than-tall-hires monitors.  Will let you do a
;; C-x 3, then use both windows as a single tall window, just broken in
;; half and displayed side by side.  Neat-o.
;; get it from: http://www.andersl.com/emacs/follow.html
(autoload 'follow-mode "follow.el" nil t)
(autoload 'follow-delete-other-windows-and-split "follow.el" nil t)

;;
;; Some global keys so that I can activate Follow Mode fast.
;;

(global-set-key [f8] 'follow-mode)
(global-set-key [f7] 'follow-delete-other-windows-and-split)


;;
;; The hook;  Set better keys.  (Follow Mode is not allowed to
;; set keys other than `C-c <punctuation character> <whatever>').
;;

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

(defun my-follow-mode-hook ()
  (define-key follow-mode-map "\C-c\C-v"  'follow-scroll-up)
  (define-key follow-mode-map "\C-cv"	  'follow-scroll-down)
  (define-key follow-mode-map "\C-cb"	  'follow-switch-to-buffer)
  (define-key follow-mode-map "\C-cl"	  'follow-recenter))

;;
;; I quite like a php mode.
;;
(require 'php-mode)

;; =====================================================================
;; 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)
;; Hit f9 to force a re-fontify
(global-set-key (quote [f9]) (quote font-lock-fontify-buffer))

;; And htmlize could be useful on occaision.
(require 'htmlize)

;; And because of the above, load html-helper mode...
;; Can be downloaded from  http://www.gest.unipd.it/~saint/hth.html.
(autoload 'html-helper-mode "html-helper-mode" "Yay HTML" t)
;;   To invoke html-helper-mode automatically on .html files, do this:
(setq auto-mode-alist (cons '("\\.html$" . html-helper-mode) auto-mode-alist))

;; 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                     . 0)
		      (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)))
    )
  "Dave's Programming Style")

(defun my-c-mode-common-hook ()
  (c-add-style "Dave's" my-c-style t)
  (c-set-offset 'member-init-intro '+)
  (setq compile-command "nmake -f ")
  (setq tab-width 4
	indent-tabs-mode nil)
  )

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


;; 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-maximum-decoration t)
(global-font-lock-mode t)
(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)
(setq c-font-lock-extra-types
      (append
       '("BOOL" "BSTR" "LPC?\\(W\\|T\\|OLE\\)?\\STR" "HRESULT"
	 "BYTE" "DWORD" "SOCKET" "idl_char"
	 "idl_boolean" "idl_byte" "idl_\\(short\\|long\\)_float"
	 "idl_u?\\(small\\|short\\|long\\)_int"
	 "boolean32" "unsigned\\(32\\|16\\)"
	 "SAFEARRAY" "boolean" "UINT" "ULONG" "VARIANT")       c-font-lock-extra-types))
;; define extra C++ types to font-lock
(setq c++-font-lock-extra-types
      (append
       c-font-lock-extra-types       c++-font-lock-extra-types))
(load-library "mic-paren.el")
(require 'font-lock)
(add-hook 'font-lock-mode-hook 'turn-on-fast-lock)
(setq fast-lock-cache-directories '("~/.xemacs/fast-lock/" ))
(setq-default font-lock-maximum-decoration t )
(add-hook 'emacs-lisp-mode-hook 'turn-on-font-lock)
(add-hook 'lisp-mode-hook 'turn-on-font-lock)
(add-hook 'perl-mode-hook 'turn-on-font-lock)
(add-hook 'c-mode-hook 'turn-on-font-lock)
(add-hook 'c++-mode-hook 'turn-on-font-lock)

;; =================================================================
;; SMTP OUTGOING MAIL SETTINGS
;; =====================================================================
;; Use signature file. Defaults to ~/.signature
;; (setq mail-signature t)
;; Home settings
(setq user-mail-address "dave@lucien.cx")
(setq smtpmail-default-smtp-server "post.demon.co.uk")
(setq smtpmail-local-domain nil)
;; Common Settings
(setq user-full-name "David Jolley")
(setq send-mail-function 'smtpmail-send-it)
(load-library "smtpmail")
(load-library "supercite")
(setq sc-nested-citation-p 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 "localhost")
(setq gnus-user-full-name "David Jolley")
(setq gnus-user-from-line "dave-news@lucien.demon.co.uk")
(setq message-default-news-headers
	   "From: David Jolley <dave-news@lucien.demon.co.uk>\nReply-To: David Jolley <dave@lucien.cx>\n")
(setq gnus-use-generic-from "David Jolley")
(setq mail-host-address "lucien.cx")
(setq gnus-local-organization "little, if any")
(setq gnus-secondary-select-methods '((nnml "")))
(setq nnmail-pop-password-required t)(setq gnus-use-cache t)
(setq message-yank-prefix ">")

;; 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 [f6] 'insert-function-comment)

;; Redefine the Home/End keys to (nearly) the same as visual studio behaviour...
;; special home and end by Shan-leung Maverick WOO <sw77@cornell.edu>
(global-set-key [home] 'My-smart-home)
(global-set-key [end] 'My-smart-end)
(defun My-smart-home ()
  "Odd home to beginning of line, even home to beginning of text/code."
  (interactive)
  (if (and (eq last-command 'My-smart-home)
	   (/= (line-beginning-position) (point)))
    (beginning-of-line)
    (beginning-of-line-text))
)
(defun My-smart-end ()
  "Odd end to end of line, even end to begin of text/code."
  (interactive)
  (if (and (eq last-command 'My-smart-end)
	   (= (line-end-position) (point)))
    (end-of-line-text)
    (end-of-line))
)
(defun end-of-line-text ()
  "Move to end of current line and skip comments and trailing space.
Require `font-lock'."
  (interactive)
  (end-of-line)
  (let ((bol (line-beginning-position)))
    (unless (eq font-lock-comment-face (get-text-property bol 'face))
      (while (and (/= bol (point))
		  (eq font-lock-comment-face
		      (get-text-property (point) 'face)))
	(backward-char 1))
      (unless (= (point) bol)
	(forward-char 1) (skip-chars-backward " \t\n"))))
)

;; 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)

;; Get the desktop & buffers re-loaded on emacs start.
;; Need to do M-x desktop-save to save it the first time.
(load "desktop")
(desktop-load-default)
(desktop-read)

;; I quite fancy a web browser within Emacs...
;; ---------------------------------------------------------------------------
;; w3 - emacs as a html Browser !!
;; available at: http://www.cs.indiana.edu/l/www/elisp/w3/docs.html
;; I'll give it a try
;; ---------------------------------------------------------------------------
(setq load-path
      (cons "~/lisp/elisp/w3-4.0pre.46/lisp" load-path))
;; I moved from this job a while back, but these are here for when I'm behind
;; another proxy server, and need to get this working pronto.
;;(setq url-proxy-services '(("http"     . "10.96.1.50:80")
;;			   ("ftp"      . "100.1.1.3:8080")
;;                           ))
(require 'w3-auto)

;; A function for printing an ASCII table.  Bind it to F3
;; Also, a function for making my appaling maths better.  Bound to F4.

(global-set-key [f3] 'ascii-table)
(global-set-key [f4] 'mult-table)

(setq ascii-unprint-chars-low ["NUL " "SOH " "STX " "ETX " "EOT "
			       "ENQ " "ACK " "BEL " "BS  " "HT  "
			       "LF  " "VT  " "FF  " "CR  " "SO  "
			       "SI  " "DLE " "DC1 " "DC2 " "DC3 "
			       "DC4 " "NAK " "SYN " "ETB " "CAN "
			       "EM  " "SUB " "ESC " "FS  " "GS  "
			       "RS  " "US  "])

;; I make no apologies for my maths being awful, so here's my get
;; out of jail free function.  Sometimes it's nice instead of going
;; to *scratch* and evaluating some stuff.
;; It's also dead useful for mpuz, too...
(defun mult-table()
  "Prints a formatted multiplication table."
  (interactive)
  (switch-to-buffer "*MULT*")
  (erase-buffer)
  (insert "Multiplication table:\n\n")
  (let ((i 1))
					; Start of table.  Print header.
    (insert "     1  2  3  4  5  6  7  8  9 10\n")
    (while (< i 11)
      (setq j 1)
      (if (< i 10)
	(insert (format "\n %d " i))
	(insert (format "\n%d " i))
	)
      (while (< j 11)
	(setq k (* i j))
	(if (< k 10)
	  (insert (format "  %d" k))
	  (insert (format " %d" k))
	  )
	(setq j (+ j 1))
	)
      (setq i (+ i 1))
      )
    )
  (beginning-of-buffer)
  )

(defun ascii-table ()
  "Prints a formatted ASCII table.  With control characters symbolically shown"
  (interactive)
  (switch-to-buffer "*ASCII*")
  (erase-buffer)
  (insert "ASCII Table:\n\n")
  (let ((i 0))
    (let ((j 0))
      ; Start of table.  Print header.
      (insert "    0   1   2   3   4   5   6   7   8   9   A   B   C   D   E   F")
      (while (< i 16)
	(setq j 0)
	; Add in "Not Ascii after this point seperator" if i = 8
	(if (= i 8)
	    (insert "\n\nCharacters after 127 aren't defined in the ASCII spec\n but are defined on this computer's locale as\n")
	  )
	; start of new line, insert table index
	(insert (format "\n %X  " i))
	(while (< j 16)
	  (let ((char-num (+ (* i 16) j)))
	    (if (or (< char-num 32))
		(insert (aref ascii-unprint-chars-low char-num))
	      (if (= char-num 127)
		  (insert "DEL ")
		(if (or (< char-num 127) (> char-num 159))
		    (insert (format "%c   " char-num))
		  (insert "    ")
		  )
		)
	      )
	    )
	  (setq j (+ j 1))
	  )
	(setq i (+ i 1))
	)
      )
    )
  (beginning-of-buffer)
  )

;; Color-themes package.  Headers in source file:
;; Author: Jonadab the Unsightly One <jonadab@bright.net>
;; Maintainer: Alex Schroeder <alex@gnu.org>
;; URL: http://www.emacswiki.org/cgi-bin/wiki.pl?ColorTheme
;;
(require 'color-theme)
(color-theme-sitaramv-solaris) ; mmm - cuddly.

;; Now some trickery to print from emacs.
;; Uses Ghostview http://www.cs.wisc.edu/~ghost
;; and ghostscript http://sourceforge.net/projects/ghostscript/
(require 'ps-print)

(setq ps-lpr-command "c:\\Ghostgum\\gsview\\gsprint.exe")

;; THis line causes ghostscript to query which printer to
;; use - which you may not need if, for example, you only
;; have one printer.
(setq ps-lpr-switches '("-query"))
(setq ps-printer-name t)
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