-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmyemacs.el
385 lines (313 loc) · 11.1 KB
/
myemacs.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
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
(setenv "TERM" "dumb")
;; No noise from emacs
(setq ring-bell-function 'ignore)
;; Use java mode for Gosu files
(add-to-list 'auto-mode-alist '("\\.gs$" . java-mode))
(setq myemacs-dir (file-name-directory load-file-name))
(add-to-list 'custom-theme-load-path myemacs-dir)
(load-theme 'zenburn t)
(load "meta-bindings/meta-bindings")
;; Browsing search history doesn't move to minibuffer to edit search string
(setq search-ring-update t)
;; Initialize "Plan 9 smart shell" as described
;; [here](http://www.masteringemacs.org/article/complete-guide-mastering-eshell)
(require 'eshell)
(require 'em-smart)
(setq eshell-where-to-jump 'begin)
(setq eshell-review-quick-commands nil)
(setq eshell-smart-space-goes-to-end t)
(add-hook 'eshell-mode-hook 'eshell-smart-initialize)
;; No menus as [Steve Yegge advices](https://sites.google.com/site/steveyegge2/effective-emacs)
(if (fboundp 'scroll-bar-mode) (scroll-bar-mode -1))
(if (fboundp 'tool-bar-mode) (tool-bar-mode -1))
(if (fboundp 'menu-bar-mode) (menu-bar-mode -1))
;; Russian input method for dvorak layout
;; Got from [here](http://www.emacswiki.org/emacs/WritingRussianWithDvorak)
(load "cyrillic-dvorak")
(setq default-input-method "cyrillic-dvorak")
;; From [here](http://stackoverflow.com/a/27908343/1060693)
(defun eshell/clear ()
"Clear terminal"
(interactive)
(let ((inhibit-read-only t))
(erase-buffer)
(eshell-send-input)))
;; [groovy-emacs-mode](http://groovy.codehaus.org/Emacs+Groovy+Mode).
(add-to-list 'auto-mode-alist '("\\.gradle$" . groovy-mode))
(add-to-list 'auto-mode-alist '("\\.groovy$" . groovy-mode))
;; http://ergoemacs.org/emacs/emacs_package_system.html
(require 'package)
(add-to-list 'package-archives
'("melpa-stable" . "https://stable.melpa.org/packages/") t)
(package-initialize)
(unless package-archive-contents
(package-refresh-contents))
;; Promised to be faster than the default `scp`
;; as said [here](http://www.emacswiki.org/emacs/TrampMode)
(setq tramp-default-method "ssh")
;; http://thinkinghard.com/software/rules-editing-mode/index.html
(load "drools-mode")
(add-to-list 'auto-mode-alist '("\\.drl$" . drools-mode))
;; Make auto-revert mode quiet
(setq auto-revert-verbose nil)
(load "column-marker")
(add-hook 'prog-mode-hook
(lambda ()
(interactive)
(column-marker-1 80)
(column-marker-3 120)))
(setq-default indent-tabs-mode nil)
(setq-default tab-width 4)
(setq-default nxml-child-indent 4)
(setq-default nxml-attribute-indent 8)
(setq column-number-mode t)
(add-to-list 'auto-mode-alist '("\\.json$" . json-mode))
(setq c-basic-offset 4)
(add-hook 'haskell-mode-hook
(lambda()
(haskell-indentation-mode)))
(setq dabbrev-case-replace case-replace)
(setq dabbrev-case-distinction nil)
;; Set it to nil to halt display redraw if any input event is detected.
;; This is an "old" performance optimization irrelevant
;; this days as described
;; [here](https://www.masteringemacs.org/article/improving-performance-emacs-display-engine),
;; but I still want to use it.
(setq redisplay-dont-pause nil)
;; Indent long arguments properly
;; http://stackoverflow.com/a/6952408/1060693
(c-set-offset 'arglist-intro '+)
;; Copied from [github](https://github.com/atomontage/xterm-color)
;; from commit 1bc4ddb0e1bf7562cbf4b6b3bdd2ce3f9b596b39
(load "xterm-color")
;; Setup somewhat zenburn colors for xterm-colors
(setq xterm-color-names
["#192033" ; black
"#E89393" ; red
"#9ECE9E" ; green
"#F0DFAF" ; yellow
"#8CD0D3" ; blue
"#C0BED1" ; magenta
"#DFAF8F" ; cyan
"#EFEFEF"] ; white
)
(setq xterm-color-names-bright
["#192033" ; black
"#E89393" ; red
"#9ECE9E" ; green
"#F0DFAF" ; yellow
"#8CD0D3" ; blue
"#C0BED1" ; magenta
"#DFAF8F" ; cyan
"#EFEFEF"] ; white
)
;; comint install
(progn (add-hook 'comint-preoutput-filter-functions 'xterm-color-filter)
(setq comint-output-filter-functions (remove 'ansi-color-process-output comint-output-filter-functions))
(setq font-lock-unfontify-region-function 'xterm-color-unfontify-region))
;; You can also use it with eshell (and thus get color output from system ls):
(add-hook 'eshell-mode-hook
(lambda ()
(setq xterm-color-preserve-properties t)))
(add-to-list 'eshell-preoutput-filter-functions 'xterm-color-filter)
(setq eshell-output-filter-functions (remove 'eshell-handle-ansi-color eshell-output-filter-functions))
;; A workaround as emacs sets to "dumb" in `normal-top-level` function
(add-hook 'eshell-mode-hook (lambda() (setenv "TERM" "xterm-256color")))
(package-install 'yasnippet)
(require 'yasnippet)
(add-hook 'prog-mode-hook 'yas-minor-mode)
(setq yas-snippet-dirs
(list
(concat
(file-name-directory load-file-name)
"snippets")
yas-installed-snippets-dir))
(yas-reload-all)
(add-hook 'eshell-mode-hook
(lambda ()
(add-to-list
'eshell-command-aliases-list
'("gradle" "TERM=dumb gradle $*"))
(add-to-list
'eshell-command-aliases-list
'("./gradlew" "TERM=dumb ./gradlew $*"))))
(defun set-window-width (n)
"Set the selected window's width."
(window-resize (selected-window) (- n (window-width)) t))
(defun set-80-columns ()
"Set the selected window to 80 columns."
(interactive)
(set-window-width 80))
(add-to-list 'yank-excluded-properties 'xterm-color)
(add-to-list 'yank-excluded-properties 'face)
(defun main-frame-27-inch()
(interactive)
(set-frame-font "Monospace 14"))
(defun second-frame-27-inch ()
(interactive)
(let ((f (make-frame)))
(set-frame-font "Monospace 14" nil (list f))
f))
(defun second-frame-24-inch ()
(interactive)
(let ((f (make-frame)))
(set-frame-font "Monospace 12" nil (list f))))
(defun main-frame-mbp15()
(interactive)
(set-face-attribute 'default (selected-frame) :height 150))
(defun second-frame-mbp15 ()
(interactive)
(let ((f (make-frame)))
(set-face-attribute 'default f :height 150)))
(defun clear-colors ()
(interactive)
(remove-text-properties (region-beginning) (region-end) '(xterm-color nil face nil)))
(defun quote-line-break ()
"Function to split pasted text into lines with quotation on tokens found"
(interactive)
(let* (
(linestart (eq (point) (line-beginning-position)))
(emptyline (and linestart (eq (point) (line-end-position)))))
(if emptyline
(progn
(insert "> ")
(next-line)
(beginning-of-line)
(quote-line-break))
(unless linestart
(unless (eq (char-before) (string-to-char " "))
(backward-word))
(newline))
(insert "> "))))
(defun add-tags (dir)
(add-to-list 'tags-table-list dir))
(defun new-eshell (name dir)
(let (d default-directory)
(cd dir)
(eshell)
(rename-buffer name)
(unless (not d) (cd d))))
(package-install 'markdown-mode)
(require 'markdown-mode)
(add-to-list 'auto-mode-alist '("\\.md\\'" . markdown-mode))
(define-key markdown-mode-map "\t" 'indent-relative)
(define-key markdown-mode-map "\M-\r" 'markdown-insert-list-item)
;; Making `comment-style` buffer local by supplying `t`
;; to the `LOCAL` argument of `add-hook` doesn`t work.
;; The hook isn't executed then.
(add-hook 'markdown-mode-hook
(lambda()
(setq comment-start ">")
(setq comment-end ">")
(setq comment-continue ">")
(make-local-variable 'comment-style)
(setq comment-style 'extra-line)))
(add-hook 'markdown-mode-hook
(lambda()
(visual-line-mode)))
(package-install 'dockerfile-mode)
(put 'upcase-region 'disabled nil)
(put 'erase-buffer 'disabled nil)
;; The LANG variable is necessary to let hunspell know
;; a dictionary to use as default.
(setenv "LANG" "en_US.UTF-8")
(setq ispell-program-name "hunspell")
;; Dirty hacks to init dictionaries manually
(setq ispell-local-dictionary "english")
(setq ispell-local-dictionary-alist
'(("english" "[[:alpha:]]" "[^[:alpha:]]" "[']"
nil ("-d" "en_US") nil utf-8)
("russian" "[А-Яа-я]" "[^А-Яа-я]" "[']"
nil ("-d" "ru_RU") nil utf-8)
))
(condition-case nil
(ispell-change-dictionary "english")
(error nil))
(setenv "SHELL" "/bin/bash")
;; Enable xclip support
(package-install 'xclip)
(xclip-mode)
(package-install 'haskell-mode)
(package-install 'haskell-snippets)
(org-mode)
(load "etags-select")
(package-install 'groovy-mode)
(package-install 'gradle-mode)
(package-install 'nodejs-repl)
(package-install 'typescript-mode)
(package-install 'nodejs-repl)
(package-install 'typescript-mode)
;; (package-install 'purescript-mode)
;; As suggested [here](https://github.com/epost/psc-ide-emacs/issues/60#issuecomment-228606407)
(add-hook 'purescript-mode-hook
(lambda ()
(turn-on-purescript-indentation)))
(setq compilation-ask-about-save nil)
(add-to-list 'auto-mode-alist '("\\.libsonnet\\'" . jsonnet-mode))
(defun copy-file-name-to-clipboard--filename (full-filename copy-full-path)
(when full-filename
(if copy-full-path full-filename
(if (equal "/" (substring full-filename -1))
(file-name-nondirectory (substring full-filename 0 -1))
(file-name-nondirectory full-filename)
)
)
)
)
;; Derived
;; [here](http://emacsredux.com/blog/2013/03/27/copy-filename-to-the-clipboard/)
(defun copy-filename (arg)
"Copy the current buffer file name to the clipboard."
(interactive "P")
(let ((copy-full-path arg)
(full-filename
(if (member major-mode '(dired-mode eshell-mode shell-mode))
default-directory
(buffer-file-name))))
(let ((filename (copy-file-name-to-clipboard--filename
full-filename copy-full-path)))
(when filename
(kill-new filename)
(message
"Copied buffer file name '%s' to the clipboard." filename)))
)
)
(defalias 'cpfn 'copy-filename)
; Emacs workspace (ws-*) functions
(defun ws-open-eshell (buffer-name location)
(if (not (get-buffer buffer-name))
(progn
(eshell)
(insert location)
(eshell-send-input)
(rename-buffer buffer-name))))
(defun ws-project (buffer-name location)
(message "ws-project %s %s" buffer-name location)
(ws-open-eshell buffer-name location)
(let ((file (concat location "/TAGS")))
(and
(file-exists-p file)
(visit-tags-table-buffer file))))
(defun ws-visit-tags-table (f)
(message "ws-visit-tags-table %s" f)
(visit-tags-table f)
)
; Doing this, because `package-install` stopped working
(let ((php-mode-autoloads (concat
(file-name-directory load-file-name)
"php-mode/php-mode-autoloads.el")))
(if (file-exists-p php-mode-autoloads)
(load php-mode-autoloads)
(error
(format "Git Init 'php-mode' submodule and run 'make'. %s file doesn't exist"
php-mode-autoloads))
)
)
(setq haskell-interactive-popup-errors nil)
;; https://github.com/skuro/puml-mode
;; Using a deprecated one as it supports Emacs 24
(load "puml-mode")
(add-to-list 'auto-mode-alist '("\\.pu$" . puml-mode))
(load "tasktags/task-tags-mode.el")
(server-start)
(setenv "PAGER" "cat")