summaryrefslogtreecommitdiff
path: root/emacs/init.el
blob: dc9dead9ba71237c70fdf6921ce52f9ea73654bb (plain)
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
(custom-set-variables
 ;; custom-set-variables was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 '(package-selected-packages
   (quote
    (helm-flyspell flycheck which-key helm-swoop evil-leader helm spaceline evil use-package))))
(custom-set-faces
 ;; custom-set-faces was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 )

;; Bootstrap `use-package'
(require 'package)
(add-to-list 'package-archives '("melpa" . "http://melpa.org/packages/"))
(package-initialize)
(unless (package-installed-p 'use-package)
 (package-refresh-contents)
 (package-install 'use-package))

;; packages ---------------------------------------------------------------------------------------

;; evil
(use-package evil-leader
  :ensure t
  :config
  (global-evil-leader-mode)
  )
(use-package evil
  :config
  (evil-mode 1)
  (modify-syntax-entry ?_ "w")
  )

;; flycheck
(use-package flycheck
  :ensure t
  :init (global-flycheck-mode))

;; helm
(use-package helm
  :ensure t
  :config
  (define-key helm-map (kbd "TAB") #'helm-execute-persistent-action)
  (define-key helm-map (kbd "<tab>") #'helm-execute-persistent-action)
  (define-key helm-map (kbd "C-z") #'helm-select-action)
  )
(use-package helm-flyspell
  :ensure t
  :init (flyspell-mode)
  )
(use-package helm-swoop
  :ensure t
  )

;; org
(use-package org
  :ensure t
  )
(use-package org-brain 
  :ensure t
  :init
  (setq org-brain-path "~/brain")
  ;; For Evil users
  (with-eval-after-load 'evil
    (evil-set-initial-state 'org-brain-visualize-mode 'emacs))
  :config
  (setq org-id-track-globally t)
  (setq org-id-locations-file "~/.emacs.d/.org-id-locations")
  (setq org-brain-visualize-default-choices 'all)
  (setq org-brain-title-max-length 12))

;; spaceline
(use-package spaceline :ensure t)
(setq powerline-default-separator 'bar)
(spaceline-emacs-theme)

;; which-key
(use-package which-key
  :ensure t
  :config
  (setq which-key-popup-type 'minibuffer)
  (setq which-key-allow-evil-operators t)
  )
(which-key-mode)

;; theme ------------------------------------------------------------------------------------------

(menu-bar-mode -1)
(tool-bar-mode -1)
(toggle-scroll-bar -1)
;; TODO: color theme

(setq-default left-margin-width 0 right-margin-width 0)

(load-file "~/source/dotfiles/emacs/color-theme-tomorrow.el")
(color-theme-tomorrow-night)
(set-face-attribute 'helm-selection nil 
                    :background "#373b41"
                    :foreground "#c5c8c6")

;;; functions -------------------------------------------------------------------------------------

(defun flyspell-goto-previous-error (arg)
  "Go to arg previous spelling error."
  (interactive "p")
  (while (not (= 0 arg))
    (let ((pos (point))
          (min (point-min)))
      (if (and (eq (current-buffer) flyspell-old-buffer-error)
               (eq pos flyspell-old-pos-error))
          (progn
            (if (= flyspell-old-pos-error min)
                ;; goto beginning of buffer
                (progn
                  (message "Restarting from end of buffer")
                  (goto-char (point-max)))
              (backward-word 1))
            (setq pos (point))))
      ;; seek the next error
      (while (and (> pos min)
                  (let ((ovs (overlays-at pos))
                        (r '()))
                    (while (and (not r) (consp ovs))
                      (if (flyspell-overlay-p (car ovs))
                          (setq r t)
                        (setq ovs (cdr ovs))))
                    (not r)))
        (backward-word 1)
        (setq pos (point)))
      ;; save the current location for next invocation
      (setq arg (1- arg))
      (setq flyspell-old-pos-error pos)
      (setq flyspell-old-buffer-error (current-buffer))
      (goto-char pos)
      (if (= pos min)
          (progn
            (message "No more miss-spelled word!")
            (setq arg 0))))))

(defun check-previous-spelling-error ()
  "Jump to previous spelling error and correct it"
  (interactive)
  (push-mark-no-activate)
  (flyspell-goto-previous-error 1)
  (call-interactively 'helm-flyspell-correct))

(defun check-next-spelling-error ()
  "Jump to next spelling error and correct it"
  (interactive)
  (push-mark-no-activate)
  (flyspell-buffer)
  (flyspell-goto-next-error)
  (call-interactively 'helm-flyspell-correct))

(defun push-mark-no-activate ()
  "Pushes `point' to `mark-ring' and does not activate the region
 Equivalent to \\[set-mark-command] when \\[transient-mark-mode] is disabled"
  (interactive)
  (push-mark (point) t nil)
  (message "Pushed mark to ring"))

;;; hooks -----------------------------------------------------------------------------------------

(add-hook 'text-mode-hook 'flyspell-mode)

;; keybindings ------------------------------------------------------------------------------------

(evil-leader/set-key "b" 'org-brain-visualize)
(evil-leader/set-key "f" 'helm-find-files)
(evil-leader/set-key "j" 'dired-jump)
(evil-leader/set-key "k" 'kill-buffer)
(evil-leader/set-key "m" 'helm-mini)
(evil-leader/set-key "q" 'save-buffers-kill-terminal)
(evil-leader/set-key "s" 'check-next-spelling-error)
(evil-leader/set-key "t" 'color-theme-tomorrow-night)
(evil-leader/set-key "T" 'color-theme-tomorrow)
(evil-leader/set-key "x" 'helm-M-x)
(evil-leader/set-key "," 'other-window)