.emacs 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  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. ;; easy navigation between windows
  133. (global-set-key "\C-n" 'other-window)
  134. (global-set-key "\C-p" '(lambda () (interactive) (other-window -1)))
  135. ;; spliting windows
  136. (global-set-key [f5] 'split-window-vertically)
  137. (global-set-key [f6] 'split-window-horizontally)
  138. (global-set-key [f7] 'delete-window)
  139. (global-set-key [f8] 'delete-other-windows)
  140. ;; indent
  141. (global-set-key [TAB] 'indent-according-to-mode)
  142. (global-set-key "\M-g" 'goto-line)
  143. (global-set-key "\C-q" 'kill-this-buffer)
  144. (global-set-key "\M-c" 'compile)
  145. (global-set-key [f9] 'compile)
  146. ;; mouse settings (emacs X11)
  147. ;;(global-set-key (quote [(mouse-5)]) (quote scroll-up))
  148. ;;(global-set-key (quote [(mouse-4)]) (quote scroll-down))
  149. ;;-------------------------------------------------------------------
  150. ;; Mutt(ng) stuff
  151. (load-library "mutt-post")
  152. ;; use muttrc-mode with mutt related files
  153. ;; muttrc-mode is available in debian package emacs-goodies-el
  154. (add-to-list 'auto-mode-alist '("\\.mutt\\(.*\\)$" . muttrc-mode))
  155. (add-to-list 'auto-mode-alist '("\\.mutt/conf/\\(.*\\)$" . muttrc-mode))
  156. (add-to-list 'auto-mode-alist '("\\.muttng/conf/\\(.*\\)$" . muttrc-mode))
  157. ;; automtically wrap lines when composing mail
  158. (add-to-list 'auto-mode-alist '(".mutt/tmp/mutt-" . post-mode))
  159. (add-to-list 'auto-mode-alist '(".muttng/tmp/muttng-" . post-mode))
  160. ;;-------------------------------------------------------------------
  161. ;; CMake stuff
  162. (add-to-list 'auto-mode-alist '("\\.cmake$" . cmake-mode))
  163. (add-to-list 'auto-mode-alist '("\\CMakeLists.txt$" . cmake-mode))
  164. ;;-------------------------------------------------------------------
  165. ;; Ispell / Aspell settings
  166. ;; set default ispell dictionnary to french one
  167. (setq ispell-program-name "/usr/bin/aspell")
  168. (setq ispell-dictionary "francais")
  169. ;; enable flyspell on text-mode
  170. ;;(add-hook 'text-mode-hook
  171. ;; '(lambda()
  172. ;; (flyspell-mode)
  173. ;; ))
  174. ;; enable flyspell on post-mode
  175. ;;(add-hook 'post-mode-hook
  176. ;; '(lambda()
  177. ;; (flyspell-mode)
  178. ;; ))
  179. ;;-------------------------------------------------------------------
  180. ;; WeeChat coding style
  181. (setq c-mode-hook
  182. '(lambda ()
  183. (c-set-style "K&R")
  184. (setq c-basic-offset 4)
  185. (setq c-tab-always-indent t)))
  186. ;;-------------------------------------------------------------------
  187. ;; WEB coding
  188. (load-library "multi-mode")
  189. (defun web-mode () (interactive)
  190. (multi-mode 1
  191. 'html-mode
  192. '("<%" ruby-mode)
  193. '("<?php" php-mode)
  194. '("<?" php-mode)
  195. '("<script" java-mode)
  196. '("<style" css-mode)
  197. '("</script" html-mode)
  198. '("?>" html-mode)
  199. '("%>" html-mode)))
  200. (add-hook 'php-mode-hook
  201. (lambda()
  202. (defalias 'c-electric-backspace 'delete-backward-char)
  203. (defun c-indent-command () (interactive "*") (self-insert-command 1))
  204. (define-key php-mode-map "\C-a" 'beginning-of-line-text)
  205. (define-key php-mode-map [home] 'beginning-of-line-text)
  206. )
  207. )
  208. (add-hook 'html-mode-hook
  209. (lambda()
  210. (defun indent-for-tab-command () (interactive "*") (self-insert-command 1))
  211. (define-key html-mode-map "\C-a" 'beginning-of-line-text)
  212. (define-key html-mode-map [home] 'beginning-of-line-text)
  213. (define-key html-mode-map (kbd "RET") 'newline-and-indent)
  214. )
  215. )
  216. (add-to-list 'auto-mode-alist '("\\.php$" . web-mode))
  217. (add-to-list 'auto-mode-alist '("\\.rhtml$" . web-mode))
  218. (defun indent-region-with-tab ()
  219. (interactive)
  220. (save-excursion
  221. (if (< (point) (mark)) (exchange-point-and-mark))
  222. (let ((save-mark (mark)))
  223. (if (= (point) (line-beginning-position)) (previous-line 1))
  224. (goto-char (line-beginning-position))
  225. (while (>= (point) save-mark)
  226. (goto-char (line-beginning-position))
  227. (insert "\t")
  228. (previous-line 1)))
  229. (setq deactivate-mark nil)
  230. ))
  231. (defun unindent-region-with-tab ()
  232. (interactive)
  233. (save-excursion
  234. (if (< (point) (mark)) (exchange-point-and-mark))
  235. (let ((save-mark (mark)))
  236. (if (= (point) (line-beginning-position)) (previous-line 1))
  237. (goto-char (line-beginning-position))
  238. (while (>= (point) save-mark)
  239. (goto-char (line-beginning-position))
  240. (if (= (string-to-char "\t") (char-after (point))) (delete-char 1))
  241. (previous-line 1)))
  242. (setq deactivate-mark nil)
  243. ))
  244. (global-set-key "\C-xi" 'indent-region-with-tab)
  245. (global-set-key "\C-xj" 'unindent-region-with-tab)