summary refs log tree commit diff
path: root/emacs.d/init.el
blob: dccae8e78bb372177fd2042f99e3a30e5d4d42c1 (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
(require 'package)
(setq package-user-dir "~/.emacs.d/var/elpa")

;;; Code:
(setq package-archives
      (append package-archives
              '(("melpa" . "https://melpa.milkbox.net/packages/"))))

(package-initialize)
(setq package-enable-at-startup nil)

(unless package-archive-contents
  (message "Refreshing ELPA package archives...")
  (package-refresh-contents))

(unless (package-installed-p 'use-package)
  (message "`use-package' not found.  Installing...")
  (package-install 'use-package))

(require 'use-package)
(setq use-package-minimum-reported-time 0
      use-package-verbose t)

;; alias yes-or-no to y-or-n
(fset 'yes-or-no-p 'y-or-n-p)

;; set utf-8 as the default encoding
(prefer-coding-system 'utf-8-unix)

;; reload the buffer when a file changes
(global-auto-revert-mode 1)

(setq
 auto-save-default nil
 auto-save-list-file-prefix nil
 make-backup-files nil
 require-final-newline t
 vc-follow-symlinks t
 next-screen-context-lines 5
 tab-always-indent 'complete)

;; turn off indent tabs
(setq-default indent-tabs-mode nil)

;; nice font
(set-face-attribute 'default nil :font "Source Code Pro" :height 130)

;; light background
;; (set-background-color "#FFFFFF")

;; no menu
(menu-bar-mode -1)

;; show parenthesis
(show-paren-mode +1)

;; disable colors
(global-font-lock-mode -1)

;; no startup screen
(setq inhibit-startup-message t)
(setq initial-scratch-message "")

;; no blink cursor
(blink-cursor-mode -1)

;; show the column number in the mode-line
(setq column-number-mode t)

(when window-system
  (tool-bar-mode 0)    ;;hide tool-bar
  (scroll-bar-mode 0)  ;;hide scroll-bar
  (menu-bar-mode -1))  ;;hide menu-bar

;; no frindge
(set-fringe-mode 0)

;; auto close bracket insertion
(electric-pair-mode 1)

;; if running in macos, load environment variables
(when (memq window-system '(mac ns x))
  (use-package exec-path-from-shell
    :ensure t
    :init (setq exec-path-from-shell-debug +1)
    :config
    (exec-path-from-shell-initialize)
    (exec-path-from-shell-copy-envs '("TMPDIR"))))

;; I want dired
(use-package dired
  :commands dired
  :init
  (setq dired-listing-switches "-laGhv"))

;; install recentf
(use-package recentf
  :config
  (setq recentf-save-file "~/.emacs.d/var/recentf"))

;; get counsel and swiper
(use-package swiper
  :ensure t
  :bind (("C-s"   . swiper))
  :config
  (setq ivy-use-virtual-buffers t)
  (ivy-mode))

(use-package counsel
  :ensure t
  :config
  (setq counsel-find-file-at-point t))

;; I need helm
(use-package helm
  :ensure t)

;; interface to ag
(use-package ag
  :ensure t
  :defer t)

;; get projectile
(use-package projectile
  :ensure t
  :init
  (setq projectile-enable-caching t)
  (setq projectile-completion-system 'ivy)
  (setq projectile-known-projects-file "~/.emacs.d/var/projectile-bookmarks.eld")
  (setq projectile-cache-file "~/.emacs.d/var/projectile.cache")
  :config
  (projectile-global-mode))

;; check my spelling, it can only help
(use-package flyspell
  :ensure t
  :init
  (progn
    (setq ispell-program-name "aspell"
          ispell-list-command "--list")
    (add-hook 'prog-mode-hook 'flyspell-prog-mode)
    (add-hook 'text-mode-hook 'turn-on-flyspell)
    (add-hook 'org-mode-hook 'turn-on-flyspell)))

;; this makes emacs slow to work with source
(delete 'Git vc-handled-backends)

(use-package magit
  :ensure t
  :bind ("C-x g" . magit-status)
  :config
  (progn
    (setq magit-completing-read-function 'ivy-completing-read)
    (setq magit-item-highlight-face 'bold)))

;; run magit in full screen
;; http://www.lunaryorn.com/2016/04/28/fullscreen-magit-status.html
(add-to-list 'display-buffer-alist
             `(,(rx "*magit: ")
               (fcuny/display-buffer-fullframe)
               (reusable-frames . nil)))

(defun fcuny/display-buffer-fullframe (buffer alist)
  "Display BUFFER in fullscreen.

ALIST is a `display-buffer' ALIST.

Return the new window for BUFFER."
  (let ((window (display-buffer-pop-up-window buffer alist)))
    (when window
      (delete-other-windows window))
    window))

;; pants related stuff
(load-file "~/src/pants.el/pants.el")

(use-package pants
  :bind (("C-c b" . pants-find-build-file)
         ("C-c r" . pants-run-binary)
         ("C-c t" . pants-run-test))
  :config
  (progn
    (setq pants-source-tree-root "/Users/fcuny/src/source"
          pants-bury-compilation-buffer t)))

;; validate the syntax on the fly
(use-package flycheck
  :ensure t
  :defer t
  :preface (progn
             (defun check-source-predicate ()
               (and (executable-find "check.pex")
                    (buffer-file-name)
                    (string-match "src/source/.*\.py$" (buffer-file-name)))))
  :init
  (progn
    (add-hook 'prog-mode-hook 'flycheck-mode)
    (setq-default flycheck-disabled-checkers '(emacs-lisp-checkdoc)))
  :config
  (progn
    (setq flycheck-mode-line
      '(:eval
        (pcase flycheck-last-status-change
          (`not-checked nil)
          (`no-checker (propertize " -" 'face 'warning))
          (`running "")
          (`errored (propertize " ✘" 'face 'error))
          (`finished
           (if flycheck-current-errors
               (let* ((error-counts (flycheck-count-errors flycheck-current-errors))
                      (no-errors (cdr (assq 'error error-counts)))
                      (no-warnings (cdr (assq 'warning error-counts)))
                      (flycheck-face (cond (no-errors 'error)
                                           (no-warnings 'warning))))
                 (propertize (format " [✗:%s/%s]" (or no-errors 0) (or no-warnings 0)) 'face flycheck-face))
             (propertize " [✓]" 'face 'success)))
          (`interrupted " -")
          (`suspicious '(propertize " ?" 'face 'warning)))))

    (setq flycheck-puppet-lint-rc "/Users/fcuny/src/twitter-ops/utilities/puppet/.puppet-lint.rc")

    (flycheck-define-checker source-check
      "A syntax checker for python source code in Source, using `check.pex'"
      :command ("check.pex" source)
      ;;; errors are reported like this:
      ;;; E241:ERROR   <file name>:<line> <message>
      :error-patterns ((error line-start (id (1+ nonl)) ":ERROR" (1+ nonl) ":" line (message) line-end)
                       (warning line-start (id (1+ nonl)) ":WARNING" (1+ nonl) ":" line (message) line-end))
      :predicate check-source-predicate
      :modes (python-mode))
    (add-to-list 'flycheck-checkers 'source-check)))

(use-package flycheck-pos-tip
  :defer t
  :init
  (progn
    (eval-after-load 'feature-flycheck
      '(setq-default flycheck-display-errors-function #'flycheck-pos-tip-error-messages)))
  :ensure t)

;; configuration for ansible
(use-package ansible
  :ensure t)

(use-package ansible-doc
  :ensure t)

;; configuration for puppet
(when (memq window-system '(mac ns x))
    (dolist (var '("GEM_HOME" "MY_RUBY_HOME"))
      (unless (getenv var)
        (exec-path-from-shell-copy-env var))))

(use-package puppet-mode
  :ensure t
  :mode ("\\.pp$" . puppet-mode)
  :init
  (progn
    (add-hook 'puppet-mode-hook 'flycheck-mode)))

;; configuration for thrift
(use-package thrift
  :ensure t
  :defer t)

;; configuration for yaml
(use-package yaml-mode
  :mode ("\\.\\(yml\\|yaml\\)\\'" . yaml-mode)
  :ensure t
  :defer t)

;; configuration for go
(when (memq window-system '(mac ns x))
    (dolist (var '("GOPATH" "GO15VENDOREXPERIMENT"))
      (unless (getenv var)
        (exec-path-from-shell-copy-env var))))

(use-package go-mode
  :ensure t
  :defer t
  :config
  (progn
    (bind-key "C-c C-f" 'gofmt go-mode-map)
    (bind-key "C-c h" 'godoc go-mode-map)
    (bind-key "C-c C-g" 'go-goto-imports go-mode-map)
    (bind-key "C-c C-r" 'go-remove-unused-imports go-mode-map))
  :init
  (progn (add-hook 'go-mode-hook (lambda ()
                                   (go-eldoc-setup)
                                   (add-hook 'before-save-hook 'gofmt-before-save)))))

(use-package go-eldoc
  :ensure t
  :defer t
  :init (add-hook 'go-mode-hook 'go-eldoc-setup))

;; configuration for markdown
(use-package markdown-mode
  :ensure t
  :mode ("\\.\\(m\\(ark\\)?down\\|md\\)$" . markdown-mode)
  :config
  (progn
    (let ((preferred-markdown-impl "peg-markdown"))
      (when (executable-find preferred-markdown-impl)
        (setq markdown-command preferred-markdown-impl)))))

;; configuration for python
(use-package python
  :mode ("BUILD\\|\\(\\.\\(py\\|aurora\\)\\)$" . python-mode)
  :config
  (progn
    (setq python-indent-offset 2)))

;; configuration for racket
(use-package geiser
  :config
  (setq geiser-active-implementations '(racket))
  :ensure t)

;; configuration for shell
(setq-default
 sh-basic-offset 2
 sh-indentation 2)

;; some bindings
(global-set-key (kbd "M-j") 'join-line)
(global-set-key (kbd "C-x C-b") 'ibuffer)
(global-set-key (kbd "<s-return>") 'toggle-frame-fullscreen)
(global-set-key (kbd "C-c s") 'fc/visit-term-buffer)
(global-set-key (kbd "s-N") 'fc/switch-to-scratch)
(define-key emacs-lisp-mode-map (kbd "C-c C-e") 'eval-buffer)

;; custom functions
(defun fc/switch-to-scratch ()
  "Switch to scratch, grab the region if it's active."
  (interactive)
  (let ((contents
         (and (region-active-p)
              (buffer-substring (region-beginning)
                                (region-end)))))
    (switch-to-buffer "*scratch*")
    (if contents
        (progn
          (goto-char (buffer-end 1))
          (insert contents)))))

(defun fc/rename-this-buffer-and-file ()
  "Renames current buffer and file it is visiting."
  (interactive)
  (let ((name (buffer-name))
        (filename (buffer-file-name))
        (read-file-name-function 'read-file-name-default))
    (if (not (and filename (file-exists-p filename)))
        (error "Buffer '%s' is not visiting a file!" name)
      (let ((new-name (read-file-name "New name: " filename)))
        (cond ((get-buffer new-name)
               (error "A buffer named '%s' already exists!" new-name))
              (t
               (rename-file filename new-name 1)
               (rename-buffer new-name)
               (set-visited-file-name new-name)
               (set-buffer-modified-p nil)
               (message "File '%s' successfully renamed to '%s'" name (file-name-nondirectory new-name))))))))

;; start the server if not already running
(use-package server
  :config
  (unless (server-running-p)
    (server-start)))