Initial commit

This commit is contained in:
Némunaire 2012-10-13 21:35:28 +02:00
commit 99e3df82b7
28 changed files with 2639 additions and 0 deletions

26
configs/coding-style.el Normal file
View file

@ -0,0 +1,26 @@
(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)))))
(c-add-style
"e"
'("gnu"
(show-trailing-whitespace t)
(indent-tabs-mode . nil)
(tab-width . 8)
(c-offsets-alist .
((defun-block-intro . 3)
(statement-block-intro . 3)
(case-label . 1)
(statement-case-intro . 3)
(inclass . 3)
))))

114
configs/custom.el Normal file
View file

@ -0,0 +1,114 @@
;; Remove useless features
(menu-bar-mode nil)
;(tool-bar-mode nil)
;(scroll-bar-mode nil)
(setq inhibit-startup-message t)
;;Save backup files into a specific directory, not in the working directry
(defun make-backup-file-name (file)
(concat "~/.emacs.d/backup/" (file-name-nondirectory file) "~"))
;; Enable some minor mode changing mode line
(column-number-mode t) ; Show column number
(line-number-mode t) ; Show line number
(display-time-mode t) ; A clock in the mode line
;; Show matching parentheses
(show-paren-mode t)
(defadvice show-paren-function
(after show-matching-paren-offscreen activate)
"If the matching paren is offscreen, show the matching line in the
echo area. Has no effect if the character before point is not of
the syntax class ')'."
(interactive)
(if (not (minibuffer-prompt))
(let ((matching-text nil))
;; Only call `blink-matching-open' if the character before point
;; is a close parentheses type character. Otherwise, there's not
;; really any point, and `blink-matching-open' would just echo
;; "Mismatched parentheses", which gets really annoying.
(if (char-equal (char-syntax (char-before (point))) ?\))
(setq matching-text (blink-matching-open)))
(if (not (null matching-text))
(message matching-text)))))
;; Enable usefull modes
(global-font-lock-mode t) ; syntax highlighting
(setq font-lock-maximum-decoration t) ; max decoration for all modes
(auto-compression-mode t) ; Auto decompress compressed files.
(setq set-mark-command-repeat-pop t)
(autoload 'nuke-trailing-whitespace "whitespace" nil t)
(setq delete-old-versions t) ; delete oldversion file
(setq default-major-mode 'text-mode) ; change default major mode to text
(global-auto-revert-mode t) ; auto revert modified files
(dynamic-completion-mode) ; dynamic completion
;; setting for auto-close brackets for electric-pair-mode regardless of current major mode syntax table
(electric-pair-mode t)
(setq electric-pair-pairs '(
(?\" . ?\")
(?\{ . ?\})
) )
;; In linux, make copy/paste work with other apps
(setq x-select-enable-clipboard t)
;; Compilation window
(setq compilation-window-height 14)
(setq compilation-scroll-output t)
(require 'uniquify)
(setq uniquify-buffer-name-style 'post-forward-angle-brackets)
(setq-default ispell-program-name "aspell")
;; GDB use all existing window
(setq-default gdb-many-windows t)
;; Recognize test suite output
(require 'compile)
(add-to-list 'compilation-error-regexp-alist '("^\\(PASS\\|SKIP\\|XFAIL\\|TFAIL\\): \\(.*\\)$" 2 () () 0 2))
(add-to-list 'compilation-error-regexp-alist '("^\\(FAIL\\|XPASS\\): \\(.*\\)$" 2 () () 2 2))
(require 'flymake)
(add-hook 'find-file-hooks 'flymake-find-file-hook)
;;IswitchBuffer configuration
(iswitchb-mode t)
(setq iswitchb-buffer-ignore '("^\\*"))
(defun iswitchb-local-keys ()
(mapc (lambda (K)
(let* ((key (car K)) (fun (cdr K)))
(define-key iswitchb-mode-map (edmacro-parse-keys key) fun)))
'(("<right>" . iswitchb-next-match)
("<left>" . iswitchb-prev-match)
("<up>" . ignore )
("<down>" . ignore ))))
(add-hook 'iswitchb-define-mode-map-hook 'iswitchb-local-keys)
;; Save and restore window layout
(defvar winconf-ring ())
(defun push-winconf ()
(interactive)
(window-configuration-to-register ?%)
(push (get-register ?%) winconf-ring))
(defun pop-winconf ()
(interactive)
(set-register ?% (pop winconf-ring))
(jump-to-register ?%))
(defun restore-winconf ()
(interactive)
(set-register ?% (car winconf-ring))
(jump-to-register ?%))
;; 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)

173
configs/editing.el Normal file
View file

@ -0,0 +1,173 @@
(defun c-switch-hh-cc ()
(interactive)
(let ((other
(let ((file (buffer-file-name)))
(if (string-match "\\.hh$" file)
(replace-regexp-in-string "\\.hh$" ".cc" file)
(replace-regexp-in-string "\\.cc$" ".hh" file)))))
(find-file other)))
(defun count-word (start end)
(let ((begin (min start end))(end (max start end)))
(save-excursion
(goto-char begin)
(re-search-forward "\\W*") ; skip blank
(setq i 0)
(while (< (point) end)
(re-search-forward "\\w+")
(when (<= (point) end)
(setq i (+ 1 i)))
(re-search-forward "\\W*"))))
i)
(defun stat-region (start end)
(interactive "r")
(let
((words (count-word start end)) (lines (count-lines start end)))
(message
(concat "Lines: "
(int-to-string lines)
" Words: "
(int-to-string words)))
)
)
(defun ruby-command (cmd &optional output-buffer error-buffer)
"Like shell-command, but using ruby."
(interactive (list (read-from-minibuffer "Ruby command: "
nil nil nil 'ruby-command-history)
current-prefix-arg
shell-command-default-error-buffer))
(shell-command (concat "ruby -e '" cmd "'") output-buffer error-buffer))
;; Shebangs
(defun insert-shebang (bin)
(interactive "sBin: ")
(save-excursion
(goto-char (point-min))
(insert "#!" bin "\n\n")))
(defun insert-shebang-if-empty (bin)
(when (buffer-empty-p)
(insert-shebang bin)))
;; C/C++
;; Comment boxing
(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")))))
(defun insert-header-inclusion ()
(interactive)
(when (buffer-file-name)
(let
((name
(replace-regexp-in-string ".c$" ".h"
(replace-regexp-in-string ".cc$" ".hh"
(file-name-nondirectory buffer-file-name)))))
(insert "#include \"" name "\"\n\n"))))
(defun sandbox ()
"Opens a C++ sandbox in current window."
(interactive)
(cd "/tmp")
(let ((file (make-temp-file "/tmp/" nil ".cc")))
(find-file file)
(insert "int main()\n{\n\n}\n")
(line-move -2)
(save-buffer)
(compile (concat "g++ -W -Wall -I /usr/include/qt4/ -I /usr/include/qt4/QtCore/ -L /usr/lib/qt4 -lQtCore " file " && ./a.out"))))
(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)
(insert "\n")
(insert "\n")
(insert "private:")
(c-indent-line)
(insert "\n")
(c-indent-line)
(line-move -3)
(end-of-line))

28
configs/hooks.el Normal file
View file

@ -0,0 +1,28 @@
; Delete trailing whitespaces on save
(add-hook 'write-file-hooks 'delete-trailing-whitespace)
;; Mode to collapse code block
(add-hook 'c-mode-common-hook (lambda () (hs-minor-mode 1)))
(add-hook 'lisp-mode-hooks (lambda () (hs-minor-mode 1)))
(add-hook 'java-mode-hooks (lambda () (hs-minor-mode 1)))
(add-hook 'python-mode-hooks (lambda () (hs-minor-mode 1)))
; 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"))))
(add-hook 'find-file-hooks
(lambda ()
(when (and (memq major-mode '(c-mode c++-mode)) (equal (point-min) (point-max)) (string-match ".*\\.cc?" (buffer-file-name)))
(insert-header-inclusion))))
(add-hook 'sh-mode-hook
(lambda ()
(insert-shebang-if-empty "/bin/sh")))
(add-hook 'ruby-mode-hook
(lambda ()
(insert-shebang-if-empty "/usr/bin/ruby")))

77
configs/key-binding.el Normal file
View file

@ -0,0 +1,77 @@
;; Goto line #
(global-set-key [(meta g)] 'goto-line)
;; Move between windnow
(global-set-key [C-left] 'windmove-left)
(global-set-key [C-right] 'windmove-right)
(global-set-key [C-up] 'windmove-up)
(global-set-key [C-down] 'windmove-down)
;; Compile file
(global-set-key (kbd "C-c M-c") 'compile)
(global-set-key (kbd "C-c c") 'recompile)
(global-set-key (kbd "C-c e") 'next-error)
(global-set-key (kbd "C-c g") 'gdb)
;; Get some stat on region
(global-set-key [(meta =)] 'stat-region)
;; Move in buffer
(global-set-key [C-home] 'beginning-of-buffer)
(global-set-key [C-end] 'end-of-buffer)
(global-set-key [home] 'beginning-of-line)
(global-set-key [end] 'end-of-line)
(global-set-key (kbd "C-c h") 'replace-string)
(global-set-key (kbd "C-c j") 'replace-regexp)
(global-set-key (kbd "C-c o") 'bury-buffer)
(global-set-key (kbd "C-c k") 'kill-this-buffer)
(put 'narrow-to-region 'disabled nil)
;; Don't shift-selection
(setq shift-select-mode nil)
;; BINDINGS :: C/C++
(require 'cc-mode)
(define-key
c-mode-base-map
[(control c) (w)]
'c-switch-hh-cc) ; switch between .hh and .cc
(define-key
c-mode-base-map
[(control c) (f)]
'hs-hide-block) ; fold code
(define-key
c-mode-base-map
[(control c) (s)]
'hs-show-block) ; unfold code
(define-key
c-mode-base-map
[(control c) (control n)]
'c-insert-ns) ; insert namespace
(define-key
c-mode-base-map
[(control c) (control s)]
'c-insert-switch) ; insert switch
(define-key
c-mode-base-map
[(control c) (control i)]
'c-insert-if) ; insert if
(define-key
c-mode-base-map
[(control c) (control b)]
'c-insert-braces) ; insert braces
(define-key
c-mode-base-map
[(control c) (control f)]
'insert-fixme) ; insert fixme
(define-key
c-mode-base-map
[(control c) (control d)]
'c-insert-debug) ; insert debug
(define-key
c-mode-base-map
[(control c) (control l)]
'c-insert-class) ; insert class

13
configs/mail.el Normal file
View file

@ -0,0 +1,13 @@
(add-to-list 'auto-mode-alist '("/mutt" . mail-mode))
(add-hook 'mail-mode-hook 'turn-on-auto-fill)
(add-hook 'mail-mode-hook 'mail-abbrevs-setup)
;; colorizing multiply-quoted lines
(add-hook 'mail-mode-hook
(lambda ()
(font-lock-add-keywords nil
'(("^[ \t]*>[ \t]*>[ \t]*>.*$"
(0 'mail-multiply-quoted-text-face))
("^[ \t]*>[ \t]*>.*$"
(0 'mail-double-quoted-text-face))))))

30
configs/modes.el Normal file
View file

@ -0,0 +1,30 @@
;; Tiger mode
(autoload 'tiger-mode "tiger" "Load tiger-mode" t)
(add-to-list 'auto-mode-alist '("\\.ti[gh]$" . tiger-mode))
;; C++ mode
(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 '("Drakefile$" . c++-mode))
;; SH mode
(add-to-list 'auto-mode-alist '("\\.pro$" . sh-mode)) ; Qt .pro files
(add-to-list 'auto-mode-alist '("configure$" . sh-mode))
;; Changelog mode
(add-to-list 'auto-mode-alist '("COMMIT_EDITMSG" . change-log-mode))
;; Edje-mode
(require 'edje-mode)
(add-to-list 'auto-mode-alist '("\\.edc$" . edje-mode))
;; Org-mode
(require 'org-install)
(add-to-list 'auto-mode-alist '("\\.org$" . org-mode))
(define-key global-map "\C-cl" 'org-store-link)
(define-key global-map "\C-ca" 'org-agenda)
(setq org-log-done t)

17
configs/perso.el Normal file
View file

@ -0,0 +1,17 @@
;; E-mail adress
(custom-set-variables '(user-mail-address "nemunaire@pomail.fr")
'(query-user-mail-address nil))
;; Ispell check default language
(ispell-change-dictionary "francais" t)
(defvar cpu-number 8
"Number of parallel processing units on this system")
(setq compile-command "make")
(setq c-default-style "epita")
;; Chargement de mes paramètres personnels
(if (file-exists-p "~/.private.el")
(load-file "~/.private.el"))

17
configs/project.el Normal file
View file

@ -0,0 +1,17 @@
(setq project-roots
`(("Django project"
:root-contains-files ("manage.py")
:filename-regex ,(regexify-ext-list '(py html css js sh))
:exclude-paths '("contrib"))))
(global-set-key (kbd "C-c p f") 'project-root-find-file)
(global-set-key (kbd "C-c p g") 'project-root-grep)
(global-set-key (kbd "C-c p a") 'project-root-ack)
(global-set-key (kbd "C-c p d") 'project-root-goto-root)
(global-set-key (kbd "C-c p l") 'project-root-browse-seen-projects)
(global-set-key (kbd "C-c p s")
(lambda () (interactive)
(with-project-root
(ansi-term (getenv "SHELL")
(concat (car project-details) "-shell")))

25
configs/tags.el Normal file
View file

@ -0,0 +1,25 @@
(defadvice find-tag (around refresh-etags activate)
"Rerun etags and reload tags if tag not found and redo find-tag.
If buffer is modified, ask about save before running etags."
(let ((extension (file-name-extension (buffer-file-name))))
(condition-case err
ad-do-it
(error (and (buffer-modified-p)
(not (ding))
(y-or-n-p "Buffer is modified, save it? ")
(save-buffer))
(er-refresh-etags extension)
ad-do-it))))
(defun er-refresh-etags (&optional extension)
"Run etags on all peer files in current dir and reload them silently."
(interactive)
(shell-command (format "etags *.%s" (or extension "el")))
(let ((tags-revert-without-query t)) ; don't query, revert silently
(visit-tags-table default-directory nil)))
(defun create-tags (dir-name)
"Create tags file."
(interactive "DDirectory: ")
(eshell-command
(format "find %s -type f -name \"*.[ch]\" | etags -" dir-name)))