-
Notifications
You must be signed in to change notification settings - Fork 1
/
.emacs.el
executable file
·1492 lines (1246 loc) · 49.1 KB
/
.emacs.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
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
;;; package --- Summary
;;; Commentary:
;;;
;;; code:
(setq custom-file "~/etc/el/bartuer-custom.el")
(load custom-file)
(defun cygw2u (path)
(mapconcat (lambda (x) x) (split-string (car (cdr (split-string path "C:\\\\cygwin64")) ) "\\\\") "/" )
)
(when (>= emacs-major-version 24)
(require 'package)
(package-initialize)
(add-to-list 'package-archives '("melpa" . "http://melpa.org/packages/"))
)
(require 'phi-search nil t)
(require 'multiple-cursors nil t)
(global-set-key "\C-xx" 'mc/mark-all-dwim)
(global-set-key "\C-xj" 'mc/mark-all-in-region-regexp)
(global-set-key "\C-xy" 'mc/insert-numbers)
(global-set-key "\C-xp" 'mc/edit-lines)
(global-set-key "\C-x[" 'er/expand-region)
(global-set-key "\C-x]" 'er/contract-region)
(global-set-key "\C-xs" 'ace-jump-mode)
(require 'color-moccur nil t)
(require 'moccur-edit nil t)
(require 'dash-at-point nil t)
(defvar last-post-command-position 0
"Holds the cursor position from the last run of post-command-hooks.")
(make-variable-buffer-local 'last-post-command-position)
(defun dash-doc-query ()
(unless (equal (point) last-post-command-position)
(let ((my-current-word (thing-at-point 'word)))
(message "%s" my-current-word)
(dash-at-point-run-search my-current-word)
))
(setq last-post-command-position (point)))
(global-set-key "\C-cd" `dash-at-point)
(require 'expand-region nil t)
(require 'ace-jump-mode nil t)
(electric-pair-mode t)
(require 'auto-complete-clang nil t)
(global-set-key "\C-c " 'ace-jump-mode)
(defun cygu2w (path)
(concat "C:\\cygwin64" (subst-char-in-string ?/ ?\\ path))
)
(defun ammend-file-exists-p (file-name)
(let ((path-util (executable-find "cygpath")))
(if path-util
(file-exists-p (cygw2u file-name))
(file-exists-p file-name)
))
)
(defun ammend-buffer-file-name (&optional name)
(let* ((path-util (executable-find "cygpath"))
(file-name (if (not name)
(buffer-file-name)
name)))
(if path-util
(cygu2w file-name)
file-name
)
)
)
(defun what-face (pos)
(interactive "d")
(let ((face (or (get-char-property (point) 'read-face-name)
(get-char-property (point) 'face))))
(if face (message "Face: %s" face) (message "No face at %d" pos))))
(if (string= system-type "windows-nt") (menu-bar-mode -1) (menu-bar-mode -1))
(if (string= system-type "windows-nt") (setq find-program "findnix") (setq find-program "find"))
(if(fboundp 'tool-bar-mode) (tool-bar-mode -1))
(if(fboundp 'scroll-bar-mode) (scroll-bar-mode -1))
(fset 'yes-or-no-p 'y-or-n-p)
(put 'set-goal-column 'disabled nil)
(setq-default source-directory (expand-file-name "~/local/src/emacs/"))
(setq-default major-mode 'text-mode)
(defalias 'n 'rename-buffer)
(defun link (file point)
(interactive)
(find-file-other-window file)
(goto-char point))
(defalias ': (lambda () (interactive) (align-regexp (region-beginning) (region-end) "\\(\\s-*\\):")))
(defalias 'll (lambda ()
(interactive)
(kill-new (format "(link \"%s\" %d)"
(replace-regexp-in-string
(shell-command-to-string "printf $HOME") "~" (buffer-file-name))
(point)))))
(defalias 'r (lambda ()
(interactive)
(revert-buffer t t)))
(defalias 'p 'finder-commentary)
(defalias 'c 'emacs-lisp-byte-compile)
;; (add-to-list 'load-path (expand-file-name "~/etc/el/icicles"))
(add-to-list 'load-path (expand-file-name "~/etc/el"))
(defalias 'g 'global-set-key)
(defalias 'l 'local-set-key)
(global-set-key "\C-w" 'backward-kill-word) ;for case <BS> does not mean <DEL>,anywhere
(global-set-key "\C-c\C-k" 'kill-region) ;for case <BS> does not mean <DEL>,anywhere
(global-set-key "\C-ck" 'kill-region) ;delete to the beginning "\C-x-DEL",move 1
(global-set-key "\C-xk" 'kill-whole-line) ;delete whole line, move 1
(require 'guess-style)
(autoload 'guess-style-set-variable "guess-style" nil t)
(autoload 'guess-style-guess-variable "guess-style")
(autoload 'guess-style-guess-all "guess-style" nil t)
(global-guess-style-info-mode 1)
(defun ttt()
(interactive)
(whitespace-mode)
(guess-style-guess-all)
)
(global-set-key "\r" 'newline-and-indent) ;depend on if this line is a comment
(defun default-tab-behavior ()
(interactive)
(if (not (window-minibuffer-p))
(cond ((indent-for-tab-command))
(t (indent-relative-maybe))
(t (indent-for-comment)))))
(global-set-key "\C-i" ' default-tab-behavior)
(require 'smart-tabs-mode)
(global-set-key "\C-z" (lambda ()
(interactive)
(recenter-top-bottom 0)))
(defun mark-whole-sexp(&optional arg)
"Mark sexp contain the point, \\[mark-whole-sexp]
If give a positive ARG, mark sexp ARG levels outside from point.
Using \\[repeat] mark one level once.
If give a negative ARG, will undo the last mark action, thus the
inner level sexp is marked. There is no difference between
negative variant. "
(interactive "p")
(unless arg (setq arg 1))
(cond ((> arg 0)
(progn
(unless (eq (syntax-class (syntax-after (point))) 4)
(backward-up-list arg))
(mark-sexp 1)))
((< arg 0)
(when (not (and transient-mark-mode mark-active))
(error "Cannot cancel sexps mark without marked sexp"))
(set-mark-command 0)
(set-mark-command 0)
(backward-sexp)
(down-list)
(when (scan-lists (point) 1 -1)
(mark-whole-sexp)))))
(global-set-key "\C-cp" 'mark-whole-sexp)
(global-set-key "\C-c\C-p" 'mark-whole-sexp)
(defun mark-whole-sentence (&optional arg)
"\\[mark-whole-sentence], Steal from `mark-paragraph'"
(interactive "p")
(unless arg (setq arg 1))
(when (zerop arg)
(error "Cannot mark zero sentences"))
(cond ((or (and (eq last-command this-command) (mark t))
(and transient-mark-mode mark-active))
(set-mark
(save-excursion
(goto-char (mark))
(forward-sentence arg)
(point))))
(t
(forward-sentence arg)
(push-mark nil t t)
(backward-sentence arg))))
(global-set-key "\C-cs" 'mark-whole-sentence)
(global-set-key "\C-x\M-s" 'mark-whole-sentence)
(defun kill-whole-sexp(keep-this)
(interactive "P")
(if (eq keep-this '-)
(kill-backward-up-list)
(progn
(backward-up-list)
(kill-sexp))))
(global-set-key "\C-x\C-\M-k" 'kill-whole-sexp)
(defun kill-whole-sentence()
(interactive)
(backward-kill-sentence)
(kill-sentence))
(global-set-key "\C-x\M-k" 'kill-whole-sentence)
(global-set-key "\C-x\M-t" 'transpose-sentences)
(global-set-key "\C-x\C-\M-t" 'transpose-paragraphs) ;\C-\M-t bind transpose-sexps
(defun meta-n-dwim()
"multiple bindings for M-n"
(interactive)
(if (windowp (car (window-tree)))
(forward-paragraph) ;M-]
(scroll-other-window 10))) ;C-M-v
(global-set-key "\M-n" 'meta-n-dwim)
(if(require 'info nil t)
(add-hook
'Info-mode-hook
(lambda()
(define-key Info-mode-map "\M-n" 'meta-n-dwim))))
(defun meta-p-dwim()
"multiple bindings for M-p"
(interactive)
(if (windowp (car (window-tree)))
(backward-paragraph)
(scroll-other-window -10)))
(global-set-key "\M-p" 'meta-p-dwim)
(defun ctrl-meta-n-dwim()
"multiple bindings for C-M-n"
(interactive)
(if (windowp (car (window-tree)))
(forward-list)
(if (eq major-mode 'shell-mode)
(scroll-other-window 10)
(next-error))))
(global-set-key "\C-\M-n" 'ctrl-meta-n-dwim)
(defun ctrl-meta-p-dwim()
"multiple bindings for C-M-p"
(interactive)
(if (windowp (car (window-tree)))
(backward-list)
(if (eq major-mode 'shell-mode)
(scroll-other-window -10)
(previous-error))))
(global-set-key "\C-\M-p" 'ctrl-meta-p-dwim)
(defalias 'f 'auto-fill-mode)
(global-set-key "\C-j" 'eval-last-sexp)
(defalias 'e 'eval-current-buffer)
(require 'bartuer-typescript nil t)
(autoload 'bartuer-typescript-load "~/etc/el/bartuer-typescript.el"
"mode for typescript mode" t nil)
(add-hook 'typescript-mode-hook 'bartuer-typescript-load)
(setq auto-mode-alist (cons '("\\.ts\\'" . typescript-mode) auto-mode-alist))
(setq auto-mode-alist (cons '("\\.tsx\\'" . tsx-mode) auto-mode-alist))
(require 'bartuer-python nil t)
(autoload 'bartuer-python-load "~/etc/el/bartuer-python.el"
"mode for python mode" t nil)
(add-hook 'python-mode-hook 'bartuer-python-load)
(add-to-list 'auto-mode-alist '("\\.py$" . python-mode))
(add-to-list 'auto-mode-alist '("\\.gyp$" . gyp-mode))
(when (>= emacs-major-version 29)
(require 'use-package)
(setq treesit-extra-load-path `("~/etc/el/tree-sitter/"))
(require 'tree-sitter)
(require 'tree-sitter-langs)
(require 'treesit-mode-bind)
(treesit-mode-bind)
(add-hook 'combobulate-after-setup-hook #'tree-sitter-hl-mode)
(require 'markdown-mode)
(use-package eglot
:ensure t
:config
(add-to-list 'eglot-server-programs '(python-mode . ("jedi-language-server")))
(add-to-list 'eglot-server-programs '(typescript-mode . ("typescript-language-server"
"--stdio")))
(eldoc-doc-buffer)
(setq eldoc-echo-area-use-multiline-p nil)
:hook
((python-mode . eglot-ensure)
(python-ts-mode . eglot-ensure)
(typescript-mode . eglot-ensure)
(typescript-ts-mode . eglot-ensure))))
(require 'flymake-jslint)
(lintnode-start)
(require 'swanknode)
(swanknode-start)
(require 'web-beautify)
(autoload 'glsl-mode "glsl-mode" nil t)
(add-to-list 'auto-mode-alist '("\\.glsl\\'" . glsl-mode))
(add-to-list 'auto-mode-alist '("\\.vert\\'" . glsl-mode))
(add-to-list 'auto-mode-alist '("\\.frag\\'" . glsl-mode))
(add-to-list 'auto-mode-alist '("\\.geom\\'" . glsl-mode))
(require 'powershell)
(require 'powershell-mode)
(add-to-list 'auto-mode-alist '("\.ps1$" . powershell-mode))
(add-hook 'shell-mode-hook
(lambda ()
(ansi-color-for-comint-mode-on)
(define-key shell-mode-map "\C-\M-i"
'shell-dynamic-complete-environment-variable)
))
(add-hook 'comint-mode-hook
(lambda ()
(ansi-color-for-comint-mode-on)))
(global-set-key [(f5)] 'compile)
(global-set-key "\M-3" 'shell-command)
(global-set-key "\M-1" (if (string= system-type "windows-nt") 'shell 'shell))
(global-set-key "\M-5" 'everything-find-file)
(global-set-key "\M-6" 'nav-toggle)
(defun call-stack-parse ()
(interactive)
(setq next-error-function 'compilation-next-error-function)
(set (make-local-variable 'compilation-locs)
(make-hash-table :test 'equal :weakness 'value))
(compilation--ensure-parse (point))
(setq compilation-current-error (point))
)
(defalias 'cs 'call-stack-parse)
(defun do-ql-dwim()
(interactive)
(let* ((proc (get-buffer-process "*Async Shell Command*")))
(if proc
(kill-process proc)
(dired-do-async-shell-command
"qlmanage -p 2>/dev/null" ""
(dired-get-marked-files))
))
)
(require 'bartuer-dired nil t)
(defun shell-instead-dired ()
(interactive)
(let ((dired-buffer (current-buffer)))
(shell (concat default-directory "-shell"))
(delete-other-windows)))
(add-hook 'dired-load-hook (lambda ()
(load "dired-x")
))
(add-hook 'dired-mode-hook (lambda ()
(define-key dired-mode-map " " 'do-ql-dwim)
(define-key dired-mode-map "c" 'shell-instead-dired)
(define-key dired-mode-map "w" 'dired-copy-filename-as-kill-fix)
))
(require 'nav)
(nav-disable-overeager-window-splitting)
(defun color-print ()
(interactive)
(require 'htmlize nil t)
(require 'color-theme nil t)
(load "~/etc/el/auto-install/bartuer-theme.el")
)
(global-set-key "\M-8" 'find-file)
(defalias 'ff 'find-file-at-point)
(defun clean-thing-at-point ()
(let ((bounds (bounds-of-thing-at-point 'word)))
(if bounds
(buffer-substring-no-properties (car bounds) (cdr bounds)))))
(require 'ibuffer nil t)
(when (fboundp 'ibuffer)
(defalias 'j 'ibuffer))
(global-set-key "\M-=" 'switch-to-buffer)
(global-set-key "\M-l" 'switch-to-buffer)
(global-set-key "\M-4" 'kill-buffer-and-window)
(global-set-key "\C-\M-j" 'save-buffer)
(global-set-key "\C-xc" 'copy-to-buffer)
(global-set-key "\C-xa" 'append-to-buffer)
(require 'winner nil t)
(defun restore-frames ()
"resort saved frame configuration at 'f'"
(interactive)
(let ((val (cdr (assq 102 register-alist))))
(when (and (consp val) (frame-configuration-p (car val)))
(set-frame-configuration (car val) t)
(if (functionp 'gud-refresh)
(progn
(gud-refresh)
(goto-char (point-max)))))))
(defalias 'rf 'restore-frames)
(defun meta-space-dwim()
"multiple bindings for M-SPC"
(interactive)
(if (windowp (car (window-tree)))
(unless (restore-frames)
(winner-undo))
(delete-other-windows)))
(global-set-key "\M- " 'meta-space-dwim)
(global-set-key "\M-k" 'other-window)
(defvar calc-mode-hook nil
"Hook run when entering calc-mode.")
(add-hook 'calc-mode-hook (lambda ()
(interactive)
(define-key calc-mode-map "\M-k" 'other-window)
))
(if (require 'diff-mode nil t)
(add-hook 'diff-mode-hook
(lambda ()
(define-key diff-mode-map "\M-k" 'other-window)
(define-key diff-mode-map "\M-h" 'diff-hunk-kill))))
(require 'binary-diff)
(global-set-key [(prior)] 'scroll-other-window-down)
(global-set-key [(next)] 'scroll-other-window)
(defun f1()
"select the first frame "
(interactive)
(select-frame-by-name "F1"))
(defun f2()
"select frame 2"
(interactive)
(select-frame-by-name "F2"))
(global-set-key [(f2)] 'f2)
(defun f3()
"select frame 3"
(interactive)
(select-frame-by-name "F3"))
(global-set-key [(f3)] 'f3)
(defun f4()
"select frame 4"
(interactive)
(select-frame-by-name "F4"))
(global-set-key [(f4)] 'f4)
(defalias 'fr 'make-frame)
(global-set-key "\M-7" 'find-dired)
(global-set-key "\M-9" 'grep-find)
(global-set-key [(f9)] 'grep-find)
(defun match-lines (&optional arg)
(interactive "P")
(if (eq arg nil)
(progn
(let ((regexp (occur-read-primary-args))
)
(list-matching-lines (car regexp))
)
)
(let ((bufregexp
(let* ((default (car regexp-history))
(input
(read-from-minibuffer
(if current-prefix-arg
"List lines in buffers whose names match regexp: "
"List lines in buffers whose filenames match regexp: ")
nil
nil
nil
'regexp-history)))
(if (equal input "")
default
input))
)
(regexp (occur-read-primary-args)))
(multi-occur-in-matching-buffers bufregexp (car regexp)))
))
(global-set-key "\M-0" 'match-lines)
(global-set-key "\C-\M-s" 'isearch-forward)
(global-set-key "\C-\M-r" 'isearch-backward)
(global-set-key "\C-s" 'isearch-forward-regexp)
(global-set-key "\C-r" 'isearch-backward-regexp)
(global-set-key [(f7)] 'man-follow)
(global-set-key [(f8)] 'info-lookup-symbol)
(defalias 'm 'flymake-mode)
(defalias 'a 'apropos) ;C-u C-h a for command and function
;;; jslint
(add-hook
'eshell-mode-hook
(lambda ()
(setq pcomplete-cycle-completions nil)))
(require 'google-define nil t)
(defalias 'gd 'google-define)
(defalias 'x 'buddy-define)
(require 'fast-wiki nil t)
(require 'bartuer-buddy nil t)
(defalias 'bd 'buddy-minor-mode)
(if (fboundp 'server-start)
(server-start))
(if (fboundp 'show-paren-mode)
(show-paren-mode 1))
(if (fboundp 'winner-mode)
(winner-mode 1))
(if (fboundp 'which-function-mode)
(which-function-mode 1))
(require 'remember nil t)
(require 'org-remember nil t)
(org-remember-insinuate)
(setq org-directory "~/org")
(setq org-default-notes-file (concat org-directory "/note.org"))
(define-key global-map "\C-cr" 'org-remember)
(define-key global-map "\C-cc" 'org-capture)
(autoload 'bartuer-setup-capture "bartuer-org.el" "capture define" t)
(bartuer-setup-capture)
(add-hook 'remember-mode-hook (lambda ()
(setq remember-annotation-functions nil)))
(require 'bartuer-sql nil t)
(require 'csv-mode nil t)
(add-to-list 'auto-mode-alist '("\.csv$" . csv-mode))
(add-hook 'csv-mode-hook 'bartuer-csv-load)
(require 'sqlite-mode nil t)
(add-to-list 'auto-mode-alist '("\.db$" . sqlite-mode))
(add-to-list 'auto-mode-alist '("\.sqlite$" . sqlite-mode))
(defun postfix ()
(interactive)
(find-file "~/local/share/doc/postfix")
(occur "*[12]"))
(require 'auto-install nil t)
(require 'ispell nil t)
(if (fboundp 'ispell-region)
(progn
(ispell-region (point-min) (point-min))
(global-set-key "\C-x\C-\M-i" 'ispell-complete-word)
))
(global-set-key "\M-i" 'hippie-expand)
(global-set-key "\M-j" 'dabbrev-expand)
(global-set-key "\M-/" 'tab-to-tab-stop)
;; if the major mode has bind M-TAB to complete symbol, then
;; flyspell-auto-correct-word will bind to C-c M-TAB , if major mode not
;; using M-TAB, then M-TAB is flyspell-auto-correct-word
(autoload 'bartuer-flyspell-load "bartuer-flyspell.el" "flyspell modification")
(add-hook 'flyspell-mode-hook 'bartuer-flyspell-load)
(global-set-key "\C-c\C-\M-n" 'flyspell-goto-next-error)
(require 'ggtags nil t)
;; M-TAB do the tags and symbol complete
(defalias 'tl (quote (lambda ()
(interactive)
(list-tags (buffer-file-name)))))
(defalias 'ta 'tags-apropos)
(defalias 'ts 'tags-search)
(defalias 'tq 'tags-query-replace)
(defalias 'im 'imenu)
(global-set-key "\C-c\M-." 'anything-etags-select-from-here)
(global-set-key "\M-." 'xref-find-definitions)
(load "~/etc/el/bartuer-etags.el")
(load "~/etc/el/anything-c-source-mark-ring.el")
(defun anything-imenu-jump (p)
"(number-or-marker-p p), need move window first"
(interactive)
(if (overlayp p)
(setq jump-pos (overlay-start p))
(setq jump-pos p)
(if (> jump-pos 100)
(set-window-start (selected-window) (- jump-pos 100))
(set-window-start (selected-window) 1))
)
(goto-char jump-pos)
)
(defun anything-c-imenu-kiss-action (elm)
"The kiss action for `anything-c-source-imenu'."
(interactive)
(push-mark)
(let ((path (split-string elm anything-c-imenu-delimiter))
(alist anything-c-cached-imenu-alist))
(if (> (length path) 1)
(progn
(setq alist (last (mapcar (lambda (elem)
(setq alist
(assoc elem alist)))
path)))
(let* ((pos (cdr
(assoc (car (last path)) alist))))
(if (overlayp pos)
(anything-imenu-jump (overlay-start pos))
(anything-imenu-jump pos)))
)
(let ((position (cdr
(assoc elm alist))))
(anything-imenu-jump position)
))))
(setq anything-sources
'(
((name . "Imenu Jump")
(candidates . anything-c-imenu-candidates)
(action . anything-c-imenu-kiss-action)
)
anything-c-source-complete-syntax
;; seems kill ring is not useful than mark ring for programming, right?
anything-c-source-mark-ring
anything-c-source-global-mark-ring
((name . "Kill Ring")
(init . (lambda () (anything-attrset 'last-command last-command)))
(candidates . (lambda ()
(loop for kill in kill-ring
unless (or (< (length kill) anything-kill-ring-threshold)
(string-match "^[\\s\\t]+$" kill))
collect kill)))
(action . anything-c-kill-ring-action)
(last-command)
(migemo)
(multiline)
)
))
(require 'anything-yasnippet)
(require 'anything-etags)
;; (require 'icicles nil t)
;; (global-set-key [(f6)] 'icicle-complete-keys)
(global-set-key "\M-'" 'advertised-undo)
;; (defun bartuer-icicle-key-map()
;; (when icicle-mode
;; (let ((map minibuffer-local-completion-map))
;; (define-key map [(f1)] 'icicle-completion-help)
;; (define-key map "\M-." 'anything-etags-select-from-here)
;; (define-key map "\M-'" 'advertised-undo)
;; (define-key map "\M-o" 'icicle-erase-minibuffer-or-history-element)
;; (define-key map "\M-v" 'icicle-switch-to-Completions-buf)
;; (define-key map "\C-w" 'backward-kill-word)
;; (define-key map "\C-\M-y" 'icicle-apropos-complete-and-narrow)
;; (define-key map "\C-\M-i" 'icicle-apropos-complete)
;; (define-key map "\C-i" 'minibuffer-complete)
;; (define-key map " " 'minibuffer-complete-word)
;; (define-key map "\C-j" 'exit-minibuffer)
;; (define-key map "\C-s" 'icicle-narrow-candidates)
;; (define-key map "\M-l" 'switch-to-buffer)
;; (define-key map "\M-k" 'other-window)
;; (define-key map "\C-n" 'icicle-next-apropos-candidate-action)
;; (define-key map "\C-p" 'icicle-previous-apropos-candidate-action)
;; (define-key map "\C-\M-n" 'icicle-help-on-next-apropos-candidate)
;; (define-key map "\C-\M-p" 'icicle-help-on-previous-apropos-candidate))))
;; (add-hook 'icicle-mode-hook 'bartuer-icicle-key-map)
;; (when(fboundp 'icy-mode)
;; (defalias 'i 'icy-mode)
;; (icy-mode))
(defadvice execute-extended-command (before icicle-m-x-help activate)
"do right thing for icicle-candidate-help-fn ."
(setq icicle-candidate-help-fn nil))
(defadvice icicle-execute-extended-command-1 (before icicle-m-x-help activate)
"do right thing for icicle-candidate-help-fn ."
(setq icicle-candidate-help-fn nil))
(require 'icomplete nil t)
(when (fboundp 'icomplete-mode)
(setq-default icomplete-mode t)
(icomplete-mode 1))
(require 'complete nil t)
(when (fboundp 'partial-completion-mode)
(setq-default partial-completion-mode t)
(partial-completion-mode 1))
(require 'ido nil t)
(when (fboundp 'ido-mode)
(setq-default ido-mode 'both)
(ido-mode 1))
(require 'bartuer-filecache nil t)
(bartuer-filecache-load)
(require 'anything nil t)
(setq anything-candidate-number-limit nil)
(require 'anything-match-plugin nil t)
(require 'anything-complete nil t)
(require 'anything-show-completion)
(when (require 'anything-show-completion nil t)
(progn
(use-anything-show-completion 'anything-etags-complete-objc-message
'(message-length))
))
(require 'swift-mode nil t)
(require 'json nil t)
(when (require 'anything-show-completion nil t)
(progn
(use-anything-show-completion 'anything-complete-js
'(js-message-length))
))
(when (require 'anything-show-completion nil t)
(progn
(use-anything-show-completion 'rct-complete-symbol--anything
'(length pattern))
))
(when (fboundp 'anything)
(global-set-key "\C-l" 'anything))
(require 'magit nil t)
(global-set-key "\C-xg" 'magit-status)
(autoload 'bartuer-magit-load "bartuer-magit.el" "add rinari-launch in magit" t)
(add-hook 'magit-mode-hook 'bartuer-magit-load)
(require 'bartuer-sd)
(defun accumulate-rectangle (start end &optional fill)
"add numbers up in rectangle"
(interactive "r*\nP")
(setq killed-rectangle (extract-rectangle start end))
(message
(let*
((formulas '("vsum" "vmin" "vmax" "vmean" "vgmean" "vcount" "vsdev" "vmeane"))
(args (mapconcat
(lambda (n)
(format "%d" n)
)
(mapcar
(lambda (str)
(read (substring-no-properties str)))
killed-rectangle) ",")))
(mapconcat
(lambda (formula)
(format "%6s:%s"
formula
(calc-eval (format "%s(%s)" formula args)))
) formulas "\n")
))
)
(global-set-key "\C-xrp" 'accumulate-rectangle)
(defun git-link (repos commit &optional graph)
"insert link can jump to diff"
(interactive)
(if graph
(shell-command (concat "cd " repos ";git difftool " commit "~" " " commit))
(shell-command (concat "cd " repos ";git diff " commit "~" " " commit) "*git link output*"))
(pop-to-buffer "*git link output*")
(diff-mode)
(diff-refine-hunk))
(defun git-grep (command-args)
"Run grep over git documents"
(interactive
(progn
(grep-compute-defaults)
(list (read-shell-command "grep git docs: "
"find ~/local/share/doc/git-doc -type f |grep -vE \"BROWSE|TAGS|.svn|drw|Binary|.bzr|svn-base|*.pyc\" |xargs grep -niHE " 'grep-find-history))))
(when command-args
(let ((null-device nil)) ; see grep
(grep command-args))))
(defun html-2-txt ()
"invoke html2text to see the downloaded html"
(interactive)
(shell-command-on-region (point-min) (point-max) "html2text -nobs -style pretty"
(get-buffer-create "html-text"))
(with-current-buffer "html-text"
(replace-match "" "'" nil (point-min) (point-max))
(replace-match "" "\"" nil (point-min) (point-max))
(replace-match "" "\"" nil (point-min) (point-max))
(replace-match "
\\([A-Z]\\)" "
\\&" nil (point-min) (point-max))
)
)
(defun html-2-md ()
"invoke html2text.py to see document in markdown"
(shell-command-on-region (point-min) (point-max) (if (string= system-type "windows-nt") "html2text.exe" "html2text.py")
(get-buffer-create "html-markdown"))
(with-current-buffer "html-markdown"
(markdown-mode)
(setq buffer-file-name "/tmp/preview-url.md")
(save-buffer)
(flymake-mode t)
)
)
(defalias 'u (lambda (url-content-insert-location)
(interactive "surl: ")
(shell-command (concat "curl -n --ntlm -k " url-content-insert-location (if (string= system-type "windows-nt") " 2>nul" " 2>/dev/null"))
(get-buffer-create "preview-url") (get-buffer "*Shell Command Output*"))
(with-current-buffer "preview-url"
(goto-char (point-min))
(if (search-forward "html" (point-max) t)
(html-2-md)
)
)
(pop-to-buffer "preview-url" t)
(pop-to-buffer "html-text" t)
(pop-to-buffer "html-markdown" t)
))
(defun macman (name)
(u (concat "http://developer.apple.com/mac/library/documentation/Darwin/Reference/ManPages/10.5/man3/" name ".3.html?useVersion=10.5")))
(require 'cheat nil t)
(require 'gist nil t)
(require 'pastie nil t)
(require 'dockerfile-mode)
(add-to-list 'auto-mode-alist '("Dockerfile\\'" . dockerfile-mode))
(require 'docker-images nil t)
(require 'docker-containers nil t)
(require 'docker-volumes nil t)
(require 'docker-networks nil t)
(require 'docker nil t)
(require 'yasnippet)
(yas-global-mode 1)
;;(yas--initialize)
(yas-load-directory "~/etc/el/vendor/yasnippet/snippets")
(global-set-key "\C-cy" (lambda ()
(interactive)
(message "load yas")
mshp,192.168.0.142 ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBDUN5H+NwJiEzImPdw90dtHSgI5WbWqByLRR9yuIfWMz/MTEH5JnXQogsfZ9DPoVm6jhBqV7u4KDxdXflB78if4=
(yas-load-directory "~/etc/el/vendor/yasnippet/snippets")))
(add-hook 'yas-after-exit-snippet-hook (lambda ()
(cond (not (eq major-mode "js2-mode")) (flymake-mode t))
))
(defalias 'y 'yas-reload-all)
(require 'rinari nil t)
(add-hook 'rinari-minor-mode-hook (lambda ()
(define-key rinari-minor-mode-map "\M-r" 'rinari-ido)))
(defadvice rinari-cap (before icicle-cap-help activate)
"do right thing for icicle-candidate-help-fn ."
(setq icicle-candidate-help-fn (lambda (entry)
"return the cap documents of entry"
(let ((item (widget-princ-to-string entry)))
(with-output-to-temp-buffer (format "cap -e %s" item)
(princ (shell-command-to-string (concat "cap -e " item))))))))
(defadvice rinari-script (before icicle-script-help activate)
"do right thing for icicle-candidate-help-fn ."
(setq icicle-candidate-help-fn
(lambda (entry)
"return the script documents of entry"
(let ((item (widget-princ-to-string entry)))
(with-output-to-temp-buffer (format "%s help" item)
(princ (shell-command-to-string
(concat
(rinari-root) "script/"
item
((lambda ()
(unless (or
(string-equal "performance/profiler" item)
(string-equal "performance/benchmarker" item)
(string-match "generate \w" item)
)
" -h")))
((lambda ()
(when (string-equal "browserreload" item)
(concat ";" (rinari-root) "script/browserreload help run")
)))))))
(with-current-buffer (format "%s help" item)
(toggle-read-only -1)
(ansi-color-apply-on-region (point-min) (point-max))
(copy-to-buffer "*current script help*" (point-min) (point-max)))))))
(defadvice rinari-rake (before icicle-rake-help activate)
"do right thing for icicle-candidate-help-fn ."
(setq icicle-candidate-help-fn (lambda (entry)
"return the cap documents of entry"
(let ((item (widget-princ-to-string entry)))
(with-output-to-temp-buffer (format "rake help %s" item)
(princ (shell-command-to-string (concat "rake -D " item))))))))
(require 'bartuer-gem nil t) ;for gem and mongrel
(require 'apache-mode nil t)
(add-to-list 'auto-mode-alist '("httpd.conf" . apache-mode))
(require 'conf-mode nil t)
(add-to-list 'auto-mode-alist '("nginx.conf" . conf-nginx-mode))
(require 'bartuer-ruby nil t)
(require 'flymake nil t)
(require 'rcodetools nil t)
(require 'anything-rcodetools nil t)
(load "~/etc/el/vendor/ruby-mode/ruby-electric.el")
(require 'ruby-eletric-mode nil t)
(require 'ruby-mode nil t)
(autoload 'bartuer-ruby-load "~/etc/el/bartuer-ruby.el"
"mode for ruby mode" t nil)
(add-hook 'ruby-mode-hook 'bartuer-ruby-load)
(add-to-list 'auto-mode-alist '("\.rb$" . ruby-mode))
(add-to-list 'auto-mode-alist '("\.ru$" . ruby-mode))
(add-to-list 'auto-mode-alist '("\.rjs$" . ruby-mode))
(add-to-list 'auto-mode-alist '("\.builder$" . ruby-mode))
(add-to-list 'auto-mode-alist '("Rakefile" . ruby-mode))
(add-to-list 'auto-mode-alist '("\.rake$" . ruby-mode))
(load "~/etc/el/vendor/ri/ri-ruby.el")
(require 'ri nil t)
; need check fastri-server and
; start it?
(defadvice ri-ruby-read-keyw (before icicle-ri-help activate)
"do right thing for icicle-candidate-help-fn ."
(setq icicle-candidate-help-fn 'bartuer-ruby-ri))
(defadvice inf-ruby-completions (before icicle-ri-help activate)
"do right thing for icicle-candidate-help-fn ."
(setq icicle-candidate-help-fn 'bartuer-ruby-ri))
;;; for java emacs-eclim
(require 'eclim)
(require 'eclimd)
(setq eclim-auto-save t)
(global-eclim-mode)
(setq help-at-pt-display-when-idle t)
(setq help-at-pt-timer-delay 0.1)
(help-at-pt-set-timer)
(require 'auto-complete)
(add-to-list 'ac-dictionary-directories "~/etc/el/vendor/auto-complete/dict")
(require 'auto-complete-config)
(ac-config-default)
(require 'company)
(autoload 'company-mode "company" nil t)
(eval-after-load 'company
'(add-to-list 'company-backends 'company-omnisharp))
(require 'company-emacs-eclim)
(company-emacs-eclim-setup)
(global-company-mode t)
(require 'ac-emacs-eclim-source)
(ac-emacs-eclim-config)