summaryrefslogtreecommitdiffstats
path: root/emacs.d/init.el
blob: b582bf7c67070e01752b2f65ce7c6238c23ec393 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
;; -*- self-compile-mode: t; foldingo-close: t -*-

(setq custom-file "~/.emacs.d/emacs-custom.el")
(load custom-file)
(setq warning-suppress-types nil)

;;{{{ load-path anpassen

(let* ((my-lisp-dir "~/.emacs.d/lisp")
       (default-directory my-lisp-dir)
       (orig-load-path load-path))
  (setq load-path (cons my-lisp-dir nil))
  (normal-top-level-add-subdirs-to-load-path)
  (nconc load-path orig-load-path))

;;}}}

;;{{{ fix scroll bug with emacs 24.1

(when (boundp 'bidi-paragraph-direction)
  (setq-default bidi-paragraph-direction 'left-to-right))

;;}}}

;;{{{ load own color theme
(when (require 'color-theme nil 'noerror)
  (color-theme-initialize)
  (if (not window-system)
      (color-theme-alex-console)
    (color-theme-alex)))
;;}}}

;;{{{ user settings
(setq user-full-name "Alexander Sulfrian"
      user-mail-address "alexander@sulfrian.net")
;;}}}

;; define F1 to display man page of the current word
(global-set-key [(f1)] (lambda () (interactive) (manual-entry (current-word))))

(load "/usr/share/emacs/site-lisp/site-gentoo" 'noerror)

(setq text-mode-hook 'turn-on-auto-fill)
(setq fill-column 72)

(setq semanticdb-default-save-directory "~/.emacs.d/semantic")

(setq locale-coding-system 'latin-1)
(set-terminal-coding-system 'latin-1)
(set-keyboard-coding-system 'latin-1)
(set-selection-coding-system 'latin-1)
(prefer-coding-system 'latin-1)

(global-set-key [mouse-3] 'imenu)

;;{{{ fix keys for urxvt
(if (not window-system)
    (mapc (lambda (map)
	    (define-key function-key-map
	      (read-kbd-macro (cadr map))
	      (read-kbd-macro (car map))))
	  '(("<S-tab>"     "M-[ Z")
	    ("<S-up>"      "<select>")
	    ("<S-down>"    "M-[ b")
	    ("<S-right>"   "M-[ c")
	    ("<S-left>"    "M-[ d")
	    ("<M-up>"      "ESC M-O A")
	    ("<M-down>"    "ESC M-O B")
	    ("<M-right>"   "ESC M-O C")
	    ("<M-left>"    "ESC M-O D")
	    ("<C-up>"      "M-O a")
	    ("<C-down>"    "M-O b")
	    ("<C-right>"   "M-O c")
	    ("<C-left>"    "M-O d")
	    ("<C-M-up>"    "ESC M-O a")
	    ("<C-M-down>"  "ESC M-O b")
	    ("<C-M-right>" "ESC M-O c")
	    ("<C-M-left>"  "ESC M-O d")
	    ("<M-S-up>"    "ESC M-[ a")
	    ("<M-S-down>"  "ESC M-[ b")
	    ("<M-S-right>" "ESC M-[ c")
	    ("<M-S-left>"  "ESC M-[ d")
	    )))
;;}}}

(setq auto-mode-alist (cons '("README" . text-mode) auto-mode-alist))
(setq compilation-scroll-output t)

;; css-mode
(setq cssm-indent-level 4)
(setq cssm-newline-before-closing-bracket t)
(setq cssm-indent-function #'cssm-c-style-indenter)

;; delphi-mode
(load "delphi-mode-ench.el")

;: removing annoyances
(setq inhibit-startup-message t)
(setq require-final-newline t)
(fset 'yes-or-no-p 'y-or-n-p)
(setq next-line-add-newlines nil)

;: general settings
(require 'paren) (show-paren-mode t)
(global-font-lock-mode t)
(setq font-lock-maximum-decoration t)
(follow-mode t)
(setq vc-follow-symlinks t)

(require 'uniquify)
(setq uniquify-buffer-name-style 'reverse)

(defun back-to-indentation-or-beginning () (interactive)
  (if (= (point) (progn (back-to-indentation) (point)))
      (beginning-of-line)))
(global-set-key (kbd "<home>") 'back-to-indentation-or-beginning)

;; c/c++-mode stuff
(setq indent-tabs-mode t)
(setq c-default-style "linux")
(c-set-offset 'arglist-cont-nonempty '(c-lineup-arglist-tabs-only c-lineup-gcc-asm-reg))

(add-hook 'c-mode-common-hook
            (lambda ()
              (setq fill-column 80)
              (turn-on-auto-fill)

              ;; now '_' is not considered a word-delimiter
              (modify-syntax-entry ?_ "w")

              ;; set indentation style
              (c-set-style "linux")
              (local-set-key (kbd "M-m") 'eassist-list-methods)
              (local-set-key (kbd "C-o") 'semantic-complete-jump-local)
              (local-set-key (kbd "C-c o") 'ff-find-other-file)))

(global-set-key [C-return] 'dabbrev-expand)
(define-key esc-map [C-return] 'dabbrev-completion)

(global-set-key [f12] 'indent-region)

;; Enable Doxygen syntax highlighting for C and C++
(when (require 'doxymacs nil 'noerror)
  (add-hook 'font-lock-mode-hook
	    '(lambda ()
	       (if (or (eq major-mode 'c-mode) (eq major-mode 'c++-mode))
		   (doxymacs-font-lock)))))

;; flyspell (with aspell for Unicode)
(setq ispell-program-name "aspell"
      ispell-extra-args '("--sug-mode=ultra"))

;; define variable to store default dictionary for automatic flyspell enabling
(defvar flyspell-dict nil "Dictionary name, that should be set during find-file for flyspell-mode.
If this is set during find-file, flyspell mode gets enabled automaticaly.")
(make-variable-buffer-local 'flyspell-dict)

(when (require 'ispell nil 'noerror)
  ;; change dictionary
  (defun switch-dictionary()
    (interactive)
    (let* ((dic ispell-current-dictionary)
           (change (if (string= dic "german") "english" "german")))
      (ispell-change-dictionary change)
      (message "Dictionary switched from %s to %s" dic change)
      (if flyspell-mode (save-excursion (flyspell-buffer)))))
  (global-set-key (kbd "<f8>") 'switch-dictionary)

  (when (require 'flyspell nil 'noerror)
    ;; check buffer if enable flyspell
    (add-hook 'flyspell-mode-hook
              (lambda ()
                (when flyspell-mode (flyspell-buffer))))

    ;; ignore all #include stings
    (add-hook 'flyspell-incorrect-hook
              (lambda (left right undef)
                (save-excursion
                  (goto-char left)
                  (beginning-of-line)
                  (if (looking-at "#include") t nil))))

    ;; activate flyspell mode during find-file if flyspell-dict is set
    (add-hook 'find-file-hook
              (lambda ()
                (when flyspell-dict
                  (ispell-change-dictionary flyspell-dict)
                  (flyspell-mode t))))

    ;; update flyspell after changing personal dictionary
    (defadvice ispell-pdict-save (after advice)
      (save-excursion (flyspell-buffer)))
    (ad-activate 'ispell-pdict-save t)))


;; auto compile files
(require 'self-compile-mode nil 'noerror)

;; keine Abfrage wenn ein template existiert
(when (require 'template nil 'noerror)
  (setq template-auto-insert t
        template-message-prompt-format nil
        template-default-directories (list (expand-file-name "~/.emacs.d/templates/")))

  (add-to-list 'template-find-file-commands 'ido-exit-minibuffer)
  (template-initialize))

;; remember last position in file
(setq save-place-file "~/.emacs.d/saveplace")
(setq-default save-place t)
(require 'saveplace)

;; ignore .d files in completion
(setq completion-ignored-extensions
    (append (list ".d") completion-ignored-extensions))

;; clever auto complete mode
(require 'ido)
(ido-mode t)
(setq
   ido-ignore-buffers '("\\` " "^\*Mess" "^\*Back" ".*Completion" "^\*Ido")
   ido-case-fold  t
   ido-use-filename-at-point nil
   ido-use-url-at-point nil
   ido-enable-flex-matching t
   ido-max-prospects 10
   ido-enable-tramp-completion nil
   ido-confirm-unique-completion t)

;; start server if not running (to edit files with emacsclient)
(when (require 'server nil 'noerror)
  (if (and (fboundp 'server-running-p)
	   (not (server-running-p)))
      (server-start))

  (add-hook 'server-switch-hook
          (lambda ()
            (when (current-local-map)
              (use-local-map (copy-keymap (current-local-map))))
            (when server-buffer-clients
              (local-set-key (kbd "C-x k") 'server-edit)))))

; emacs code browser
(when (require 'ecb nil 'noerror)
  (ecb-activate))

;; smex
(setq smex-save-file "~/.emacs.d/smex.save")
(when (require 'smex nil 'noerror)
  (smex-initialize)
  (global-set-key (kbd "M-X") 'smex))

;; snippets
(when (require 'yasnippet nil 'noerror)
  (yas/initialize)
  (yas/load-directory "~/.emacs.d/snippets"))

;; html-php-multi-mode
(when (require 'html-php nil 'noerror)
  (setq auto-mode-alist (cons '("\\.php" . html-php-mode) auto-mode-alist)))

;; copy/paste enhancements
;; share clipboard with other X11-Apps
(when (fboundp 'x-cut-buffer-or-selection-value)
  (progn
    (setq x-select-enable-clipboard t)
    (setq interprogram-paste-function 'x-cut-buffer-or-selection-value)))

;; use cua-mode, but only for rectangle selections
(setq cua-enable-cua-keys nil)
(cua-mode t)

;; copy/kill whole line when no region is active
(defadvice kill-ring-save (before slick-copy activate compile)
  (interactive (if mark-active (list (region-beginning) (region-end)) (message
  "Copied line") (list (line-beginning-position) (line-beginning-position
  2)))))
(ad-activate 'kill-ring-save)

(defadvice kill-region (before slick-cut activate compile)
  (interactive
    (if mark-active (list (region-beginning) (region-end))
      (list (line-beginning-position)
        (line-beginning-position 2)))))
(ad-activate 'kill-region)

;; rudel (obby/... connection)
(load "rudel-loaddefs.el")

;; magit
(when (require 'magit nil 'noerror)
  ;; magit-status (bind if available on <f5>)
  (global-set-key (kbd "<f5>") 'magit-status)
  (add-hook 'magit-log-edit-mode-hook (lambda () (flyspell-mode 1))))


;; linum (generic & *scratch*)
(when (require 'linum-narrow nil 'noerror)
  (add-hook 'find-file-hook (lambda () (linum-mode 1)))
  (add-hook 'lisp-interaction-mode-hook (lambda () (linum-mode 1))))

;; bookmarks
(setq bookmark-default-file "~/.emacs.d/bookmarks")
(setq bookmark-save-flag 1)

;; winring
(when (require 'winring nil 'noerror)
  ;; ecb support if ecb is available
  (when (fboundp 'ecb-winman-winring-enable-support)
    (ecb-winman-winring-enable-support))

  (winring-initialize)
  (global-set-key (kbd "C-x j") 'winring-jump-to-configuration)
  (global-set-key (kbd "C-x n") 'winring-new-configuration)

  ;; ask before deleting winring configuration
  (defun winring-ask-delete-configuration ()
    (interactive)
    (if (y-or-n-p "Delete winring configuration? ")
	(winring-delete-configuration)))

  (global-set-key (kbd "C-x K") 'winring-ask-delete-configuration))

;; etags
(require 'etags-table nil 'noerror)

; autocompletion for etags
(require 'auto-complete-etags nil 'noerror)

;; change cursor according to the mode (normal, read only, overwrite)
(when (require 'cursor-chg nil 'noerror)
  (toggle-cursor-type-when-idle 1)
  (change-cursor-mode 1))

;; windmove (only if available)
(when (fboundp 'windmove-default-keybindings) (windmove-default-keybindings))

;; lisp-eassist
(define-key lisp-mode-shared-map (kbd "M-m") 'eassist-list-methods)

;; dir-locals
(require 'dir-locals nil 'noerror)

;; use sml-modeline if available
(when (require 'sml-modeline nil 'noerror)
  (progn
    ;; show buffer pos in the mode line
    ;; and turn off the scrollbar
    (sml-modeline-mode 1)
    (when (fboundp 'scroll-bar-mode) (scroll-bar-mode -1)))
  (when (fboundp 'scroll-bar-mode)
    (progn
      ;; otherwise, show a scrollbar...
      ;; ... on the right
      (scroll-bar-mode 1)
      (set-scroll-bar-mode 'right))))

;; smooth-scrolling (do not jump to the middle of the screen)
(require 'smooth-scrolling nil 'noerror)

;; browse-kill-ring
(when (require 'browse-kill-ring nil 'noerror)
  (progn (browse-kill-ring-default-keybindings)
	(global-set-key "\C-cy" '(lambda () (interactive)
				   (popup-menu 'yank-menu)))))

;; fill adapt
(when (require 'filladapt nil 'noerror)
  (setq-default filladapt-mode t))

;; jshint-mode
(when (require 'flymake-jshint nil 'noerror)
  (add-hook 'js-mode-hook
          (lambda () (flymake-mode t))))

;;{{{ org-mode

(when (require 'org nil 'noerror)
  (progn
    (setq org-todo-keywords
        '((sequence "TODO(t)" "PROGRESS(p!)" "WAIT(w@/!)" "|"
                    "CANCELED(c@/!)" "DONE(d!)")))

    (setq org-todo-keyword-faces
          '(("TODO" . org-warning) ("PROGRESS" . "yellow")
            ("CANCELED" . (:foreground "blue" :weight bold))))
    (setq org-startup-folded 'content)
    (setq org-startup-indented t)))

;;}}}

;; promela-mode
(when (require 'promela-mode nil 'noerror)
  (setq auto-mode-alist
        (append (list '("\\.promela\\'" . promela-mode)
                      '("\\.spin\\'" . promela-mode)
                      '("\\.pml\\'" . promela-mode)
                      '("\\.prm\\'" . promela-mode)
                      '("\\.porm\\'" . promela-mode))
                auto-mode-alist)
        promela-block-indent 2
        promela-selection-indent 0
        promela-selection-option-indent 3))

;; dired+ mode
(when (require 'dired-x nil 'noerror)
  (setq dired-omit-files (rx (or (seq bol (? ".") "#")
                                 (seq "~" eol)
                                 (seq bol "svn" eol)
                                 (seq ".pyc" eol)
                                 (seq bol ".git" eol)
                                 (seq ".d" eol)
                                 (seq ".o" eol)))

        dired-omit-extensions (append dired-latex-unclean-extensions
                                      dired-bibtex-unclean-extensions
                                      dired-texinfo-unclean-extensions))

  (add-hook 'dired-mode-hook (lambda () (dired-omit-mode 1))))

;; arduino-mode
(require 'arduino-mode nil 'noerror)

;;{{{ deft
(when (require 'deft nil 'noerror)
   (setq deft-extension "org"
         deft-directory "~/.org/deft/"
         deft-text-mode 'org-mode)
   (global-set-key (kbd "<f9>") 'deft))
;;}}}

;; edit with emacs
(when (require 'edit-server nil 'noerror)
  (setq edit-server-new-frame nil)
  (edit-server-start))

;;{{{ fix raise-frame
(defadvice raise-frame (after make-it-work (&optional frame) activate)
    "Work around some bug? in raise-frame/Emacs/GTK/Metacity/something.
     Katsumi Yamaoka <yamaoka@jpl.org> posted this in
     http://article.gmane.org/gmane.emacs.devel:39702"
     (call-process
      "wmctrl" nil nil nil "-i" "-R"
      (frame-parameter (or frame (selected-frame)) 'outer-window-id)))
;;}}}

;;{{{ quick open shell

(defun dirname (file)
  (replace-regexp-in-string "[^/]*$" "" file))

(defun open-buffer-shell ()
  (interactive)
  (if buffer-file-name
      (start-process-shell-command
       "urxvt"
       nil
       (concat "DIR=" (dirname buffer-file-name) " urxvt"))
    (message "Buffer does not contain a file.")))

(global-set-key (kbd "<f12>") 'open-buffer-shell)

;;}}}

;;{{{ foldingo-mode
(when (require 'foldingo nil 'noerror)
  (add-hook 'find-file-hooks
            'install-fold-mode-if-needed)

  ;; we want never implicit foldings
  (defun alex-fold-mode-hook ()
    (setq-default fold-implicit-fold-threshold 1000000))
  (add-hook 'fold-mode-hook
            'alex-fold-mode-hook)

  ;; close all folds when requested with file local variable folding-close
  (defadvice install-fold-mode-if-needed (after alex-foldingo-fold-all compile activate)
    (if (and fold-mode foldingo-close)
      (fold-close-all-folds)))

  ;; shortcut for toggling a fold
  (defun alex-fold-toggle-current-fold ()
    (interactive)
    (fold-toggle (fold-current-fold)))
  (define-key fold-keymap (kbd "C-c C-f") 'alex-fold-toggle-current-fold)

  ;; refresh the folds after save, but do not change the current status
  (defun alex-fold-refresh-after-save ()
    (when fold-mode
      (if foldingo-close
          (fold-enter-fold-mode-close-all-folds)
        (fold-enter-mode))))
  (add-hook 'after-save-hook 'alex-fold-refresh-after-save))
;;}}}