update
[configs.git] / .emacs
1 ;; .emacs
2
3 ;; Added by Package.el.  This must come before configurations of
4 ;; installed packages.  Don't delete this line.  If you don't want it,
5 ;; just comment it out by adding a semicolon to the start of the line.
6 ;; You may delete these explanatory comments.
7 (package-initialize)
8
9 (add-to-list 'load-path "~/.emacs.d/lisp/yang")
10 (load "yang-mode.el")
11
12 (add-to-list 'load-path "~/.emacs.d/lisp/flatbuffers")
13 (load "flatbuffers-mode.el")
14
15 (editorconfig-mode 1)
16
17 (require 'xcscope)
18
19 ;;; uncomment this line to disable loading of "default.el" at startup
20 ;; (setq inhibit-default-init t)
21
22 ;; enable visual feedback on selections
23 ;(setq transient-mark-mode t)
24
25 ;; default to better frame titles
26 (setq frame-title-format
27       (concat  "%b - emacs@" (system-name)))
28
29 ;; default to unified diffs
30 (setq diff-switches "-u")
31
32 ;; always end a file with a newline
33 ;(setq require-final-newline 'query)
34
35 ;;; uncomment for CJK utf-8 support for non-Asian users
36 ;; (require 'un-define)
37
38 (set-background-color "black")
39 (set-foreground-color "grey")
40 (set-cursor-color "white")
41 (set-mouse-color "white")
42
43 (setq delete-auto-save-files t)
44 (setq inhibit-startup-message t)
45
46 (menu-bar-mode 0)
47 (tool-bar-mode 0)
48
49 (electric-indent-mode 0)
50 (setq column-number-mode t)
51
52 ;; (require 'color-theme)
53 ;; (if window-system
54 ;;       (color-theme-emacs-21)
55 ;;       (color-theme-hober))
56 ;;(color-theme-arjen)
57
58 (set-frame-font "7x14")
59
60 ;; Mousewheel
61 (defun sd-mousewheel-scroll-up (event)
62   "Scroll window under mouse up by five lines."
63   (interactive "e")
64   (let ((current-window (selected-window)))
65     (unwind-protect
66         (progn
67           (select-window (posn-window (event-start event)))
68           (scroll-up 5))
69       (select-window current-window))))
70
71 (defun sd-mousewheel-scroll-down (event)
72   "Scroll window under mouse down by five lines."
73   (interactive "e")
74   (let ((current-window (selected-window)))
75     (unwind-protect
76         (progn
77           (select-window (posn-window (event-start event)))
78           (scroll-down 5))
79       (select-window current-window))))
80
81 ;; from https://unix.stackexchange.com/questions/26360/emacs-deleting-a-line-without-sending-it-to-the-kill-ring
82 ;; better than https://www.emacswiki.org/emacs/ElispCookbook#toc13
83 (defun delete-line (&optional arg)
84   "Delete the rest of the current line; if no nonblanks there, delete thru newline.
85 With prefix argument ARG, delete that many lines from point.
86 Negative arguments delete lines backward.
87 With zero argument, delete the text before point on the current line.
88
89 When calling from a program, nil means \"no arg\",
90 a number counts as a prefix arg.
91
92 If `show-trailing-whitespace' is non-nil, this command will just
93 delete the rest of the current line, even if there are no nonblanks
94 there.
95
96 If option `kill-whole-line' is non-nil, then this command deletes the whole line
97 including its terminating newline, when used at the beginning of a line
98 with no argument.
99
100 If the buffer is read-only, Emacs will beep and refrain from deleting
101 the line."
102   (interactive "P")
103   (delete-region
104    (point)
105    (progn
106      (if arg
107          (forward-visible-line (prefix-numeric-value arg))
108        (if (eobp)
109            (signal 'end-of-buffer nil))
110        (let ((end
111               (save-excursion
112                 (end-of-visible-line) (point))))
113          (if (or (save-excursion
114                    ;; If trailing whitespace is visible,
115                    ;; don't treat it as nothing.
116                    (unless show-trailing-whitespace
117                      (skip-chars-forward " \t" end))
118                    (= (point) end))
119                  (and kill-whole-line (bolp)))
120              (forward-visible-line 1)
121            (goto-char end))))
122      (point))))
123
124 (global-set-key (kbd "<mouse-5>") 'sd-mousewheel-scroll-up)
125 (global-set-key (kbd "<mouse-4>") 'sd-mousewheel-scroll-down)
126
127 ; Montrer la correspondance des parenthèses
128 ; (systématiquement et non seulement après la frappe)
129 (require 'paren)
130 (show-paren-mode t)
131 (setq blink-matching-paren t)
132 (setq blink-matching-paren-on-screen t)
133 (setq blink-matching-paren-dont-ignore-comments t)
134
135 ; Afficher l'heure dans la barre d'état (format 24 heures)
136 (setq display-time-24hr-format t)
137 (display-time)
138
139 ; Nom en clair des jours et mois apparaissant dans le calendrier
140 (setq european-calendar-style t)
141 (setq calendar-week-start-day 1)
142 (defvar calendar-day-name-array
143   ["dimanche" "lundi" "mardi" "mercredi" "jeudi" "vendredi" "samedi"])
144 (defvar calendar-month-name-array
145   ["janvier" "février" "mars" "avril" "mai" "juin"
146    "juillet" "août" "septembre" "octobre" "novembre" "décembre"])
147
148 ; C'est fastidieux de taper « yes » pour confirmer, raccourcissons
149 ; cela à « y » (idem pour « no », désormais « n »).
150 (fset 'yes-or-no-p 'y-or-n-p)
151
152 ;; Raccourcis clavier
153 (global-set-key [f2]           'magit-status)
154 (global-set-key [f3]           'vc-git-grep)
155 (global-set-key [f4]           'magit-blame-addition)
156 (global-set-key [f5]           'toggle-read-only)
157 (global-set-key [f6]           'goto-line)
158 (global-set-key [f7]           'rgrep)
159 (global-set-key [f8]           'revert-buffer)
160 (global-set-key [f9]           'compile)
161 (global-set-key [f10]          'next-error)
162 (global-set-key [f11]          'toggle-fill-mode)
163 (global-set-key [f12]          'toggle-whitespace-begin-space)
164
165 (global-set-key "\M-?"         'tags-search)
166 (global-set-key "\M-s"         'search-word)
167 (global-set-key (kbd "C-x <down>") 'rotate-windows)
168
169 (global-set-key (kbd "M-k") 'delete-line)
170 (global-set-key (kbd "M-%") 'query-replace-regexp)
171 (global-set-key (kbd "C-s") 'isearch-forward-regexp)
172 (global-set-key (kbd "C-r") 'isearch-backward-regexp)
173
174
175 ;; page up, page down
176 (fset 'page-down
177    [next])
178 (fset 'page-up
179    [prior])
180
181 (global-set-key "\M-p" 'page-up)
182 (global-set-key "\M-n" 'page-down)
183
184 ;; Pour utiliser gnumake par defaut
185 ;; M-x customize !
186 (custom-set-variables
187  ;; custom-set-variables was added by Custom.
188  ;; If you edit it by hand, you could mess it up, so be careful.
189  ;; Your init file should contain only one such instance.
190  ;; If there is more than one, they won't work right.
191  '(compile-command "make")
192  '(ediff-split-window-function (quote split-window-horizontally))
193  '(ediff-window-setup-function (quote ediff-setup-windows-plain))
194  '(magit-commit-arguments nil)
195  '(magit-log-arguments (quote ("--decorate" "-n256")))
196  '(rst-adornment-faces-alist
197    (quote
198     ((t . font-lock-keyword-face)
199      (nil . font-lock-keyword-face)
200      (nil . rst-level-1-face)
201      (nil . rst-level-2-face)
202      (nil . rst-level-3-face)
203      (nil . rst-level-4-face)
204      (nil . rst-level-5-face)
205      (nil . rst-level-6-face))))
206  '(safe-local-variable-values
207    (quote
208     ((c-indent-level . 4)
209      (eval c-set-offset
210            (quote arglist-close)
211            0)
212      (eval c-set-offset
213            (quote arglist-intro)
214            (quote ++))
215      (eval c-set-offset
216            (quote case-label)
217            0)
218      (eval c-set-offset
219            (quote statement-case-open)
220            0)
221      (eval c-set-offset
222            (quote substatement-open)
223            0))))
224  '(shell-file-name "/bin/bash")
225  '(split-height-threshold 120)
226  '(split-width-threshold 240)
227  '(vc-handled-backends (quote (RCS CVS SVN SCCS Bzr Git Hg Mtn Arch))))
228
229 ; Effacer tous les espaces en fin de ligne
230 (defun delete-trailing-spaces ()
231   "Effacer les espaces et tabulations en fin de chaque ligne du tampon"
232   (interactive)
233   (progn
234     (save-excursion
235       (goto-line 1)
236       (replace-regexp "[ \t]+$" "")
237     )
238   )
239 )
240
241
242 ; Conversion des fins de lignes du format MS-DOS au format Unix
243 (defun dos2unix ()
244   (interactive)
245   (goto-char (point-min))
246   (while (search-forward "\r" nil t)
247     (replace-match "")
248   )
249 )
250
251
252 ; Conversion des fins de ligne du format Unix au format MS-DOS
253 (defun unix2dos ()
254   (interactive)
255   (goto-char (point-min))
256   (while (search-forward "\n" nil t)
257     (replace-match "\r\n")
258   )
259 )
260
261
262 ; Montrer la table des caractères ASCII étendus
263 ; Fonction fournie par Alex Schroeder <asc@bsiag.com>
264 (defun ascii-table ()
265   "Afficher la table de caractères ASCII."
266   (interactive)
267   (switch-to-buffer "*ASCII*")
268   (erase-buffer)
269   (insert (format "Caractères ASCII de code 1 à 254.\n"))
270   (let ((i 0))
271     (while (< i 254) (setq i (+ i 1))
272       (insert (format "%4d %c\n" i i))
273     )
274   )
275   (beginning-of-buffer)
276 )
277
278
279 ; Activation des fonctions « upcase-region » et « downcase-region »
280 ; Ces fonctions sont désactivées par défaut sous Emacs 21 ; pourquoi ?
281 (put 'upcase-region 'disabled nil)
282 (put 'downcase-region 'disabled nil)
283
284 ; taille de la fenetre de compil
285 (setq compilation-window-height 15)
286
287 ; indentation
288 (require 'cc-mode)
289 (defun my-build-tab-stop-list (width)
290   (let ((num-tab-stops (/ 80 width))
291         (counter 1)
292         (ls nil))
293     (while (<= counter num-tab-stops)
294       (setq ls (cons (* width counter) ls))
295       (setq counter (1+ counter)))
296     (set (make-local-variable 'tab-stop-list) (nreverse ls))))
297
298 ;; Add kernel style
299
300 (defun c-lineup-arglist-tabs-only (ignored)
301   "Line up argument lists by tabs, not spaces"
302   (let* ((anchor (c-langelem-pos c-syntactic-element))
303          (column (c-langelem-2nd-pos c-syntactic-element))
304          (offset (- (1+ column) anchor))
305          (steps (floor offset c-basic-offset)))
306     (* (max steps 1)
307        c-basic-offset)))
308
309 (c-add-style
310  "linux-tabs-only"
311  '("linux"
312    (c-basic-offset . 8)
313    (c-label-minimum-indentation . 0)
314    (c-offsets-alist . (
315 ; before:
316 ;                      (arglist-close         . c-lineup-arglist-tabs-only)
317 ;                       (arglist-cont-nonempty .
318 ;                                             (c-lineup-gcc-asm-reg c-lineup-arglist-tabs-only))
319                        (arglist-close         . c-lineup-arglist)
320                        (arglist-cont-nonempty . c-lineup-arglist)
321                        (arglist-intro         . +)
322                        (brace-list-intro      . +)
323                        (c                     . c-lineup-C-comments)
324                        (case-label            . 0)
325                        (comment-intro         . c-lineup-comment)
326                        (cpp-define-intro      . +)
327                        (cpp-macro             . -1000)
328                        (cpp-macro-cont        . +)
329                        (defun-block-intro     . +)
330                        (else-clause           . 0)
331                        (func-decl-cont        . +)
332                        (inclass               . +)
333                        (inher-cont            . c-lineup-multi-inher)
334                        (knr-argdecl-intro     . 0)
335                        (label                 . -1000)
336                        (statement             . 0)
337                        (statement-block-intro . +)
338                        (statement-case-intro  . +)
339                        (statement-cont        . +)
340                        (substatement          . +)
341                        ))))
342
343 (add-hook 'c-mode-hook
344           (lambda ()
345             (c-set-style "linux-tabs-only"))
346 )
347
348 (add-hook 'c-mode-common-hook
349   (lambda ()
350     (font-lock-add-keywords nil
351     '(("\\<\\(FIXME\\|TODO\\|HACK\\|fixme\\|todo\\|hack\\|XXX\\)" 1
352          font-lock-warning-face t)))))
353
354 (defun set-indent-2 ()
355   (interactive)
356   (setq c-basic-offset 2)
357   (setq tab-width 8 indent-tabs-mode nil)
358 )
359
360 (defun set-indent-4 ()
361   (interactive)
362   (setq c-basic-offset 4)
363   (setq tab-width 8 indent-tabs-mode nil)
364 )
365
366 (defun set-indent-8 ()
367   (interactive)
368   (setq c-basic-offset . 8)
369   (setq tab-width 8 indent-tabs-mode 1)
370 )
371
372 (defun toggle-whitespace-begin-space ()
373   (interactive)
374   (whitespace-toggle-options '(indentation::tab indentation))
375 )
376
377 ;; indentation of shell scripts
378 (defun set-sh-indent-8 ()
379   (interactive)
380   (setq sh-basic-offset 8
381         sh-indentation 8
382         sh-indent-comment t))
383
384 (defun set-sh-indent-4 ()
385   (interactive)
386   (setq sh-basic-offset 4
387         sh-indentation 4
388         sh-indent-comment t
389         indent-tabs-mode nil))
390
391 ;; with spaces
392 (defun set-sh-indent-4-spaces ()
393   (interactive)
394   (setq sh-basic-offset 4
395         sh-indentation 4
396         sh-indent-comment t))
397
398 (custom-set-faces
399  ;; custom-set-faces was added by Custom.
400  ;; If you edit it by hand, you could mess it up, so be careful.
401  ;; Your init file should contain only one such instance.
402  ;; If there is more than one, they won't work right.
403  '(magit-diff-added ((t (:foreground "#335533"))))
404  '(magit-diff-added-highlight ((t (:foreground "#336633"))))
405  '(magit-diff-base ((t (:foreground "#555522"))))
406  '(magit-diff-base-highlight ((t (:foreground "#666622"))))
407  '(magit-diff-removed ((t (:foreground "#553333"))))
408  '(magit-diff-removed-highlight ((t (:foreground "#663333"))))
409  '(magit-hash ((t (:foreground "white")))))
410
411 ;; (set-terminal-coding-system 'latin-9)
412 ;; (set-keyboard-coding-system 'latin-9)
413 ;; (set-language-environment 'latin-9)
414
415 (add-to-list 'kill-emacs-query-functions
416              (lambda () (y-or-n-p "Should Emacs really close? ")))
417
418 (define-key global-map [(control f3)]  'cscope-set-initial-directory)
419 (define-key global-map [(control f4)]  'cscope-unset-initial-directory)
420 (define-key global-map [(control f5)]  'cscope-find-this-symbol)
421 (define-key global-map [(control f6)]  'cscope-find-global-definition)
422 (define-key global-map [(control f7)]  'cscope-find-global-definition-no-prompting)
423 (define-key global-map [(control f8)]  'cscope-pop-mark)
424 (define-key global-map [(control f9)]  'cscope-next-symbol)
425 (define-key global-map [(control f10)] 'cscope-next-file)
426 (define-key global-map [(control f11)] 'cscope-prev-symbol)
427 (define-key global-map [(control f12)] 'cscope-prev-file)
428 (define-key global-map [(meta f9)]  'cscope-display-buffer)
429 (define-key global-map [(meta f10)] 'cscope-display-buffer-toggle)
430 ;(setq cscope-display-cscope-buffer nil)
431
432 (global-set-key (kbd "C-<up>") 'windmove-up)
433 (global-set-key (kbd "C-<down>") 'windmove-down)
434 (global-set-key (kbd "C-<left>") 'windmove-left)
435 (global-set-key (kbd "C-<right>") 'windmove-right)
436 (global-set-key (kbd "M-RET") 'other-window)
437 (global-set-key (kbd "C-<next>") 'next-buffer)
438 (global-set-key (kbd "C-<prior>") 'previous-buffer)
439
440 (setq-default gdb-display-io-nopopup t)
441
442 (defun vi-nolist ()
443   "Simulate a :set nolist in Vi."
444   (interactive)
445   (standard-display-ascii ?\t "\t")
446   (standard-display-ascii ?\ "\ ") )
447
448 (defun sign ()
449   "Insert signature."
450   (interactive "*")
451   (insert "Signed-off-by: Olivier Matz <olivier.matz@6wind.com>")
452 )
453
454 (defun ack-choice ()
455   "Insert acked-by."
456   (interactive
457    (let ((string (read-string "Name: " nil 'my-history)))
458      (insert (shell-command-to-string (concat "acked-by.py " string))))
459   )
460 )
461
462 (defun sign-choice ()
463   "Insert acked-by."
464   (interactive
465    (let ((string (read-string "Name: " nil 'my-history)))
466      (insert (shell-command-to-string (concat "acked-by.py -s " string))))
467   )
468 )
469
470 (defun toggle-fill-mode ()
471   "toggle fill mode between 72 and 80"
472   (interactive "*")
473   (if (<= fill-column 72)
474     (setq-default fill-column 80)
475     (setq-default fill-column 72)))
476
477 (defun rotate-windows-helper(x d)
478   (if (equal (cdr x) nil) (set-window-buffer (car x) d)
479     (set-window-buffer (car x) (window-buffer (cadr x))) (rotate-windows-helper (cdr x) d)))
480
481 (defun rotate-windows ()
482   (interactive)
483   (rotate-windows-helper (window-list) (window-buffer (car (window-list))))
484   (select-window (car (last (window-list)))))
485
486 ;; http://www.emacswiki.org/emacs/WhiteSpace
487 (require 'whitespace)
488 (global-whitespace-mode 1)
489 (setq whitespace-style '(face trailing lines-tail indentation::tab indentation
490                                   space-after-tab::tab space-after-tab::space
491                                   space-after-tab space-before-tab::tab
492                                   space-before-tab::space space-before-tab))
493 ;; for xms, remove indentation::tab and indentation
494 ;; (setq whitespace-style '(face trailing lines-tail
495 ;;                                space-after-tab::tab space-after-tab::space
496 ;;                                space-after-tab space-before-tab::tab
497 ;;                                space-before-tab::space space-before-tab))
498
499
500 (defun bf-pretty-print-xml-region (begin end)
501   "Pretty format XML markup in region. You need to have nxml-mode
502 http://www.emacswiki.org/cgi-bin/wiki/NxmlMode installed to do
503 this.  The function inserts linebreaks to separate tags that have
504 nothing but whitespace between them.  It then indents the markup
505 by using nxml's indentation rules."
506   (interactive "r")
507   (save-excursion
508       (nxml-mode)
509       (goto-char begin)
510       (while (search-forward-regexp "\>[ \\t]*\<" nil t)
511         (backward-char) (insert "\n"))
512       (indent-region begin end))
513     (message "Ah, much better!"))
514
515 ; fill column to 80 when we use M-q
516 (setq-default fill-column 80)
517
518 ; to remove once fixed (make 4.0 compat)
519 (setq-default compilation-directory-matcher '("\\(?:Entering\\|Leavin\\(g\\)\\) directory [`']\\(.+\\)'$" (2 . 1)))
520
521 ;; epylint start.py --rcfile=~/.pylintrc