algorithm /.emacs

This .emacs depends on a lot of external .els. It can only by pure luck successfully be loaded on other machines than mine. I should add that yasnippets are wonderful. Pymacs works with this setup and there are a lot of goodies for those who dig far in this file...
;Time-stamp: <2008-10-09 21:29:52 algorithm>
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; initialize load-paths ;;;;;;;;;;;;;;;;;;;;;;;;;
(add-to-list 'load-path "~/lib/elisp")
(add-to-list 'load-path "~/lib/elisp/color-theme")
(add-to-list 'load-path "~/lib/elisp/yasnippet")
(add-to-list 'load-path "~/lib/elisp/orgmode")
;(add-to-list 'load-path "~/lib/elisp/pymacs")
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; load modes &c.
(require 'color-theme)
(color-theme-initialize)

;; (require 'highlight-current-line)
;; (highlight-current-line-on "y")

; templates resides in ~/lib/elisp/templates.el
(require 'templates)

(require 'ido)
(ido-mode t)

(require 'yasnippet)
(yas/initialize)
(yas/load-directory "~/lib/elisp/yasnippet/snippets")

(load "auctex.el" nil t t)
(load "preview-latex.el" nil t t)

(require 'psvn)

(autoload 'lua-mode "lua-mode" "Lua editing mode." t)

;; make del and insertions overwrite a selected region
(require 'delsel)
(delete-selection-mode t)
;(setq delete-selection-mode 't)

(require 'org-install)


;; number the windows (yes, frames) for easy access, maybe I should replace this with windmove, just maybe...
(autoload 'window-number-meta-mode "window-number" t)
;; and enable it globally
(window-number-meta-mode)

; for the mode-line, enable column-numbering
(column-number-mode)

;; mode-list
(add-to-list 'auto-mode-alist '("\\.org\\'" . org-mode))
(add-to-list 'auto-mode-alist '("\\.xml\\'" . nxml-mode))
(add-to-list 'auto-mode-alist '("\\.xsd\\'" . nxml-mode))
(add-to-list 'auto-mode-alist '("\\.cs\\'" . java-mode))
(add-to-list 'auto-mode-alist '("\\.rst\\'" . rst-mode))
(add-to-list 'auto-mode-alist '("\\.ipy\\'" . python-mode))
(add-to-list 'auto-mode-alist '("\\.lua\\'" . lua-mode))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ui things
;(color-theme-deep-blue) ;; afslappet
;(color-theme-high-contrast) ;; nemlig det.
(color-theme-colorful-obsolescence) ;;farver og striber!

;(set-face-background 'highlight-current-line-face "grey100")
(show-paren-mode t)

;(set-face-font 'default "-bitstream-bitstream vera sans mono-medium-r-*-*-*-80-*-*-*-*-*-*")
(set-face-font 'default "-adobe-courier-medium-r-normal--0-0-100-100-m-0-iso10646-1")
;(set-face-font 'default "-b&h-lucidatypewriter-medium-r-normal-sans-0-0-100-100-m-0-iso10646-1")

;(set-face-font 'default "-*-lucidatypewriter-medium-*-*-*-16-*-*-*-*-*-*-*")
;(set-face-font 'default "-adobe-courier-medium-r-normal-*-16-100-*-*-*-*-iso10646-1")

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; hooks and functions ;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;
;; hooks
(add-hook 'after-save-hook 'my-aftershave-function)

; Time stamp hook on save
(add-hook 'write-file-hooks 'time-stamp)
; but only within the first 10 lines
(setq time-stamp-line-limit 10)

;;;;;;;;;;;
;;functions
(defun my-aftershave-function ()
  (and (equal (expand-file-name "~/.emacs") buffer-file-name)
       (load-file (expand-file-name "~/.emacs"))))

(defun insert-timestamp ()
  "Inserts time-stamp in top of file, commented"
  (interactive)
  (goto-char (point-min))
  (insert (concat comment-start "Time-stamp: <>\n"))
)

;; Toggles fullscreen mode. not needed in ion3, but here for reference
(defun toggle-full-screen ()
  (interactive)
  (shell-command "wmctrl -r :ACTIVE: -btoggle,fullscreen"))

;; Like C-k but from the end of line, cool
(defun backwards-kill-line () (interactive) (kill-region
                   (point) (progn (beginning-of-line) (point))))

;; resize frames with one line
(defun shrink-window-1 ()
  (interactive)
  (shrink-window 1))
(defun grow-window-1 ()
  (interactive)
  (shrink-window (- 0 1)))
(defun scroll-up-1 ()
  (interactive)
  (scroll-up 1))
(defun scroll-down-1 ()
  (interactive)
  (scroll-down 1))

(defun scroll-up-5 ()
  (interactive)
  (scroll-up 5))
(defun scroll-down-5 ()
  (interactive)
  (scroll-down 5))

(defun iwb ()
  "indent whole buffer"
  (interactive)
  (delete-trailing-whitespace)
  (indent-region (point-min) (point-max) nil)
  (untabify (point-min) (point-max)))

(defun copy-line (&optional arg)
      "Save current line into Kill-Ring without mark the line "
       (interactive "P")
       (let ((beg (line-beginning-position)) 
     	(end (line-end-position arg)))
         (copy-region-as-kill beg end))
     )

;; Split a window in two coloums, two rows
(defun split-window-in-four ()
  "Splits a window in two columns, two rows"
  (interactive)
  (split-window-horizontally)
  (split-window-vertically)
  (other-window 2)
  (split-window-vertically)
  (other-window -2)
)
(defun toggle-window-split ()
  (interactive)
  (if (= (count-windows) 2)
      (let* ((this-win-buffer (window-buffer))
	     (next-win-buffer (window-buffer (next-window)))
	     (this-win-edges (window-edges (selected-window)))
	     (next-win-edges (window-edges (next-window)))
	     (this-win-2nd (not (and (<= (car this-win-edges)
					 (car next-win-edges))
				     (<= (cadr this-win-edges)
					 (cadr next-win-edges)))))
	     (splitter
	      (if (= (car this-win-edges)
		     (car (window-edges (next-window))))
		  'split-window-horizontally
		'split-window-vertically)))
	(delete-other-windows)
	(let ((first-win (selected-window)))
	  (funcall splitter)
	  (if this-win-2nd (other-window 1))
	  (set-window-buffer (selected-window) this-win-buffer)
	  (set-window-buffer (next-window) next-win-buffer)
	  (select-window first-win)
	  (if this-win-2nd (other-window 1))))))

;; does a general java.sun.com search, but mostly hits the api
(defun search-java-at-point ()
  (interactive)
  (let ((search (thing-at-point 'word)))
    (browse-url-firefox (concat "http://search.sun.com/search/sun/index.jsp?qt=" search)
                        )
    )
)

;; docs.python.org
(defun search-python-at-point ()
  (interactive)
  (let ((search (thing-at-point 'word)))
    (browse-url-firefox (concat "http://www.google.com/search?q=" search"&domains=docs.python.org&sitesearch=docs.python.org&sourceid=google-search&submit=submit")
                        )
    )
)

;;searches on emacswiki.org
(defun search-elisp-at-point ()
  (interactive)
  (let ((search (thing-at-point 'word)))
    (browse-url-firefox (concat "http://www.google.com/search?q=" search"&domains=www.emacswiki.org&sitesearch=www.emacswiki.org&sourceid=google-search&submit=submit")
                        )
    )
)

;; registers search-functions with major modes
(defun search-expr-at-point ()
  (interactive)
  (cond 
   ((eq major-mode 'java-mode) (search-java-at-point))
   ((eq major-mode 'python-mode) (search-python-at-point))
   ((eq major-mode 'emacs-lisp-mode) (search-elisp-at-point))
   )
)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; variable settings

;; reduce number of standard keypresses for Steen
(fset 'yes-or-no-p 'y-or-n-p)

;; makes the emacs frame title display the absolute path of the buffer-file-name
(setq frame-title-format "%f")

;(setq printer-name "Minolta")
(setq ps-paper-type 'a4)
(setq ps-font-size '(9 . 10.5))
(setq ps-n-up-printing 2)
(setq printer-name "pdf")

;make all emacs backupfiles go into ~/.emacs.d
(setq backup-directory-alist
      '(("." . "~/.emacs.d")))

; orgmode variables

;;I use org-mode from the git repos. Currently installed is: do eval-last-sexp on next line
;; (org-version)

; I prefer return to activate a link
; Carsten tells us (http://article.gmane.org/gmane.emacs.orgmode/2088/match=return+follows+link),
; that we need to set the variable _before_ running org.el (or org-install)
; go figure...
(setq org-return-follows-link t)

;; org-mode customizations
(if (file-exists-p "~/.org/org.emacs")
    (load-file "~/.org/org.emacs"))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; programming language specifics

;;; python ;;;

;; Pymacs and autocomplete
 (require 'python)
;; (require 'ipython)
(require 'pycomplete)

(autoload 'pymacs-apply "pymacs")
(autoload 'pymacs-call "pymacs")
(autoload 'pymacs-eval "pymacs" nil t)
(autoload 'pymacs-exec "pymacs" nil t)
(autoload 'pymacs-load "pymacs" nil t)

 (autoload 'python-mode "python-mode" "Python editing mode." t)

;; (setq interpreter-mode-alist(cons '("python" . python-mode)
;;                                  interpreter-mode-alist))
(setq python-mode-hook
     '(lambda () (progn
                   (set-variable 'py-python-command "/usr/bin/ipython")
                   (set-variable 'py-indent-offset 4)
                   (set-variable 'py-smart-indentation nil)
                   (set-variable 'indent-tabs-mode nil)
                   (set-variable 'yas/minor-mode t)))

;; Highlight long lines on python mode
(font-lock-add-keywords
 'python-mode
 '(("^[^\n]\\{80\\}\\(.*\\)$"
    1 font-lock-warning-face prepend)))

;(define-key python-mode-map [C-tab]  'py-complete)
(global-set-key [C-tab] 'py-complete)

; python default http://www.python.org/dev/peps/pep-0008/
(setq-default tab-width 4)

;;; ReST ;;;

;; mode for restructured text
(require 'rst)  ;; or (load "rst")
(setq auto-mode-alist (cons '( "\\.rst\\'" . rst-mode ) auto-mode-alist ))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; key bindings ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; jeg foretrækker ansi-term som min shell og naturligvis zshell
(global-set-key [M-f2] '(lambda () (interactive) (ansi-term "/bin/zsh" "terminal")))

;; custom functions bound here, see under functions
(global-set-key [C-prior] 'shrink-window-1)
(global-set-key [C-next]  'grow-window-1)

(global-set-key [s-down] 'scroll-up-1)
(global-set-key [s-up] 'scroll-down-1)

;med logitech keyboard
(global-set-key [XF86AudioRaiseVolume] 'scroll-down-5)
(global-set-key [XF86AudioLowerVolume] 'scroll-up-5)

;hurtig switch mellem buffers i en frame
(global-set-key [s-left] 'previous-buffer)
(global-set-key [s-right] 'next-buffer)

(global-set-key "\M-o" 'other-window)

(global-set-key "\M-r" 'revert-buffer)

;; mark-whole-buffer bruges tit ( brug i stedet C-x h)
;;(global-set-key "\M-a" 'mark-whole-buffer)

(global-set-key "\M-n" 'linum-mode)

;; undo gør jeg mig meget i
(global-set-key [M-backspace] 'undo-only)

;; inserts predefined headers based on major mode
(global-set-key "\C-c\ h" 'insert-header)

;; see function defs
(global-set-key "\C-c\ t" 'insert-timestamp)

;; split window in four
(global-set-key "\C-x\ 4" 'split-window-in-four)

;kill-copy line
(global-set-key "\C-c\ l" 'copy-line)

;reverse of C-k
(global-set-key "\C-l" 'backwards-kill-line) ; C-u in zsh

;; see printer variables for more info
(global-set-key "\C-cp" 'ps-print-buffer-with-faces)

;; org-mode keybindings
(global-set-key "\C-cl" 'org-store-link)
(global-set-key "\C-ca" 'org-agenda)
(global-set-key "\C-cb" 'org-iswitchb)
(global-set-key "\C-cr" 'org-remember)
;; jump to line no.
(global-set-key "\M-g" 'goto-line)

;; does a search at point
(global-set-key "\C-c\ s" 'search-expr-at-point)

;; I really need to configure this...
;(global-set-key [C-tab] 'hippie-expand)

;; un-bindings:
;;;;;;;;;;;;;;;
;; ingen godnat til emacs
(when window-system
    (global-unset-key (kbd "C-z")))

;; jeg mailer andetsteds fra
(global-unset-key (kbd "C-x m"))

;; insert: nej, hellere yank
(global-unset-key [insert])
(global-set-key [insert] 'yank)

;; jeg rammer af en eller anden grund hele tiden denne tastkombo...
(global-unset-key (kbd "C-o"))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; variables ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(setq auto-insert-directory "~/.emacs.d/insert")
(setq ido-save-directory-list-file "~/.emacs.d/.ido.last")

;; no startup screen
(setq inhibit-startup-screen t)

;; and scratch should be scratch
(setq initial-scratch-message "" )
(setq history-delete-duplicates t)
(setq history-length 100)
(setq icomplete-mode t)
(setq ido-everywhere t)
(setq initial-major-mode (quote text-mode))
(setq visible-bell t)

;; use spaces when indenting
(setq-default indent-tabs-mode nil)

;; Scroll step - how much the screen scrolls up and down.
(setq-default scroll-step 1)
(setq-default scroll-conservatively 1000)

;; enlarge bytes for undo's (from 20000)
(setq undo-strong-limit 150000)
(setq undo-limit 100000)

;; Increase the maximum size on buffers that should be fontified
(setq font-lock-maximum-size 1256000)

; no toolbar, no scrollbar, no menubar
(if (fboundp 'scroll-bar-mode) (scroll-bar-mode -1))
(if (fboundp 'tool-bar-mode) (tool-bar-mode -1))
;(if (fboundp 'menu-bar-mode) (menu-bar-mode -1))

;; do various stuff based on the ip address we recieve
(let ((address (shell-command-to-string "ifconfig  | grep 'inet addr' | awk -F: '{print $2}' | awk '{print $1}' | grep -v '^127.'")))
  (cond ((string-match "^172\\." address)
         ;; at dbc:
         (setq my-org-file "dbc.org"))
        ((string-match "^192\\." address)
         ;; at home:
         (setq my-org-file "home.org"))
        (t
         ;; anywhere else
         (setq my-org-file "home.org"))))