
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Emacs Configuration File by Vjeux (vjeuxx@gmail | chedea_c - EPITA 2012);
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Useful configs
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


;; CEDET

;(load-file "~/bin/cedet-1.0pre6/common/cedet.el")

;(global-ede-mode 1)

;(defun my-c-mode-cedet-hook ()
; (local-set-key " " 'semantic-complete-self-insert)
; (local-set-key "." 'semantic-complete-self-insert)
; (local-set-key ">" 'semantic-complete-self-insert))
;(add-hook 'c-mode-common-hook 'my-c-mode-cedet-hook)

;(semantic-load-enable-gaudy-code-helpers)

; Slime

(add-to-list 'load-path "~/.emacs.d/slime/")  ; your SLIME directory
(setq inferior-lisp-program "/usr/local/bin/sbcl") ; your Lisp system

(require 'slime)
(slime-setup '(slime-fancy slime-banner))
(define-key slime-mode-map (kbd "M-<tab>") 'slime-fuzzy-complete-symbol)
(define-key slime-repl-mode-map (kbd "M-<tab>") 'slime-fuzzy-complete-symbol)
(slime-setup)


;; Display Tabs

(load "~/.emacs.d/tabbar.el")
(tabbar-mode 1)

(global-set-key (kbd "<A-left>") 'tabbar-backward)
(global-set-key (kbd "<A-right>") 'tabbar-forward)

;; Autocomplete
;; (load "~/bin/auto-complete.el")
;; (load "~/bin/auto-complete-config.el")
;; (require 'auto-complete)
;; (global-auto-complete-mode t)


;; GDB Enhancement
(ido-mode)

(setq ido-ignore-buffers (quote ("\\'\\*breakpoints of.*\\*\\'"
                                 "\\'\\*stack frames of.*\\*\\'"
                                 "\\'\\*gud\\*\\'"
                                 "\\'\\*locals of.*\\*\\'" "\\' ")))
(setq-default gdb-many-windows t)


;; Replace
(global-set-key (kbd "C-r") 'replace-regexp)
;; (global-set-key (kbd "C-h") 'replace-string)

;; Use the mouse
(xterm-mouse-mode 1)

;; Wheel Mouse Scrolling
(mouse-wheel-mode t)

;; Indent Style
(setq c-default-style "bsd"
      c-basic-offset 2)

;; Indent by 2
(setq standard-indent 2)

;; Prevent Emacs from making backup files
(setq make-backup-files nil)

;; Show line-number in the mode line
(line-number-mode 1)

;; Show column-number in the mode line
(column-number-mode 1)

;; Remove Startup message
(setq inhibit-startup-message t)

;; Remove the Top bar
(menu-bar-mode nil)

;; Don't make me type out 'yes' and 'no'
(fset 'yes-or-no-p 'y-or-n-p)

;; Color the code
(require 'font-lock)
(global-font-lock-mode t)

;; Activate the <end> key to go at the end of the line
(global-set-key "\e[4~" 'end-of-line)
(global-set-key (kbd "<end>") 'end-of-line)

;; Set scrolling 1 line by 1, the default configuration is confusing
(setq scroll-step 1)
(setq scroll-preserve-screen-position nil)
(setq scroll-conservatively 50)

;; Prevents emacs from adding a tab character. Will be replaced by spaces
; (setq-default indent-tabs-mode nil)

;; Show trailing whitespace
(setq-default show-trailing-whitespace t)

;; Delete key
(normal-erase-is-backspace-mode 0)

;; Show matching parenthesis
(show-paren-mode t)

;; Set the window title to the active buffer
(setq frame-title-format "%b")

;; Dynamic Completion (Press "alt + /" to use)
(dynamic-completion-mode)

;; Comments are all in red
(custom-set-faces
 '(font-lock-comment-face ((t (:foreground "brown")))))
  (if (functionp 'global-hi-lock-mode)
      (global-hi-lock-mode 1)
    (hi-lock-mode 1))

;; Highlight when > 80 cols
(defun eightycols nil
  (defface line-overflow
    '((t (:background "red" :foreground "black")))
    "Face to use for `hl-line-face'.")
  (highlight-regexp "^.\\{80,\\}$" 'line-overflow)
)
(add-hook 'find-file-hook 'eightycols)

;; Alt + Arrows -> Change buffer
;;(global-set-key [A-left] 'windmove-left)
;;(global-set-key [A-right] 'windmove-right)
(global-set-key [A-up] 'windmove-up)
(global-set-key [A-down] 'windmove-down)

;; block hide (C, CPP)
; (add-hook 'c-mode-common-hook 'hs-minor-mode)
; (define-key c-mode-base-map [f10] 'hs-hide-block)
; (define-key c-mode-base-map [f11] 'hs-show-block)
(global-set-key [f4] 'previous-error)
(global-set-key [f3] 'next-error)
(global-set-key [f2] 'recompile)
(global-set-key [f5] 'compile)

;; Headers
(defun insert-header-guard ()
  (interactive)
  (save-excursion
    (when (buffer-file-name)
        (let*
            ((name (file-name-nondirectory buffer-file-name))
             (macro (replace-regexp-in-string
                     "\\." "_"
                     (replace-regexp-in-string
                      "-" "_"
                      (upcase name)))))
          (goto-char (point-min))
          (insert "#ifndef " macro "_\n")
          (insert "# define " macro "_\n\n")
          (goto-char (point-max))
          (insert "\n#endif /* !"macro"_ */\n")))))

(add-hook 'find-file-hooks
          (lambda ()
            (when (and (memq major-mode '(c-mode c++-mode)) (equal (point-min) (point-max)) (string-match ".*\\.hh?" (buffer-file-name)))
              (insert-header-guard)
              (goto-line 3)
              (insert "\n"))))


;; Kill word forward
(global-set-key [(control delete)]
                'kill-word)
