root/init.el

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
(setq tab-width 4)
(setq indent-tabs-mode nil)
(setq custom-buffer-indent 4)
(setq c-basic-offset 4)
(setq-default tab-width 4)
(setq sgml-basic-offset 4)
(setq js-indent-level 4)
(setq inhibit-startup-screen t)
(setq default-cursor-type '(bar . 1))
(column-number-mode)
;;(setq blink-cursor-interval 0.)
(require 'iso-transl)

;; remove whitespace before save. This is going to fuckup something I know it.
(add-hook 'before-save-hook
          (lambda () (when (not indent-tabs-mode)
                       (progn
                         (untabify (point-min) (point-max))
                         (whitespace-cleanup)))))

;; go full utf-8 everywhere!
(add-hook 'before-save-hook
          (lambda () (set-buffer-file-coding-system 'utf-8-unix)))
(setq utf-translate-cjk-mode nil) ; disable CJK coding/encoding (Chinese/Japanese/Korean characters)
(set-language-environment 'utf-8)
(set-keyboard-coding-system 'utf-8-mac) ; For old Carbon emacs on OS X only
(setq locale-coding-system 'utf-8)
(set-default-coding-systems 'utf-8)
(set-terminal-coding-system 'utf-8)
(unless (eq system-type 'windows-nt) ;; this would break the windows clipboard
  (set-selection-coding-system 'utf-8))
(prefer-coding-system 'utf-8)

(menu-bar-mode -1)
(tool-bar-mode -1)

;; me lisp now
(let ((last-state (frame-parameter nil 'fullscreen)))
  (defun toggle-fullscreen ()
    (interactive)
    (when (eq window-system 'x)
      (set-frame-parameter
       nil
       'fullscreen
       (let ((state (frame-parameter nil 'fullscreen)))
         (if (not (string= state 'fullboth))
             (progn (set 'last-state state) 'fullboth)
           last-state))))))

;; TODO use the give lambda, no idea why it is void
(defun in-each-file-in-directory (cb)
  (mapcar (lambda (file)
            (when (and (not (string= ".." file))
                       (not (string= "." file))
                       (not (file-directory-p file)))
              (progn
                (find-file file)
                (ignore-errors
                  (call-last-kbd-macro))
                1)))
          (directory-files ".")))

;; TODO see fn above
(defun in-each-file-in-directory-call-last-macro ()
  (interactive)
  (in-each-file-in-directory '(lambda () (interactive) (call-last-kbd-macro))))

;; might rename
(defun close-all-buffers-but-this ()
   (interactive)
   (let ((tobe-killed (cdr (buffer-list (current-buffer)))))
     (while tobe-killed
       (kill-buffer (car tobe-killed))
       (setq tobe-killed (cdr tobe-killed)))))

;; special chars for mac keyboards
(if (eq system-type 'darwin)
    (if (eq window-system 'mac)
        (progn
          (setq mac-keyboard-text-encoding kTextEncodingISOLatin1)
          ;; Workaround for not having Latin-9 Fonts
          (latin1-display 'latin-9))
      (if (eq window-system 'nil)
          (progn
            ;; "fix" the broken keyboard
            (global-set-key "\M-l" '(lambda () (interactive) (insert "@")))
            (global-set-key "\M-5" '(lambda () (interactive) (insert "[")))
            (global-set-key "\M-6" '(lambda () (interactive) (insert "]")))
            (global-set-key "\M-7" '(lambda () (interactive) (insert "|")))
            (global-set-key "\M-/" '(lambda () (interactive) (insert "\\")))
            (global-set-key "\M-8" '(lambda () (interactive) (insert "{")))
            (global-set-key "\M-9" '(lambda () (interactive) (insert "}")))
            (global-set-key "\M-n" '(lambda () (interactive) (insert "~")))))))


(global-set-key [f11] 'toggle-fullscreen)

(setq show-paren-delay 0.04)         ; how long to wait?
(show-paren-mode t)                  ; turn paren-mode on
(setq show-paren-style 'parenthesis) ; alternatives are 'parenthesis' and 'mixed'

(setq backup-directory-alist `(("." . "~/.emacs.d/tmpsaves")))

(add-hook 'html-mode-hook
          (lambda ()
            (sgml-electric-tag-pair-mode)))

(defun open-line-above ()
  "Insert a newline above the current line and put point at beginning."
  (interactive)
  (unless (bolp)
    (beginning-of-line))
  (newline)
  (forward-line -1)
  (indent-according-to-mode))

(defun open-line-below ()
  "Insert a newline below the current line and put point at beginning."
  (interactive)
  (unless (eolp)
    (end-of-line))
  (newline-and-indent))

(global-set-key (kbd "C-S-O") 'open-line-below)
(global-set-key (kbd "C-o") 'open-line-above)


;; includes
;;(add-to-list 'load-path "~/.emacs.d")

(defun enable-tab-on-enter ()
  (local-set-key (kbd "RET") (key-binding (kbd "M-j")))
  (local-set-key (kbd "<S-return>") 'newline))
(enable-tab-on-enter)


(add-to-list 'custom-theme-load-path "~/.emacs.d/themes/")

(load-file "~/.emacs.d/nemu.el")
(require 'nemu)

(add-to-list 'load-path "~/.emacs.d/popup-el")
(add-to-list 'load-path "~/.emacs.d/auto-complete")
(require 'auto-complete-config)
(add-to-list 'ac-dictionary-directories "~/.emacs.d/auto-complete/dict")
(ac-config-default)

(add-to-list 'load-path "~/.emacs.d/multiple-cursors.el")
(require 'multiple-cursors)

(add-to-list 'load-path "~/.emacs.d/js2-mode")
(require 'js2-mode)
;; disabled, since it's validation is pretty slow
;; (add-to-list 'auto-mode-alist '("\\.js$" . js2-mode))

(if window-system
    (load-theme 'zenburn t)
    ;; (progn
    ;;   (add-to-list 'load-path "~/.emacs.d/oblivion-emacs")
    ;;   (require 'color-theme-oblivion)
    ;;   (color-theme-oblivion))
  )

(load-file "~/.emacs.d/linum.el")
(linum-mode)
(global-linum-mode)

(load-file "~/.emacs.d/column-marker.el")
(add-hook 'text-mode-hook (lambda() (column-marker-1 80)))

(add-to-list 'load-path "~/.emacs.d/twittering-mode")
(require 'twittering-mode)
(setq twittering-use-master-password t)

(progn
 (autoload 'enable-paredit-mode "~/.emacs.d/paredit.el"
   "Turn on pseudo-structural editing of Lisp code."
   t)
 (add-hook 'emacs-lisp-mode-hook       #'enable-paredit-mode)
 (add-hook 'eval-expression-minibuffer-setup-hook #'enable-paredit-mode)
 (add-hook 'ielm-mode-hook             #'enable-paredit-mode)
 (add-hook 'lisp-mode-hook             #'enable-paredit-mode)
 (add-hook 'lisp-interaction-mode-hook #'enable-paredit-mode)
 (add-hook 'scheme-mode-hook           #'enable-paredit-mode))

(add-to-list 'load-path "~/.emacs.d/expand-region.el")
(require 'expand-region)
(global-set-key (kbd "C-j") 'er/expand-region)

(load-file "~/.emacs.d/rust-mode.el")
(require 'rust-mode)
(load-file "~/.emacs.d/eval-and-replace.el")
(load-file "~/.emacs.d/pretty-xml.el")

;; invoke make if that directory is freshly cloned
(if (not (file-exists-p "~/.emacs.d/haskell-mode/haskell-mode-autoloads.el"))
    (progn
      (cd "~/.emacs.d/haskell-mode/")
      (call-process-shell-command "make haskell-mode-autoloads.el")))

(add-to-list 'load-path "~/.emacs.d/haskell-mode/")
(require 'haskell-mode-autoloads)
(add-to-list 'Info-default-directory-list "~/.emacs.d/haskell-mode/")
(add-hook 'haskell-mode-hook 'turn-on-haskell-doc-mode)

(load-file "~/.emacs.d/auto-complete-haskell.el")
(require 'auto-complete-haskell)
(add-hook 'haskell-mode-hook
          '(lambda () (auto-complete-mode 1)
             (setq ac-sources (cons my/ac-source-haskell ac-sources))
             nil))

;;(add-hook 'haskell-mode-hook 'turn-on-haskell-indentation)
(add-hook 'haskell-mode-hook 'turn-on-haskell-indent)
;;(add-hook 'haskell-mode-hook 'turn-on-haskell-simple-indent)

(load-file "~/.emacs.d/geiser/elisp/geiser.el")

(add-to-list 'load-path "~/.emacs.d/slime")
(require 'slime-autoloads)
(setq inferior-lisp-program "/usr/bin/env sbcl")
(setq slime-contribs '(slime-fancy))

(add-to-list 'load-path "~/.emacs.d/dash.el/")
(require 'dash)
(add-to-list 'load-path "~/.emacs.d/projectile/")
(require 'projectile)
(projectile-global-mode)

(add-to-list 'load-path "~/.emacs.d/git-modes")
(add-to-list 'load-path "~/.emacs.d/magit")
(eval-after-load 'info
  '(progn (info-initialize)
          (add-to-list 'Info-directory-list "~/.emacs.d/magit/")))
(require 'magit)

(add-to-list 'auto-mode-alist '("\\.cs\\'" . java-mode))
(add-to-list 'auto-mode-alist '("\\.alist\\'" . scheme-mode))

;; (add-to-list 'load-path "~/.emacs.d/emms/lisp")
;; (require 'emms-setup)
;; (require 'emms-browser)
;; (emms-standard)
;; (emms-default-players)
;; (setq emms-browser-default-covers
;;        (list "/path/to/cover_small.jpg" nil nil))

(load "~/.emacs.d/let-alist-1.0.4.el")
(add-to-list 'load-path "~/.emacs.d/seq.el")
(add-to-list 'load-path "~/.emacs.d/flycheck")
(require 'flycheck)
;;; npm install --global eslint
;;; ln -s /usr/bin/nodejs /usr/local/bin/node
(add-hook 'after-init-hook #'global-flycheck-mode)

(load-file "~/.emacs.d/aggressive-indent.el")
(require 'aggressive-indent)
(global-aggressive-indent-mode 1)
(add-to-list 'aggressive-indent-excluded-modes 'haskell-mode)
(add-to-list 'aggressive-indent-excluded-modes 'python-mode)

(load-file "~/.emacs.d/graphviz-dot-mode.el")
(require 'graphviz-dot-mode)


(setq custom-file "~/.emacs.d/custom.el")
(load custom-file)

;; (setq emms-player-started-hook
;;       (lambda ()
;;         (call-process-shell-command
;;          (format "notify-send '%s'"
;;                  (cdr (assoc 'name (emms-playlist-current-selected-track)))))))

;; (defadvice emms-browser-next-mapping-type
;;   (after no-album (current-mapping))
;;   (when (eq ad-return-value 'info-album)
;;     (setq ad-return-value 'info-title)))

;; (defvar emms-browser-info-title-format "%i%A - %T. %t")
;; (defvar emms-browser-playlist-info-title-format
;;   emms-browser-info-title-format)

;; (require 'emms-info-libtag)
;; (setq emms-info-functions '(emms-info-libtag))



(let ((enable-tab-lambda (lambda ()
                           (setq indent-tabs-mode t))))
  (add-hook 'python-mode-hook enable-tab-lambda)
  (add-hook 'diff-mode-hook enable-tab-lambda)
  (add-hook 'godot-mode-hook enable-tab-lambda))

(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.
 '(inhibit-startup-screen t))
(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.
 )

(defun insert-lambda-sign ()
  (interactive)
  (insert-string "λ"))

(defun replace-stuff (stuff str)
  (if stuff
      (let ((pair (car stuff))
            (rest (cdr stuff)))

        (replace-stuff rest (replace-regexp-in-string (car pair) (cdr pair) str)))
    str))

(defun ddate-string ()
  (replace-stuff
    '(("Chaos"         . "1")
      ("Discord"       . "2")
      ("Bureaucracy"   . "3")
      ("The Aftermath" . "4")
      ("\n"            . ""))
    (shell-command-to-string "ddate +%Y-%B-%d")))

(defun  insert-ddate () ;;⬠
  (interactive)         ;;⬠
  (insert-string
   (let ((str (ddate-string)))
     (if (string= str "")               ;St. Tib’s D
         (replace-stuff '(("\n" . ""))
                        (concat (shell-command-to-string "ddate +%Y")
                                "-?-?"))
       str)))) ;; 🍐

(defun rename-buffer-and-move-file (new-path)
  (interactive (list (read-file-name "Move/Save Buffer at:")))
  (let ((old-path (buffer-file-name)))
    (if (and (not (string= old-path new-path))
             (null (write-file new-path)))
        (progn (delete-file old-path)
               (save-buffer)            ; just to be sure
               )
      nil))
  (message new-path))

;; hotkeys
(global-set-key (kbd "M-\"") 'insert-pair)
(global-set-key (kbd "C-c o") 'ff-find-other-file)
(global-set-key (kbd "C-x C-M-e") 'eval-and-replace)
(global-set-key (kbd "C-c C-r") 'mc/mark-sgml-tag-pair) ; todo hook to mode
(global-set-key (kbd "C-c C-l") 'insert-lambda-sign)
(global-set-key (kbd "C-x C-M-F") 'insert-ddate)
(global-set-key (kbd "C-x M-w") 'rename-buffer-and-move-file)
(global-set-key (kbd "<f7>") 'recompile)
(put 'narrow-to-region 'disabled nil)
(put 'set-goal-column 'disabled nil)
(put 'downcase-region 'disabled nil)