-
Notifications
You must be signed in to change notification settings - Fork 5
/
late-init.el
2257 lines (1891 loc) · 87.8 KB
/
late-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
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
;; late-init.el --- My config with postpone.el -*- lexical-binding: t -*-
(defvar my-late-init-start (current-time))
(require 'init-autoloads nil t)
(defvar measure-exec-time-list nil)
(dolist (f measure-exec-time-list)
(advice-add f :around #'ad:measure-exec-time))
;; (setq byte-compile-warnings '(obsolete))
;; Suppress warning on cl.el loading
(defvar my-exclude-deprecated-packages '(cl tls))
(advice-add 'do-after-load-evaluation :override #'ad:do-after-load-evaluation)
(setq save-silently t) ;; No need shut-up.el for saving files.
;; originally defined in `diary-lib.el'
(defun diary-entry-time (s)
"Return time at the beginning of the string S as a military-style integer.
For example, returns 1325 for 1:25pm.
Returns `diary-unknown-time' (default value -9999) if no time is recognized.
The recognized forms are XXXX, X:XX, or XX:XX (military time), and XXam,
XXAM, XXpm, XXPM, XX:XXam, XX:XXAM, XX:XXpm, or XX:XXPM. A period (.) can
be used instead of a colon (:) to separate the hour and minute parts."
(let (case-fold-search)
(cond ((string-match ; military time
"\\`[ \t\n]*\\([0-9]?[0-9]\\)[:.]?\\([0-9][0-9]\\)\\(\\>\\|[^ap]\\)"
s)
(+ (* 100 (string-to-number (match-string 1 s)))
(string-to-number (match-string 2 s))))
((string-match ; hour only (XXam or XXpm)
"\\`[ \t\n]*\\([0-9]?[0-9]\\)\\([ap]\\)m\\>" s)
(+ (* 100 (% (string-to-number (match-string 1 s)) 12))
(if (equal ?a (downcase (aref s (match-beginning 2))))
0 1200)))
((string-match ; hour and minute (XX:XXam or XX:XXpm)
"\\`[ \t\n]*\\([0-9]?[0-9]\\)[:.]\\([0-9][0-9]\\)\\([ap]\\)m\\>" s)
(+ (* 100 (% (string-to-number (match-string 1 s)) 12))
(string-to-number (match-string 2 s))
(if (equal ?a (downcase (aref s (match-beginning 3))))
0 1200)))
(t diary-unknown-time))))
;; Avoid to load diary-lib to use `diary-entry-time'
(defun run-at-time (time repeat function &rest args)
"Perform an action at time TIME.
Repeat the action every REPEAT seconds, if REPEAT is non-nil.
REPEAT may be an integer or floating point number.
TIME should be one of:
- a string giving today's time like \"11:23pm\"
(the acceptable formats are HHMM, H:MM, HH:MM, HHam, HHAM,
HHpm, HHPM, HH:MMam, HH:MMAM, HH:MMpm, or HH:MMPM;
a period `.' can be used instead of a colon `:' to separate
the hour and minute parts);
- a string giving a relative time like \"90\" or \"2 hours 35 minutes\"
(the acceptable forms are a number of seconds without units
or some combination of values using units in `timer-duration-words');
- nil, meaning now;
- a number of seconds from now;
- a value from `encode-time';
- or t (with non-nil REPEAT) meaning the next integral multiple
of REPEAT. This is handy when you want the function to run at
a certain \"round\" number. For instance, (run-at-time t 60 ...)
will run at 11:04:00, 11:05:00, etc.
The action is to call FUNCTION with arguments ARGS.
This function returns a timer object which you can use in
`cancel-timer'."
(interactive "sRun at time: \nNRepeat interval: \naFunction: ")
(when (and repeat
(numberp repeat)
(< repeat 0))
(error "Invalid repetition interval"))
(let ((timer (timer-create)))
;; Special case: nil means "now" and is useful when repeating.
(unless time
(setq time (current-time)))
;; Special case: t means the next integral multiple of REPEAT.
(when (and (eq time t) repeat)
(setq time (timer-next-integral-multiple-of-time nil repeat))
(setf (timer--integral-multiple timer) t))
;; Handle numbers as relative times in seconds.
(when (numberp time)
(setq time (timer-relative-time nil time)))
;; Handle relative times like "2 hours 35 minutes".
(when (stringp time)
(when-let ((secs (timer-duration time)))
(setq time (timer-relative-time nil secs))))
;; Handle "11:23pm" and the like. Interpret it as meaning today
;; which admittedly is rather stupid if we have passed that time
;; already. (Though only Emacs hackers hack Emacs at that time.)
(when (stringp time)
;; (require 'diary-lib) ;; *Modified*
(let ((hhmm (diary-entry-time time))
(now (decode-time)))
(when (>= hhmm 0)
(setq time (encode-time 0 (% hhmm 100) (/ hhmm 100)
(decoded-time-day now)
(decoded-time-month now)
(decoded-time-year now)
(decoded-time-zone now))))))
(timer-set-time timer time repeat)
(timer-set-function timer function args)
(timer-activate timer)
timer))
(when (autoload-if-found '(gcmh-time gcmh-mode) "gcmh" nil t)
(defvar my-gcmh-timer
(unless noninteractive
(run-with-idle-timer (+ 10 my-default-loading-delay)
nil #'my-gcmh-activate)))
(with-eval-after-load "gcmh"
(setq gcmh-verbose nil)
(advice-add 'garbage-collect :around #'ad:garbage-collect)
(advice-add 'gcmh-idle-garbage-collect
:around #'ad:gcmh-idle-garbage-collect)))
(setq message-log-max 5000) ;; メッセージバッファの長さ
(defvar shutup-p nil)
(with-eval-after-load "comp"
(setq native-comp-async-query-on-exit t)
(setf comp-num-cpus (max 1 (- (num-processors) 2))))
(with-eval-after-load "comp"
(add-hook 'native-comp-async-all-done-hook #'my-native-comp-packages-done))
;; Limit the final word to a line break code (automatically correct)
(setq require-final-newline t)
(setq truncate-lines nil)
(setq truncate-partial-width-windows nil)
(setq-default fringe-indicator-alist
(append (list '(continuation . (nil right-curly-arrow)))
(remove (assoc 'continuation fringe-indicator-alist)
fringe-indicator-alist)))
;; fringeに表示するマークの形状を変更
(define-fringe-bitmap 'right-curly-arrow
[#b00000000
#b00000000
#b00000000
#b00000000
#b01111110
#b01111110
#b00000110
#b00000110])
(setq mouse-drag-copy-region t)
(setq compilation-scroll-output t)
(setq hscroll-margin 40)
(autoload-if-found '(el-get-version
el-get-bundle my-elget-list my-elget-reset-links
el-get-cd el-get-remove el-get-update
el-get-install el-get-reinstall
my-elget-nativecomp-all-packages)
"elget-config" nil t)
(setq-default tab-width 2)
(setq-default indent-tabs-mode nil)
(setq indent-line-function 'insert-tab)
(add-hook 'emacs-lisp-mode-hook #'my-emacs-lisp-mode-conf)
(add-hook 'emacs-lisp-mode-hook #'turn-on-font-lock)
(setq vc-follow-symlinks t)
(unless noninteractive
(add-hook 'find-file-hook #'my-auto-revert-activate)
;; revert されるのが org バッファのとき,自動的にドロワをたたむ
;; カーソルが (point-max) に移動してしまう場合は非推奨
(with-eval-after-load "org"
(add-hook 'after-revert-hook 'my-org-hide-drawers-all)))
(unless noninteractive
(when (fboundp 'pixel-scroll-mode)
(pixel-scroll-mode 1))) ;; 26.1
(add-hook 'find-file-hook #'my-shorten-default-directory 1)
(when (autoload-if-found '(aggressive-indent-mode)
"aggressive-indent" nil t)
(dolist (hook
'(;; python-mode-hook
;; nxml-mode-hook
;; web-mode-hook
emacs-lisp-mode-hook
lisp-mode-hook perl-mode-hook c-mode-common-hook))
(add-hook hook #'aggressive-indent-mode)))
(setq uniquify-buffer-name-style 'post-forward-angle-brackets)
(when (autoload-if-found '(ws-butler-mode ws-butler-global-mode)
"ws-butler" nil t)
(dolist (hook '(emacs-lisp-mode-hook
lisp-mode-hook perl-mode-hook c-mode-common-hook))
(add-hook hook #'ws-butler-mode))
(with-eval-after-load "ws-butler"
(custom-set-variables
'(ws-butler-global-exempt-modes
(append '(org-mode empty-booting-mode change-log-mode epa-mode)
ws-butler-global-exempt-modes)))))
(unless noninteractive
(defvar my-private-conf-timer
(run-with-idle-timer (+ 6 my-default-loading-delay)
nil #'my-private-conf-activate))
(when (version< "27.0" emacs-version)
;; ミニバッファでパスワードを入力する
(setq epg-pinentry-mode 'loopback)))
(with-eval-after-load "epa"
;; Suppress message when saving encrypted file (hoge.org.gpg)
(advice-add 'epa-file-write-region :around #'ad:suppress-message))
(autoload 'mail "~/Dropbox/config/my-mail.el.gpg" nil t)
(when (memq window-system '(ns nil))
(custom-set-faces
'(ns-marked-text-face
((t (:foreground "black"
:background "light pink" :underline "OrangeRed2"))))
'(ns-unmarked-text-face
((t (:foreground "black"
:background "light sky blue" :underline "royal blue")))))
(when (and (fboundp 'mac-get-current-input-source)
(version< "27.0" emacs-version))
;; "com.apple.inputmethod.Kotoeri.RomajiTyping.Japanese" for Big Sur
(custom-set-variables
'(mac-default-input-source "com.google.inputmethod.Japanese.base"))
(unless noninteractive
(mac-input-method-mode 1))
;; see also activate-mark-hook, deactivate-mark-hook
(add-hook 'isearch-mode-hook #'my-isearch-ime-deactivate-sticky)
(add-hook 'isearch-mode-end-hook #'mac-ime-activate-sticky))
(with-eval-after-load "org"
;; カーソル移動で heading に来たときは即座にIMEをOFFにする
;; (add-hook 'ah-after-move-cursor-hook #'my-ns-org-heading-auto-ascii)
;; カーソル移動で heading に留まった時にIMEをOFFにする
(unless noninteractive
(run-with-idle-timer 0.2 t #'my-ns-org-heading-auto-ascii)))
(with-eval-after-load "hl-line"
(add-hook 'input-method-activate-hook #'my-working-text-face-on)
(add-hook 'input-method-deactivate-hook #'my-working-text-face-off)))
(autoload-if-found '(er/mark-symbol) "expand-region" nil t)
(advice-add 'mark-sexp :around #'ad:mark-sexp)
(advice-add 'mark-sexp :around #'ad:er:mark-sexp)
;; Scroll window on a line-by-line basis
(setq scroll-conservatively 1000)
(setq scroll-step 1)
(setq scroll-preserve-screen-position t) ;; スクロール時にスクリーン内で固定
;; (setq scroll-margin 0) ; default=0
;; Scroll window on a page-by-page basis with N line overlapping
(setq next-screen-context-lines 10)
(setq set-mark-command-repeat-pop t)
(setq mark-ring-max 32)
(setq global-mark-ring-max 64)
(unless noninteractive
(when (require 'ah nil t)
(setq ah-lighter "")
(ah-mode 1)))
(when (autoload-if-found '(smooth-scroll-mode)
"smooth-scroll" nil t)
(with-eval-after-load "smooth-scroll"
(custom-set-variables
'(smooth-scroll/vscroll-step-size 6)
'(smooth-scroll/hscroll-step-size 6)))
(unless noninteractive
(smooth-scroll-mode t)))
(with-eval-after-load "bs"
(custom-set-variables
'(bs-cycle-configuration-name "files-and-scratch")
'(bs-max-window-height 10))
;; リストを縦表示する
(when (require 'bsv nil t)
(setq bsv-max-height 5
bsv-message-timeout 9)))
(when (autoload-if-found '(my-toggle-bm
my-bm-next bm-buffer-save bm-buffer-restore
bm-buffer-save-all bm-repository-save
bm-repository-load counsel-bm)
"bm" nil t)
;; ファイルオープン時にブックマークを復帰
(keymap-global-set "<f10>" 'my-toggle-bm)
(keymap-global-set "C-<f10>" 'my-bm-next)
(keymap-global-set "S-<f10>" 'bm-show-all)
(add-hook 'find-file-hook #'bm-buffer-restore)
;; ビルトイン bookmark の配色を無効にする(as of 28.1)
(setq bookmark-fontify nil)
;; ビルトイン bookmark がfringeに出すマークを無効にする(as of 28.1)
(setq bookmark-set-fringe-mark nil)
(with-eval-after-load "ivy"
(keymap-global-set "S-<f10>" 'counsel-bm))
(with-eval-after-load "bm"
(advice-add 'bm-repository-load :around #'ad:suppress-message)
;; (setq bm-annotation-width 30)
(setq-default bm-buffer-persistence t)
(setq bm-restore-repository-on-load t)
(setq bm-cycle-all-buffers t)
;; (setq bm-toggle-buffer-persistence t)
(setq bm-buffer-persistence t)
(setq bm-persistent-face 'bm-face)
(setq bm-repository-file
(expand-file-name
(concat (getenv "SYNCROOT") "/emacs.d/.bm-repository")))
(unless noninteractive
(bm-repository-load)
(add-hook 'kill-buffer-hook 'bm-buffer-save)
(add-hook 'after-save-hook 'bm-buffer-save)
(add-hook 'after-revert-hook 'bm-buffer-restore)
(add-hook 'kill-emacs-hook #'my-bm-save-all))
(advice-add 'bm-show-mode :after #'ad:bm-show-mode)))
(when (autoload-if-found '(centered-cursor-mode)
"centered-cursor-mode" nil t)
(with-eval-after-load "isearch"
;; isearch の時はOFFにする
(add-hook 'isearch-mode-hook #'my-centered-cursor-activate)
(add-hook 'isearch-mode-end-hook #'my-centered-cursor-deactivate)))
(when (autoload-if-found '(smart-mark-mode)
"smart-mark" nil t)
(add-hook 'find-file-hook #'my-smart-mark-activate)
(with-eval-after-load "smart-mark"
(progn ;; C-M-SPC SPC SPC ... C-g の場合に正しくカーソルと元に戻す.
(advice-add 'smart-mark-restore-cursor :override
#'ad:smart-mark-restore-cursor)
(advice-add 'smart-mark-set-restore-before-mark :override
#'ad:smart-mark-set-restore-before-mark)
(when (require 'expand-region-core nil t)
(advice-add 'keyboard-quit :after #'ad:er:keyboard-quit))
;; (advice-add 'keyboard-quit :before #'ad:er:pre:keyboard-quit)
)))
;; (defun my-smart-mark-activate () (smart-mark-mode 1))
;; (defun my-smart-mark-dectivate () (smart-mark-mode -1))
;; (add-hook 'isearch-mode-hook #'my-smart-mark-dectivate)
;; (add-hook 'isearch-mode-end-hook #'my-smart-mark-activate)
(when (autoload-if-found '(global-syntax-subword-mode
syntax-subword-backward-kill
syntax-subword-mode syntax-subword-kill)
"syntax-subword" nil t)
(advice-add 'forward-word :before #'my-syntax-subword-activate)
(advice-add 'backward-word :before #'my-syntax-subword-activate)
(keymap-global-set "C-<backspace>" #'syntax-subword-backward-kill)
(with-eval-after-load "syntax-subword"
;; C-<backspace> で,削除領域をコピーしない.
(advice-add 'syntax-subword-kill :override #'ad:syntax-subword-kill)))
(setq yank-excluded-properties t)
(add-hook 'before-save-hook #'my-time-stamp)
(with-eval-after-load "time-stamp"
(setq time-stamp-start "#\\+date:[ \t]*") ;; "Time-stamp:[ \t]+\\\\?[\"<]+"
(setq time-stamp-end "$") ;; "\\\\?[\">]"
(setq time-stamp-line-limit 10)) ;; def=8
(with-eval-after-load "isearch"
(advice-add 'isearch-mode :around #'ad:isearch-mode)
;; C-g を isearch-exit に割り当てて途中中断とする.(カーソルを留めておきたい)カーソルを検索開始時点の場所に戻すには,別途 counsel-mark-ring を使う
(keymap-set isearch-mode-map "C-g" 'isearch-exit))
(with-eval-after-load "add-log"
(add-hook 'change-log-mode-hook
(lambda ()
(view-mode 1)
(my-orgalist-activate)
(setq tab-width 4)
(setq left-margin 4)))
(advice-add 'add-change-log-entry-other-window
:before #'ad:add-change-log-entry-other-window))
(when (autoload-if-found '(modern-c++-font-lock-mode)
"modern-cpp-font-lock" nil t)
(push '("\\.[hm]$" . c++-mode) auto-mode-alist)
(add-hook 'c-mode-hook #'modern-c++-font-lock-mode)
(add-hook 'c++-mode-hook #'modern-c++-font-lock-mode))
(add-hook 'nxml-mode-hook
(lambda ()
(keymap-set nxml-mode-map "RET" 'newline-and-indent)
(auto-fill-mode -1)
(setq indent-tabs-mode t)
(setq nxml-slash-auto-complete-flag t)
(setq tab-width 1)
(setq nxml-child-indent 1)
(setq nxml-attribute-indent 0)))
(when (autoload-if-found '(yaml-mode)
"yaml-mode" nil t)
(push '("\\.yml$" . yaml-mode) auto-mode-alist))
(when (autoload-if-found '(json-mode)
"json-mode" nil t)
(push '("\\.json$" . json-mode) auto-mode-alist)
(with-eval-after-load "json-mode"
(add-hook 'before-save-hook #'my-json-mode-beautify)
(add-hook 'after-save-hook #'my-json-pretty-print-buffer)))
(when (autoload-if-found '(csv-mode)
"csv-mode" nil t)
(push '("\\.csv$" . csv-mode) auto-mode-alist))
(autoload-if-found '(ascii-on ascii-off) "ascii" nil t)
(when (autoload-if-found '(cc-mode)
"cc-mode" nil t)
(push '("\\.pde$" . java-mode) auto-mode-alist) ;; Processing
(push '("\\.java$" . java-mode) auto-mode-alist))
(when (autoload-if-found '(es-mode)
"es-mode" nil t)
(push '("\\.es$" . es-mode) auto-mode-alist))
(when (autoload-if-found '(markdown-mode)
"markdown-mode" nil t)
(push '("\\.markdown$" . markdown-mode) auto-mode-alist)
(push '("\\.md$" . markdown-mode) auto-mode-alist))
(when (autoload-if-found '(cmake-mode)
"cmake-mode" nil t)
(add-to-list 'auto-mode-alist '("CMakeLists\\.txt\\'" . cmake-mode))
(add-to-list 'auto-mode-alist '("\\.cmake\\'" . cmake-mode))
(with-eval-after-load "cmake-mode"
(unless (executable-find "cmake")
(message "--- cmake is NOT installed."))))
(when (autoload-if-found '(logview-mode)
"logview" nil t)
(push '("\\.log$" . logview-mode) auto-mode-alist))
;; 特定の拡張子・ディレクトリ
(defvar my-auto-view-regexp "\\.el.gz$\\|\\.patch$\\|\\.xml$\\|\\.gpg$\\|\\.csv$\\|\\.emacs.d/[^/]+/el-get\\|config")
(defvar my-auto-view-buffers '("*Messages*"))
;; 特定のディレクトリ(絶対パス・ホームディレクトリ以下)
(defvar my-auto-view-dirs nil)
(add-to-list 'my-auto-view-dirs "~/devel/emacs-head/emacs/")
(add-to-list 'my-auto-view-dirs "~/devel/git/org-mode/lisp/")
(when (eq window-system 'w32)
(add-to-list 'my-auto-view-dirs "c:/msys64/mingw64"))
;; (autoload 'my-auto-view "view" nil t)
(add-hook 'find-file-hook #'my-auto-view)
(with-eval-after-load "view"
;; note: messages-buffer-mode-hook may not work
(advice-add 'switch-to-buffer :after #'ad:switch-to-buffer)
(keymap-set view-mode-map "i" 'View-exit-and-edit)
(keymap-set view-mode-map "SPC" 'ignore)
(keymap-set view-mode-map "<delete>" 'ignore)
(keymap-set view-mode-map "S-SPC" 'mac-ime-toggle)
(keymap-set view-mode-map "e" 'my-view-exit)
(when (require 'helpful nil t)
(keymap-set view-mode-map "h" 'helpful-at-point))
(keymap-set view-mode-map "f" 'forward-char)
(keymap-set view-mode-map "b" 'backward-char)
(keymap-set view-mode-map "n" 'my-org-view-next-heading)
(keymap-set view-mode-map "p" 'my-org-view-previous-heading)
(keymap-set view-mode-map "g" #'my-google-this)
(keymap-set view-mode-map "<tab>" 'my-view-tab)
(keymap-set view-mode-map "S-<tab>" 'my-view-shifttab)
(unless my-toggle-modeline-global
(advice-add 'view--enable :before #'ad:view--enable)
(advice-add 'view--disable :before #'ad:view--disable)))
(when (autoload-if-found '(web-mode)
"web-mode" "web mode" t)
;; web-mode で開くファイルの拡張子を指定
(push '("\\.phtml\\'" . web-mode) auto-mode-alist)
(push '("\\.tpl\\.php\\'" . web-mode) auto-mode-alist)
(push '("\\.jsp\\'" . web-mode) auto-mode-alist)
(push '("\\.as[cp]x\\'" . web-mode) auto-mode-alist)
(push '("\\.erb\\'" . web-mode) auto-mode-alist)
(push '("\\.mustache\\'" . web-mode) auto-mode-alist)
(push '("\\.djhtml\\'" . web-mode) auto-mode-alist)
(push '("\\.html?\\'" . web-mode) auto-mode-alist)
(with-eval-after-load "web-mode"
(keymap-set web-mode-map "S-<tab>" 'my-web-indent-fold)
;; indent
(setq web-mode-markup-indent-offset 1)
;; 色の設定
(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.
'(web-mode-comment-face ((t (:foreground "#D9333F"))))
'(web-mode-css-at-rule-face ((t (:foreground "#FF7F00"))))
'(web-mode-css-pseudo-class-face ((t (:foreground "#FF7F00"))))
'(web-mode-css-rule-face ((t (:foreground "#A0D8EF"))))
'(web-mode-doctype-face ((t (:foreground "#82AE46"))))
'(web-mode-html-attr-name-face ((t (:foreground "#C97586"))))
'(web-mode-html-attr-value-face ((t (:foreground "#82AE46"))))
'(web-mode-html-tag-face ((t (:foreground "##4682ae" :weight bold))))
'(web-mode-server-comment-face ((t (:foreground "#D9333F")))))))
;;(autoload 'po-mode "po-mode+" nil nil)
;;(autoload 'po-mode "po-mode" nil t)
(when (autoload-if-found '(po-mode)
"po-mode" nil t)
(push '("\\.po[tx]?\\'\\|\\.po\\$" . po-mode) auto-mode-alist))
(when (autoload-if-found '(go-mode)
"go-mode" nil t)
(push '("\\.go\\'" . go-mode) auto-mode-alist))
(when (autoload-if-found '(ispell-region ispell-complete-word)
"ispell" nil t)
;; Spell checking within a specified region
(keymap-global-set "C-c f 7" 'ispell-region)
;; 補完候補の表示(flyspell が使える時はそちらを優先して <f7> にする.
(keymap-global-set "<f7>" 'ispell-word)
(with-eval-after-load "ispell"
;; This could hild other messages from loading functions regarding org-mode.
(advice-add 'ispell-init-process :around #'ad:suppress-message)
;; for English and Japanese mixed
(add-to-list 'ispell-skip-region-alist '("[^\000-\377]+"))
;; http://endlessparentheses.com/ispell-and-org-mode.html
(add-to-list 'ispell-skip-region-alist '("^#\\+begin_src" . "^#\\+end_src"))
(add-to-list 'ispell-skip-region-alist '("~" "~"))
(add-to-list 'ispell-skip-region-alist '("=" "="))
(add-to-list 'ispell-skip-region-alist '(org-property-drawer-re))
(setq ispell-encoding8-command t)
(cond
((executable-find "hunspell")
;; (setenv "LC_ALL" "en_US") ;; Don't use this line.
;; (setq ispell-extra-args '("--lang=en_US"))
;; (setenv "DICPATH" "/Applications/LibreOffice.app/Contents/Resources/extensions/dict-en")
(setenv "DICPATH" (concat (getenv "SYNCROOT") "/emacs.d/hunspell/dict-en"))
(setq ispell-local-dictionary-alist
'(("ja_JP" "[[:alpha:]]" "[^[:alpha:]]" "[']" nil
("-d" "en_US") nil utf-8)
("en_US" "[[:alpha:]]" "[^[:alpha:]]" "[']" nil
("-d" "en_US") nil utf-8)))
(setq ispell-local-dictionary "en_US")
(setq ispell-dictionary ispell-local-dictionary)
(setq ispell-hunspell-dictionary-alist ispell-local-dictionary-alist)
(if shutup-p
;; 必要.しかも ispell-program-name 指定の前で.
;; ただし,ispell-local-dictionary-alist の後で.
(shut-up (ispell-change-dictionary "en_US" t))
(ispell-change-dictionary "en_US" t))
(setq-default ispell-program-name (executable-find "hunspell"))
;; Not regal way, but it's OK (usually ispell-local-dictionary-alist)
(setq ispell-personal-dictionary
(concat (getenv "SYNCROOT") "/emacs.d/hunspell.en.dic")))
((executable-find "aspell")
;; (message "--- aspell loaded.")
(setq-default ispell-program-name "aspell")
;; (when (eq window-system 'w32)
;; (setq-default ispell-program-name
;; "C:/Program Files/Aspell/bin/aspell.exe"))
(setq ispell-dictionary "english")
;; This will also avoid an IM-OFF issue for flyspell-mode.
;; (setq ispell-aspell-supports-utf8 t) ;; Obsolete
(setq ispell-local-dictionary-alist
'((nil "[a-zA-Z]" "[^a-zA-Z]" "'" t
("-d" "en" "--encoding=utf-8") nil utf-8)))
(setq ispell-personal-dictionary
(concat (getenv "SYNCROOT") "/emacs.d/config/aspell.en.pws")))
(t
nil))))
(when (autoload-if-found '(flyspell-mode-on
flyspell-prog-mode flyspell-mode my-flyspell-on)
"flyspell" nil t)
(defvar major-mode-with-flyspell
'(text-mode change-log-mode latex-mode yatex-mode
git-commit-mode org-mode))
(defvar major-mode-with-flyspell-prog
'(c-mode-common emacs-lisp-mode perl-mode python-mode))
(defvar my-flyspell-target-modes
(append major-mode-with-flyspell
major-mode-with-flyspell-prog))
;; バッファ内の全てをチェック対象にするモードの hook に flyspell 起動を登録
(dolist (hook major-mode-with-flyspell)
(add-hook (intern (format "%s-hook" hook)) #'flyspell-mode))
;; コメント行のみをチェック対象にする
(dolist (hook major-mode-with-flyspell-prog)
(add-hook (intern (format "%s-hook" hook)) #'flyspell-prog-mode))
(with-eval-after-load "flyspell"
;; C-; をオーバーライド
(keymap-set flyspell-mode-map "C-;" 'comment-dwim)
(setq flyspell-duplicate-distance 0)
;; (setq flyspell-mode-line-string " F")
(setq flyspell-mode-line-string "")
;; (setq flyspell-large-region 200)
(set-face-attribute 'flyspell-duplicate nil
:foreground "#EA5506" :bold t
:background 'unspecified :underline t)
(set-face-attribute 'flyspell-incorrect nil
:foreground "#BA2636" :bold nil
:background 'unspecified :underline t)
;; ispell-complete-word のキーバインドを上書き
(keymap-global-set "<f7>" 'flyspell-correct-at-point)
;; ivy を用いる
(when (require 'flyspell-correct-ivy nil t)
(setq flyspell-correct-interface #'flyspell-correct-ivy))
;; Auto complete との衝突を回避
(with-eval-after-load "auto-complete"
(ac-flyspell-workaround))
;; [FIXME] nextstep+inline-patch版で flyspell すると,日本語nyuuのようになる場合があるので,それを回避(IME が ONになったら一時的に flyspell を止める)
(add-hook 'input-method-activate-hook #'my-flyspell-off)
(add-hook 'input-method-deactivate-hook #'my-flyspell-on)))
(autoload-if-found '(counsel-world-clock) "counsel-world-clock" nil t)
(when (autoload-if-found '(latex-math-preview-expression
latex-math-preview-insert-symbol
latex-math-preview-save-image-file
latex-math-preview-beamer-frame)
"latex-math-preview" nil t nil)
(keymap-global-set "<f6>" 'latex-math-preview-expression)
(with-eval-after-load "latex-math-preview"
(setq latex-math-preview-command-path-alist
'((latex . "latex")
(dvipng . "dvipng")
(dvips . "dvips")))
(keymap-set latex-math-preview-expression-mode-map "<f6>"
'latex-math-preview-delete-buffer)))
(when (autoload-if-found '(yatex-mode)
"yatex" "Yet Another LaTeX mode" t)
(push '("\\.tex$" . yatex-mode) auto-mode-alist)
(with-eval-after-load "yatex"
;; Disable auto line break
(add-hook 'yatex-mode-hook
(lambda ()
(setq auto-fill-function nil)))
;; 1=Shift JIS, 2=JIS, 3=EUC, 4=UTF-8
;; (setq YaTeX-kanji-code nil)
(modify-coding-system-alist 'file "\\.tex$'" 'utf-8)
(keymap-set YaTeX-mode-map "C-M-SPC" 'mark-sexp)
(keymap-set YaTeX-mode-map "C-M-@" 'mark-sexp)))
(with-eval-after-load "yatex"
(put 'YaTeX-insert-braces 'begend-guide 2)
(advice-add 'YaTeX-insert-begin-end :override #'ad:YaTeX-insert-begin-end))
(with-eval-after-load "yasnippet"
(require 'ivy-yasnippet nil t))
(when (autoload-if-found '(osx-dictionary-search-pointer
osx-dictionary-search-input)
"osx-dictionary" nil t)
(keymap-global-set "C-M-w" #'osx-dictionary-search-pointer)
(keymap-global-set "C-c f w" #'osx-dictionary-search-input)
(with-eval-after-load "osx-dictionary"
(custom-set-variables
'(osx-dictionary-dictionary-choice "英辞郎 第七版"))))
(when (autoload-if-found '(js2-mode)
"js2-mode" nil t)
(with-eval-after-load "js2-mode"
(if (executable-find "js-beautify")
(when (require 'web-beautify nil t)
(keymap-set js2-mode-map "C-c b" 'web-beautify-js)
(keymap-set js2-mode-map "C-c b" 'web-beautify-css))
(message "--- js-beautify is NOT installed.")
(message "--- Note: brew install node")
(message "--- npm -g install js-beautify"))))
(when (autoload-if-found '(smartparens-global-mode
turn-on-show-smartparens-mode)
"smartparens" nil t)
(add-hook 'yatex-mode-hook #'my-smartparens-mode)
(add-hook 'org-mode-hook #'my-smartparens-mode) ;; FIXME use activate()?
(with-eval-after-load "smartparens"
(setq-default sp-highlight-pair-overlay nil)
(setq-default sp-highlight-wrap-overlay nil)
(setq-default sp-highlight-wrap-tag-overlay nil)
(sp-pair "`" nil :actions :rem)
(sp-pair "'" nil :actions :rem)
(sp-pair "[" nil :actions :rem)
(sp-local-pair 'org-mode "=" "=")
(sp-local-pair 'org-mode "$" "$" :actions '(wrap)) ;; 選択時のみ有効
(sp-local-pair 'org-mode "'" "'" :actions '(wrap)) ;; 選択時のみ有効
(sp-local-pair 'org-mode "<" ">" :actions '(wrap)) ;; 選択時のみ有効
(sp-local-pair 'org-mode "_" "_" :actions '(wrap)) ;; 選択時のみ有効
(sp-local-pair 'org-mode "~" "~" :actions '(wrap)) ;; 選択時のみ有効
(sp-local-pair 'org-mode "[" "]" :actions '(wrap)) ;; 選択時のみ有効
(sp-local-pair 'org-mode "+" "+" :actions '(wrap)) ;; 選択時のみ有効
(sp-local-pair 'org-mode "/" "/" :actions '(wrap)) ;; 選択時のみ有効
(sp-local-pair 'org-mode "*" "*" :actions '(wrap)) ;; 選択時のみ有効
(sp-local-pair 'yatex-mode "$" "$" :actions '(wrap))))
(when (autoload-if-found '(grugru-default grugru)
"grugru-default" nil t)
(keymap-global-set "C-9" #'grugru)
(with-eval-after-load "grugru-default"
(custom-set-faces
'(grugru-edit-completing-function #'ivy-completing-read)
'(grugru-highlight-face ((t (:bold t :underline "#FF3333"))))
'(grugru-highlight-idle-delay 1))
(add-hook 'grugru-before-hook #'my-unlock-view-mode)
(add-hook 'grugru-after-hook #'save-buffer)
(add-hook 'ah-after-move-cursor-hook #'grugru--highlight-remove)
(grugru-define-on-major-mode 'org-mode 'word '("TODO" "DONE"))
(grugru-define-global 'word '("True" "False"))
(grugru-define-global 'word '("TRUE" "FALSE")) ;; FIXME
(grugru-default-setup)
(grugru-find-function-integration-mode 1)
(grugru-highlight-mode 1)))
(autoload-if-found '(query-replace-from-region query-replace-regexp-from-region)
"replace-from-region" nil t)
(autoload-if-found '(embark-act) "embark" nil t)
(when (autoload-if-found '(selected-global-mode)
"selected" nil t)
(add-hook 'activate-mark-hook #'my-activate-selected)
(with-eval-after-load "selected"
(keymap-set selected-keymap "a" #'embark-act)
(keymap-set selected-keymap ";" #'comment-dwim)
(keymap-set selected-keymap "e" #'my-eval-region)
(keymap-set selected-keymap "E" #'my-eval-region-as-function)
;; (keymap-set selected-keymap "=" #'count-words-region)
(when (require 'helpful nil t)
(keymap-set selected-keymap "h" #'helpful-at-point)
(keymap-set selected-keymap "v" #'my-helpful-variable))
(keymap-set selected-keymap "w" #'osx-dictionary-search-pointer)
(keymap-set selected-keymap "d" #'osx-dictionary-search-pointer)
(keymap-set selected-keymap "5" #'query-replace-from-region)
(keymap-set selected-keymap "g" #'my-google-this)
(keymap-set selected-keymap "s" #'osx-lib-say-region)
(keymap-set selected-keymap "q" #'selected-off)
(keymap-set selected-keymap "x" #'my-hex-to-decimal)
(keymap-set selected-keymap "X" #'my-decimal-to-hex)
;; (defun my-eval-region ()
;; (interactive)
;; (when (use-region-p)
;; (eval-region (region-beginning) (region-end) t)))
(setq selected-org-mode-map (make-sparse-keymap))
(keymap-set selected-org-mode-map "t" #'org-toggle-checkbox)
(keymap-set selected-org-mode-map "-" #'my-org-bullet-and-checkbox)
(when (require 'expand-region nil t)
(keymap-set selected-keymap "SPC" #'er/expand-region))
(when (require 'counsel-selected nil t)
(keymap-set selected-keymap "l" 'counsel-selected))
(when (require 'help-fns+ nil t)
(keymap-set selected-keymap "H" #'my-describe-selected-keymap))))
(when (autoload-if-found '(git-complete)
"git-complete" nil t)
(keymap-global-set "C-c f <tab>" 'git-complete))
(when (autoload-if-found '(bratex-config)
"bratex" nil t)
(add-hook 'yatex-mode-hook #'bratex-config))
(setq echo-keystrokes 0.5)
(defvar my-narrow-modeline '("#426EBB" "#FFFFFF")) ;; background, foreground
(defvar my-buffer-narrowed-last nil)
(make-local-variable 'my-buffer-narrowed-last)
(defvar my-selected-window-last nil)
(add-hook 'buffer-list-update-hook #'my-update-modeline-face)
(setq mode-line-modes
(mapcar
(lambda (entry)
(if (equal entry "%n")
'(:eval (progn
;; org が widen を乱発するのでこちらをトリガーにする.
;; 色の変更
(my-update-modeline-color)
;; "Narrow" を "N" に短縮表示
(if (and (buffer-narrowed-p)
(fboundp 'icons-in-terminal-octicon))
(concat " " (icons-in-terminal-octicon
"fold" :v-adjust 0.0)) "")))
entry))
mode-line-modes))
(when (require 'mlscroll nil t)
(custom-set-variables
'(mlscroll-in-color "light coral") ;; #FFA07A
'(mlscroll-out-color "#FFFFEF")
'(mlscroll-width-chars 10))
(unless noninteractive
(mlscroll-mode 1))
(with-eval-after-load "moom"
(add-hook 'moom-font-after-resize-hook #'my-reload-mlscroll)
(add-hook 'moom-after-reset-hook #'my-reload-mlscroll)))
(with-eval-after-load "icons-in-terminal"
;; 変更がアリ時は赤アイコン,そうでない時に緑アイコンをモードラインに表示
(make-face 'mode-line-vc-normal-face)
(make-face 'mode-line-vc-modified-face)
(set-face-attribute 'mode-line-vc-normal-face nil :foreground "#AFFFAF")
(set-face-attribute 'mode-line-vc-modified-face nil :foreground "#EEAFAF"))
(with-eval-after-load "bindings" ;; "bindings"
(let ((vc (assq 'vc-mode mode-line-format)))
;; (message "--- %s" vc)
(when vc (setcdr vc '((:eval (my-mode-line-vc-mode-icon)))))))
(unless noninteractive
(my-empty-booting-header-line)) ;; Update header of scratch buffer
(unless (display-graphic-p)
;; ターミナルの縦分割線をUTF-8できれいに描く
(add-hook 'window-configuration-change-hook 'my-change-window-divider))
;; Show line number in the mode line.
(unless noninteractive
(line-number-mode 1))
(when (autoload-if-found '(my-toggle-display-line-numbers-mode)
"display-line-numbers" nil t)
(keymap-global-set "C-<f12>" 'my-toggle-display-line-numbers-mode)
(with-eval-after-load "hl-line"
(my-update-display-line-numbers-face)
(add-hook 'my-ime-off-hline-hook #'my-update-display-line-numbers-face)
(add-hook 'my-ime-on-hline-hook #'my-update-display-line-numbers-face))
(with-eval-after-load "display-line-numbers"
(require 'moom nil t)
(custom-set-faces
'(line-number-current-line
((t (:bold t)))))
(custom-set-variables
'(display-line-numbers-width-start t))
;; ウィンドウ左に表示する行数の幅を5以上に固定する.
(add-hook 'display-line-numbers-mode-hook
#'my-display-line-numbers-width)))
(setq line-number-display-limit-width 100000)
;; モードラインの行数表示の前にアイコンを追加
(with-eval-after-load "icons-in-terminal"
(setq mode-line-position-line-format
`(,(icons-in-terminal-material "edit") "%3l")))
;; Show clock in in the mode line
(setq display-time-format "%H:%M w%V") ;; %y%m%d. ;; "%H%M.%S"
(setq display-time-interval 1)
(setq display-time-default-load-average nil)
(unless noninteractive
(display-time-mode 1))
;; スペース
(defface my-face-b-1
'((t (:background "gray" :bold t :underline "red")))
nil :group 'font-lock-highlighting-faces)
;; タブだけの行
(defface my-face-b-2
'((t (:background "orange" :bold t :underline "red")))
nil :group 'font-lock-highlighting-faces)
;; 半角スペース
(defface my-face-b-3 '((t (:background "orange")))
nil :group 'font-lock-highlighting-faces)
(advice-add 'font-lock-mode :before #'ad:font-lock-mode)
(unless (version< emacs-version "28.0")
;; 全角スペース" "にデフォルトで黒下線が付くのを回避する
(setq nobreak-char-display nil))
;; 改行文字の文字列表現
(set 'eol-mnemonic-dos "CRLF")
(set 'eol-mnemonic-unix "LF")
(set 'eol-mnemonic-mac "CR")
(set 'eol-mnemonic-undecided "?")
(make-face 'mode-line-file-icon-face)
(custom-set-faces
'(mode-line-file-icon-face
((((background dark)) :foreground "VioletRed1")
(t (:foreground "LightGoldenrod1")))))
;; `mode-line-mule-info' の文字エンコーディングの文字列表現を差し替える
(setq-default mode-line-mule-info
(cl-substitute '(:eval (my-buffer-coding-system-mnemonic))
"%z" mode-line-mule-info :test 'equal))
(add-hook 'find-file-hook #'my-delight-activate)
(with-eval-after-load "delight"
(delight
'(;; Major modes
;; (c-mode "C" :major)
;; (c++mode "C++" :major)
(js2-mode "JS" :major)
(csharp-mode "C#" :major)
(prog-mode "Pr" :major)
(emacs-lisp-mode "El" :major)
(python-mode "Py" :major)
(perl-mode "Pl" :major)
(web-mode "W" :major)
(change-log-mode "CLog" :major)
(lisp-interaction-mode "Lisp" :major)
;; Shorten for minor modes
(ggtags-mode " G" "ggtags")
;; (orgstruct-mode " OrgS" "org")
(orgalist-mode " ol" "orgalist")
(view-mode " V" "view")
;; Stop to display for minor modes
(org-fancy-priorities-mode nil "org-fancy-priorities")
(smooth-scroll-mode nil "smooth-scroll")
(eldoc-mode nil "eldoc")
(ivy-mode nil "ivy")
(counsel-mode nil "counsel")
(centered-cursor-mode nil "centered-cursor-mode")
(volatile-highlights-mode nil "volatile-highlights")
(aggressive-indent-mode nil "aggressive-indent")
(all-the-icons-dired-mode nil "all-the-icons-dired")
(icons-in-terminal-dired-mode nil "icons-in-terminal-dired")
(yas-minor-mode nil "yasnippet")
(auto-complete-mode nil "auto-complete")
(company-mode nil "company")
(ws-butler-mode nil "ws-butler")
(isearch-mode nil "isearch")
(auto-revert-mode nil "autorevert")
(global-whitespace-mode nil "whitespace")
(emmet-mode nil "emmet-mode")