.emacs 8.9 KB

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