summary refs log tree commit diff
path: root/emacs.d/init.el
blob: 461eea850cb72c855ae95acfc28b3db1f79b6154 (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
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
;; setup packages
(require 'package)
(setq package-user-dir (expand-file-name "var/elpa" user-emacs-directory)
      package-enable-at-startup nil
      package-archives (append package-archives
                               '(("melpa" . "https://melpa.milkbox.net/packages/"))))

(package-initialize)

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

;; install the package 'use-package' unless it's already installed
(unless (package-installed-p 'use-package)
  (progn
    (package-install 'use-package)))

;; ... and load 'use-package'
(require 'use-package)

(use-package settings
  :load-path (lambda () (expand-file-name  "lib" user-emacs-directory)))

(use-package funcs
  ;; Contains some functions
  :load-path (lambda () (expand-file-name  "lib" user-emacs-directory))
  :commands (fc/load-time)
  :bind (("s-=" . fc/scale-up-font)
         ("s--" . fc/scale-down-font)
         ("s-0" . fc/reset-font-size)))

(use-package basic-theme
  ;; this is my own custom theme. No syntax highlighting
  :load-path (lambda () (expand-file-name "lib" user-emacs-directory))
  :config
  (load-theme 'basic t))

(use-package bindings
  ;; my own custom bindings
  :load-path (lambda () (expand-file-name  "lib" user-emacs-directory)))

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

(use-package  diminish
  ;; remove clutter from the mode line
  :ensure t)

(use-package ag
  ;; interface to the 'ag' tool
  :ensure t
  :commands (counsel-ag ag)
  :init
  (setq ag-reuse-buffers t
        ag-reuse-window t))

(use-package autorevert
  ;; automatically revert the buffer if the content changed on disk
  :diminish auto-revert-mode)

(use-package counsel
  ;; completion functions for ivy
  :ensure t

  :bind*
  (("M-x"     . counsel-M-x)
   ("C-s"     . counsel-grep-or-swiper)
   ("C-x C-f" . counsel-find-file)
   ("C-x C-r" . counsel-recentf)
   ("C-c f"   . counsel-git)
   ("C-c s"   . counsel-git-grep)
   ("C-c /"   . counsel-ag))

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

(use-package dired
  ;; configuration for dired
  :bind ("C-x C-d" . dired)

  :config
  (let ((gls "/opt/twitter/bin/gls"))
    (if (file-exists-p gls)
        (setq insert-directory-program gls
              dired-listing-switches "-aBhl --group-directories-first")))
  (use-package dired-x
    :init
    (add-hook 'dired-load-hook (lambda () (load "dired-x")))
    :config
    (add-hook 'dired-mode-hook #'dired-omit-mode)
    (setq dired-omit-verbose nil)
    (setq dired-omit-files
          (concat dired-omit-files "\\|^.DS_Store$\\|^.projectile$\\|^.git$"))))

(use-package dockerfile-mode
  ;; support for dockerfile mode
  :ensure t)

(use-package lisp-mode
  ;; simple configuration for various lisp mode
  :config
  (add-hook 'emacs-lisp-mode-hook
            (lambda()
              (setq mode-name "λ"))))

(use-package eldoc
  ;; documentation with eldoc
  :ensure t

  :commands eldoc-mode

  :diminish ""

  :init
  (add-hook 'emacs-lisp-mode-hook 'eldoc-mode)
  (add-hook 'lisp-interaction-mode-hook 'eldoc-mode))

(use-package eshell
  ;; configuration for eshell
  :ensure t

  :bind ("C-x e" . eshell)

  :init
  (progn
    (setq eshell-directory-name (expand-file-name "var/eshell/" user-emacs-directory))
    (add-hook 'eshell-mode-hook '(lambda ()(exec-path-from-shell-initialize)))
    (add-hook 'eshell-mode-hook (lambda ()
                                  (setenv "PAGER" "less")
                                  (setenv "EDITOR" "emacsclient"))))
  :config
  (progn
    (use-package em-term
      :defer t
      :config
      (setq eshell-destroy-buffer-when-process-dies t
            eshell-visual-commands
            (append '("less" "tmux" "ssh" "htop" "top") eshell-visual-commands)))))

(use-package exec-path-from-shell
  ;; environment fixup for macOS.
  :ensure t

  :if (and (eq system-type 'darwin) (display-graphic-p))

  :init
  (setq exec-path-from-shell-check-startup-files nil)

  :config
  (progn
    (setq exec-path-from-shell-debug t)
    (exec-path-from-shell-initialize)))

(use-package flycheck
  ;; check syntax
  :ensure t

  :config
  (progn
    (use-package flycheck-pos-tip
      :ensure t
      :config
      (setq flycheck-display-errors-function #'flycheck-pos-tip-error-messages)
      :init
      (flycheck-pos-tip-mode))

    (add-hook 'prog-mode-hook 'flycheck-mode)
    (setq-default flycheck-disabled-checkers '(emacs-lisp-checkdoc))
    (setq flycheck-highlighting-mode 'lines)
    (setq flycheck-check-syntax-automatically '(mode-enabled save))

    (defun check-source-predicate ()
      (and (executable-find "check.pex")
           (buffer-file-name)
           (string-match "src/source/.*\.py$" (buffer-file-name))))

    ;;; errors are reported like this:
    ;;; E241:ERROR   <file name>:<line> <message>
    (flycheck-define-checker source-check
      "A syntax checker for python source code in Source, using `check.pex'"
      :command ("check.pex" source)
      :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 flyspell
  ;; check the spelling
  :ensure t

  :init
  (progn
    (setq ispell-program-name "aspell"
          ispell-list-command "--list")
    (add-hook 'text-mode-hook 'flyspell-mode))

  :config
  (use-package flyspell-popup
    :ensure t
    :bind ("C-:" . flyspell-popup-correct)))

(use-package geiser
  ;; to work with various schemes
  :ensure t

  :config
  (progn
    (setq geiser-default-implementation 'racket
          geiser-racket-binary "~/src/devbox/racket/racket-repl.sh")))

(use-package gist
  ;; interface to gist.github.com
  :ensure t
  :bind ("C-c G" . gist-region-or-buffer))

(use-package go-mode
  ;; support for go
  :mode (("\\.go\\'" . go-mode))

  :ensure t

  :config
   (when (memq window-system '(mac ns x))
    (dolist (var '("GOPATH"))
      (unless (getenv var)
        (exec-path-from-shell-copy-env var))))
   (use-package go-eldoc
     :ensure t
     :config
     (add-hook 'go-mode-hook 'go-eldoc-setup))
   (use-package gotest
     :ensure t)
   (add-hook 'before-save-hook 'gofmt-before-save)
   (add-hook 'go-mode-hook (lambda () (setq-local tab-width 4))))

(use-package hl-line
  ;; highlight current line
  :defer t
  :init
  (progn
    (add-hook 'text-mode-hook 'hl-line-mode)
    (add-hook 'prog-mode-hook 'hl-line-mode)))

(use-package ibuffer
  ;; configuration for ibuffer
  :ensure t
  :defer t
  :bind ("C-x C-b" . ibuffer)
  :init
  (setq ibuffer-show-empty-filter-groups nil
        ibuffer-saved-filter-groups
        (quote (("default"
                 ("dired"  (mode . dired-mode))
                 ("elisp"  (mode . emacs-lisp-mode))
                 ("emacs"  (or (name . "^\\*.*\\*$") (mode . fundamental-mode)))
                 ("go"     (mode . go-mode))
                 ("java"   (mode . java-mode))
                 ("json"   (mode . json-mode))
                 ("lisp"   (mode . lisp-mode))
                 ("magit"  (mode . magit-mode))
                 ("puppet" (mode . puppet-mode))
                 ("python" (mode . python-mode))
                 ("repl"   (name . "repl"))
                 ("ruby"   (mode . ruby-mode))
                 ("sh"     (mode . sh-mode))
                 ("text"   (mode . text-mode))))))

  (add-hook 'ibuffer-mode-hook  ;; organise by filter-groups
            '(lambda ()
               (ibuffer-auto-mode 1)
               (setq mode-name "≣")
               (ibuffer-switch-to-saved-filter-groups "default"))))

(use-package ivy
  ;; completion system
  :diminish (ivy-mode . "")

  :bind ("C-c m" . ivy-switch-project)

  :config
  (ivy-mode 1)
  (setq ivy-use-virtual-buffers t
        ivy-height 10
        ivy-count-format "(%d/%d) "
        ivy-initial-inputs-alist nil
        ivy-use-ignore-default 'always
        ivy-ignore-buffers '("company-statistics-cache.el" "company-statistics-autoload.el")
        ivy-re-builders-alist '((swiper . ivy--regex-ignore-order)
                                (t      . ivy--regex-fuzzy)
                                (t      . ivy--regex-ignore-order)))

  (defun ivy-switch-project ()
    (interactive)
    (ivy-read
     "Switch to project: "
     (if (projectile-project-p)
         (cons (abbreviate-file-name (projectile-project-root))
               (projectile-relevant-known-projects))
       projectile-known-projects)
     :action #'projectile-switch-project-by-name))

  (ivy-set-actions
   'ivy-switch-project
   '(("d" dired "Open Dired in project's directory")
     ("v" counsel-projectile "Open project root in vc-dir or magit")
     ("c" projectile-compile-project "Compile project")
     ("r" projectile-remove-known-project "Remove project(s)"))))

(use-package json-mode
  ;; mode to support json files
  :ensure t

  :mode "\\.json\\'"

  :config
  (setq json-reformat:indent-width 2))

(use-package magit
  ;; interface to git
  :ensure t

  :bind (("C-x g s" . magit-status)
         ("C-x g b" . magit-checkout))

  :init
  (progn
    (setq magit-completing-read-function 'ivy-completing-read))

  :config
  (progn
    (global-git-commit-mode)
    (use-package git-commit :ensure t :defer t)
    (add-hook 'magit-mode-hook
              (lambda()
                (setq mode-name "⎇")))
    (add-hook 'magit-log-edit-mode-hook
              #'(lambda ()
                  (set-fill-column 72)
                  (flyspell-mode)))))

(use-package make-mode
  ;; mode to support Makefile
  :config
  (add-hook 'makefile-mode-hook (lambda ()
                                  (setq-local tab-width 2))))

(use-package markdown-mode
  ;; mode to support files in the Markdown format
  :ensure t

  :commands (markdown-mode gfm-mode)

  :mode (("\\.md\\'"       . gfm-mode)
         ("\\.markdown\\'" . gfm-mode))

  :init (setq markdown-command "pandoc -f markdown_github -c https://goo.gl/OVmlwT --self-contained")

  :config
  (add-hook 'gfm-mode-hook 'visual-line-mode))

(use-package midnight
  ;; clean old buffers at midnight
  :ensure t)

(use-package pants
  ;; interface to pants
  :load-path (lambda () (expand-file-name  "~/src/pants.el/"))

  :config
  (setq pants-completion-system 'ivy
        pants-source-tree-root "/Users/fcuny/src/source"
        pants-bury-compilation-buffer t
        pants-extra-args "-q")

  :bind (("C-c b" . pants-find-build-file)
         ("C-c r" . pants-run-binary)
         ("C-c t" . pants-run-test)))

(use-package phabricator
  ;; interface to phabricator
  :load-path (lambda () (expand-file-name  "~/src/phabricator.el/"))

  :config
  (setq diffusion-repo-prefix-list '(("source" "source"))))

(use-package projectile
  ;; library to interact with projects
  :ensure t

  :diminish ""

  :bind-keymap ("C-c p" . projectile-command-map)

  :init
  (add-hook 'after-init-hook #'projectile-mode)

  :config
  (use-package counsel-projectile :ensure t)
  (setq projectile-switch-project-action 'projectile-dired
        projectile-enable-caching t
        projectile-completion-system 'ivy
        projectile-known-projects-file (expand-file-name "var/projectile-bookmarks.eld" user-emacs-directory)
        projectile-cache-file (expand-file-name "var/projectile.cache" user-emacs-directory))
  (add-to-list 'projectile-globally-ignored-files ".DS_Store"))

(use-package puppet-mode
  ;; mode to support puppet and work with puppet
  :ensure t

  :mode ("\\.pp\\'" . puppet-mode)

  :init (add-hook 'puppet-mode-hook 'flycheck-mode)

  :config
  (when (memq window-system '(mac ns x))
    (dolist (var '("GEM_HOME" "GEM_PATH" "MY_RUBY_HOME"))
      (unless (getenv var)
        (exec-path-from-shell-copy-env var))))
  (setq flycheck-puppet-lint-rc "/Users/fcuny/src/twitter-ops/utilities/puppet/.puppet-lint.rc"))

(use-package python
  ;; configuration for Python
  :mode(("\\.aurora$" . python-mode)
        ("BUILD$"     . python-mode)
        ("\\.py$"     . python-mode))

  :interpreter ("python" . python-mode)

  :init
  (setq-default indent-tabs-mode nil)

  :config
  (setq python-indent-offset 2)
  (add-hook 'python-mode-hook 'eldoc-mode t)
  (add-hook 'python-mode-hook 'color-identifiers-mode))

(use-package recentf
  ;; configuration for recentf, to interact with recent files
  :config
  (setq recentf-save-file (expand-file-name "var/recentf" user-emacs-directory)))

(use-package sh-script
  ;; configuration to interact with shell scripts
  :mode ("bashrc" . sh-mode)

  :config
  (defun set-sh-mode-indent ()
    (setq sh-basic-offset 2
          sh-indentation 2))
  (add-hook 'sh-mode-hook 'set-sh-mode-indent)
  (add-hook 'after-save-hook 'executable-make-buffer-file-executable-if-script-p))

(use-package swiper
  ;; install swiper
  :ensure t)

(use-package term
  ;; configuration to manage multiple terminals inside emacs
  :bind (("C-x t" . fc/open-term)
         ("C-x m" . fc/switch-to-term-buffer))

  :config
  (progn
    (defun fc/make-term (new-buffer-name cmd &rest switches)
      (setq term-ansi-buffer-name (concat "<" new-buffer-name ">"))
      (setq term-ansi-buffer-name (generate-new-buffer-name term-ansi-buffer-name))
      (setq term-ansi-buffer-name (apply 'make-term term-ansi-buffer-name cmd nil switches))
      (set-buffer term-ansi-buffer-name)
      (term-mode)
      (term-char-mode)
      (term-set-escape-char ?\C-x)
      (switch-to-buffer term-ansi-buffer-name))

    (defun fc/open-term (name)
      (interactive "sName: ")
      (fc/make-term name "bash"))

    (defun fc/list-term-buffers ()
      "Returns a list of term buffers"
      (delq nil
            (mapcar (lambda(x)
                      (set-buffer x)
                      (when (string= major-mode "term-mode")
                        (buffer-name)))
                    (buffer-list))))

    (defun fc/switch-to-term-buffer ()
      "Switch to a term buffer."
      (interactive)
      (let ((collection (fc/list-term-buffers)))
        (ivy-read "term buffers:" collection
                  :action (lambda (x) (switch-to-buffer x))
                  :caller 'fc/find-term-buffers)))))

(use-package thrift
  ;; mode to work with thrift files
  :ensure t

  :mode ("\\.thrift\\'" . thrift-mode)

  :config
  (setq thrift-indent-level 2))

(use-package tramp
  ;; configuration for tramp
  :config
  (setq tramp-default-method "ssh"
        tramp-persistency-file-name (expand-file-name "var/tramp" user-emacs-directory)))

(use-package whitespace
  ;; highlight white spaces
  :config
  (setq whitespace-style '(face trailing tabs))
  (add-hook 'prog-mode-hook 'whitespace-mode))

(use-package yaml-mode
  ;; mode to work wity YAML files
  :ensure t

  :init (add-hook 'yaml-mode-hook 'flycheck-mode)

  :mode ("\\.ya?ml\\'" . yaml-mode))

(add-hook 'emacs-startup-hook #'fc/load-time)