/
init.el
145 lines (107 loc) · 3.9 KB
/
init.el
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
;; Key Bindings ------------------------------------------
;; moving to other window is frequent action when using ESS
(define-key global-map (kbd "C-t") 'other-window)
;; Use command as control
(setq mac-command-modifier 'control)
;; Packages ----------------------------------------------
;; setup repositories
(require 'package)
(add-to-list 'package-archives '("elpa" . "https://elpa.gnu.org/packages/"))
(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/"))
(package-initialize)
(setq pkgs '(ivy
ivy-hydra
counsel
swiper
company
ess
powerline
dracula-theme
flycheck
quickrun
projectile
counsel-projectile
magit
markdown-mode
yaml-mode
company-go))
(require 'cl)
;; if there are any packages not yet installed, get package list and install it
(let ((pkgs-not-yet-installed (remove-if 'package-installed-p pkgs)))
(if pkgs-not-yet-installed
(progn
(package-refresh-contents)
(dolist (pkg pkgs-not-yet-installed)
(package-install pkg)))))
;; Flycheck ----------------------------------------------
(global-flycheck-mode)
;; Auto-Completion ----------------------------------------
(add-hook 'after-init-hook 'global-company-mode)
;; Theme --------------------------------------------------
(load-theme 'dracula t)
;; hide menu bar and tool bar
(menu-bar-mode -1)
(tool-bar-mode -1)
;; use powerline
(require 'powerline)
(powerline-default-theme)
;; disable beeps
(setq ring-bell-function 'ignore)
;; Ivy -----------------------------------------------------
(ivy-mode)
(counsel-mode)
(setq ivy-use-virtual-buffers t)
(global-set-key (kbd "C-s") 'swiper)
;; Projectile ----------------------------------------------
(counsel-projectile-mode)
;; ignore files that git ignores
(setq projectile-indexing-method 'hybrid)
(setq projectile-use-git-grep t)
;; As of version 1.1, projectile requires users to define-key
(define-key projectile-mode-map (kbd "C-c p") 'projectile-command-map)
;; magit ---------------------------------------------------
(global-set-key (kbd "C-x g") 'magit-status)
;; Ess -----------------------------------------------------
(require 'ess-site)
;; shut up and start R
(setq ess-ask-for-ess-directory nil)
;; set default indentation as the same as RStudio
(setq ess-default-style 'RStudio)
;; we are so young that _ no more means <-
(ess-toggle-underscore nil)
(defun R-mode-hooks ()
;; show help of the active candidate of completion
(define-key company-active-map (kbd "M-h") 'company-show-doc-buffer)
;; set the working directory as the project root
(setq ess-startup-directory (projectile-project-root))
;; start R
(ess-request-a-process "Start R process" t)
;; use TAB for completion
(define-key inferior-ess-mode-map (kbd "TAB") 'company-complete))
(add-hook 'R-mode-hook 'R-mode-hooks)
(defun inferior-ess-mode-hooks ()
;; always use company-complete instead of completion-at-point
;; See https://github.com/emacs-ess/ESS/blob/37b9fdc7383417643cabb6af9c39f037908403bf/lisp/ess-inf.el#L2008
(define-key inferior-ess-mode-map (kbd "TAB") 'company-complete))
(add-hook 'inferior-ess-mode-hook 'inferior-ess-mode-hooks)
;; Go ---------------------------------------------------
(require 'company-go)
;; Use company-mode only
(add-hook 'go-mode-hook (lambda ()
(set (make-local-variable 'company-backends) '(company-go))
(company-mode)))
;; fmt codes
(add-hook 'before-save-hook 'gofmt-before-save)
(setq gofmt-command "goimports")
;; Others ------------------------------------------------
;; load variables
(load-file "~/.emacs.d/vars.el")
;; move custom to another file
(setq custom-file "./custom.el")
(load custom-file)
;; do not create files with ~
(setq make-backup-files nil)
;; Use LF for line ending
(setq default-buffer-file-coding-system 'utf-8-unix)
;; start server
(server-start)