init
[configs.git] / .emacs
1 ;; .emacs
2
3 (add-to-list 'load-path "~/.emacs.d/lisp/egg")
4
5 ;;; uncomment this line to disable loading of "default.el" at startup
6 ;; (setq inhibit-default-init t)
7
8 ;; enable visual feedback on selections
9 ;(setq transient-mark-mode t)
10
11 ;; default to better frame titles
12 (setq frame-title-format
13       (concat  "%b - emacs@" (system-name)))
14
15 ;; default to unified diffs
16 (setq diff-switches "-u")
17
18 ;; always end a file with a newline
19 ;(setq require-final-newline 'query)
20
21 ;;; uncomment for CJK utf-8 support for non-Asian users
22 ;; (require 'un-define)
23
24 (set-background-color "black")
25 (set-foreground-color "grey")
26 (set-cursor-color "white")
27 (set-mouse-color "white")
28
29 (setq delete-auto-save-files t)
30 (setq inhibit-startup-message t)
31
32 (menu-bar-mode 0)
33 (tool-bar-mode 0)
34
35 (electric-indent-mode 0)
36
37 ;; (require 'color-theme)
38 ;; (if window-system
39 ;;       (color-theme-emacs-21)
40 ;;       (color-theme-hober))
41 ;;(color-theme-arjen)
42
43 (set-frame-font "7x14")
44
45 ;; Mousewheel
46 (defun sd-mousewheel-scroll-up (event)
47   "Scroll window under mouse up by five lines."
48   (interactive "e")
49   (let ((current-window (selected-window)))
50     (unwind-protect
51         (progn
52           (select-window (posn-window (event-start event)))
53           (scroll-up 5))
54       (select-window current-window))))
55
56 (defun sd-mousewheel-scroll-down (event)
57   "Scroll window under mouse down by five lines."
58   (interactive "e")
59   (let ((current-window (selected-window)))
60     (unwind-protect
61         (progn
62           (select-window (posn-window (event-start event)))
63           (scroll-down 5))
64       (select-window current-window))))
65
66 (global-set-key (kbd "<mouse-5>") 'sd-mousewheel-scroll-up)
67 (global-set-key (kbd "<mouse-4>") 'sd-mousewheel-scroll-down)
68
69 ; Montrer la correspondance des parenthèses
70 ; (systématiquement et non seulement après la frappe)
71 (require 'paren)
72 (show-paren-mode t)
73 (setq blink-matching-paren t)
74 (setq blink-matching-paren-on-screen t)
75 (setq blink-matching-paren-dont-ignore-comments t)
76
77 ; Afficher l'heure dans la barre d'état (format 24 heures)
78 (setq display-time-24hr-format t)
79 (display-time)
80
81 ; Nom en clair des jours et mois apparaissant dans le calendrier
82 (setq european-calendar-style t)
83 (setq calendar-week-start-day 1)
84 (defvar calendar-day-name-array
85   ["dimanche" "lundi" "mardi" "mercredi" "jeudi" "vendredi" "samedi"])
86 (defvar calendar-month-name-array
87   ["janvier" "février" "mars" "avril" "mai" "juin"
88    "juillet" "août" "septembre" "octobre" "novembre" "décembre"])
89
90 ; C'est fastidieux de taper « yes » pour confirmer, raccourcissons
91 ; cela à « y » (idem pour « no », désormais « n »).
92 (fset 'yes-or-no-p 'y-or-n-p)
93
94 ;; Raccourcis clavier
95 (global-set-key [f2]           'egg-status)
96 (global-set-key [f3]           'cvs-status)
97 (global-set-key [f4]           'cvs-quickdir)
98 (global-set-key [f5]           'toggle-read-only)
99 (global-set-key [f6]           'goto-line)
100 (global-set-key [f7]           'rgrep)
101 (global-set-key [f8]           'revert-buffer)
102 (global-set-key [f9]           'compile)
103 (global-set-key [f10]          'next-error)
104 (global-set-key [f11]          'toggle-fill-mode)
105 (global-set-key [f12]          'toggle-whitespace-begin-space)
106
107 (global-set-key "\M-?"         'tags-search)
108 (global-set-key "\M-s"         'search-word)
109 (global-set-key (kbd "C-x <down>") 'rotate-windows)
110
111
112 ;; page up, page down
113 (fset 'page-down
114    [next])
115 (fset 'page-up
116    [prior])
117
118 (global-set-key "\M-p" 'page-up)
119 (global-set-key "\M-n" 'page-down)
120
121 ;; Pour utiliser gnumake par defaut
122 ;; M-x customize !
123 (custom-set-variables
124  ;; custom-set-variables was added by Custom.
125  ;; If you edit it by hand, you could mess it up, so be careful.
126  ;; Your init file should contain only one such instance.
127  ;; If there is more than one, they won't work right.
128  '(compile-command "make")
129  '(ediff-split-window-function (quote split-window-horizontally))
130  '(ediff-window-setup-function (quote ediff-setup-windows-plain))
131  '(egg-buffer-hide-section-type-on-start nil)
132  '(egg-mode-key-prefix "C-x !")
133  '(rst-adornment-faces-alist (quote ((t . font-lock-keyword-face) (nil . font-lock-keyword-face) (nil . rst-level-1-face) (nil . rst-level-2-face) (nil . rst-level-3-face) (nil . rst-level-4-face) (nil . rst-level-5-face) (nil . rst-level-6-face))))
134  '(shell-file-name "/bin/bash")
135  '(vc-handled-backends (quote (RCS CVS SVN SCCS Bzr Hg Mtn Arch))))
136
137 ; Effacer tous les espaces en fin de ligne
138 (defun delete-trailing-spaces ()
139   "Effacer les espaces et tabulations en fin de chaque ligne du tampon"
140   (interactive)
141   (progn
142     (save-excursion
143       (goto-line 1)
144       (replace-regexp "[ \t]+$" "")
145     )
146   )
147 )
148
149
150 ; Conversion des fins de lignes du format MS-DOS au format Unix
151 (defun dos2unix ()
152   (interactive)
153   (goto-char (point-min))
154   (while (search-forward "\r" nil t)
155     (replace-match "")
156   )
157 )
158
159
160 ; Conversion des fins de ligne du format Unix au format MS-DOS
161 (defun unix2dos ()
162   (interactive)
163   (goto-char (point-min))
164   (while (search-forward "\n" nil t)
165     (replace-match "\r\n")
166   )
167 )
168
169
170 ; Montrer la table des caractères ASCII étendus
171 ; Fonction fournie par Alex Schroeder <asc@bsiag.com>
172 (defun ascii-table ()
173   "Afficher la table de caractères ASCII."
174   (interactive)
175   (switch-to-buffer "*ASCII*")
176   (erase-buffer)
177   (insert (format "Caractères ASCII de code 1 à 254.\n"))
178   (let ((i 0))
179     (while (< i 254) (setq i (+ i 1))
180       (insert (format "%4d %c\n" i i))
181     )
182   )
183   (beginning-of-buffer)
184 )
185
186
187 ; Activation des fonctions « upcase-region » et « downcase-region »
188 ; Ces fonctions sont désactivées par défaut sous Emacs 21 ; pourquoi ?
189 (put 'upcase-region 'disabled nil)
190 (put 'downcase-region 'disabled nil)
191
192 ; taille de la fenetre de compil
193 (setq compilation-window-height 15)
194
195 ; indentation
196 (require 'cc-mode)
197 (defun my-build-tab-stop-list (width)
198   (let ((num-tab-stops (/ 80 width))
199         (counter 1)
200         (ls nil))
201     (while (<= counter num-tab-stops)
202       (setq ls (cons (* width counter) ls))
203       (setq counter (1+ counter)))
204     (set (make-local-variable 'tab-stop-list) (nreverse ls))))
205
206 ; from linux/Documentation/CodingStyle
207 ;
208 (defun c-lineup-arglist-tabs-only (ignored)
209   "Line up argument lists by tabs, not spaces"
210   (let* ((anchor (c-langelem-pos c-syntactic-element))
211          (column (c-langelem-2nd-pos c-syntactic-element))
212          (offset (- (1+ column) anchor))
213          (steps (floor offset c-basic-offset)))
214     (* (max steps 1)
215        c-basic-offset)))
216
217 ;; Add kernel style
218 (c-add-style
219  "linux-tabs-only"
220  '("linux" (c-offsets-alist
221             (arglist-cont-nonempty
222              c-lineup-gcc-asm-reg
223              c-lineup-arglist-tabs-only))))
224
225 (add-hook 'c-mode-hook
226           (lambda ()
227             (c-set-style "linux-tabs-only"))
228 )
229
230 (add-hook 'c-mode-common-hook
231   (lambda ()
232     (font-lock-add-keywords nil
233     '(("\\<\\(FIXME\\|TODO\\|HACK\\|fixme\\|todo\\|hack\\|XXX\\)" 1
234          font-lock-warning-face t)))))
235
236 (defun set-indent-quagga ()
237   (interactive)
238   (setq c-basic-offset 2)
239   (setq tab-width 8 indent-tabs-mode nil)
240 )
241
242 (defun set-indent-xms ()
243   (interactive)
244   (setq c-basic-offset 4)
245   (setq tab-width 8 indent-tabs-mode nil)
246 )
247
248 (defun set-indent-std ()
249   (interactive)
250   (c-set-offset 'arglist-cont-nonempty 8)
251   (c-set-offset 'arglist-intro '+)
252   (c-set-offset 'arglist-close 0)
253   (setq c-basic-offset 8)
254   (setq tab-width 8 indent-tabs-mode 1)
255 )
256
257 ;; marche pas...
258 (defun set-indent-dpdk ()
259   (interactive)
260   (c-set-offset 'arglist-cont-nonempty 16)
261   (c-set-offset 'arglist-intro '+)
262   (c-set-offset 'arglist-close 0)
263   (setq c-basic-offset 8)
264   (setq tab-width 8 indent-tabs-mode 1)
265 )
266
267 (defun toggle-whitespace-begin-space ()
268   (interactive)
269   (whitespace-toggle-options '(indentation::tab indentation))
270 )
271
272  '(sh-basic-offset 2)
273  '(sh-indent-after-function (quote -))
274  '(sh-indent-comment t)
275
276 ;; indentation of shell scripts
277 (defun set-sh-indent-8 ()
278   "My own personal preferences for `sh-mode'.
279
280 This is a custom function that sets up the parameters I usually
281 prefer for `sh-mode'.  It is automatically added to
282 `sh-mode-hook', but is can also be called interactively."
283   (interactive)
284   (setq sh-basic-offset 8
285         sh-indentation 8
286         sh-indent-comment t))
287 (add-hook 'sh-mode-hook 'set-sh-indent-8)
288
289 ;; packager
290 (defun set-sh-indent-4 ()
291   (interactive)
292   (setq sh-basic-offset 4
293         sh-indentation 4
294         sh-indent-comment t
295         indent-tabs-mode nil))
296
297 (custom-set-faces
298  ;; custom-set-faces was added by Custom.
299  ;; If you edit it by hand, you could mess it up, so be careful.
300  ;; Your init file should contain only one such instance.
301  ;; If there is more than one, they won't work right.
302  )
303
304 ;; (set-terminal-coding-system 'latin-9)
305 ;; (set-keyboard-coding-system 'latin-9)
306 ;; (set-language-environment 'latin-9)
307
308 (add-to-list 'kill-emacs-query-functions
309              (lambda () (y-or-n-p "Should Emacs really close? ")))
310
311 (require 'xcscope)
312
313 (define-key global-map [(control f3)]  'cscope-set-initial-directory)
314 (define-key global-map [(control f4)]  'cscope-unset-initial-directory)
315 (define-key global-map [(control f5)]  'cscope-find-this-symbol)
316 (define-key global-map [(control f6)]  'cscope-find-global-definition)
317 (define-key global-map [(control f7)]  'cscope-find-global-definition-no-prompting)
318 (define-key global-map [(control f8)]  'cscope-pop-mark)
319 (define-key global-map [(control f9)]  'cscope-next-symbol)
320 (define-key global-map [(control f10)] 'cscope-next-file)
321 (define-key global-map [(control f11)] 'cscope-prev-symbol)
322 (define-key global-map [(control f12)] 'cscope-prev-file)
323 (define-key global-map [(meta f9)]  'cscope-display-buffer)
324 (define-key global-map [(meta f10)] 'cscope-display-buffer-toggle)
325 ;(setq cscope-display-cscope-buffer nil)
326
327
328 (defun vi-nolist ()
329   "Simulate a :set nolist in Vi."
330   (interactive)
331   (standard-display-ascii ?\t "\t")
332   (standard-display-ascii ?\ "\ ") )
333
334 (defun sign ()
335   "Insert signature."
336   (interactive "*")
337   (insert "Signed-off-by: Olivier Matz <olivier.matz@6wind.com>")
338 )
339
340 (defun ack-choice ()
341   "Insert acked-by."
342   (interactive
343    (let ((string (read-string "Name: " nil 'my-history)))
344      (insert (shell-command-to-string (concat "acked-by.py " string))))
345   )
346 )
347
348 (defun sign-choice ()
349   "Insert acked-by."
350   (interactive
351    (let ((string (read-string "Name: " nil 'my-history)))
352      (insert (shell-command-to-string (concat "acked-by.py -s " string))))
353   )
354 )
355
356 (defun toggle-fill-mode ()
357   "toggle fill mode between 72 and 80"
358   (interactive "*")
359   (if (<= fill-column 72)
360     (setq-default fill-column 80)
361     (setq-default fill-column 72)))
362
363 (defun rotate-windows-helper(x d)
364   (if (equal (cdr x) nil) (set-window-buffer (car x) d)
365     (set-window-buffer (car x) (window-buffer (cadr x))) (rotate-windows-helper (cdr x) d)))
366
367 (defun rotate-windows ()
368   (interactive)
369   (rotate-windows-helper (window-list) (window-buffer (car (window-list))))
370   (select-window (car (last (window-list)))))
371
372 ;; http://www.emacswiki.org/emacs/WhiteSpace
373 (require 'whitespace)
374 (global-whitespace-mode 1)
375 (setq whitespace-style '(face trailing lines-tail indentation::tab indentation
376                                   space-after-tab::tab space-after-tab::space
377                                   space-after-tab space-before-tab::tab
378                                   space-before-tab::space space-before-tab))
379 ;; for xms, remove indentation::tab and indentation
380 ;; (setq whitespace-style '(face trailing lines-tail
381 ;;                                space-after-tab::tab space-after-tab::space
382 ;;                                space-after-tab space-before-tab::tab
383 ;;                                space-before-tab::space space-before-tab))
384
385
386 (defun bf-pretty-print-xml-region (begin end)
387   "Pretty format XML markup in region. You need to have nxml-mode
388 http://www.emacswiki.org/cgi-bin/wiki/NxmlMode installed to do
389 this.  The function inserts linebreaks to separate tags that have
390 nothing but whitespace between them.  It then indents the markup
391 by using nxml's indentation rules."
392   (interactive "r")
393   (save-excursion
394       (nxml-mode)
395       (goto-char begin)
396       (while (search-forward-regexp "\>[ \\t]*\<" nil t)
397         (backward-char) (insert "\n"))
398       (indent-region begin end))
399     (message "Ah, much better!"))
400
401 ; git
402 (require 'egg)
403
404 ; fill column to 80 when we use M-q
405 (setq-default fill-column 80)
406
407 ; to remove once fixed (make 4.0 compat)
408 (setq-default compilation-directory-matcher '("\\(?:Entering\\|Leavin\\(g\\)\\) directory [`']\\(.+\\)'$" (2 . 1)))