-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathinit.el
2033 lines (1831 loc) · 81.1 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
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
;;; init.el --- emacs configuration. -*- lexical-binding: t -*-
;;; Code:
(defvar tv:startup-time (current-time))
(defun tv:emacs-load-time ()
(let ((time (float-time (time-subtract (current-time) tv:startup-time))))
(message "Emacs config loaded in %s seconds"
(format "%.2f" time))))
;;; Packages.el config.
;;
(defun tv:fix-selected-packages ()
(interactive)
(package-initialize)
(package--save-selected-packages (package--find-non-dependencies)))
;;; load-path
;;
(defun tv:add-subdirs-to-load-path (dir)
(let ((default-directory (file-name-as-directory
(expand-file-name dir))))
(normal-top-level-add-subdirs-to-load-path)
(add-to-list 'load-path (expand-file-name dir))))
(tv:add-subdirs-to-load-path "~/elisp")
;;; gcmh-mode disable GC and increase gc-cons-threshold while not idle,
;; when idle, restore gc-cons-threshold and run GC after
;; gcmh-idle-delay seconds or (* gcmh-auto-idle-delay-factor
;; gcmh-last-gc-time) if set to auto.
(autoload 'gcmh-mode "gcmh.el") ; Installed in ~/elisp.
(with-eval-after-load 'gcmh
(setq gcmh-idle-delay 'auto))
(gcmh-mode 1)
(with-eval-after-load 'find-func
(setq find-library-include-other-files nil))
;;; Emacs customize own file
;;
(setq custom-file "~/.emacs.d/.emacs-custom.el")
(load custom-file)
;;; VC
;;
;; Possible values for vc backends: (RCS CVS SVN SCCS Bzr Git Hg Mtn Arch)
(setq vc-handled-backends nil)
;; Let's psession loading buffers before setting this (much faster).
;; When it is needed to run e.g. vc-annotate revert buffer before proceding.
(add-hook 'emacs-startup-hook (lambda ()
(setq vc-handled-backends '(RCS Git)
vc-follow-symlinks t
vc-ignore-dir-regexp
(format "\\(%s\\)\\|\\(%s\\)"
vc-ignore-dir-regexp
tramp-file-name-regexp)))
100)
;;; Global settings
;;
;; Disable annoying bindings
(global-set-key (kbd "C-z") nil) ; Disable `suspend-frame'.
(global-set-key (kbd "<f11>") nil) ; Disable `toggle-frame-fullscreen'
;; Prevent emacs warning when hitting <XF86TouchpadOff> and
;; <XF86TouchpadOn> to disable/enabling TouchPad.
(define-key global-map (kbd "<XF86TouchpadOff>") (lambda () (interactive) (message "TouchPad disabled")))
(define-key global-map (kbd "<XF86TouchpadOn>") (lambda () (interactive) (message "TouchPad reenabled")))
;; Revert-buffer
(defun tv:revert-buffer-no-query ()
(interactive)
;; Try to save excursion as Emacs-29 moves point nowhere after
;; reverting.
(save-excursion
(revert-buffer t t)))
(global-set-key (kbd "C-c R") #'tv:revert-buffer-no-query)
;; y-or-n-p everywhere
(fset 'yes-or-no-p 'y-or-n-p)
;; Stop/restart emacs
(defun tv:stop-emacs-1 ()
(if (daemonp)
(save-buffers-kill-emacs)
(save-buffers-kill-terminal)))
(defun tv:stop-emacs (arg)
"Close emacs, with a prefix arg restart it.
Restart works only on graphic display."
(interactive "P")
(let ((confirm-kill-emacs (unless (and arg (display-graphic-p))
'y-or-n-p))
(kill-emacs-query-functions
(if (and arg (display-graphic-p))
(append (list
(lambda ()
(when (y-or-n-p (format "Really restart %s? "
(capitalize (invocation-name))))
(add-hook 'kill-emacs-hook
(lambda ()
(call-process-shell-command
(format "(%s &)"
;; eselect-emacs.sh
;; should have kept
;; only one of
;; emacs/remacs.
(or (executable-find "emacs")
(executable-find "remacs")))))
t))))
kill-emacs-query-functions)
kill-emacs-query-functions)))
(tv:stop-emacs-1)))
(global-set-key [remap save-buffers-kill-terminal] 'tv:stop-emacs) ; C-x C-c
;; Add newline at end of files
(setq require-final-newline t)
;; Limit max lisp
(setq max-lisp-eval-depth 40000
max-specpdl-size 100000)
;; Disable bidi
;; (setq-default bidi-display-reordering nil)
(setq-default bidi-paragraph-direction 'left-to-right)
;; column-number in mode-line.
(column-number-mode 1)
;; Environment variables
;;
;; grep matches with background yellow and foreground black
(setenv "GREP_COLORS" "ms=30;43:mc=30;43:sl=01;37:cx=:fn=35:ln=32:bn=32:se=36")
;; For eshell env settings.
(setenv "STARDICT_DATA_DIR" "~/.stardict/dic")
;; Coding system.
(prefer-coding-system 'utf-8)
;; Themes
(setq custom-theme-directory "~/.emacs.d/themes/")
(add-hook 'emacs-startup-hook (lambda () (load-theme 'naquadah t)))
;;; emacs-backup-config
;;
(defun tv:backup-file-p (file)
(and (normal-backup-enable-predicate file)
(null (locate-dominating-file file ".git"))))
(setq backup-directory-alist '(("" . "~/.emacs.d/emacs_backup"))
backup-enable-predicate #'tv:backup-file-p
backup-by-copying t
version-control t
vc-make-backup-files nil
kept-old-versions 2
kept-new-versions 20
delete-old-versions t)
(setq tramp-backup-directory-alist backup-directory-alist)
;; Start-emacs-server
;;
(autoload 'server-running-p "server")
(add-hook 'after-init-hook (lambda ()
(unless (or (daemonp) (server-running-p))
(server-start)
(setq server-raise-frame t))))
;; Copy/paste
(setq select-active-regions t)
(setq x-select-enable-clipboard-manager nil
;; save-interprogram-paste-before-kill 72
select-enable-clipboard t
select-enable-primary nil)
(defun tv:mark-symbol-at-point ()
(interactive)
(let ((bounds (bounds-of-thing-at-point 'symbol)))
(cl-assert bounds nil "No symbol at point")
(goto-char (car bounds))
(push-mark (cdr bounds) nil t)))
;; I don't use cycle-spacing (M-SPC)
(global-set-key (kbd "M-SPC") #'tv:mark-symbol-at-point)
;; Enable some commands disabled by default
(put 'narrow-to-region 'disabled nil) ; C-x n n
(put 'narrow-to-page 'disabled nil) ; C-x n p
(put 'scroll-left 'disabled nil) ; C-x > or <
(put 'downcase-region 'disabled nil) ; C-x C-l
(put 'upcase-region 'disabled nil) ; C-x C-u
(put 'set-goal-column 'disabled nil) ; C-x C-n ==> disable with C-u
(put 'dired-find-alternate-file 'disabled nil) ; a in dired
;; setup-minibuffer
(setq enable-recursive-minibuffers t)
(minibuffer-depth-indicate-mode 1)
;; Remove message and error popping up at end of active minibuffer in
;; emacs-27.
(when (boundp 'minibuffer-message-clear-timeout) ; Emacs-27+
;; (setq minibuffer-message-clear-timeout 1.5)
(setq set-message-function nil
clear-message-function nil)
(remove-hook 'minibuffer-setup-hook 'minibuffer-error-initialize))
(setq report-emacs-bug-no-explanations t
comint-prompt-read-only t
uniquify-buffer-name-style nil
inhibit-startup-message t
message-log-max 1000
kill-ring-max 120
mark-ring-max 60
global-mark-ring-max 200)
;; Disable indent-tabs-mode
(setq-default indent-tabs-mode nil)
;; Disable all isearch bindings
(global-set-key [remap isearch-forward] 'undefined)
(global-set-key [remap isearch-backward] 'undefined)
(global-set-key [remap isearch-forward-regexp] 'undefined)
(global-set-key [remap isearch-backward-regexp] 'undefined)
(global-set-key (kbd "C-r") nil)
(global-set-key (kbd "C-s") nil)
(global-set-key (kbd "C-M-s") nil)
(global-set-key (kbd "C-M-r") nil)
;; `while-no-input-ignore-events' is not set in emacs-27+ (bug#46940).
(unless (and (boundp 'while-no-input-ignore-events)
while-no-input-ignore-events)
(setq while-no-input-ignore-events
'(focus-in
focus-out
help-echo
iconify-frame
make-frame-visible
selection-request)))
;; Don't beep even with visible-bell (debian)
(setq ring-bell-function 'ignore)
;; moves point by logical lines.
(setq line-move-visual nil)
;; Align-regexp
(global-set-key (kbd "C-}") #'align-regexp)
;; Move to bol or back-to-indentation depending of context.
(defun tv:bol-or-back-to-indentation ()
"Move to bol or indentation depending of context."
(interactive)
(if (and (derived-mode-p 'prog-mode)
(or (bolp)
(save-excursion (re-search-backward "[^[:blank:]]" (pos-bol) t))))
(back-to-indentation)
(move-beginning-of-line 1)))
(global-set-key (kbd "C-a") #'tv:bol-or-back-to-indentation)
;;; Compatibility
;;
;;
;; For `osm' in skitour (open street map)
(unless (fboundp 'json-available-p)
(defun json-available-p ()
(fboundp 'json-parse-string)))
;;;; Package configurations.
;;; History
;;
(setq history-delete-duplicates t)
(setq history-length 100)
(put 'file-name-history 'history-length 1000)
;; Limit M-x history to 50.
(put 'extended-command-history 'history-length 50)
;;; Isearch-light (Installed in site-lisp with make)
;;
(load "isl-autoloads")
(global-set-key (kbd "C-s") 'isl-search)
(global-set-key (kbd "C-z") 'isl-narrow-to-defun)
(global-set-key (kbd "C-M-s") 'isl-resume)
(with-eval-after-load 'isl
(setq isl-before-position-string "≤"
isl-after-position-string "≥"))
;;; Info
;;
;; Cleanup `Info-directory-list'.
;; When an empty string is in `Info-directory-list' info search by
;; default in .emacs.d, and if it finds a file with same name as
;; the info file it uses it even if it is not an info file, e.g. tramp.
(with-eval-after-load 'info
(setq Info-directory-list (delete "" Info-directory-list))
;; Additional info directories
(add-to-list 'Info-directory-list "/usr/local/share/info")
(add-to-list 'Info-directory-list "/usr/share/info")
(add-to-list 'Info-directory-list "~/elisp/info")
;; Fancy faces in info.
(defface tv:info-ref-item
'((((background dark)) :background "DimGray" :foreground "Gold")
(((background light)) :background "firebrick" :foreground "LightGray"))
"Face for item stating with -- in info." :group 'Info :group 'faces)
(defvar tv:info-title-face 'tv:info-ref-item)
(defvar tv:info-underline 'underline)
(defvar info-unicode-quote-start (string 8216))
(defvar info-unicode-quote-end (string 8217))
(defvar info-unicode-quoted-regexp (format "[%s]\\([^%s%s]+\\)[%s]"
info-unicode-quote-start
info-unicode-quote-start
info-unicode-quote-end
info-unicode-quote-end
))
(defun tv:font-lock-doc-rules ()
(font-lock-add-keywords
nil `(("[^][\\s`]\\([^[](`'+\\)`']?[^][\\s']?" 1 font-lock-type-face)
(,info-unicode-quoted-regexp 1 font-lock-type-face)
("^ --.*$" . tv:info-title-face)
(" [_]\\([^_]+\\)[_] " 1 tv:info-underline)
("[\"]\\([^\"]*\\)[\"]" . font-lock-string-face)
("\\*Warning:\\*" . font-lock-warning-face)
("^ *\\([*•]\\) " 1 font-lock-variable-name-face)
("^[[:upper:],]\\{2,\\}$" . font-lock-comment-face)
("^[[:upper]][a-z- ]*:" . font-lock-variable-name-face)
)))
(add-hook 'Info-mode-hook 'tv:font-lock-doc-rules)
(define-key Info-mode-map [remap Info-index] 'helm-info-at-point))
;;; Async
;;
;; Need to be called before helm config.
;; Temporary fix for emacs bug 58919.
(when (< emacs-major-version 29)
(with-eval-after-load 'async
(setq async-child-init "~/.emacs.d/fix-copy-directory.el")))
;; Dired async.
(autoload 'dired-async-mode "dired-async" nil t)
(dired-async-mode 1)
;; async-bytecomp
(autoload 'async-byte-recompile-directory "async-bytecomp")
(autoload 'async-byte-compile-file "async-bytecomp")
;;; Helm
;;
(autoload 'helm-define-key-with-subkeys "helm-core")
(require 'init-helm)
;;; Term - ansi-term
;;
;; Kill buffer after C-d in ansi-term.
(defun tv:advice-term-sentinel (&rest _args) (kill-buffer))
(advice-add 'term-sentinel :after #'tv:advice-term-sentinel)
(defun tv:term ()
(interactive)
(ansi-term "/bin/bash"))
(global-set-key (kbd "<f11> t") 'tv:term)
;; Browse url
;;
;;
(with-eval-after-load 'browse-url
;; See avail browser at ~/work/github/helm/helm-net.el:253
(setq browse-url-firefox-program "firefox"
browse-url-browser-function 'helm-browse-url-firefox))
;;; Dif/Ediff
;;
(setq ediff-window-setup-function 'ediff-setup-windows-plain
ediff-split-window-function 'split-window-horizontally
ediff-show-ancestor nil)
;; Fix unreadable diff/ediff in emacs-27+
(when (>= emacs-major-version 27)
(with-eval-after-load 'diff-mode
(set-face-attribute 'diff-refine-added nil :background 'unspecified)
(set-face-attribute 'diff-refine-removed nil :background 'unspecified)
(set-face-attribute 'diff-refine-changed nil :background 'unspecified))
(with-eval-after-load 'ediff-init
(set-face-attribute 'ediff-fine-diff-A nil :background 'unspecified)
(set-face-attribute 'ediff-fine-diff-B nil :background 'unspecified))
(with-eval-after-load 'hl-line
(set-face-attribute 'hl-line nil :extend t))
(set-face-attribute 'region nil :extend t))
;; diff buffers read-only
(setq diff-default-read-only t)
;;; Save place
;;
(autoload 'tv-save-place-mode "tv-save-place" nil t)
(tv-save-place-mode 1)
;;; Byzanz - screencast ffrom Emacs
;;
(autoload 'byzanz-record "tv-byzanz" nil t)
;;; wttr weather
;;
(autoload 'wttr-weather "wttr-weather" nil t)
;;; tv-utils functions.
;;
;; TODO: Make an autoload file for emacs-config dir.
(autoload 'tv:restore-scratch-buffer "tv-utils" nil t)
(autoload 'tv:insert-double-quote "tv-utils" nil t)
(autoload 'tv:insert-vector "tv-utils" nil t)
(autoload 'tv:insert-double-backquote "tv-utils" nil t)
(autoload 'tv:move-pair-forward "tv-utils" nil t)
(autoload 'tv:insert-double-quote-and-close-forward "tv-utils" nil t)
(autoload 'tv:insert-pair-and-close-forward "tv-utils" nil t)
(autoload 'tv:toggle-calendar "tv-utils" nil t)
(autoload 'tv:kill-whole-line "tv-utils" nil t)
(autoload 'tv:kill-line "tv-utils" nil t)
(autoload 'tv:delete-char "tv-utils" nil t)
(autoload 'tv:delete-char "tv-utils" nil t)
(autoload 'other-window-backward "tv-utils" nil t)
(autoload 'other-window-forward "tv-utils" nil t)
(autoload 'tv:scroll-down "tv-utils" nil t)
(autoload 'tv:scroll-up "tv-utils" nil t)
(autoload 'tv:scroll-other-down "tv-utils" nil t)
(autoload 'tv:scroll-other-up "tv-utils" nil t)
(autoload 'tv:insert-kbd-at-point "tv-utils" nil t)
(autoload 'tv:eval-region "tv-utils" nil t)
(autoload 'tv:mount-sshfs "tv-utils" nil t)
(define-key lisp-interaction-mode-map (kbd "C-M-!") 'tv:eval-region)
(define-key emacs-lisp-mode-map (kbd "C-M-!") 'tv:eval-region)
(global-set-key (kbd "M-\"") 'tv:insert-double-quote)
(global-set-key (kbd "M-[") 'tv:insert-vector)
(global-set-key (kbd "C-M-`") 'tv:insert-double-backquote)
(global-set-key (kbd "C-M-(") 'tv:move-pair-forward)
(global-set-key (kbd "C-M-\"") 'tv:insert-double-quote-and-close-forward)
(global-set-key (kbd "C-M-)") 'tv:insert-pair-and-close-forward)
(global-set-key (kbd "<f5> c") 'tv:toggle-calendar)
(global-set-key [remap kill-whole-line] 'tv:kill-whole-line)
(global-set-key [remap kill-line] 'tv:kill-line)
(global-set-key [remap delete-char] 'tv:delete-char)
(global-set-key [remap c-electric-delete-forward] 'tv:delete-char)
(global-set-key (kbd "C-<") 'other-window-backward)
(global-set-key (kbd "C->") 'other-window-forward)
(global-set-key (kbd "<M-down>") 'tv:scroll-down)
(global-set-key (kbd "<M-up>") 'tv:scroll-up)
(global-set-key (kbd "<C-M-down>") 'tv:scroll-other-down)
(global-set-key (kbd "<C-M-up>") 'tv:scroll-other-up)
(global-set-key (kbd "C-c k") 'tv:insert-kbd-at-point)
;;; Help
;;
;; Fix curly quotes in emacs-25
(when (boundp 'text-quoting-style)
(setq text-quoting-style 'grave))
;; Advice describe-variable.
(require 'describe-variable)
(define-key help-mode-map (kbd "C-c e") 'tv:pp-value-in-help)
;;; comment
;;
(define-key global-map (kbd "C-M-;") 'next-line)
(with-eval-after-load 'newcomment
(setq comment-style 'plain)
;; Change the behavior of `M-;' by commenting line.
;; Much simpler than emacs-25 `comment-line'.
(defun comment--advice-dwim (old--fn &rest args)
(if (region-active-p)
(apply old--fn args)
(let ((bol (point-at-bol))
(eol (point-at-eol)))
(save-excursion
(goto-char bol)
(push-mark eol t t)
(unless (eql bol eol)
(apply old--fn args)))
(indent-region bol eol)
(forward-line 1)
(back-to-indentation))))
(advice-add 'comment-dwim :around 'comment--advice-dwim))
;;; Woman/man
;;
(with-eval-after-load 'woman
(setq woman-use-own-frame nil))
(with-eval-after-load 'man
(setq Man-notify-method 'pushy)
;; Get rid of the most of the time unuseful default.
(advice-add 'Man-default-man-entry :override #'ignore))
;;; show-paren-mode
;;
(with-eval-after-load 'paren
(show-paren-mode 1)
(setq show-paren-ring-bell-on-mismatch t))
;;; Electric-mode (disable)
;;
(with-eval-after-load 'electric
(electric-indent-mode -1))
;;; auto-compression-mode
;;
(with-eval-after-load 'jka-cmpr-hook
(auto-compression-mode 1))
;;; Flymake
;;
(with-eval-after-load 'flymake
(if (> emacs-major-version 28)
(customize-set-variable 'flymake-mode-line-lighter "🪰")
(defvar flymake-mode-line-lighter "🪰")
(setq flymake-mode-line-title
`(:propertize
,flymake-mode-line-lighter
mouse-face mode-line-highlight
help-echo
,(lambda (&rest _)
(concat
(format "%s known backends\n" (hash-table-count flymake--state))
(format "%s running\n" (length (flymake-running-backends)))
(format "%s disabled\n" (length (flymake-disabled-backends)))
"mouse-1: Display minor mode menu\n"
"mouse-2: Show help for minor mode"))
keymap
,(let ((map (make-sparse-keymap)))
(define-key map [mode-line down-mouse-1]
flymake-menu)
(define-key map [mode-line down-mouse-3]
flymake-menu)
(define-key map [mode-line mouse-2]
(lambda ()
(interactive)
(describe-function 'flymake-mode)))
map)))))
;;; Shell script
;;
(with-eval-after-load 'sh-script
(defun tv:set-sh-script-mode-name ()
(setq-local mode-name (if (fboundp 'all-the-icons-alltheicon)
(all-the-icons-alltheicon "script" :height 1.0 :v-adjust 0.0)
"Sh "))
(setq mode-line-process nil))
(add-to-list 'auto-mode-alist '("\\.bashrc\\'" . sh-mode))
(add-hook 'sh-mode-hook 'flymake-mode)
(add-hook 'sh-mode-hook #'tv:set-sh-script-mode-name)
;; Use shellcheck as backend for flymake.
(autoload 'flymake-shellcheck-load "flymake-shellcheck")
(add-hook 'sh-mode-hook 'flymake-shellcheck-load)
(define-key sh-mode-map (kbd "RET") 'newline-and-indent)
(define-key sh-mode-map (kbd "C-h f") 'helm-info-bash))
;;; Auto-conf
;;
(add-to-list 'auto-mode-alist '("\\.ac\\'\\|configure\\.in\\'" . autoconf-mode))
(add-to-list 'auto-mode-alist '("\\.at\\'" . autotest-mode))
;;; Winner
;;
(setq winner-boring-buffers '("*Completions*"
"*Compile-Log*"
"*inferior-lisp*"
"*Fuzzy Completions*"
"*Apropos*"
"*Help*"
"*cvs*"
"*Buffer List*"
"*Ibuffer*"
"*mu4e-loading*"
))
(winner-mode 1)
(helm-define-key-with-subkeys
winner-mode-map (kbd "C-c <left>")
'left 'winner-undo '((right . winner-redo))
nil nil 3)
;;; Undo
;;
(define-key global-map [remap undo] 'undo-only)
(define-key global-map (kbd "M-_") 'undo-redo)
;;; All-the-icons and mode-line
;;
;; Don't forget to install necessary fonts with M-x
;; all-the-icons-install-fonts.
;; Align at right (only emacs-30).
(unless (boundp 'mode-line-format-right-align)
(defvar mode-line-format-right-align "")
(defvar mode-line-right-align-edge nil))
(defun tv:git-branch-in-mode-line ()
(require 'helm-ls-git)
(when (and (buffer-file-name (current-buffer))
(fboundp 'helm-ls-git--branch)
(helm-ls-git-root-dir))
(format " (%s %s)"
(char-to-string #x29a9) ; (⦩) Needs a one line height char.
(propertize (helm-ls-git--branch) 'face '(:foreground "yellow")))))
(defun tv:select-git-branches-menu ()
(let ((branchs (split-string (shell-command-to-string "git branch") "\n" t)))
(cl-loop with current
for b in branchs
for branch = (replace-regexp-in-string "[ ]" "" b)
when (string-match "\\`\\*" branch) do (setq current branch)
collect (vector branch
`(lambda ()
(interactive)
(let ((real (replace-regexp-in-string "\\`\\*" "" ,branch)))
(if (string= ,branch ,current)
(message "Already on %s branch" real)
(shell-command (format "git checkout -q '%s'" real))
(message "Switched to %s branch" real)))))
into lst
finally return
(append '("Git branches")
lst
'("--" ["Git status" helm-browse-project])))))
(defun tv:custom-modeline-github-vc ()
(require 'helm-ls-git)
(let* ((fname (buffer-file-name (current-buffer)))
(branch
(when (and fname
;; Don't do fancy things on remote files, tramp
;; is enough slow.
(not (file-remote-p fname))
(fboundp 'helm-ls-git--branch)
(helm-ls-git-root-dir))
(helm-ls-git--branch)))
(status-color "SkyBlue")
(git-icon (all-the-icons-faicon "git"))
(git-branch-icon (all-the-icons-octicon "git-branch")))
(when branch
(concat
(propertize (format " %s" git-icon) 'face '(:height 1.2) 'display '(raise -0.1))
" · "
(propertize (format "%s" git-branch-icon)
'face `(:height 1.3 :family ,(all-the-icons-octicon-family) :foreground "Deepskyblue3")
'display '(raise -0.1))
(propertize (format " %s" branch)
'face `(:height 0.9 :foreground ,status-color)
'mouse-face 'highlight
'help-echo "Mouse-1: Switch to branch"
'local-map (make-mode-line-mouse-map
'mouse-1 (lambda ()
(interactive)
(popup-menu (tv:select-git-branches-menu)))))))))
(with-eval-after-load 'all-the-icons
;; Will have no effect in emacs-30<.
(setq mode-line-right-align-edge 'right-fringe)
(setq-default mode-line-format `("%e"
mode-line-front-space
mode-line-mule-info
mode-line-client
mode-line-modified
mode-line-remote
mode-line-frame-identification
mode-line-buffer-identification
" "
mode-line-modes
" "
"%p %l/%c"
" "
(:eval (tv:custom-modeline-github-vc))
" "
;; Align at right (emacs-30 only).
mode-line-format-right-align
(:eval (progn
;; Keep time always at right.
(setq global-mode-string
(append (delete 'display-time-string
global-mode-string)
'(display-time-string)))
""))
mode-line-misc-info
mode-line-end-spaces))
;; Icons for file extensions.
(setf (alist-get "dat" all-the-icons-extension-icon-alist nil nil 'equal)
'(all-the-icons-faicon "bar-chart" :face all-the-icons-cyan :height 0.9 :v-adjust 0.0))
(add-to-list 'all-the-icons-extension-icon-alist
'("avi" all-the-icons-faicon "film" :face all-the-icons-blue))
(add-to-list 'all-the-icons-extension-icon-alist
'("3gp" all-the-icons-faicon "film" :face all-the-icons-blue))
(add-to-list 'all-the-icons-extension-icon-alist
'("m4v" all-the-icons-faicon "film" :face all-the-icons-blue))
(add-to-list 'all-the-icons-extension-icon-alist
'("xz" all-the-icons-octicon "file-binary"
:v-adjust 0.0 :face all-the-icons-lmaroon))
(add-to-list 'all-the-icons-extension-icon-alist
'("eln" all-the-icons-octicon "file-binary"
:v-adjust 0.0 :face all-the-icons-dsilver))
(add-to-list 'all-the-icons-extension-icon-alist
'("epub" all-the-icons-octicon "book"
:v-adjust 0.0 :face all-the-icons-red-alt))
(add-to-list 'all-the-icons-extension-icon-alist
'("torrent" all-the-icons-material "cloud_upload"
:v-adjust 0.0 :face all-the-icons-lgreen))
(add-to-list 'all-the-icons-extension-icon-alist
'("gitignore" all-the-icons-alltheicon "git" :height 1.0 :face all-the-icons-lred))
;; Icons for directories
(add-to-list 'all-the-icons-dir-icon-alist
'("Vidéos" all-the-icons-faicon "film" :height 0.9 :v-adjust -0.1))
(add-to-list 'all-the-icons-dir-icon-alist
'("Musique" all-the-icons-faicon "music" :height 1.0 :v-adjust -0.1))
(add-to-list 'all-the-icons-dir-icon-alist
'("Images" all-the-icons-faicon "picture-o" :height 0.9 :v-adjust -0.2))
(add-to-list 'all-the-icons-dir-icon-alist
'("Téléchargements" all-the-icons-faicon "cloud-download" :height 0.9 :v-adjust -0.1))
(add-to-list 'all-the-icons-dir-icon-alist
'("Bureau" all-the-icons-octicon "device-desktop" :height 1.0 :v-adjust -0.1))
;; Icons for modes.
(setf (alist-get 'sh-mode all-the-icons-mode-icon-alist)
'(all-the-icons-alltheicon "terminal" :face all-the-icons-purple :v-adjust 0.0))
(add-to-list 'all-the-icons-mode-icon-alist
'(diary-mode all-the-icons-faicon "calendar" :height 1.0
:v-adjust -0.1 :face all-the-icons-yellow))
(add-to-list 'all-the-icons-mode-icon-alist
'(diary-fancy-display-mode all-the-icons-faicon "calendar" :height 1.0
:v-adjust -0.1 :face all-the-icons-yellow))
(add-to-list 'all-the-icons-mode-icon-alist
'(calendar-mode all-the-icons-faicon "calendar" :height 1.0
:v-adjust -0.1 :face all-the-icons-yellow))
(add-to-list 'all-the-icons-mode-icon-alist
'(Info-mode all-the-icons-faicon "info"
:v-adjust -0.1 :face all-the-icons-purple))
;; Regexp icons.
(setq all-the-icons-regexp-icon-alist
(append '(("^bookmark" all-the-icons-octicon "bookmark"
:height 1.1 :v-adjust 0.0 :face all-the-icons-lpink))
(delete (assoc "bookmark" all-the-icons-regexp-icon-alist)
all-the-icons-regexp-icon-alist))))
;;; Time
;;
(with-eval-after-load 'time
(defun tv:round-time-to-nearest-hour ()
(let* ((time-string (format-time-string " %I:%M "))
(split (split-string time-string ":"))
(hour (string-to-number (car split)))
(min (string-to-number (cadr split))))
(cond ((and (> min 45) (<= min 59))
(format " %02d:%02d" (1+ hour) 0))
((or (= min 0) (<= min 15))
(format " %02d:%02d" hour 0))
((and (> min 15) (<= min 45))
(format " %02d:%s" hour 30)))))
(defvar tv:time-icons
'((" 00:00" . "🕛")
(" 01:00" . "🕐")
(" 02:00" . "🕑")
(" 03:00" . "🕒")
(" 04:00" . "🕓")
(" 05:00" . "🕔")
(" 06:00" . "🕕")
(" 07:00" . "🕖")
(" 08:00" . "🕗")
(" 09:00" . "🕘")
(" 10:00" . "🕙")
(" 11:00" . "🕚")
(" 12:00" . "🕛")
(" 00:30" . "🕧")
(" 01:30" . "🕜")
(" 02:30" . "🕝")
(" 03:30" . "🕞")
(" 04:30" . "🕟")
(" 05:30" . "🕠")
(" 06:30" . "🕡")
(" 07:30" . "🕢")
(" 08:30" . "🕣")
(" 09:30" . "🕤")
(" 10:30" . "🕥")
(" 11:30" . "🕦")
(" 12:30" . "🕧")))
(defun tv:custom-modeline-time ()
(let* ((hour (tv:round-time-to-nearest-hour))
(icon (assoc-default (tv:round-time-to-nearest-hour) tv:time-icons)))
(concat
(propertize (format-time-string " %H:%M ")
'face `(:height 0.9 :foreground "green")
'help-echo (format "%s\n Mouse-1: display calendar"
(format-time-string " %A %e %b, %Y" now))
'mouse-face 'highlight
'local-map (make-mode-line-mouse-map 'mouse-1 'tv:toggle-calendar))
icon)))
;; World-time
(when (eq display-time-world-list t) ; emacs-26+
(setq display-time-world-list
(let ((nyt (format-time-string "%z" nil "America/New_York"))
(gmt (format-time-string "%z" nil "Europe/London")))
(if (string-equal nyt gmt)
legacy-style-world-list
zoneinfo-style-world-list))))
(add-to-list 'display-time-world-list '("Greenwich" "Greenwich"))
(add-to-list 'display-time-world-list '("Australia/Sydney" "Sydney"))
(add-to-list 'display-time-world-list '("Australia/Melbourne" "Melbourne"))
(add-to-list 'display-time-world-list '("Australia/Canberra" "Canberra"))
(add-to-list 'display-time-world-list '("America/Chicago" "Chicago"))
(add-to-list 'display-time-world-list '("America/Denver" "Denver"))
(add-to-list 'display-time-world-list '("America/Los_Angeles" "Los_Angeles/Seattle"))
(add-to-list 'display-time-world-list '("America/Denver" "Moab"))
(add-to-list 'display-time-world-list '("America/Vancouver" "Vancouver"))
(add-to-list 'display-time-world-list '("America/Montreal" "Montreal"))
(add-to-list 'display-time-world-list '("America/New_York" "Ottawa"))
(add-to-list 'display-time-world-list '("Europe/Moscow" "Moscow"))
(add-to-list 'display-time-world-list '("Europe/Berlin" "Berlin"))
(add-to-list 'display-time-world-list '("Europe/Oslo" "Oslo"))
(add-to-list 'display-time-world-list '("Europe/Lisbon" "Lisbon"))
(add-to-list 'display-time-world-list '("Europe/Athens" "Athens"))
(add-to-list 'display-time-world-list '("Asia/Dubai" "Dubai"))
(add-to-list 'display-time-world-list '("Asia/Tokyo" "Tokyo"))
(add-to-list 'display-time-world-list '("Hongkong" "Hongkong"))
(add-to-list 'display-time-world-list '("Indian/Antananarivo" "Antananarivo"))
(add-to-list 'display-time-world-list '("Indian/Reunion" "Reunion"))
(setq display-time-24hr-format t
display-time-day-and-date (null (display-graphic-p))
display-time-string-forms
'(;; date
(if (and (not display-time-format) display-time-day-and-date)
(format-time-string " %a%e %b " now)
"")
;; time
(concat
(tv:custom-modeline-time)
;; `time-zone' is a let-bounded var in `display-time-update'.
(and time-zone (format "(%s)" time-zone))))))
(display-time)
;;; Frame and window config.
;;
;;
;; My current-font: [EVAL]: (assoc-default 'font (frame-parameters))
;; Choose a font: [EVAL]: (progn (when (require 'helm-font) (helm 'helm-source-xfonts)))
;; Choose a color: [EVAL]: (progn (when (require 'helm-color) (helm 'helm-source-colors)))
;; To reload .Xresources [EVAL]: (shell-command "xrdb ~/.Xdefaults")
;; For ligatures use either
;; "-SAJA-Cascadia Code-normal-normal-normal-*-*-*-*-*-m-0-iso10646-1"
;; or
;; "-CTDB-Fira Code-normal-normal-normal-*-*-*-*-*-m-0-iso10646-1".
;; Cascadia is available at
;; https://github.com/microsoft/cascadia-code/releases and Fira is
;; available in linuxmint.
;; Need fonts-emojione package (apt)
;; See (info "(elisp) Fontsets")
(when (member "Emoji One" (font-family-list))
(set-fontset-font
t 'symbol (font-spec :family "Emoji One") nil 'prepend))
(setq-default frame-background-mode 'dark)
(setq initial-frame-alist '((fullscreen . maximized)))
(setq frame-auto-hide-function 'delete-frame)
(when (boundp 'other-window-scroll-default)
(setq other-window-scroll-default (lambda () (get-mru-window 'visible nil t))))
(defun tv:transparency-modify-1 (arg)
"Increase Emacs frame transparency.
If ARG is non nil decrease transparency."
(when (window-system)
(let* ((ini-val (frame-parameter nil 'alpha))
(ini-alpha (if (floatp ini-val) (round (* ini-val 100)) ini-val))
(def-alpha (or ini-alpha 80))
(mod-alpha (if arg
(min (+ def-alpha 10) 100)
(max (- def-alpha 10)
frame-alpha-lower-limit)))) ; 20
(modify-frame-parameters nil (list (cons 'alpha mod-alpha)))
(message "Alpha[%s]" mod-alpha))))
(defun tv:transparency-modify-increase ()
(interactive)
(tv:transparency-modify-1 nil))
(defun tv:transparency-modify-decrease ()
(interactive)
(tv:transparency-modify-1 'decrease))
(if (or (daemonp)
(not (window-system))
(< emacs-major-version 24))
(setq default-frame-alist `((vertical-scroll-bars . nil)
(tool-bar-lines . 0)
(menu-bar-lines . 0)
(title . ,(format "%s-%s"
(capitalize (invocation-name))
emacs-version))
(cursor-color . "red")))
(setq default-frame-alist `((foreground-color . "Wheat")
(background-color . "Gray20")
(alpha . 100) ;; Needs compositing manager.
;; New frames go in right corner.
(left . ,(- (* (window-width) 8) 160)) ; Chars are 8 bits long.
(vertical-scroll-bars . nil)
(title . ,(format "%s-%s"
(capitalize (invocation-name))
emacs-version))
(tool-bar-lines . 0)
(menu-bar-lines . 0)
(cursor-color . "red")
(fullscreen . nil)
)))
;; Special buffer display.
;; Use `display-buffer-alist' instead of deprecated
;; `special-display-regexps'. All entries must be dedicated to
;; replicate `special-display-regexps' behavior.
(customize-set-variable 'display-buffer-alist
(append '(("\\*Help"
;; Avoid creating new frames
;; when pressing buttons
;; in help buffer.
(display-buffer-reuse-window
display-buffer-pop-up-frame)
(reusable-frames . 0)
(dedicated . t)
(pop-up-frame-parameters .
((minibuffer . nil)
(width . 80)
(height . 24)
(left-fringe . 0)
(border-width . 0)
(menu-bar-lines . 0)
(tool-bar-lines . 0)
(unsplittable . t)
(top . 24)
(left . 450)
(background-color . "Lightsteelblue1")
(foreground-color . "black")
(alpha . nil)
(fullscreen . nil))))
("\\*Compile-Log"
;; Without these settings
;; compile creates a new frame
;; for each block compiled in file!
(display-buffer-reuse-window
display-buffer-pop-up-frame)
(reusable-frames . 0)
(dedicated . t)
(pop-up-frame-parameters .
((minibuffer . nil)
(width . 85)
(height . 24)
(left-fringe . 0)
(border-width . 0)
(menu-bar-lines . 0)
(tool-bar-lines . 0)
(unsplittable . t)
(top . 24)
(left . 450)
(background-color . "Brown4")
(foreground-color . "black")
(alpha . nil)
(fullscreen . nil))))
("\\*helm apt show\\*"
(display-buffer-pop-up-frame)
(dedicated . t)
(pop-up-frame-parameters .
((minibuffer . nil)
(width . 80)
(height . 24)
(left-fringe . 0)
(border-width . 0)
(menu-bar-lines . 0)
(tool-bar-lines . 0)
(unsplittable . t)
(top . 24)
(left . 450)
(background-color . "Lightsteelblue4")
(foreground-color . "black")
(alpha . nil)
(fullscreen . nil))))
("^\\*osm"
(display-buffer-same-window)
(dedicated . t)))
display-buffer-alist))
;; Don't split windows horizontally.
(setq split-width-threshold nil)
(setq fit-window-to-buffer-horizontally 1)
(helm-define-key-with-subkeys global-map (kbd "C-x ^") ?^ 'enlarge-window
'((?ç . shrink-window)
(?} . enlarge-window-horizontally)
(?{ . shrink-window-horizontally))
(propertize "^:Enl.ver, }:Enl.hor, ç:Shr.ver, {:Shr.hor" 'face 'minibuffer-prompt))