summaryrefslogtreecommitdiff
path: root/init.el
blob: 269f05319461e32c96594191a3fcc9ac61e40605 (about) (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
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
;; Turn off mouse interface early in startup to avoid momentary display
(if (fboundp 'menu-bar-mode) (menu-bar-mode -1))
(if (fboundp 'tool-bar-mode) (tool-bar-mode -1))
(if (fboundp 'scroll-bar-mode) (scroll-bar-mode -1))

;; No splash screen please ...
(setq inhibit-startup-message t)

;; display tool tips in echo area only
(tooltip-mode -1)
(setq tooltip-use-echo-area t)

;; disable mouse scrolling
(mouse-wheel-mode -1)

(add-to-list 'load-path user-emacs-directory)
(add-to-list 'load-path "/usr/share/emacs/site-lisp/")

(require 'cask "~/.cask/cask.el")
(cask-initialize)

(require 'better-defaults)

;; Keep emacs Custom-settings in separate file
(setq custom-file (expand-file-name "custom.el" user-emacs-directory))
(load custom-file)

(require 'package)
(add-to-list 'package-archives
    '("melpa"     . "http://melpa.milkbox.net/packages/")
    '("marmalade" . "http://marmalade-repo.org/packages/"))
(package-initialize)

; sublime-themes must be installed
(load-theme 'spolsky t)
(set-cursor-color "White")
(setq evil-default-cursor '("white" box))
(set-background-color "#181818")


; smart mode line
(setq sml/theme 'respectful)
(sml/setup)

(require 'visual-regexp-steroids)
(define-key global-map (kbd "C-c r") 'vr/replace)
(define-key global-map (kbd "C-c q") 'vr/query-replace)

;; use visual-regexp-steroids's isearch instead of the built-in regexp
;; isearch
(define-key esc-map (kbd "C-r") 'vr/isearch-backward) ;; C-M-r
(define-key esc-map (kbd "C-s") 'vr/isearch-forward) ;; C-M-s



; C-d on an empty line in the shell terminates the process.
(defun comint-delchar-or-eof-or-kill-buffer (arg)
  (interactive "p")
  (if (null (get-buffer-process (current-buffer)))
      (kill-buffer)
    (comint-delchar-or-maybe-eof arg)))

(add-hook 'shell-mode-hook
          (lambda ()
            (define-key shell-mode-map
              (kbd "C-d") 'comint-delchar-or-eof-or-kill-buffer)))
;; TODO: this isn't working
(add-hook 'term-mode-hook
          (lambda ()
            (define-key term-mode-map
              (kbd "C-d") 'comint-delchar-or-eof-or-kill-buffer)))

(add-hook 'haskell-mode-hook
          (lambda ()
            (turn-on-haskell-indentation)
            (turn-on-haskell-doc)))

;; jump to first or last file in dired, not to the very top or bottom
(require 'dired)
(defun dired-back-to-top ()
  (interactive)
  (beginning-of-buffer)
  (dired-next-line 4))

(define-key dired-mode-map
  (vector 'remap 'beginning-of-buffer) 'dired-back-to-top)

(defun dired-jump-to-bottom ()
  (interactive)
  (end-of-buffer)
  (dired-next-line -1))

(define-key dired-mode-map
  (vector 'remap 'end-of-buffer) 'dired-jump-to-bottom)
(define-key dired-mode-map
  (kbd "<return>") 'dired-find-alternate-file) ; was dired-advertised-find-file
(define-key dired-mode-map
  (kbd "^") (lambda () (interactive) (find-alternate-file "..")))  ; was dired-up-directory


(require 'tramp)
(setq tramp-default-method "ssh")

;; for root connections to remote hosts, log in via ssh with normal
;; user account first, then su/sudo to root
(add-to-list 'tramp-default-proxies-alist
             '(".*" "\\`root\\'" "/ssh:%h:"))

;; Backup (file~) disabled and auto-save (#file#) locally to prevent delays in editing remote files
(add-to-list 'backup-directory-alist
             (cons tramp-file-name-regexp nil))
(setq tramp-auto-save-directory temporary-file-directory)
(setq tramp-verbose 3)

;; Write backup files to own directory
;; TODO: conflicts with previous manipulation of backup-directory-alist
(setq backup-directory-alist
      `(("." . ,(expand-file-name
                 (concat user-emacs-directory "backups")))))

;; Make backups of files, even when they're in version control
(setq vc-make-backup-files t)

(autoload 'markdown-mode "markdown-mode"
   "Major mode for editing Markdown files" t)
(autoload 'js2-mode "js2-mode" nil t)
(add-to-list 'auto-mode-alist '("\\.markdown\\'" . markdown-mode))
(add-to-list 'auto-mode-alist '("\\.md\\'" . markdown-mode))
(add-to-list 'auto-mode-alist '("\\.js$" . js2-mode))

;; full screen magit-status
(require 'magit)
(defadvice magit-status (around magit-fullscreen activate)
  (window-configuration-to-register :magit-fullscreen)
  ad-do-it
  (delete-other-windows))

(defun magit-quit-session ()
  "Restores the previous window configuration and kills the magit buffer"
  (interactive)
  (kill-buffer)
  (jump-to-register :magit-fullscreen))

(defun magit-toggle-whitespace ()
  "Toggles git option -w"
  (interactive)
  (if (member "-w" magit-diff-options)
      (magit-dont-ignore-whitespace)
    (magit-ignore-whitespace)))

(defun magit-ignore-whitespace ()
  "Adds git option -w"
  (interactive)
  (add-to-list 'magit-diff-options "-w")
  (magit-refresh))

(defun magit-dont-ignore-whitespace ()
  "Removes git option -w"
  (interactive)
  (setq magit-diff-options (remove "-w" magit-diff-options))
  (magit-refresh))

(define-key magit-status-mode-map (kbd "q") 'magit-quit-session)
(define-key magit-status-mode-map (kbd "W") 'magit-toggle-whitespace)


;; ido mode
(require 'ido)
(ido-mode 1)
;; hit ~ to go straight to the home directory in ido mode
(add-hook 'ido-setup-hook
 (lambda ()
   ;; Go straight home
   (define-key ido-file-completion-map
     (kbd "~")
     (lambda ()
       (interactive)
       (if (looking-back "/")
           (insert "~/")
         (call-interactively 'self-insert-command))))))

;; Use ido everywhere
(require 'ido-ubiquitous)
(ido-ubiquitous-mode 1)
;; use ido for yes/no questions
(ido-yes-or-no-mode 1)

;; fullscreen mode with F11
(fullscreen-mode 1)
(global-set-key (kbd "<f11>") 'fullscreen-mode-fullscreen-toggle)

(setq scss-compile-at-save nil)


(global-whitespace-mode 1)
(set-face-attribute 'whitespace-space nil :background nil :foreground "gray20")
(set-face-attribute 'whitespace-newline nil :background nil :foreground "gray20")
(setq whitespace-style
       '(face spaces tabs newline space-mark tab-mark newline-mark))
(setq whitespace-display-mappings
      ;; all numbers are Unicode codepoint in decimal. try
      ;; (insert-char 182 ) to see it
      '(
        (space-mark 32 [183] [46]) ; 32 SPACE, 183 MIDDLE DOT 「·」,
                                   ; 46 FULL STOP 「.」
        (newline-mark 10 [182 10]) ; 10 LINE FEED
        (tab-mark 9 [9655 9] [92 9]) ; 9 TAB, 9655 WHITE
                                     ; RIGHT-POINTING TRIANGLE 「▷」
        ))

(desktop-save-mode t)

;; use cat as the pager in shell mode, because shell-mode is not an ANSI terminal
(setenv "PAGER" "cat")

;; ediff settings
(setq ediff-diff-options "-w")

;; TODO: what does this do?
(put 'dired-find-alternate-file 'disabled nil)

;; cause Emacs to fully redraw the display *before* it processes queued input events.
(setq redisplay-dont-pause t)

;; fewer backslashes in regexp builder
(require 're-builder)
(setq reb-re-syntax 'string)

;; remove prompt on killing process buffer
(setq kill-buffer-query-functions
  (remq 'process-kill-buffer-query-function
         kill-buffer-query-functions))

;; enable narrow-to-region feature
(put 'narrow-to-region 'disabled nil)


;; http://blog.vivekhaldar.com/post/4809065853/dotemacs-extract-interactively-change-font-size
(defun zoom-in ()
  "Increase font size by 10 points"
  (interactive)
  (set-face-attribute 'default nil
                      :height
                      (+ (face-attribute 'default :height)
                         10)))

(defun zoom-out ()
  "Decrease font size by 10 points"
  (interactive)
  (set-face-attribute 'default nil
                      :height
                      (- (face-attribute 'default :height)
                         10)))

;; change font size, interactively
(global-set-key (kbd "C-.") 'zoom-in)
(global-set-key (kbd "C-,") 'zoom-out)

;; easier way to jump to other window
(global-set-key (kbd "M-o") 'other-window)

(require 'smex)
(smex-initialize)
(global-set-key (kbd "M-x") 'smex)
(global-set-key (kbd "M-X") 'smex-major-mode-commands)
(global-set-key (kbd "<menu>") 'smex)
(global-set-key (kbd "S-<menu>") 'smex-major-mode-commands)

;; expand region
(global-set-key (kbd "M-@") 'er/expand-region)

;; Swap C-t and C-x, so it's easier to type on Dvorak layout
(keyboard-translate ?\C-t ?\C-x)
(keyboard-translate ?\C-x ?\C-t)

;; kill current buffer
(global-set-key (kbd "C-x C-k") (lambda ()
                                  (interactive)
                                  (kill-buffer (current-buffer))))

(require 'shell-switcher)
(setq shell-switcher-mode t)
(add-hook 'eshell-mode-hook 'shell-switcher-manually-register-shell)

(load "email.el")
(require 'rekado-mode)
(rekado-mode 1)