aboutsummaryrefslogtreecommitdiff
path: root/home/.emacs.d/init.el
blob: 9f3d8f19b769153f8504addef0ef6202d8895cad (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
;;; General editor configuration

;; clean up interface
(menu-bar-mode -1)
(tool-bar-mode -1)
(scroll-bar-mode -1)
(global-linum-mode t)
(setq column-number-mode t)
(setq inhibit-splash-screen t)
(setq initial-scratch-message nil)
(setq ring-bell-function 'ignore)

;; disable backups, autosave and lockfiles
(setq make-backup-files nil)
(setq backup-inhibited t)
(setq auto-save-default nil)
(setq create-lockfiles nil)
(global-auto-revert-mode t)

;; font
; value is in 1/10pt, so 100 will give you 10pt, etc.
(set-face-attribute 'default nil :height 110)

;; simplify questions
(defalias 'yes-or-no-p 'y-or-n-p)
(setq vc-follow-symlinks t)

;; kill the current buffer immediately (only ask if buffer modified)
(global-set-key (kbd "C-x k") 'kill-this-buffer)

;; set title of frame to current buffer
(setq frame-title-format '(buffer-file-name "%f" "%b"))

;; Highlight corresponding parentheses when cursor is on one
(show-paren-mode t)

;; Show directories first
(setq dired-listing-switches "-alh  --group-directories-first")

;; save customizations to separate file
(setq custom-file (expand-file-name "custom.el" user-emacs-directory))
(load custom-file 'noerror)

;; don't send emacs to background
(global-unset-key (kbd "C-z"))

;;(setq initial-buffer-choice "~/readme.org")

(global-set-key (kbd "C-x C-b") 'ibuffer)
(global-set-key (kbd "M-o") 'other-window)

(defun show-file-name ()
  "Show the absolute path file name in the minibuffer."
  (interactive)
  (message (buffer-file-name)))
(global-set-key (kbd "C-x n") 'show-file-name)

;;; Enable use-package

(require 'package)
(add-to-list 'package-archives
	     '("melpa" . "https://melpa.org/packages/"))
(package-initialize)

(when (not package-archive-contents)
  (package-refresh-contents))

(unless (package-installed-p 'use-package)
  (package-install 'use-package))

(require 'use-package)
(setq use-package-verbose t)
(setq use-package-always-ensure t)

;;; Specialized packages

(use-package ido
  :init
  (setq ido-enable-flex-matching t)
  (setq ido-everywhere t)
  (ido-mode 1))

(use-package goto-chg
  :commands goto-last-change
  :bind (("C-." . goto-last-change)
         ("C-," . goto-last-change-reverse)))

(use-package popup-imenu
  :commands popup-imenu
  :bind ("M-i" . popup-imenu))

(use-package projectile
  :init
  (setq projectile-use-git-grep t)
  :config
  (setq projectile-completion-system 'ido)
  (define-key projectile-mode-map (kbd "C-c p") 'projectile-command-map)
  (projectile-mode +1)
  :diminish projectile-mode)

(use-package magit
  :bind ("C-x g" . magit-status)
  :config
  (setq magit-completing-read-function 'magit-ido-completing-read)
  (setq magit-save-repository-buffer 'dontask))

(use-package zoom-frm
  :bind (("C-+" . zoom-all-frames-in)
	 ("C--" . zoom-all-frames-out)
	 ("C-0" . zoom-frm-unzoom)))

(use-package expand-region
  :commands 'er/expand-region
  :bind ("C-=" . er/expand-region))

(defun unfill-paragraph (&optional region)
  ;; http://www.emacswiki.org/emacs/UnfillParagraph
  "Transforms a paragraph in REGION into a single line of text."
  (interactive)
  (let ((fill-column (point-max)))
    (fill-paragraph nil region)))
(define-key global-map "\M-Q" 'unfill-paragraph)

(defun revert-buffer-no-confirm ()
  ;; http://www.emacswiki.org/emacs-en/download/misc-cmds.el
  "Revert buffer without confirmation."
  (interactive)
  (revert-buffer t t))
(global-set-key [f5] 'revert-buffer-no-confirm)

;; Markdown
(use-package markdown-mode
  :mode
  ("\\.markdown\\'" "\\.md\\'")
  :config
  (setq markdown-command "/usr/bin/pandoc"))

;; YML
(use-package yaml-mode
  :mode ("\\.yml\\'" "\\.yaml\\'"))

;; Completion
(use-package company
  :diminish company-mode
  :commands company-mode)

;; Snippets
(use-package yasnippet
  :diminish yas-minor-mode
  :commands yas-minor-mode
  :config
  (define-key yas-minor-mode-map [tab] nil)
  (define-key yas-minor-mode-map (kbd "TAB") nil)
  (yas-reload-all)
  :bind ("C-<tab>" . yas-expand))

(use-package yatemplate
  :config
  (auto-insert-mode t)
  (setq auto-insert-query nil)
  (setq auto-insert-alist nil)
  (yatemplate-fill-alist))

;; C
(setq c-default-style "linux")

;; Scala
(defcustom
  scala-mode-prettify-symbols
  '(("->" . ?→)
    ("<-" . ?←)
    ("=>" . ?⇒)
    ("<=" . ?≤)
    (">=" . ?≥)
    ("!=" . ?≠)
    ("implicit" . ?ⅈ))
"Prettify symbols for scala-mode.")

(use-package scala-mode
  :pin melpa
  :interpreter ("scala" . scala-mode)
  :config
  (add-hook 'scala-mode-hook
	    (lambda ()
	      (setq prettify-symbols-alist scala-mode-prettify-symbols)
	      (prettify-symbols-mode t)
	      (setq fill-column 80)
	      (ensime-mode))))

;; ENhanced Scala Interaction Mode for text Editors
(use-package ensime
  :pin melpa ;; pining to melpa uses cutting-edge snapshot version
  :commands ensime ensime-mode
  :init
  :config
  (require 'ensime-expand-region)
  (setq ensime-startup-notification nil
	ensime-startup-snapshot-notification nil))

(use-package sbt-mode
  :pin melpa)

;; Java / Scala support for templates
(defun mvn-package-for-buffer ()
  "Calculate the expected package name for the buffer;
assuming it is in a maven-style project."
  ;; see https://github.com/fommil/dotfiles/issues/66
  (let* ((kind (file-name-extension buffer-file-name))
         (root (locate-dominating-file default-directory kind)))
    (when root
      (require 'subr-x) ;; maybe we should just use 's
      (replace-regexp-in-string
       (regexp-quote "/") "."
       (string-remove-suffix "/"
                             (string-remove-prefix
                              (expand-file-name (concat root "/" kind "/"))
                              default-directory))
       nil 'literal))))

;; Java
(add-hook 'java-mode-hook (lambda ()
			    (setq c-basic-offset 4)))
;; Rust
(use-package rust-mode
  :mode "\\.rs\\'")
(use-package toml-mode
  :mode "\\.toml\\'")

;; Web development
;; Different modes in html files
(use-package web-mode
  :mode "\\.html?\\'")

;; Javascript
(use-package js3-mode
  :mode "\\.js\\'")

;; Haskell
(use-package haskell-mode)

;; Go
(use-package go-mode)

;; Docker
(use-package dockerfile-mode
  :mode "\\Dockerfile\\'")

(use-package darcula-theme)
;;(use-package solarized-theme)
;;(load-theme 'solarized-light)
(load-theme 'darcula)