summaryrefslogtreecommitdiff
path: root/init.el
blob: 4436a6eefac9026205db8eeac6253a7a704dfbc8 (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
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
;; 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)
(require 'paren-face)
(paren-face-mode 1)

;; 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 my/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") 'my/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") 'my/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)
(require 'dired+)
(defun my/dired-back-to-top ()
  (interactive)
  (beginning-of-buffer)
  (dired-next-line 4))

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

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

(define-key dired-mode-map
  (vector 'remap 'end-of-buffer) 'my/dired-jump-to-bottom)
(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
             '(nil "\\`root\\'" "/ssh:%h:"))
(add-to-list 'tramp-default-proxies-alist
             '((regexp-quote (system-name)) nil nil))

;; respect the PATH variable on the remote machine
(add-to-list 'tramp-remote-path 'tramp-own-remote-path)

;; 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 my/magit-quit-session ()
  "Restores the previous window configuration and kills the magit buffer"
  (interactive)
  (kill-buffer)
  (jump-to-register :magit-fullscreen))

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

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

(defun my/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") 'my/magit-quit-session)
(define-key magit-status-mode-map (kbd "W") 'my/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)


(setq whitespace-global-modes '(not erc-mode))
(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)

;; keep the cursor centered to avoid sudden scroll jumps
(centered-cursor-mode 1)

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

(defun my/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-.") 'my/zoom-in)
(global-set-key (kbd "C-,") 'my/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))))

;; delete up to non-whitespace character
(global-set-key (kbd "C-c C-d") 'hungry-delete-forward)

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

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

;; author: KaiGrossjohann on EmacsWiki
(defun eshell/ff (&rest args)
  "Invoke `find-file' on the file.
    \"ff +42 foo\" also goes to line 42 in the buffer."
  (while args
    (if (string-match "\\`\\+\\([0-9]+\\)\\'" (car args))
        (let* ((line (string-to-number (match-string 1 (pop args))))
               (file (pop args)))
          (find-file file)
          (goto-line line))
      (find-file (pop args)))))


;; convenience functions to input the remote root/home dir when in a
;; directory on a remote host
(defun my/tramp-root ()
   "Print root directory on the remote host."
   (interactive)
   (let ((pieces (split-string (eshell/pwd) ":/")))
     (insert-string (if (> (length pieces) 1)
                        (concat (car pieces) ":/")
                      "/"))))

(defun my/tramp-home ()
   "Print home directory path on the remote host."
   (interactive)
   (let ((pieces (split-string (eshell/pwd) ":/")))
     (insert-string (if (> (length pieces) 1)
                        (concat (car pieces) ":~/")
                      "~/"))))

(add-hook 'eshell-mode-hook
          '(lambda () (define-key eshell-mode-map (kbd "C-c /") 'my/tramp-root)))
(add-hook 'eshell-mode-hook
          '(lambda () (define-key eshell-mode-map (kbd "C-c ~") 'my/tramp-home)))



;; start a hidden eshell on startup
(add-hook 'emacs-startup-hook #'(lambda ()
                                  (let ((default-directory (getenv "HOME")))
                                    (command-execute 'eshell)
                                    (bury-buffer))))

;; start in fullscreen mode
(add-hook 'emacs-startup-hook (lambda () (fullscreen-mode-fullscreen)))

(page-break-lines-mode 1)
(global-set-key (kbd "<C-prior>") 'backward-page)
(global-set-key (kbd "<C-next>") 'forward-page)


;; http://whattheemacsd.com/key-bindings.el-01.html#disqus_thread
(require 'linum)
(global-set-key [remap goto-line] 'my/goto-line-with-feedback)
(defun my/goto-line-with-feedback ()
  "Show line numbers temporarily, while prompting for the line number input"
  (interactive)
  (let ((line-numbers-off-p (not linum-mode)))
    (unwind-protect
        (progn
          (when line-numbers-off-p
            (linum-mode 1))
          (call-interactively 'goto-line))
      (when line-numbers-off-p
        (linum-mode -1)))))


(require 'rect-mark)
(global-set-key (kbd "C-x r C-SPC") 'rm-set-mark)
(global-set-key (kbd "C-w")
                '(lambda (b e)
                   (interactive "r")
                   (if rm-mark-active
                       (rm-kill-region b e)
                     (kill-region b e))))
(global-set-key (kbd "M-w")
                '(lambda (b e)
                   (interactive "r")
                   (if rm-mark-active
                       (rm-kill-ring-save b e)
                     (kill-ring-save b e))))
(global-set-key (kbd "C-x C-x")
                '(lambda (&optional p)
                   (interactive "p")
                   (if rm-mark-active
                       (rm-exchange-point-and-mark p)
                     (exchange-point-and-mark p))))

;; show time and date in modeline
(display-time-mode 1)
(setq display-time-day-and-date t)