(fset 'yes-or-no-p 'y-or-n-p)
(load "/usr/share/emacs/site-lisp/site-gentoo")
(load "mercurial")
(partial-completion-mode)

(defun win ()
  (tool-bar-mode nil)
  (load "color-theme")
 (color-theme-initialize)
  (color-theme-deep-blue)
  (set-default-font "Bitstream Vera Sans Mono-9")
(setq inhibit-startup-message t)
;(add-to-list 'default-frame-alist '(font . "Bitstream Vera Sans Mono-10"))
;(set-default-font "-misc-fixed-medium-r-normal--16-140-75-75-c-90-iso8859-1")
;(add-to-list 'default-frame-alist '(font . "-misc-fixed-medium-r-normal--16-140-75-75-c-90-iso8859-1"))
;(set-default-font "-misc-fixed-medium-r-normal--14-130-75-75-c-70-iso8859-1")
;(set-background-color "dark gray")
;; (set-default-font "-misc-fixed-medium-r-normal--13-120-75-75-c-80-iso8859-1")
;; (set-default-font "-misc-fixed-medium-r-semicondensed--13-120-75-75-c-60-iso8859-1")
;; (set-default-font "-misc-fixed-medium-r-normal--15-120-*-*-*-*-iso8859-1")
;; (set-default-font "-misc-fixed-medium-r-normal--18-120-100-100-c-90-iso8859-1")
;; (set-default-font "-misc-fixed-medium-r-normal--20-120-*-*-*-*-iso8859-1")
;; (set-default-font "-adobe-courier-medium-r-normal--14-100-100-100-m-90-iso8859-1")
;(set-background-color "DarkBlue")
;(set-foreground-color "yellow")
;(require 'color-theme)
;(color-theme-sitaramv-solaris)
;(color-theme-blue-sea)
;(color-theme-comidia)
;(color-theme-jonadabian)
;(color-theme-subtle-hacker)
;(set-background-color "black")
;; wheel mouse
;(global-set-key [mouse-4] 'scroll-down)
;(global-set-key [mouse-5] 'scroll-up)
;;; For imwheel
;(mwheel-install)
;(setq mwheel-follow-mouse t)
)


(defun con ()
  (menu-bar-mode nil)
  ;(set-background-color "black"))
)

(if (window-system)
    (win)
  (con))

(add-to-list 'load-path "/usr/share/emacs/site-lisp/tex-utils")
;(require 'xdvi-search)
;(require 'pycomplete)
;(require 'jka-compr) (jka-compr-install)

;(define-key c-mode-base-map (kbd "<tab>") 'dabbrev-expand)
;(global-set-key § 'dabbrev-expand)


;(setq auto-mode-alist (cons '("SConstruct" . python-mode) auto-mode-alist))

(defun python-mode-untabify ()
  (save-excursion
    (goto-char (point-min))
    (while (re-search-forward "[ \t]+$" nil t)
      (delete-region (match-beginning 0) (match-end 0)))
    (goto-char (point-min))
    (if (search-forward "\t" nil t)
        (untabify (1- (point)) (point-max))))
  nil)

(add-hook 'python-mode-hook
	  '(lambda ()
	     (make-local-variable 'write-contents-hooks)
	     (setq python-basic-indent 4)
	     (add-hook 'write-contents-hooks 'python-mode-untabify)))

;(standard-display-european 1)
(setq european-calendar-style t)
;(require 'iso-syntax)
(setq display-time-day-and-date t
      display-time-24hr-format t)
(display-time)
;(setq vertical-scroll-bars 'right)
(custom-set-variables
  ;; custom-set-variables was added by Custom.
  ;; If you edit it by hand, you could mess it up, so be careful.
  ;; Your init file should contain only one such instance.
  ;; If there is more than one, they won't work right.
 '(blink-cursor nil)
 '(c-basic-indent 4)
 '(c-basic-offset 4)
 '(c-cleanup-list (quote (brace-else-brace brace-catch-brace scope-operator)))
 '(c-default-style "linux")
 '(c-progress-interval 1)
 '(c-strict-syntax-p nil)
 '(column-number-mode t)
; '(fringe-mode 0 nil (fringe))
 '(global-font-lock-mode t nil (font-lock))
 '(indent-tabs-mode nil) ; insert spaces instead
 '(scroll-bar-mode (quote right))
; '(semanticdb-default-save-directory "/tmp/")
 '(standard-indent 4)
 '(tab-width 4)
 '(tool-bar-mode nil nil (tool-bar))
 '(tooltip-mode -1 nil (tooltip))
 '(transient-mark-mode t))
;(custom-set-faces
  ;; custom-set-faces was added by Custom.
  ;; If you edit it by hand, you could mess it up, so be careful.
  ;; Your init file should contain only one such instance.
  ;; If there is more than one, they won't work right.
; )

(setq Man-notify-method 'pushy)

;; (defun ip-compile ()
;;   (interactive)
;;   (let (original-buffer (buffer-name))
;;     (switch-to-buffer "makefile.mk")
;;     (compile "dmake libs all")
;;     (switch-to-buffer original-buffer))
;;   (other-window 1)
;;   (end-of-buffer)
;;   (other-window -1)
;; )
;; (global-set-key [f7] 'ip-compile)

;(setq debug-on-error t)
;(setq debug-on-next-call t)
;(setq debug-on-entry t)
(defun gud-run-to-cursor ()
  (interactive)
  (gud-tbreak (concat
               (car (last (split-string (buffer-file-name) "/")))
               ":"
               (substring (what-line) 5)))
  (gud-cont "cont")
)
(defun lulbuf ()
  (interactive)
  (switch-to-buffer nil))
(global-set-key [f12] 'lulbuf)
;(global-set-key [f12] (other-window 1))

(defun my-c-mode-hook ()
  (setq c-basic-offset 4)
  (setq c-comment-only-line 0)
  (setq tab-width 4)
  (setq indent-tabs-mode nil)
  (c-set-offset 'substatement-open 0)
  ;; GDB key bindings
  (local-set-key [f5] 'gud-cont)
  (local-set-key [\S-f7] 'compile)
  (local-set-key [f9] 'gud-break)
  (local-set-key [\S-f9] 'gud-run-to-cursor)
  (local-set-key [f10] 'gud-next)
  (local-set-key [f11] 'gud-step)
  (local-set-key [\S-f11] 'gud-finish)
  (message "my-c-mode-hook was run")
)
(add-hook 'c-mode-common-hook 'my-c-mode-hook)

(set-scroll-bar-mode 'right)

(defun insert-tilde ()
  "mg: inserts ~ at cursorposition"
  (interactive)
  (insert "~"))
(global-set-key [dead-tilde] 'insert-tilde)

(defun other-window-backward (&optional n)
  "Select Nth previous window"
  (interactive "P")
  (other-window (- (prefix-numeric-value n))))

;; My key mappings
(global-set-key "\M-g" 'goto-line)
(global-set-key "\C-x\C-n" 'other-window)
(global-set-key "\C-x\C-p" 'other-window-backward)
(global-set-key [S-iso-lefttab] 'complete-tag)

(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.
 '(case-fold-search t)
 '(current-language-environment "English")
 '(global-font-lock-mode t nil (font-lock))
 '(show-paren-mode t nil (paren))
 '(transient-mark-mode 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.
;;  '(font-lock-builtin-face ((((class color) (background light)) (:foreground "blue" :weight bold))))
;;  '(font-lock-comment-face ((((class color) (background light)) (:foreground "green4" :slant italic :family unspecified))))
;;  '(font-lock-constant-face ((((class color) (background light)) (:foreground "CadetBlue4"))))
;;  '(font-lock-function-name-face ((((class color) (background light)) (:foreground "brown" :weight bold))))
;;  '(font-lock-keyword-face ((((class color) (background light)) (:foreground "black" :weight bold))))
;;  '(font-lock-string-face ((((class color) (background light)) (:foreground "magenta4"))))
;;  '(font-lock-type-face ((((class color) (background light)) (:foreground "steelblue4"))))
;;  '(font-lock-variable-name-face ((((class color) (background light)) (:foreground "DarkGoldenrod4")))))

(put 'upcase-region 'disabled nil)

(defun my-remove-trailing-whitespaces-hook ()
  (save-restriction
    (widen)
    (save-excursion
      (mark-whole-buffer)
      (delete-trailing-whitespace)))
)

(add-hook 'write-file-hooks 'my-remove-trailing-whitespaces-hook)
(set-language-environment 'Latin-1)

(defun insert4 (a b)
  (interactive "r")
  (indent-rigidly a b 4))
(global-set-key "\M-q" 'insert4)

;; create a backup file directory
(defun make-backup-file-name (file)
  (concat "~/.emacs_backups/" (file-name-nondirectory file) "~"))

(put 'downcase-region 'disabled nil)

(global-set-key (kbd "M-[ 1 ; 5 D") 'backward-word)
(global-set-key (kbd "M-[ 1 ; 5 C") 'forward-word)
(global-set-key (kbd "M-[ 1 ; 5 A") 'backward-paragraph)
(global-set-key (kbd "M-[ 1 ; 5 B") 'forward-paragraph)

;-highlight FIXME/HACK/XXX/TODO etc aggressively
(modify-face (quote font-lock-warning-face) "orange" "firebrick" nil t t nil nil nil)
(font-lock-add-keywords 'python-mode
 '(("\\<\\(FIXME\\|HACK\\|XXX\\|TODO\\)" 1 font-lock-warning-face prepend)))
(font-lock-add-keywords 'c-mode
 '(("\\<\\(FIXME\\|HACK\\|XXX\\|TODO\\)" 1 font-lock-warning-face prepend)))
(font-lock-add-keywords 'latex-mode
 '(("\\<\\(FIXME\\|HACK\\|XXX\\|TODO\\)" 1 font-lock-warning-face prepend)))

(setq locale-preferred-coding-systems
      (cons (cons ".*\\.utf-8" 'utf-8) locale-preferred-coding-systems))
;((lambda (cs)
;   (set-keyboard-coding-system cs)
;   (if cs (set-terminal-coding-system cs)))
; (set-locale-environment nil))
