;; ;; dot_myemacs for Conf emacs in /u/epita_2008/utard_s/cu/pub ;; ;; Made by Sylvain Utard - redox ;; Login ;; ;; Modified by Laurent Thomas - ManOnDaMoon ;; Login ;; ;; ;;; ======== ;;; MAC OS X ;;; ======== (if (eq window-system 'mac) (progn (add-to-list 'default-frame-alist '(alpha . 95)) (add-to-list 'default-frame-alist '(background-color . "black")) (add-to-list 'default-frame-alist '(foreground-color . "white")) (add-to-list 'default-frame-alist '(font . "-apple-monaco-medium-r-normal--10-100-72-72-m-100-mac-roman")) (add-to-list 'default-frame-alist '(cursor-color . "Orangered")) (load "~/.emacs.d/maxframe.el") (require 'maxframe) (add-hook 'window-setup-hook 'maximize-frame t)) (progn (set-background-color "black") (set-foreground-color "white") (set-cursor-color "Orangered") (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. ))) ;;; ======= ;;; OPTIONS ;;; ======= (setq inhibit-startup-message t) ; don't show the GNU splash screen (setq frame-title-format "%b") ; titlebar shows buffer's name (global-font-lock-mode t) ; syntax highlighting (setq font-lock-maximum-decoration t) ; max decoration for all modes (setq transient-mark-mode 't) ; highlight selection (setq line-number-mode 't) ; line number (setq column-number-mode 't) ; column number (when (display-graphic-p) ; if graphic (scroll-bar-mode nil) ; no scroll bar (mouse-wheel-mode t) ; enable mouse wheel ) (menu-bar-mode nil) ; no menu bar (tool-bar-mode nil) ; no tool bar (setq scroll-step 1) ; smooth scrolling (setq normal-erase-is-backspace-mode t) ; make delete work as it should (fset 'yes-or-no-p 'y-or-n-p) ; 'y or n' instead of 'yes or no' (setq default-major-mode 'text-mode) ; change default major mode to text (setq ring-bell-function 'ignore) ; turn the alarm totally off (setq make-backup-files nil) ; no backupfile (global-auto-revert-mode t) ; auto revert modified files (pc-selection-mode) ; selection with shift (auto-image-file-mode) ; to see picture in emacs (show-paren-mode t) ; Paren match highlighting (add-hook 'write-file-hooks 'delete-trailing-whitespace) ;; Delete trailing whitespaces on save (setq compilation-window-height 10) ;; pour que la fenetre de compilation ne soit pas trop grande (setq compilation-scroll-output t) ;; va tjs en bas de la fenetre de compile (setq-default gdb-many-windows t) ;; Better gdb ;;; ========== ;;; RUBY MODE ;;; ========== (load "~/.emacs.d/ruby-mode.el") (add-to-list 'auto-mode-alist' ("\\.rb$" . ruby-mode)) ;;; ========== ;;; UNIQUIFY ;;; ========== (require 'uniquify) (setq uniquify-buffer-name-style 'post-forward-angle-brackets) ;;; ========== ;;; ENCODING ;;; ========== (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) ;;; ========================== ;;; Open files/switch buffers ;;; ========================== (when (string-match "^22." emacs-version) (ido-mode t) (ido-everywhere t) ;; tab means tab, i.e. complete. Not "open this file", stupid. (setq ido-confirm-unique-completion t) ;; If the file doesn't exist, do try to invent one from a transplanar ;; directory. I just want a new file. (setq ido-auto-merge-work-directories-length -1) ;; Don't switch to GDB-mode buffers (setq ido-ignore-buffers (quote ("\\`\\*breakpoints of.*\\*\\'" "\\`\\*stack frames of.*\\*\\'" "\\`\\*gud\\*\\'" "\\`\\*locals of.*\\*\\'" "\\` "))) ) ;;; ======= ;;; BINDINGS ;;; ======= ;; BINDINGS :: isearch (global-set-key [(control f)] 'isearch-forward-regexp) ; search regexp (global-set-key [(control r)] 'query-replace-regexp) ; replace regexp (define-key isearch-mode-map [(control n)] 'isearch-repeat-forward) ; next occurence (define-key isearch-mode-map [(control p)] 'isearch-repeat-backward) ; previous occurence (define-key isearch-mode-map [(control z)] 'isearch-cancel) ; quit and go back to start point (define-key isearch-mode-map [(control f)] 'isearch-exit) ; abort (define-key isearch-mode-map [(control r)] 'isearch-query-replace) ; switch to replace mode (define-key isearch-mode-map [S-insert] 'isearch-yank-kill) ; paste (define-key isearch-mode-map [(control e)] 'isearch-toggle-regexp) ; toggle regexp (define-key isearch-mode-map [(control l)] 'isearch-yank-line) ; yank line from buffer (define-key isearch-mode-map [(control w)] 'isearch-yank-word) ; yank word from buffer (define-key isearch-mode-map [(control c)] 'isearch-yank-char) ; yank char from buffer ;; BINDINGS :: misc (if (display-graphic-p) (global-set-key [(control z)] 'undo) ; undo only in graphic mode ) (global-set-key [C-home] 'beginning-of-buffer) ; go to the beginning of buffer (global-set-key [C-end] 'end-of-buffer) ; go to the end of buffer (global-set-key [(meta g)] 'goto-line) ; goto line # (global-set-key [M-left] 'windmove-left) ; move to left windnow (global-set-key [M-right] 'windmove-right) ; move to right window (global-set-key [M-up] 'windmove-up) ; move to upper window (global-set-key [M-down] 'windmove-down) (global-set-key [(control tab)] 'other-window) ; Ctrl-Tab = Next buffer (global-set-key [C-S-iso-lefttab] '(lambda () (interactive) (other-window -1))) ; Ctrl-Shift-Tab = Previous buffer (global-set-key [f12] 'replace-string) ;; BINDINGS :: compile (global-set-key [f11] 'previous-error) (global-set-key [f12] 'next-error) (global-set-key [f10] 'recompile) (global-set-key [f9] 'compile) ;; BINDINGS :: font size (global-set-key [(control -)] 'dec-font-size) (global-set-key [(control +)] 'inc-font-size) (global-set-key [(control =)] 'reset-font-size) ;; BINDINGS :: ido (global-set-key [(control b)] 'ido-switch-buffer) ;;; ======= ;;; C HOOKS ;;; ======= ;; add header guard (defun insert-header-guard () (interactive) (save-excursion (when (buffer-file-name) (let* ( (name (file-name-nondirectory buffer-file-name)) (macro (replace-regexp-in-string "\\." "_" (upcase name))) (macro (replace-regexp-in-string "-" "_" macro)) (macro (concat macro "_")) ) (goto-char (point-min)) (insert "#ifndef " macro "\n") (insert "# define " macro "\n\n") (goto-char (point-max)) (insert "\n#endif /* !" macro " */\n") ) ) ) ) ; Auto insert C/C++ header guard (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")))) ;; C / C++ mode (require 'cc-mode) (add-to-list 'c-style-alist '("epita" (c-basic-offset . 2) (c-comment-only-line-offset . 0) (c-hanging-braces-alist . ((substatement-open before after))) (c-offsets-alist . ((topmost-intro . 0) (substatement . +) (substatement-open . 0) (case-label . +) (access-label . -) (inclass . ++) (inline-open . 0))))) (setq c-default-style "epita") ;; Count nb lines (defun rec-lines (count) (forward-line count) (when (not (= (char-after) (if (= count 1) ?} ?{))) (rec-lines count) ) (point) ) (defun lines () "Count number of lines of a C function" (interactive) (let ((old-pt (point)) (pt1 (rec-lines 1)) (pt2 (rec-lines -1))) (goto-char old-pt) (message (format "Lines : %d" (1- (count-lines pt1 pt2)))) ) ) (global-set-key "\C-x\C-l" 'lines) (defun c-insert-fixme (&optional msg) (interactive "sFixme: ") (save-excursion (end-of-line) (when (not (looking-back "^\\s*")) (insert " ")) (insert "// FIXME") (when (not (string-equal msg "")) (insert ": " msg)))) (defun c-insert-debug (&optional msg) (interactive) (when (not (looking-at "\W*$")) (beginning-of-line) (insert "\n") (line-move -1)) (c-indent-line) (insert "std::cerr << \"\" << std::endl;") (backward-char 15)) (defun c-insert-block (&optional r b a) (interactive "P") (unless b (setq b "")) (unless a (setq a "")) (if r (progn (save-excursion (goto-char (rbegin)) (beginning-of-line) (insert "\n") (line-move -1) (insert b "{") (c-indent-line)) (save-excursion (goto-char (- (rend) 1)) (end-of-line) (insert "\n}" a) (c-indent-line) (line-move -1) (end-of-line)) (indent-region (rbegin) (rend))) (progn (beginning-of-line) (setq begin (point)) (insert b "{\n") (end-of-line) (insert "\n}" a) (indent-region begin (point)) (line-move -1) (end-of-line)))) (defun c-insert-braces (&optional r) (interactive "P") (c-insert-block r)) (defun c-insert-ns (name r) (interactive "sName: \nP") (c-insert-block r (concat "namespace " name "\n"))) (defun c-insert-switch (value r) (interactive "sValue: \nP") (c-insert-block r (concat "switch (" value ")\n"))) (defun c-insert-if (c r) (interactive "sCondition: \nP") (c-insert-block r (concat "if (" c ")\n"))) (defun c-insert-class (name) (interactive "sName: ") (c-insert-block () (concat "class " name "\n") ";") (insert "public:") (c-indent-line) (insert "\n") (c-indent-line)) ;;; ======= ;;; ABBREV ;;; ======= ;; pabbrev (load "~/.emacs.d/pabbrev.el") (require 'pabbrev) (global-pabbrev-mode) ;;; ======= ;;; ENV ;;; ======= (defun build-path-string (pathList) "Builds a path string from the given list of path substrings." (setq path (car pathList)) ; Extract first path in the list (setq pathList (cdr pathList)) ; Rest of the list ;; If there's more paths in the list, append the first to the built path ;; string of the rest separated with path-separator. The magic of recursion. (if pathList (concat (concat path path-separator) (build-path-string pathList)) path) ) (setq exec-path (cons "/opt/local/bin" exec-path)) (setenv "PATH" (build-path-string exec-path)) ;;; ======= ;;; SHELL ;;; ======= (defun insert-shell-shebang () (interactive) (when (buffer-file-name) (goto-char (point-min)) (insert "#!/bin/zsh\n\n")) ) ;;; ================ ;;; File extensions ;;; ================= (add-to-list 'auto-mode-alist '("\\.l$" . c++-mode)) (add-to-list 'auto-mode-alist '("\\.y$" . c++-mode)) (add-to-list 'auto-mode-alist '("\\.ll$" . c++-mode)) (add-to-list 'auto-mode-alist '("\\.yy$" . c++-mode)) (add-to-list 'auto-mode-alist '("\\.xcc$" . c++-mode)) (add-to-list 'auto-mode-alist '("\\.xhh$" . c++-mode)) (add-to-list 'auto-mode-alist '("\\.pro$" . sh-mode)) ; Qt .pro files (add-to-list 'auto-mode-alist '("configure$" . sh-mode)) (add-to-list 'auto-mode-alist '("\\.rb$" . ruby-mode)) (add-to-list 'auto-mode-alist '("Drakefile$" . ruby-mode)) ;;; ===== ;;; Font ;;; ===== (setq default-font-size 120) (defun set-font-size (&optional size) "Set the font size to SIZE (default: default-font-size)." (interactive "nSize: ") (unless size (setq size default-font-size)) (set-face-attribute 'default nil :height size)) (defun reset-font-size () (interactive) (set-font-size)) (defun find-next (c l) (if (< c (car l)) (car l) (if (cdr l) (find-next c (cdr l)) (car l)))) (defun inc-font-size () (interactive) (let ((sizes '(60 75 90 105 120 135 170 280)) (current (face-attribute 'default :height))) (let ((new (find-next current sizes))) (set-font-size new) (message (int-to-string new))))) (defun dec-font-size () (interactive) (let ((sizes '(280 170 135 120 105 90 75 60)) (current (face-attribute 'default :height))) (let ((new (find-next current sizes))) (set-font-size new) (message (int-to-string new))))) (set-font-size 120)