; -*- mode: emacs-lisp -*-

;; UTF-8.. finally
(setq locale-coding-system 'utf-8)
(set-terminal-coding-system 'utf-8)
(set-keyboard-coding-system 'utf-8)
(set-selection-coding-system 'utf-8)
(prefer-coding-system 'utf-8)
;; More UTF-8
(setq file-name-coding-system 'utf-8)
(set-clipboard-coding-system 'utf-8)
(setq default-buffer-file-coding-system 'utf-8)
(setq coding-system-for-read 'mule-utf-8-unix)
(set-buffer-file-coding-system 'utf-8-unix)

;; Add loadpath
(setq load-path (append load-path (list "~/.emacs.d/lisp")))

;; Line numbers in left, kind of vi-style
;; linum is much faster than setnu
(require 'linum)
;; Toggle line numbers
(global-set-key (kbd "M-n") 'linum-mode)
;;(require 'setnu)
;;(require 'setnu+)

;; Autosave files (ie #foo#) in one place
(defvar autosave-dir
 (concat "~/.Backup/emacs/autosaves/"))

(make-directory autosave-dir t)

(defun auto-save-file-name-p (filename)
  (string-match "^#.*#$" (file-name-nondirectory filename)))

(defun make-auto-save-file-name ()
  (concat autosave-dir
   (if buffer-file-name
	  (concat "#" (file-name-nondirectory buffer-file-name) "#")
	(expand-file-name
	 (concat "#%" (buffer-name) "#")))))

;; Backup files (ie foo~) in one place too
(defvar backup-dir (concat "~/Backup/emacs/backups/"))
(setq backup-directory-alist (list (cons "." backup-dir)))

;; Highlight thing..
(global-font-lock-mode 1)
;; Display line number in the mode line
(line-number-mode 1)
;; And the column number too
(column-number-mode 1)

;; Beautiful colors..
(require 'color-theme)
(setq color-theme-is-global t)
(color-theme-arjen)

;; Pymacs and python-mode
(autoload 'pymacs-load "pymacs" nil t) 
(autoload 'pymacs-eval "pymacs" nil t)
(autoload 'pymacs-apply "pymacs")
(autoload 'pymacs-call "pymacs")
;;(eval-after-load "pymacs"
;;	'(add-to-list 'pymacs-load-path "your-pymacs-directory"))

;; Highlight selected text
(transient-mark-mode t)

;; Turn on tabs
(setq indent-tabs-mode t)
;(setq-default indent-tabs-mode t)
;; Bind the TAB key 
(global-set-key (kbd "TAB") 'self-insert-command)
;; Set the tab width
(setq default-tab-width 4)
(setq tab-width 4)
(setq c-basic-indent 4)

;; No double C+k when at beginning of a line
(setq kill-whole-line t)

;; No new lines to the bottom with down arrow
;(setq-default next-line-add-newlines nil)

;; Scroll only one line when past the edge
(setq scroll-step 1)

;; Display date and time always
(setq display-time-day-and-date t)
(display-time)

;; Highlight matching parentheses next to cursor
(require 'paren)
(show-paren-mode t)

;; Type "y"/"n" instead of "yes"/"no"
(fset 'yes-or-no-p 'y-or-n-p)

;; Make text-mode default
(setq default-major-mode 'text-mode)

;; Fontification in all modes
(global-font-lock-mode t t)
;; Maximum possible fontification
(setq font-lock-maximum-decoration t)

;; Use "newline-and-indent" when hit Enter key
;; it was handy, but awful when paste something from primary..
;(global-set-key "\C-m" 'newline-and-indent)

;; Follow-mode for long files
(follow-mode t)

;; Go away evil startup message
(setq inhibit-startup-message t)

;; Preserve the owner and group of the file you're editing 
(setq backup-by-copying-when-mismatch t)

;; Doing a pageup followed by a pagedown will now place the point at the same place
(require 'pager)
(global-set-key [next] 'pager-page-down)
(global-set-key [prior] 'pager-page-up)

(defun my-fixup-whitespace ()
  (interactive "*")
  (if (or (eolp)
		  (save-excursion
			(beginning-of-line)
			(looking-at "^\\s *$")))
	  (delete-blank-lines)
	  (fixup-whitespace)))