.emacs 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. ;;
  2. ;; GNU Emacs configuration file (~/.emacs)
  3. ;; 2000-2009, kolter <kolter@openics.org>
  4. ;;
  5. ;; This file is distributed in the hope that it will be useful,
  6. ;; but WITHOUT ANY WARRANTY
  7. ;;
  8. ;;-------------------------------------------------------------------
  9. ;; Compiling .emacs : regenerate the .emacs.elc if .emacs is newer
  10. (defun dotemacscheck! ()
  11. "If .emacs exists and is newer than .emacs.elc, recompile it"
  12. (cond
  13. ((file-newer-than-file-p "~/.emacs" "~/.emacs.elc")
  14. (let ((mode-line-format "*** Recompiling .emacs ***"))
  15. (sit-for 1)
  16. (byte-compile-file "~/.emacs")
  17. (message ".emacs.elc recompiled --- reloading...")
  18. )
  19. (load "~/.emacs.elc" t t t)
  20. )))
  21. (dotemacscheck!)
  22. ;;--------------------------------------------------------------------
  23. ;; Emacs internals stuff
  24. ;; trace errors (only for debug/testing)
  25. ;;(setq debug-on-error t)
  26. ;; adding lisp modules directory
  27. (add-to-list 'load-path "~/.emacs-lisp/")
  28. ;; y = yes && n = no
  29. (defalias 'yes-or-no-p 'y-or-n-p)
  30. ;; disable speaker's beep
  31. (setq visible-bell t)
  32. ;; set a directory to save backup files
  33. (setq
  34. backup-by-copying t
  35. backup-directory-alist '(("." . "~/.emacs-backups/"))
  36. delete-old-versions t
  37. kept-new-versions 6
  38. kept-old-versions 2
  39. version-control t)
  40. ;; autoload apache-mode
  41. ;; apache-mode is available in debian package emacs-goodies-el
  42. (autoload 'apache-mode "apache-mode" "autoloaded" t)
  43. ;; transparently work with compressed files
  44. (auto-compression-mode 1)
  45. ;; define some modes for some filenames
  46. (add-to-list 'auto-mode-alist '(".htaccess$" . apache-mode))
  47. (add-to-list 'auto-mode-alist '("httpd.conf$" . apache-mode))
  48. (add-to-list 'auto-mode-alist '("apache2.conf$" . apache-mode))
  49. (add-to-list 'auto-mode-alist '("ports.conf$" . apache-mode))
  50. (add-to-list 'auto-mode-alist (cons "/etc/ssh/ssh_config" 'shell-script-mode))
  51. (add-to-list 'auto-mode-alist (cons "/etc/ssh/sshd_config" 'shell-script-mode))
  52. (add-to-list 'auto-mode-alist '("\\.zsh$" . shell-script-mode))
  53. (add-to-list 'auto-mode-alist '("\\.zshrc$" . shell-script-mode))
  54. ;; specific settings for vt420 terminal
  55. ;;(enable-flow-control-on "vt420")
  56. ;;--------------------------------------------------------------------
  57. ;; Display stuff
  58. ;;
  59. ;; disabling menu bar
  60. (menu-bar-mode nil)
  61. ;; disabling tool bar
  62. ;; (tool-bar-mode nil)
  63. ;; Remove startup messages
  64. (setq inhibit-startup-message t)
  65. (setq inhibit-startup-echo-area-message t)
  66. ;; line and column number in modeline
  67. (setq column-number-mode t)
  68. (setq line-number-mode t)
  69. ;; fonts (emacs X11)
  70. (set-default-font "7x14")
  71. (set-frame-font "7x14")
  72. ;; do not extend buffer content with 'down' key
  73. (setq next-line-add-newlines nil)
  74. ;; parenthesis uses
  75. (show-paren-mode t)
  76. (setq blink-matching-paren t)
  77. (setq blink-matching-paren-on-screen t)
  78. (setq show-paren-style 'expression)
  79. (setq blink-matching-paren-dont-ignore-comments t)
  80. ;; setting maximum colors
  81. (font-lock-mode t)
  82. (global-font-lock-mode t)
  83. (setq font-lock-maximum-decoration t)
  84. ;; make selections more visible (color)
  85. (setq transient-mark-mode t)
  86. ;; make the compilation window size fixed
  87. (setq compilation-scroll-output t)
  88. ;; having a soft scrolling !
  89. (defun point-of-beginning-of-bottom-line ()
  90. (save-excursion
  91. (move-to-window-line -1)
  92. (point)))
  93. (defun point-of-beginning-of-line ()
  94. (save-excursion
  95. (beginning-of-line)
  96. (point)))
  97. (defun next-one-line () (interactive)
  98. (if (= (point-of-beginning-of-bottom-line) (point-of-beginning-of-line))
  99. (progn (scroll-up 1)
  100. (next-line 1))
  101. (next-line 1)))
  102. (defun point-of-beginning-of-top-line ()
  103. (save-excursion
  104. (move-to-window-line 0)
  105. (point)))
  106. (defun previous-one-line () (interactive)
  107. (if (= (point-of-beginning-of-top-line) (point-of-beginning-of-line))
  108. (progn (scroll-down 1)
  109. (previous-line 1))
  110. (previous-line 1)))
  111. (global-set-key (kbd "<down>") 'next-one-line)
  112. (global-set-key (kbd "<up>") 'previous-one-line)
  113. ;; change tab width
  114. ;(setq default-tab-width 4)
  115. ;;--------------------------------------------------------------------
  116. ;; Key bindings stuff
  117. ;; easy navigation between buffers using cyclebuffer.el
  118. ;; cyclebuffer.el is available in debian package emacs-goodies-el
  119. (global-set-key [f1] 'cyclebuffer-backward)
  120. (global-set-key [f2] 'cyclebuffer-forward)
  121. (global-set-key [f11] 'cyclebuffer-backward)
  122. (global-set-key [f12] 'cyclebuffer-forward)
  123. ;; easy navigation between windows
  124. (global-set-key "\C-n" 'other-window)
  125. (global-set-key "\C-p" '(lambda () (interactive) (other-window -1)))
  126. ;; spliting windows
  127. (global-set-key [f5] 'split-window-vertically)
  128. (global-set-key [f6] 'split-window-horizontally)
  129. (global-set-key [f7] 'delete-window)
  130. (global-set-key [f8] 'delete-other-windows)
  131. (global-set-key "\M-g" 'goto-line)
  132. (global-set-key "\C-q" 'kill-this-buffer)
  133. (global-set-key "\M-c" 'compile)
  134. (global-set-key [f9] 'compile)
  135. ;; mouse settings (emacs X11)
  136. ;;(global-set-key (quote [(mouse-5)]) (quote scroll-up))
  137. ;;(global-set-key (quote [(mouse-4)]) (quote scroll-down))
  138. ;;-------------------------------------------------------------------
  139. ;; Mutt(ng) stuff
  140. (load-library "mutt-post")
  141. ;; use muttrc-mode with mutt related files
  142. ;; muttrc-mode is available in debian package emacs-goodies-el
  143. (add-to-list 'auto-mode-alist '("\\.mutt\\(.*\\)$" . muttrc-mode))
  144. (add-to-list 'auto-mode-alist '("\\.mutt/conf/\\(.*\\)$" . muttrc-mode))
  145. (add-to-list 'auto-mode-alist '("\\.muttng/conf/\\(.*\\)$" . muttrc-mode))
  146. (add-to-list 'auto-mode-alist '("\\.madmutt\\(.*\\)$" . muttrc-mode))
  147. ;; automtically wrap lines when composing mail
  148. (add-to-list 'auto-mode-alist '(".mutt/tmp/mutt-" . post-mode))
  149. (add-to-list 'auto-mode-alist '(".muttng/tmp/muttng-" . post-mode))
  150. (add-to-list 'auto-mode-alist '(".madmutt/tmp/madmutt-" . post-mode))
  151. ;;-------------------------------------------------------------------
  152. ;; CMake stuff
  153. (add-to-list 'auto-mode-alist '("\\.cmake$" . cmake-mode))
  154. (add-to-list 'auto-mode-alist '("\\CMakeLists.txt$" . cmake-mode))
  155. ;;-------------------------------------------------------------------
  156. ;; Ispell / Aspell settings
  157. ;; set default ispell dictionnary to french one
  158. (setq ispell-program-name "/usr/bin/aspell")
  159. (setq ispell-dictionary "francais")
  160. ;; enable flyspell on text-mode
  161. ;;(add-hook 'text-mode-hook
  162. ;; '(lambda()
  163. ;; (flyspell-mode)
  164. ;; ))
  165. ;; enable flyspell on post-mode
  166. ;;(add-hook 'post-mode-hook
  167. ;; '(lambda()
  168. ;; (flyspell-mode)
  169. ;; ))
  170. ;;-------------------------------------------------------------------
  171. ;; WeeChat coding style
  172. (setq c-mode-hook
  173. '(lambda ()
  174. (c-set-style "K&R")
  175. (setq c-basic-offset 4)
  176. (setq c-tab-always-indent t)))
  177. ;;-------------------------------------------------------------------
  178. ;; WEB coding
  179. (load-library "multi-mode")
  180. (defun web-mode () (interactive)
  181. (multi-mode 1
  182. 'html-mode
  183. '("<%" ruby-mode)
  184. '("<?php" php-mode)
  185. '("<?" php-mode)
  186. '("<script" java-mode)
  187. '("<style" css-mode)
  188. '("</script" html-mode)
  189. '("?>" html-mode)
  190. '("%>" html-mode)))
  191. (add-hook 'php-mode-hook
  192. (lambda()
  193. (defalias 'c-electric-backspace 'delete-backward-char)
  194. (defun c-indent-command () (interactive "*") (self-insert-command 1))
  195. (define-key php-mode-map "\C-a" 'beginning-of-line-text)
  196. (define-key php-mode-map [home] 'beginning-of-line-text)
  197. )
  198. )
  199. (add-hook 'html-mode-hook
  200. (lambda()
  201. (defun indent-for-tab-command () (interactive "*") (self-insert-command 1))
  202. (define-key html-mode-map "\C-a" 'beginning-of-line-text)
  203. (define-key html-mode-map [home] 'beginning-of-line-text)
  204. (define-key html-mode-map (kbd "RET") 'newline-and-indent)
  205. )
  206. )
  207. (add-to-list 'auto-mode-alist '("\\.php$" . web-mode))
  208. (add-to-list 'auto-mode-alist '("\\.rhtml$" . web-mode))
  209. (defun indent-region-with-tab ()
  210. (interactive)
  211. (save-excursion
  212. (if (< (point) (mark)) (exchange-point-and-mark))
  213. (let ((save-mark (mark)))
  214. (if (= (point) (line-beginning-position)) (previous-line 1))
  215. (goto-char (line-beginning-position))
  216. (while (>= (point) save-mark)
  217. (goto-char (line-beginning-position))
  218. (insert "\t")
  219. (previous-line 1)))
  220. (setq deactivate-mark nil)
  221. ))
  222. (defun unindent-region-with-tab ()
  223. (interactive)
  224. (save-excursion
  225. (if (< (point) (mark)) (exchange-point-and-mark))
  226. (let ((save-mark (mark)))
  227. (if (= (point) (line-beginning-position)) (previous-line 1))
  228. (goto-char (line-beginning-position))
  229. (while (>= (point) save-mark)
  230. (goto-char (line-beginning-position))
  231. (if (= (string-to-char "\t") (char-after (point))) (delete-char 1))
  232. (previous-line 1)))
  233. (setq deactivate-mark nil)
  234. ))
  235. (global-set-key "\C-xi" 'indent-region-with-tab)
  236. (global-set-key "\C-xj" 'unindent-region-with-tab)