-
Notifications
You must be signed in to change notification settings - Fork 0
/
dot-emacs
616 lines (496 loc) · 18.3 KB
/
dot-emacs
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
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;Library Paths
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Show stack traces on error
(setq stack-trace-on-error t)
; Save history of my minibuffer
(savehist-mode 1)
(setq savehist-additional-variables '(search-ring regexp-search-ring))
(setq savehist-file "~/.emacs.d/.history")
; Load CEDET Devel with it's very fresh eieio
(load-file "~/.emacs.d/cedet-bzr/trunk/cedet-devel-load.el")
; Setup my configuration directory
(add-to-list 'load-path "~/.emacs.d")
(progn (cd "~/.emacs.d") (normal-top-level-add-subdirs-to-load-path))
;; Custom setup from inside of emacs
(setq custom-file "~/.emacs.d/custom.el")
(load custom-file 'noerror)
;;
;; UI setup
;;
(menu-bar-mode t)
(tool-bar-mode -1)
(windmove-default-keybindings)
;;
;; Lang support
;;
(prefer-coding-system 'utf-8)
(set-terminal-coding-system 'utf-8)
(setq default-buffer-file-coding-system 'utf-8)
;;
;; Fix for LaTeX verbatim in emacs (rhbz#684797)
(custom-set-faces
'(tex-verbatim ((t (:foundry "courier" :family "*")))))
;;
;; IDE
;;
;; Highlight matching parents
(show-paren-mode 1)
(defadvice show-paren-function
(after show-matching-paren-offscreen activate)
"If the matching paren is offscreen, show the matching line in the
echo area. Has no effect if the character before point is not of
the syntax class ')'."
(interactive)
(let* ((cb (char-before (point)))
(matching-text (and cb
(char-equal (char-syntax cb) ?\) )
(blink-matching-open))))
(when matching-text (message matching-text))))
;;
;; Snippets
;;
(require 'yasnippet) ;; not yasnippet-bundle
(require 'auto-complete-config)
;; Yasnippet
(setq yas/trigger-key (kbd "C-c kp-divide")) ;; I will trigger it using auto-complete
(yas/global-mode 1)
(yas/initialize)
;; Develop and keep personal snippets under ~/emacs.d/mysnippets
(setq yas/root-directory "~/.emacs.d/snippets")
;; Load the snippets
(yas/load-directory "~/.emacs.d/yasnippet/snippets")
(yas/load-directory yas/root-directory)
;; Let me use some snippets in comments too
(add-hook 'python-mode-hook
'(lambda ()
(setq yas/buffer-local-condition
'(if (python-in-string/comment)
'(require-snippet-condition . force-in-comment)
t))))
; Auto complete
(add-to-list 'ac-dictionary-directories "/home/msivak/.emacs.d/ac-dict")
(add-to-list 'ac-modes 'sql-mode)
(add-to-list 'ac-modes 'verilog-mode)
(ac-config-default)
; CEDET
(add-to-list 'semantic-default-submodes 'global-semanticdb-minor-mode)
(add-to-list 'semantic-default-submodes 'global-semantic-mru-bookmark-mode)
(add-to-list 'semantic-default-submodes 'global-semantic-idle-scheduler-mode)
;(add-to-list 'semantic-default-submodes 'global-semantic-stickyfunc-mode)
(add-to-list 'semantic-default-submodes 'global-cedet-m3-minor-mode)
(add-to-list 'semantic-default-submodes 'global-semantic-highlight-func-mode)
;;(add-to-list 'semantic-default-submodes 'global-semantic-show-unmatched-syntax-mode)
;;(add-to-list 'semantic-default-submodes 'global-semantic-highlight-edits-mode)
;;(add-to-list 'semantic-default-submodes 'global-semantic-show-parser-state-mode)
;; Activate semantic only in specific modes
;; (semantic-mode 1)
(require 'semantic/ia)
(require 'semantic/bovine/c)
(require 'semantic/bovine/clang)
(require 'cedet-files)
;; loading contrib...
;(require 'eassist)
;; SRecode
(global-srecode-minor-mode 0)
;; EDE
(global-ede-mode 0)
(ede-enable-generic-projects)
;; Do not use CEDET java, eclim is much faster....
;; (require 'semantic/db-javap)
;; Setup Eclipse bindings
;; requires Eclipse with m2e plugin (Maven support)
(add-to-list 'load-path (expand-file-name "~/.emacs.d/emacs-eclim/"))
(add-to-list 'load-path (expand-file-name "~/.emacs.d/emacs-eclim/vendor"))
(require 'eclim)
(require 'eclimd)
(global-eclim-mode)
(setq eclim-auto-save t
eclim-executable "/usr/lib64/eclipse/eclim"
eclimd-executable "/usr/lib64/eclipse/eclimd"
eclimd-wait-for-process nil
eclimd-default-workspace "~/Work/"
help-at-pt-display-when-idle 'never
help-at-pt-timer-delay 0.3
ac-delay 0.1
eclim-use-yasnippet nil
)
;; Call the help framework with the settings above & activate
;; eclim-mode
;; disable help-at-pt as it breaks my buffers..
(help-at-pt-set-timer)
(require 'ac-emacs-eclim-source)
; (ac-emacs-eclim-config) - use ac-source-emacs-eclim
;; Setup verilog
(autoload 'verilog-mode "verilog-mode" "Verilog mode" t )
(add-to-list 'auto-mode-alist '("\\.[ds]?vh?\\'" . verilog-mode))
;; if you want to enable support for gnu global
(when (cedet-gnu-global-version-check t)
(semanticdb-enable-gnu-global-databases 'c-mode)
(semanticdb-enable-gnu-global-databases 'c++-mode)
)
; enable ctags for some languages:
; Unix Shell, Perl, Pascal, Tcl, Fortran, Asm
(when (cedet-ectag-version-check)
(semantic-load-enable-primary-exuberent-ctags-support))
(defun my-ac-hook ()
(local-set-key [(control return)] 'auto-complete)
)
(defun my-cedet-hook ()
(semantic-mode 1)
(local-set-key (kbd "\C-c?") 'semantic-ia-show-doc)
(local-set-key (kbd "\C-cp") 'semantic-analyze-proto-impl-toggle)
(local-set-key (kbd "\C-xj") 'semantic-ia-fast-jump)
(local-set-key (kbd "\C-c \C-r") 'semantic-symref)
(add-to-list 'ac-sources 'ac-source-yasnippet)
(add-to-list 'ac-sources 'ac-source-semantic)
(add-to-list 'ac-sources 'ac-source-gtags)
(local-set-key [(control return)] 'auto-complete)
)
(defun my-java-cedet-hook ()
(setq ac-sources '(ac-source-yasnippet
ac-source-emacs-eclim
ac-source-features
ac-source-abbrev
))
(local-set-key (kbd "\C-c?") 'eclim-java-show-documentation-for-current-element)
(local-set-key (kbd "\C-cH") 'eclim-java-hierarchy)
(local-set-key (kbd "\C-cI") 'eclim-java-import-organize)
(local-set-key (kbd "\C-xj") 'eclim-java-find-declaration)
(local-set-key (kbd "\C-c \C-r") 'eclim-java-find-references)
(local-set-key [(control return)] 'auto-complete)
)
(add-hook 'c-mode-hook 'my-cedet-hook)
(add-hook 'c++-mode-hook 'my-cedet-hook)
(add-hook 'java-mode-hook 'my-java-cedet-hook)
(add-hook 'erlang-mode-hook 'my-cedet-hook)
(add-hook 'verilog-mode-hook 'my-cedet-hook)
(add-hook 'emacs-lisp-mode-hook 'my-cedet-hook)
(add-hook 'sql-mode-hook 'my-ac-hook)
; File annotations
;(require 'org-annotate-file)
;(global-set-key (kbd "C-c C-l") 'org-annotate-file)
; Emacs Code Browser
(add-to-list 'load-path "~/.emacs.d/ecb")
(require 'ecb)
;(require 'ecb-autoloads)
; - at some time must be then started using ecb-activate
;;
;; C indentation
;;
(setq c-basic-offset 4)
(setq-default indent-tabs-mode nil) ;disable tabs as spaces
(setq-default fill-column 80)
;;
;; Leading and Trailing whitespaces
;;
(require 'whitespace)
;; display only tails of lines longer than 80 columns, tabs and
;; trailing whitespaces
(setq whitespace-line-column 80
whitespace-style '(face tabs trailing)) ; lines-tail))
;; face for long lines' tails
(set-face-attribute 'whitespace-line nil
:background "red1"
:foreground "white"
:weight 'bold)
;; face for Tabs
(set-face-attribute 'whitespace-tab nil
:background "red1"
:foreground "white"
:weight 'bold)
;; nuke trailing whitespaces when writing to a file
;; activate minor whitespace mode
(add-hook 'write-file-hooks 'delete-trailing-whitespace)
(mapc (lambda (hook)
(add-hook hook 'whitespace-mode)
)
'(text-mode-hook
emacs-lisp-mode-hook
python-mode-hook
js2-mode-hook
java-mode-hook
)
)
;; Flymake
(add-to-list 'load-path "~/.emacs.d/emacs-flymake-cursor")
(eval-after-load 'flymake '(require 'flymake-cursor))
(add-to-list 'load-path "~/.emacs.d/emacs-flymake")
(require 'flymake)
(setq flymake-run-in-place nil)
(add-hook 'find-file-hook 'flymake-find-file-hook)
(when (load "flymake" t)
(defun flymake-pyflakes-init ()
(let* ((temp-file (flymake-init-create-temp-buffer-copy
'flymake-create-temp-inplace))
(local-file (file-relative-name
temp-file
(file-name-directory buffer-file-name))))
(list "~/.emacs.d/pycheckers" (list local-file))))
(add-to-list 'flymake-allowed-file-name-masks
'("\\.py\\'" flymake-pyflakes-init)))
(require 'flymake-eclim-java)
;;;
;;; IRC client
;;;
(require 'erc)
; open queries in separate buffer
(setq erc-auto-query 'bury)
; scroll by lines
(add-hook 'erc-mode-hook (lambda () (setq scroll-conservatively 100000)))
; open notices in query buffers
(add-hook 'erc-after-connect
(lambda (server nick)
(add-hook 'erc-server-NOTICE-hook 'erc-auto-query)))
; ignore server and join,part.. events
(setq erc-track-exclude-types '("JOIN" "NICK" "PART" "QUIT" "MODE"
"324" "329" "332" "333" "353" "477"))
; treat query as if it contains my nick on every line (higlighting)
(defadvice erc-track-find-face (around erc-track-find-face-promote-query activate)
(if (erc-query-buffer-p)
(setq ad-return-value (intern "erc-current-nick-face"))
ad-do-it))
; put input line at the bottom of the window
(erc-scrolltobottom-enable)
(setq erc-input-line-position -2)
; reset chan tracking when I do not care
(defun reset-erc-track-mode ()
(interactive)
(setq erc-modified-channels-alist nil)
(erc-modified-channels-update))
(global-set-key (kbd "C-c r") 'reset-erc-track-mode)
; irc servers
(setq erc-autojoin-channels-alist
'(("freenode.net" "#anaconda" "#fedora")
("irc.devel.redhat.com" "#brno" "#devel" "#jerevan" "#dup" "#anaconda")
("irc.gts.sk" "#fit07")
))
(erc :server "irc.freenode.net" :port 6667 :nick "msivak")
(erc :server "irc.devel.redhat.com" :port 6667 :nick "msivak")
;(erc :server "us.ircnet.org" :port 6667 :nick "MarSik")
;
; Notifications
;
; channel message
(require 'notify)
(defun erc-global-notify (match-type nickuserhost message)
"Notify when a message is recieved."
(notify (format "%s in %s"
;; Username of sender
(car (split-string nickuserhost "!"))
;; Channel
(or (erc-default-target) "#unknown"))
;; Remove duplicate spaces
(replace-regexp-in-string " +" " " message)
:icon "emacs-snapshot"
:timeout -1))
(add-hook 'erc-text-matched-hook 'erc-global-notify)
; query
(defun ms-erc-privmsg-notify (proc res)
(let (
(channel-buffers (erc-channel-list proc))
(target-channel-name (car (erc-response.command-args res)))
)
(unless (member (get-buffer target-channel-name) channel-buffers)
(erc-global-notify nil (erc-response.sender res) (erc-response.contents res))
)
)
nil
)
;(add-hook 'erc-server-PRIVMSG-functions 'ms-erc-privmsg-notify)
;(setq notify-method 'notify-via-libnotify)
;
; Message sending
;
; close buffer when message is sent
(setq message-kill-buffer-on-exit t)
; configure smtp server
(setq smtpmail-smtp-server "smtp.corp.redhat.com"
message-send-mail-function 'message-smtpmail-send-it)
; notmuch message reading/filtering system
(require 'notmuch)
; keystrokes for notmuch
(define-key notmuch-show-mode-map "S"
(lambda ()
"mark message as spam"
(interactive)
(notmuch-show-tag-message "+spam" "-inbox")
)
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;Libraries to autoload
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; AsciiDoc
;;
(autoload 'adoc-mode "adoc-mode")
;;
;; Bookmarks
;;
;; Make sure the repository is loaded as early as possible
(setq bm-restore-repository-on-load t)
(setq-default bm-buffer-persistence t)
(require 'bm)
(global-set-key (kbd "<f2>") 'bm-toggle)
(global-set-key (kbd "ESC <f3>") 'bm-next)
(global-set-key (kbd "ESC <f2>") 'bm-previous)
(setq bm-marker 'bm-marker-right)
(setq bm-repository-file "~/.emacs.d/bm-repository.txt")
;; Loading the repository from file when on start up.
(add-hook' after-init-hook 'bm-repository-load)
;; Restoring bookmarks when on file find.
(add-hook 'find-file-hooks 'bm-buffer-restore)
;; Saving bookmark data on killing a buffer
(add-hook 'kill-buffer-hook 'bm-buffer-save)
;; Saving the repository to file when on exit.
;; kill-buffer-hook is not called when Emacs is killed, so we
;; must save all bookmarks first.
(add-hook 'kill-emacs-hook '(lambda nil
(bm-buffer-save-all)
(bm-repository-save)))
;; Update bookmark repository when saving the file.
(add-hook 'after-save-hook 'bm-buffer-save)
;; Restore bookmarks when buffer is reverted.
(add-hook 'after-revert-hook 'bm-buffer-restore)
;; make sure bookmarks is saved before check-in (and revert-buffer)
(add-hook 'vc-before-checkin-hook 'bm-buffer-save)
;;
;; GnuPG
;;
(require 'epa)
(epa-file-enable)
;;
;;Erlang mode
;;
; (when
; (file-accessible-directory-p "/usr/lib64/erlang/lib/tools-2.6.5.1/emacs")
; (setq load-path (cons "/usr/lib64/erlang/lib/tools-2.6.5.1/emacs" load-path))
; (setq erlang-root-dir "/usr/lib64/erlang/lib")
; (setq exec-path (cons "/usr/lib64/erlang/bin" exec-path))
; (require 'erlang-start)
; )
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;Python mode
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(load-library "ms-python")
;;
;OrgMode
;;
(setq load-path (cons "~/.emacs.d/org-mode/lisp" load-path))
(load-library "org")
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;NXML mode
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(add-to-list 'auto-mode-alist
(cons (concat "\\." (regexp-opt '("xml" "xsd" "sch" "rng" "xslt" "svg" "rss" "xhtml") t) "\\'")
'nxml-mode))
(fset 'xml-mode 'nxml-mode)
;;
;;NxHTML
;;
(load "~/.emacs.d/nxhtml/autostart.el")
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;Abbrev mode
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;(add-to-list 'load-path "~/.emacs.d/predictive")
;(autoload 'predictive-mode "predictive" "predictive" t)
;(set-default 'predictive-auto-add-to-dict t)
;(setq predictive-main-dict 'rpg-dictionary
; predictive-auto-learn t
; predictive-add-to-dict-ask nil
; predictive-use-auto-learn-cache nil
; predictive-which-dict t)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;Misc
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Use "y or n" answers instead of full words "yes or no"
(fset 'yes-or-no-p 'y-or-n-p)
;Reload .emacs on the fly
(defun reload-dot-emacs()
(interactive)
(if(bufferp (get-file-buffer ".emacs"))
(save-buffer(get-buffer ".emacs")))
(load-file "~/.emacs")
(message ".emacs reloaded successfully"))
;;Place all backup copies of files in a common location
(defconst use-backup-dir t)
(setq backup-directory-alist (quote ((".*" . "~/.emacs.d/backup/")))
version-control t ; Use version numbers for backups
kept-new-versions 16 ; Number of newest versions to keep
kept-old-versions 2 ; Number of oldest versions to keep
delete-old-versions t ; Ask to delete excess backup versions?
backup-by-copying-when-linked t) ; Copy linked files, don't rename.
;;Place autosave files in a common location
(defvar autosave-dir
(concat "~" (user-login-name) "/.emacs.d/autosave/"))
(setq auto-save-file-name-transforms
`(("\\(?:[^/]*/\\)*\\(.*\\)", (concat autosave-dir "\\1") t))
)
;Never put tabs in files, use spaces instead
;Note: Use C-q C-i to put a real tab should the need ever arise.
(setq-default indent-tabs-mode nil)
;;Allow fetching files from HTTP servers
(url-handler-mode)
;;TRAMP should default to ssh
(setq tramp-default-method "ssh")
;;; Copy thing-at-point intelligently
(defun sdl-kill-ring-save-thing-at-point (&optional n)
"Save THING at point to kill-ring."
(interactive "p")
(let ((things '((?l . list) (?f . filename) (?w . word) (?s . sexp)))
(message-log-max) ; don't write to *Message*
beg t-a-p thing event)
(flet ((get-thing ()
(save-excursion
(beginning-of-thing thing)
(setq beg (point))
(if (= n 1)
(end-of-thing thing)
(forward-thing thing n))
(buffer-substring beg (point)))))
;; try detecting url email and fall back to 'line'
(dolist (thing '(url email line))
(when (bounds-of-thing-at-point thing)
(setq t-a-p (get-thing))
;; remove the last newline character
(when (and (eq thing 'line)
(>= (length t-a-p) 1)
(equal (substring t-a-p -1) "\n"))
(setq t-a-p (substring t-a-p 0 -1)))
(kill-new t-a-p)
(message "%s" t-a-p)
(return nil)))
(setq event (read-event nil))
(when (setq thing (cdr (assoc event things)))
(clear-this-command-keys t)
(if (not (bounds-of-thing-at-point thing))
(message "No %s at point" thing)
(setq t-a-p (get-thing))
(kill-new t-a-p 'replace)
(message "%s" t-a-p))
(setq last-input-event nil))
(when last-input-event
(clear-this-command-keys t)
(setq unread-command-events (list last-input-event))))))
(defun sdl-kill-ring-save-dwim ()
"This command dwim on saving text.
If region is active, call `kill-ring-save'. Else, call
`sdl-kill-ring-save-thing-at-point'.
This command is to be used interactively."
(interactive)
(if (use-region-p)
(call-interactively 'kill-ring-save)
(call-interactively 'sdl-kill-ring-save-thing-at-point)))
(global-set-key (kbd "M-w") 'sdl-kill-ring-save-dwim)
;;
;; C-x k in server mode kills the buffer using the "server way" (C-x #)
;;
(add-hook 'server-switch-hook
(lambda ()
(when (current-local-map)
(use-local-map (copy-keymap (current-local-map))))
(local-set-key (kbd "C-x k") '(lambda ()
(interactive)
(if server-buffer-clients
(server-edit)
(kill-this-buffer))))))