-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathinit.el
654 lines (553 loc) · 23.2 KB
/
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
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
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
;; See README for more information.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; override emacs-live defaults ;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(global-linum-mode) ;;; turn on line numbers
(global-git-gutter-mode -1) ;;; turn off git gutter, hides line numbers
(global-auto-revert-mode 1) ;;; allow git pulls/reverts to easily update buffers
(put 'narrow-to-region 'disabled nil) ;; allow me to narrow-to-region
(setq-default truncate-lines t) ;;; don't break lines automatically
(setq-default live-disable-zone t) ;;; this does not work well over ssh
(setq cider-repl-pop-to-buffer-on-connect nil) ;;; don't send me to the repl on connect
(add-hook 'nrepl-connected-hook 'reset-nrepl-connection-to-default) ;;; always default to first connection
(add-hook 'nrepl-connected-hook 'rename-repl-buffers-connection) ;;; always default to first connection
(add-hook 'clojure-mode-hook 'cider-mode)
(setq-default fill-column 90) ;;; I like my right margin at 90
(setq-default should-download-cider-known-hosts nil)
(setq default-nrepl-server "*default nrepl-server*")
(setq default-nrepl-connection "*default nrepl-connection*")
(setq expectations-nrepl-server "*expectations nrepl-server*")
(setq expectations-nrepl-connection "*expectations nrepl-connection*")
;; Develop in unplugged-pack snippets dir
;; use snippets from emacs-live
(setq yas/root-directory '("~/.emacs.d/local/unplugged-pack/snippets"
"~/.emacs.d/etc/snippets"))
;; Map `yas/load-directory' to every element
(mapc 'yas/load-directory yas/root-directory)
(dolist (x '(scheme emacs-lisp lisp clojure)) ;;; disable rainbow-delimiters
(remove-hook (intern (concat (symbol-name x) "-mode-hook")) 'rainbow-delimiters-mode))
(defun reset-nrepl-connection-to-default ()
(when (eq 2 (length nrepl-connection-list))
(message "resetting nrepl-connection to %s" default-nrepl-connection)
(if (get-buffer default-nrepl-connection)
(nrepl-make-repl-connection-default (get-buffer default-nrepl-connection))
(message "*** PROBABLE ERROR *** buffer %s could not be found" default-nrepl-connection))))
;; (nrepl-current-connection-buffer)
(defun load-current-buffer-to-all-nrepls ()
(interactive)
(dolist (x nrepl-connection-list)
(message "Loading to conn %s" x)
(nrepl-make-repl-connection-default (get-buffer x))
(cider-load-current-buffer))
(reset-nrepl-connection-to-default))
(define-key cider-mode-map (kbd "C-c C-k") 'load-current-buffer-to-all-nrepls)
(define-clojure-indent
(cond-> 1))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; things we used to define ourselves, now in clj-refactor. ;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define-key clojure-mode-map (kbd "C-:") 'cljr-cycle-stringlike)
(define-key clojure-mode-map (kbd "C->") 'cljr-cycle-coll)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; custom clojure font lock and key chording ;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; key chords
(key-chord-define clojure-mode-map "KL" "-> ")
(key-chord-define clojure-mode-map "KK" "{:keys [")
(key-chord-define clojure-mode-map "KP" "publish-fn")
(key-chord-define clojure-mode-map "PP" "product")
(key-chord-define clojure-mode-map "SS" "size")
(key-chord-define clojure-mode-map "Ss" "side")
(key-chord-define clojure-mode-map "II" "instrument-id")
(key-chord-define clojure-mode-map "Ii" "instrument")
(key-chord-define clojure-mode-map "BB" "bid")
(key-chord-define clojure-mode-map "AA" "ask")
(key-chord-define clojure-mode-map "TT" "term")
(key-chord-define clojure-mode-map "CC" "contract")
(key-chord-define clojure-mode-map "EE" "exchange")
(key-chord-define clojure-mode-map "ZJ" "a-fn1")
(key-chord-define clojure-mode-map "ZK" "a-fn2")
(key-chord-define clojure-mode-map "ZL" "a-fn3")
(key-chord-define clojure-mode-map "ZI" "interaction")
(key-chord-define clojure-mode-map "ZN" "no-op")
;;; font-lock
(dolist (x '((true т)
(false ғ)
(:keys ӄ)
(:strs ş)
(nil Ø)
(partial ∂)
(with-redefs я)
(comp º)
(apply ζ)
(a-fn1 α)
(a-fn2 β)
(a-fn3 γ)
(no-op ε)))
(eval-after-load 'clojure-mode
'(font-lock-add-keywords
'clojure-mode `((,(concat "[\[({[:space:]]"
"\\(" (symbol-name (first x)) "\\)"
"[\])}[:space:]]")
(0 (progn (compose-region (match-beginning 1)
(match-end 1) ,(symbol-name (second x)))
nil))))))
(eval-after-load 'clojure-mode
'(font-lock-add-keywords
'clojure-mode `((,(concat "^"
"\\(" (symbol-name (first x)) "\\)"
"[\])}[:space:]]")
(0 (progn (compose-region (match-beginning 1)
(match-end 1) ,(symbol-name (second x)))
nil))))))
(eval-after-load 'clojure-mode
'(font-lock-add-keywords
'clojure-mode `((,(concat "[\[({[:space:]]"
"\\(" (symbol-name (first x)) "\\)"
"$")
(0 (progn (compose-region (match-beginning 1)
(match-end 1) ,(symbol-name (second x)))
nil)))))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; load user specific settings ;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(let* ((local-user-settings (concat "~/.emacs.d/local/unplugged-pack/" (user-login-name) ".el")))
(if (and (file-exists-p local-user-settings) (not live-safe-modep))
(live-load-config-file local-user-settings)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; load commonly used modes ;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(add-to-list 'load-path "~/.emacs.d/local/expectations-mode/")
(require 'expectations-mode)
;; (add-to-list 'load-path "~/.emacs.d/local/Fill-Column-Indicator/")
;; (require 'fill-column-indicator)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; define environment vars ;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(setenv "EXPECTATIONS_COLORIZE" "false")
(setenv "EXPECTATIONS_SHOW_RAW" "false")
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; define keystrokes for commonly used actions ;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(global-set-key (kbd "C-.") 'er/expand-region)
(global-set-key (kbd "C-M-.") 'er/contract-region)
(global-set-key (kbd "C-S-k") 'live-paredit-forward-kill-sexp)
(global-set-key (kbd "C-c C->") 'mc/mark-next-like-this)
(global-set-key (kbd "C-c C-<") 'mc/mark-all-like-this)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; expectations common and enhanced tasks ;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define-clojure-indent
(expect 'defun)
(expect-let 'defun)
(given 'defun)
(side-effects 1)
(context 1)
(freeze-time 1)
(redef-state 1)
(from-each 1))
(defun run-expectations ()
(interactive)
(shell-command "EXPECTATIONS_COLORIZE=false lein expectations"))
(defun expectations-run-tests-synch ()
(interactive)
(expectations-run-tests t))
(defun run-isolated-expectation ()
(interactive)
(save-some-buffers nil (lambda () (equal major-mode 'clojure-mode)))
(save-window-excursion
(save-excursion
(when (clojure-find-ns)
(goto-char (match-beginning 0))
(cider-eval-defun-at-point))))
(save-window-excursion
(save-excursion
(save-restriction
(live-paredit-previous-top-level-form)
(let (pos1 pos2)
(setq pos1 (point))
(end-of-sexp)
(setq pos2 (point))
(cua-set-mark)
(narrow-to-region pos1 pos2)
(expectations-run-tests t)
)))))
(defun run-expectations-for-source ()
(interactive)
(let* ((project-root (locate-dominating-file (file-name-directory (buffer-file-name)) "project.clj")))
(if project-root
(let* ((full-path-with-clojure (test-full-path project-root "test/expectations"))
(b (current-buffer)))
(if (file-exists-p full-path-with-clojure)
(progn
(switch-to-buffer (find-file-noselect full-path-with-clojure))
(load-current-buffer-to-all-nrepls)
(expectations-run-tests)
(switch-to-buffer b))
(message (concat "could not find " full-path-with-clojure))))
(message (concat "no project.clj found at or below " (buffer-file-name))))))
(defun run-expectations-for-file (&optional prefix)
(interactive "P")
(when (get-buffer expectations-nrepl-connection)
(message "setting expectations repl for test running")
(nrepl-make-repl-connection-default (get-buffer expectations-nrepl-connection)))
(if expectations-mode
(if prefix
(run-isolated-expectation)
(expectations-run-tests))
(run-expectations-for-source))
(reset-nrepl-connection-to-default))
(define-key cider-mode-map (kbd "C-c C-,") 'run-expectations-for-file)
(define-key cider-mode-map (kbd "C-c ,") 'run-expectations-for-file)
(define-key expectations-mode-map (kbd "C-c C-,") 'run-expectations-for-file)
(define-key expectations-mode-map (kbd "C-c ,") 'run-expectations-for-file)
(defun test-full-path (project-root test-home)
(concat
(replace-regexp-in-string
(concat (expand-file-name project-root) "src/clojure")
(concat project-root test-home)
(file-name-sans-extension (buffer-file-name)))
"_expectations.clj"))
(defun path-to-ns (project-root path)
(replace-in-string
(replace-in-string
(replace-in-string path (concat project-root "test/expectations/") "")
"_" "-")
"/" "."))
(defun src-full-path (project-root file-name)
(concat
(replace-regexp-in-string
(concat (expand-file-name project-root) "test/expectations")
(concat project-root "src/clojure")
(file-name-directory file-name))
(replace-regexp-in-string
"_expectations"
""
(file-name-nondirectory file-name))))
(defun find-expectations ()
(interactive)
(let* ((project-root (locate-dominating-file (file-name-directory (buffer-file-name)) "project.clj")))
(if project-root
(let* ((full-path-with-clojure (test-full-path project-root "test/expectations")))
(if (file-exists-p full-path-with-clojure)
(set-window-buffer (next-window) (find-file-noselect full-path-with-clojure))
(when (y-or-n-p (concat "no expectations found. create " full-path-with-clojure "?"))
(let* ((b (find-file-noselect full-path-with-clojure))
(ns (path-to-ns project-root (file-name-sans-extension full-path-with-clojure))))
(set-window-buffer (next-window) b)
(switch-to-buffer-other-window b)
(insert "(ns expectations." ns)
(reindent-then-newline-and-indent)
(insert "(:use expectations ")
(insert (replace-regexp-in-string "\-expectations$" "" ns))
(insert "))")
(expectations-mode)
(save-buffer)))))
(message (concat "no project.clj found at or below " (buffer-file-name))))))
(defun find-src ()
(interactive)
(let* ((project-root (locate-dominating-file (file-name-directory (buffer-file-name)) "project.clj")))
(if project-root
(let* ((full-path (src-full-path project-root (buffer-file-name))))
(if (file-exists-p full-path)
(set-window-buffer (next-window) (find-file-noselect full-path))
(message (concat "cound not find " full-path))))
(message (concat "no project.clj found at or below " (buffer-file-name))))))
(defun toggle-expectations-and-src ()
(interactive)
(if expectations-mode
(find-src)
(find-expectations)))
(global-set-key (kbd "C-c x") 'toggle-expectations-and-src)
(defun rename-buffers-on-connected (conn-name server-name)
(message "renaming %s -> %s, %s -> %s"
nrepl-server-buffer server-name nrepl-connection-buffer conn-name)
(switch-to-buffer nrepl-connection-buffer)
(rename-buffer conn-name)
(switch-to-buffer nrepl-server-buffer)
(rename-buffer server-name)
(clojure-mode)
(make-directory "~/tmp/emacs/" t)
(let ((fname (concat "~/tmp/emacs/" server-name)))
(when (file-exists-p fname)
(delete-file fname))
(write-file fname))
(bury-buffer))
(defun rename-repl-buffers-connection ()
;; (message "nrepl-session %s" nrepl-session)
;; (message "nrepl-connection-buffer %s" nrepl-connection-buffer)
;; (message "nrepl-server-buffer %s" nrepl-server-buffer)
;; (message "connection-list length: %s" (length nrepl-connection-list))
;; (message "connection-list %s" nrepl-connection-list)
;; (message "buffer list %s" (buffer-list))
;; (message "current repl buffer %s" (cider-current-repl-buffer))
(when (eq 0 (length nrepl-connection-list))
(save-window-excursion
(rename-buffers-on-connected expectations-nrepl-connection expectations-nrepl-server))
(message "expectations repl connected"))
(when (eq 1 (length nrepl-connection-list))
(save-window-excursion
(rename-buffers-on-connected default-nrepl-connection default-nrepl-server))
(message "default repl connected"))
(reset-nrepl-connection-to-default))
;;;;;;;;;;;;;;;;;;;;;;;
;;; java helper fns ;;;
;;;;;;;;;;;;;;;;;;;;;;;
(defun find-java-src ()
(interactive)
(er/mark-word)
(let* ((project-root (locate-dominating-file (file-name-directory (buffer-file-name)) "project.clj"))
(the-str (concat (buffer-substring-no-properties (region-beginning) (region-end)) ".java")))
(if project-root
(progn
(grep-string-in the-str (concat project-root "lib/sources"))
(switch-to-grep)
(sit-for 0.25)
(search-forward (concat (expand-file-name project-root) "lib/sources/"))
(compile-goto-error)
(let* ((current-point (point)))
(search-forward-regexp ".*\.jar")
(switch-to-buffer (buffer-substring-no-properties current-point (point))))
(search-forward the-str)
(archive-extract))
(message (concat "no project.clj found at or below " (buffer-file-name))))))
(global-set-key (kbd "C-c . j") 'find-java-src)
;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; clojure project fns ;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun cider-force-quit ()
"Quit CIDER without a prompt"
(interactive)
(dolist (connection nrepl-connection-list)
(when connection
(nrepl-close connection)))
(message "All active nREPL connections were closed")
(cider-close-ancilliary-buffers))
(defun mark-buffer-umodified (buffer)
(when (get-buffer buffer)
(switch-to-buffer buffer)
(set-buffer-modified-p nil)))
(defun switch-repl (project-root)
(cd project-root)
(cider-jack-in))
(defun switch-expectations-repl (project-root)
(message "Starting expectations repl...")
(remove-hook 'nrepl-connected-hook (first nrepl-connected-hook))
(switch-repl project-root))
(defun load-project-env (project-root)
(let ((project-env (format "%s/project.el" project-root)))
(when (file-exists-p project-env)
(load-file project-env))))
(defun switch-project (project-root)
(interactive (list (ido-read-directory-name "Project Root: " (locate-dominating-file default-directory "project.clj"))))
(let ((project-name (file-name-nondirectory (directory-file-name project-root))))
(dolist (x (find-buffers "nrepl-server*"))
(mark-buffer-umodified x)
(set-process-query-on-exit-flag (get-buffer-process x) nil)
(kill-buffer x))
(cider-force-quit)
(load-project-env project-root)
(when (equal current-prefix-arg nil)
(mapc 'kill-buffer (buffer-list))
(switch-to-buffer "*Messages*"))
(let ((fn (apply-partially #'switch-expectations-repl project-root)))
(add-hook 'nrepl-connected-hook fn)
(switch-repl project-root))))
(global-set-key (kbd "C-c s p") 'switch-project)
(defun update-repl-known-hosts ()
(interactive)
(when (file-exists-p "/tmp/emacs/repl_data.el")
(setq cider-known-endpoints
(eval (read (with-temp-buffer
(insert-file-contents "/tmp/emacs/repl_data.el")
(buffer-string)))))))
(defun download-cider-known-hosts ()
(defun download-cider-known-hosts-exit (process event)
(when (eq 'exit (process-status process))
(if (eq 0 (process-exit-status process))
(update-repl-known-hosts)
(progn
(message "process status: %s" (process-status process))
(message "process exit-code: %s" (process-exit-status process))
(switch-to-buffer-other-window "*Messages*")))))
(set-process-sentinel
(start-process
"update-cider-known-hosts" "*Messages*"
"lein" "exec" (file-truename "~/.emacs.d/local/unplugged-pack/update_cider_known_hosts.clj"))
'download-cider-known-hosts-exit))
(defun cider-repl-for-connection (conn-buffer)
(buffer-local-value 'nrepl-repl-buffer
(get-buffer conn-buffer)))
;;;;;;;;;;;;;;;;;;;;;;;;
;;; layout shortcuts ;;;
;;;;;;;;;;;;;;;;;;;;;;;;
(defun default-window-layout ()
(interactive)
(let* ((w1 (get-buffer-window (current-buffer)))
(w2 (next-window))
(b2 (window-buffer w2))
(s2 (window-start w2)))
(delete-other-windows)
(split-window-right)
(set-window-buffer (second (window-list)) b2)
(set-window-start (second (window-list)) s2)))
(global-set-key (kbd "C-c w l d") 'default-window-layout)
(defun console-layout ()
(interactive)
(delete-other-windows)
(split-window-horizontally)
(win-switch-dispatch)
(switch-to-buffer default-nrepl-server)
(split-window-vertically)
(win-switch-dispatch)
(switch-to-buffer (cider-current-repl-buffer))
(win-switch-dispatch))
(global-set-key (kbd "C-c w l c") 'console-layout)
(defun linux-layout ()
(interactive)
(delete-other-windows)
(split-window-horizontally)
(split-window-horizontally)
(win-switch-dispatch)
(win-switch-dispatch)
(switch-to-buffer default-nrepl-server)
(split-window-vertically)
(win-switch-dispatch)
(switch-to-buffer (cider-current-repl-buffer))
(win-switch-dispatch)
(balance-windows))
(global-set-key (kbd "C-c w l l") 'linux-layout)
(defun visible-window (wlist)
(if (equal 1 (length wlist))
nil
(if (get-buffer-window (first wlist))
wlist
(visible-window (cdr wlist)))))
(defun toggle-window-from-list (l)
(when l
(select-window (get-buffer-window (first l)))
(switch-to-buffer (second l))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; buffer manipulation ;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun move-buffer-to-other-window ()
(interactive)
(let* ((w1 (get-buffer-window (current-buffer)))
(w2 (next-window)))
(set-window-buffer w2 (current-buffer))
(set-window-start w2 (window-start w1)))
(previous-buffer))
(global-set-key (kbd "C-c w .") 'move-buffer-to-other-window)
(defun kill-all-buffers ()
(interactive)
(mapc 'kill-buffer (buffer-list)))
(defun toggle-repl-buffers ()
(interactive)
(let* ((w1 (get-buffer-window (current-buffer)))
(default-repl (cider-repl-for-connection default-nrepl-connection))
(expectations-repl (cider-repl-for-connection expectations-nrepl-connection)))
(toggle-window-from-list (visible-window (list default-repl
expectations-repl
default-repl)))
(toggle-window-from-list (visible-window (list default-nrepl-server
expectations-nrepl-server
default-nrepl-server)))
(select-window w1)))
(global-set-key (kbd "C-c w t r") 'toggle-repl-buffers)
;;;;;;;;;;;;;;;;;;;;;;;;;
;;; line manipulation ;;;
;;;;;;;;;;;;;;;;;;;;;;;;;
(defun format-buffer ()
"format buffer"
(interactive)
(save-excursion
(save-restriction
(narrow-to-region (window-start) (window-end))
(beginning-of-buffer)
(forward-paragraph)
(narrow-to-region (point) (point-max))
(delete-trailing-whitespace)
(indent-region (point-min) (point-max) nil)
(untabify (point-min) (point-max)))))
(global-set-key (kbd "C-S-f") 'format-buffer)
(defun join-next-line ()
(interactive)
(next-line)
(join-line))
(global-set-key (kbd "C-S-j") 'join-next-line)
(defun duplicate-line ()
(interactive)
(let* ((cursor-column (current-column)))
(move-beginning-of-line 1)
(kill-line)
(yank)
(open-line 1)
(next-line 1)
(yank)
(move-to-column cursor-column)))
(global-set-key (kbd "C-S-d") 'duplicate-line)
(defun clojure-comment-sexp ()
(interactive)
(er/mark-clj-word)
(paredit-wrap-sexp)
(insert "comment ")
(fb))
(global-set-key (kbd "C-;") 'clojure-comment-sexp)
(defun clojure-comment-first-sexp-on-current-line ()
(interactive)
(move-beginning-of-line 1)
(clojure-comment-sexp))
(global-set-key (kbd "C-M-;") 'clojure-comment-first-sexp-on-current-line)
(defun remove-commas ()
(interactive)
(save-excursion
(let (pos1 pos2)
(if (region-active-p)
(progn
(setq pos1 (region-beginning) pos2 (region-end))
(replace-string "," "" nil pos1 pos2))
(replace-string "," "" nil (point-min) (point-max))))))
(global-set-key (kbd "C-<") 'remove-commas)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; grep'ing in a project ;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun grep-string-in (s project-root)
(interactive (list (read-string "string: ")
(ido-read-directory-name
"Project Root: "
(locate-dominating-file default-directory "project.clj"))))
(message (concat s project-root))
(let* ((cmd (concat "grep -nH -e \"" s "\" -R --exclude-dir=\"target\" --exclude-dir=\".git\" " project-root)))
(grep cmd)))
(defun grep-string-in-project (s)
(interactive "Mstring: ")
(let* ((project-root (locate-dominating-file (file-name-directory (buffer-file-name)) "project.clj")))
(if project-root
(grep-string-in s project-root)
(message (concat "no project.clj found at or below " (buffer-file-name))))))
(defun grep-in (project-root)
(interactive (list (ido-read-directory-name "Project Root: " (locate-dominating-file default-directory "project.clj"))))
(let (pos1 pos2 bds)
(if (not (region-active-p))
(er/mark-clj-word))
(setq pos1 (region-beginning) pos2 (region-end))
(grep-string-in (buffer-substring-no-properties pos1 pos2) project-root)))
(defun grep-in-project ()
(interactive)
(let* ((project-root (locate-dominating-file (file-name-directory (buffer-file-name)) "project.clj")))
(if project-root
(grep-in project-root)
(message (concat "no project.clj found at or below " (buffer-file-name))))))
(defun find-buffer (buffer)
(first (find-buffers buffer)))
(defun find-buffers (buffer)
(filter (lambda (b) (string-match buffer b)) (live-list-buffer-names)))
(defun filter (condp lst)
(delq nil
(mapcar (lambda (x) (and (funcall condp x) x)) lst)))
(global-set-key (kbd "C-c g p") 'grep-in-project)
(global-set-key (kbd "C-c g i") 'grep-in)
(global-set-key (kbd "C-c g s p") 'grep-string-in-project)
(global-set-key (kbd "C-c g s i") 'grep-string-in)
(when should-download-cider-known-hosts
(download-cider-known-hosts))