Browse Source

Add emacs config

Ian Adam Naval 5 years ago
parent
commit
564d72de60
1 changed files with 92 additions and 0 deletions
  1. 92
    0
      emacs/emacs.dotflie

+ 92
- 0
emacs/emacs.dotflie View File

@@ -0,0 +1,92 @@
1
+;; initialize packages
2
+(require 'package)
3
+(add-to-list 'package-archives
4
+             '("melpa" . "http://melpa.org/packages/"))
5
+(add-to-list 'package-archives
6
+             '("elpy" . "https://jorgenschaefer.github.io/packages/"))
7
+(package-initialize)
8
+
9
+;; line numbers
10
+(global-linum-mode t)
11
+(column-number-mode 1)
12
+(setq linum-format "%4d ")
13
+
14
+;; git gutter
15
+(require 'git-gutter)
16
+(global-git-gutter-mode t)
17
+(git-gutter:linum-setup)
18
+
19
+;; vim emulation
20
+(require 'evil)
21
+(evil-mode 1)
22
+(require 'evil-surround)
23
+(global-evil-surround-mode 1)
24
+
25
+;; disable menubar
26
+(menu-bar-mode -1)
27
+
28
+;; 80 column marker
29
+(require 'whitespace)
30
+(setq whitespace-style '(face indentation trailing tab-mark lines-tail))
31
+(global-whitespace-mode t)
32
+
33
+;; prevent extraneous tabs
34
+(setq-default indent-tabs-mode nil)
35
+
36
+;; infer tab settings
37
+(defun how-many-region (begin end regexp &optional interactive)
38
+    "Print number of non-trivial matches for REGEXP in region.
39
+Non-interactive arguments are Begin End Regexp"
40
+    (interactive "r\nsHow many matches for (regexp): \np")
41
+    (let ((count 0) opoint)
42
+      (save-excursion
43
+        (setq end (or end (point-max)))
44
+        (goto-char (or begin (point)))
45
+        (while (and (< (setq opoint (point)) end)
46
+                    (re-search-forward regexp end t))
47
+          (if (= opoint (point))
48
+              (forward-char 1)
49
+            (setq count (1+ count))))
50
+        (if interactive (message "%d occurrences" count))
51
+        count)))
52
+
53
+(defun infer-indentation-style ()
54
+  ;; if our source file uses tabs, we use tabs, if spaces spaces, and if
55
+  ;; neither, we use the current indent-tabs-mode
56
+  (let ((space-count (how-many-region (point-min) (point-max) "^  "))
57
+        (tab-count (how-many-region (point-min) (point-max) "^\t")))
58
+    (if (> space-count tab-count) (setq indent-tabs-mode nil))
59
+        (if (> tab-count space-count) (setq indent-tabs-mode t))))
60
+(infer-indentation-style)
61
+
62
+;; auto remove trailing whitespace
63
+(add-hook 'before-save-hook 'delete-trailing-whitespace)
64
+(setq mode-require-final-newline t)
65
+
66
+;; automatic pairs
67
+(electric-pair-mode)
68
+
69
+;; neotree
70
+(require 'neotree)
71
+(global-set-key [f8] 'neotree-toggle)
72
+(add-hook 'neotree-mode-hook
73
+          (lambda ()
74
+            (define-key evil-normal-state-local-map (kbd "TAB") 'neotree-enter)
75
+            (define-key evil-normal-state-local-map (kbd "SPC") 'neotree-enter)
76
+            (define-key evil-normal-state-local-map (kbd "RET") 'neotree-enter)
77
+            (define-key evil-normal-state-local-map (kbd "q") 'neotree-hide)))
78
+(neotree-toggle)
79
+
80
+;; backup in separate directory
81
+(setq backup-directory-alist `(("." . "~/.emacs.d/backups")))
82
+(setq backup-by-copying t)
83
+
84
+;; projectile
85
+(projectile-global-mode)
86
+(setq projectile-find-file (kbd "C-p"))
87
+
88
+;;;;;;;;;;;;;;;;;;;
89
+;; python config ;;
90
+;;;;;;;;;;;;;;;;;;;
91
+
92
+(elpy-enable)

Loading…
Cancel
Save