-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinit.el
4310 lines (3653 loc) · 142 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 --- narendraj9's Emacs configuration -*- lexical-binding: t; coding: utf-8 -*-
;; Copyright (C) 2016, 2021 Narendra Joshi
;; Author: Narendra Joshi <[email protected]>
;; Keywords: Emacs
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;; My Emacs configuration.
;;; Code:
(setq byte-compile-warnings '(not cl-functions))
;;; Avoid garbage collection during Emacs startup and garbage collect right
;;; after loading Emacs configuration.
(setq gc-cons-threshold most-positive-fixnum
garbage-collection-messages t)
(add-hook 'after-init-hook
(lambda ()
(setq garbage-collection-messages nil)
(garbage-collect)
(setq gc-cons-threshold (* 256 1024 1024))))
;; Try to make `.emacs.d` relocatable
(setq user-emacs-directory
(file-name-directory (or load-file-name
"~/.emacs.d/init.el")))
;; Remember the last 10000 keystrokes
(lossage-size 10000)
;;; GnuTLS
;; ──────────────────────────────────────────────────────────────────
(setq gnutls-verify-error t)
;;; PACKAGE ARCHIVES
;; ─────────────────────────────────────────────────────────────────
(require 'package)
(add-to-list 'package-archives (cons "melpa" "https://melpa.org/packages/"))
(setq package-native-compile t)
;;; USE-PACKAGE
;; ──────────────────────────────────────────────────────────────────
(when (not (package-installed-p 'use-package))
(package-refresh-contents)
(package-install 'use-package))
(setq use-package-compute-statistics t)
(use-package use-package-ensure-system-package)
(use-package delight :ensure t :demand t)
(use-package bind-key :ensure t)
(eval-and-compile
(add-to-list 'use-package-keywords :doc t)
(defun use-package-handler/:doc (name-symbol _keyword _docstring rest state)
"An identity handler for :doc.
Currently, the value for this keyword is just ignored. In the
future, I might want to add its value to name-symbol's
documentation string.
Argument NAME-SYMBOL is the first argument to `use-package' in a declaration.
Argument KEYWORD here is simply :doc.
Argument DOCSTRING is the value supplied for :doc keyword.
Argument REST is the list of rest of the keywords.
Argument STATE is maintained by `use-package' as it processes symbols."
(let ((body (use-package-process-keywords name-symbol rest state)))
body)))
;;; Emacs Lisp Compilation
(setq load-prefer-newer t)
(use-package comp
:if (fboundp 'native-compile)
:custom (native-comp-async-report-warnings-errors nil))
;; LIBRARIES
;; ─────────────────────────────────────────────────────────────────
(use-package s :demand t :ensure t)
(use-package f :demand t :ensure t)
(use-package dash :demand t :ensure t)
(use-package request :defer t :ensure t)
(use-package ednc :defer t :ensure t)
(use-package alert :defer t :ensure t)
(use-package re-builder
:defer t
:config
(setq reb-re-syntax 'string))
(use-package pcre2el
:doc "I intend to read the code carefully someday."
:after re-builder
:bind (:map ctl-quote-map
("c /" . pcre->elisp))
:preface
(defun pcre->elisp (beg end)
"Replace PCRE regex in region (BEG END) with its elisp equivalent."
(interactive "r")
(let ((pcre-regex (buffer-substring-no-properties beg end)))
(delete-region beg end)
(insert (pcre-to-elisp pcre-regex)))))
;;
;; ─────────────────────────────────────────────────────────────────
(use-package defs
:doc "Var and function definitions that must be loaded before
everything else."
:demand t
:load-path "lib/"
:pin manual
:init
;; Some ergonomic alternatives
(define-key input-decode-map
;; Default: \C-i => TAB
"\C-i" "\C-c")
(define-key input-decode-map
;; Default: \C-[ => ESC
"\C-[" "\C-x")
(define-key input-decode-map
;; Default: \C-m => RET
"\C-m" [C-m])
(bind-keys* :prefix [C-m] :prefix-map ctl-m-map)
(bind-keys* :prefix "C-'" :prefix-map ctl-quote-map)
(bind-keys* :prefix "C-." :prefix-map ctl-period-map)
(bind-keys* :prefix "C-;" :prefix-map ctl-semicolon-map)
(bind-keys* :prefix "C-h x" :prefix-map ctl-h-x-map)
:bind ( ("C-c m" . switch-to-minibuffer)
("C-c 0" . quick-switch-themes)
("C-c b" . switch-to-buffer-with-mode)
("<print>" . snap-it)
:map ctl-m-map
("t" . switch-to-scratch-new-tab)
("o" . run-in-other-window)
("s" . swap-ctrl-right-win)
:map ctl-quote-map
("g" . websearch-it)
("l l" . search-linguee)
("l t" . translate-with-linguee)
("." . insert-date-time-at-point)
("c e" . vicarie/eval-print-last-sexp)
("c =" . vicarie/eval-replace-last-sexp)
("c r" . rename-file-and-buffer)
;; ("C-a" . emacspeak-wizards-execute-asynchronously)
("M-x" . async-M-x)
:map ctl-period-map
("k" . project-compile)
("C-k" . project-compile)
("K" . recompile)
("$" . selective-display-beyond-col)
("u" . underline-text)
("s" . surround-symbol-with) ))
(use-package custom-registers
:load-path "etc"
:bind ( :map ctl-x-r-map ("U" . custom-registers-url-to-register) ))
(use-package no-littering
:ensure t
:init
;; Make var/ default. Paths are overridden if the files are
;; important.
;; Keep all misc state in $(user-emacs-direcotry)/var/
(make-directory (expand-file-name "var/" user-emacs-directory) t)
;; These variables need to be set before `no-littering' is loaded.
(setd no-littering-etc-directory "etc/"
no-littering-var-directory "var/"))
(progn
;; I just want to group these somehow and I don't want to use a fake
;; use-package package name because it messes up with `use-package-report'.
(setq inhibit-splash-screen t)
;; ----------------------------------------
;; Thanks to
;; https://www.masteringemacs.org/article/working-coding-systems-unicode-emacs
(prefer-coding-system 'utf-8)
(set-default-coding-systems 'utf-8)
(set-terminal-coding-system 'utf-8)
(set-keyboard-coding-system 'utf-8)
;; So that man pages are rendered properly irrespective of LC_* variable
;; values.
(setq locale-coding-system 'utf-8)
(setq buffer-file-coding-system 'utf-8)
(setq large-file-warning-threshold
(* 100 1024 1024))
;; Treat clipboard input as UTF-8 string first; compound text next, etc.
(setq x-select-request-type '(UTF8_STRING COMPOUND_TEXT TEXT STRING))
;; ----------------------------------------
(setd tutorial-directory "var/tutorial/")
;; Buffer contents auto-saved post initial file contents
(setq auto-save-list-file-prefix
(expand-file-name "var/autosaves/.saves-" user-emacs-directory))
(setq delete-by-moving-to-trash t)
;; Backups of file before current changes
(setq backup-directory-alist
`((".*" . ,(expand-file-name "var/backups/"
user-emacs-directory)))
backup-by-copying t
version-control t
delete-old-versions t
kept-new-versions 10
kept-old-versions 10)
(setq confirm-kill-emacs
(lambda (prompt)
(let* ((random-number (random 100)))
(equal (number-to-string random-number)
(read-string (format "%s [Type %d to confirm] "
prompt
random-number))))))
(setq initial-scratch-message ""
initial-major-mode
(lambda ()
(lisp-interaction-mode)
(setq header-line-format
'(:eval
(format "Emacs Uptime: %-20s | Sys Time: %-20s | System Load: %-20s"
(emacs-uptime)
(format-seconds "%Y, %D, %2H, %2M, %z%S"
(time-convert (get-internal-run-time)
'integer))
(load-average 'use-float)))))))
(use-package custom
:doc "Custom configuration and personal information."
:init
(defvar secrets-file (expand-file-name "secrets.el"
emacs-assets-directory))
(setd custom-file "custom.el")
;; My custom file usually doesn't contain settings that would be visible to
;; me. I have some variables setup though that help me reduce disk reads
;; while setting up fonts.
(when (file-exists-p custom-file)
(load custom-file))
;; The default font should be properly set by now, make sure that
;; each newly created frame uses the same font.
;; (add-hook 'after-init-hook
;; (lambda ()
;; (add-to-list 'default-frame-alist
;; `(font . ,(font-xlfd-name (face-attribute 'default :font))))))
;; Load secrets if available.
(when (file-exists-p secrets-file)
(load secrets-file))
;; Misc
(setq-default tab-width 4)
(setq-default fill-column 80)
;; Disable bell
(setq ring-bell-function (lambda ()))
;; Enable some disabled commands
(mapc (lambda (c) (put c 'disabled nil))
'(narrow-to-region
upcase-region
downcase-region
capitalize-region
erase-buffer
set-goal-column
list-timers
list-threads))
;; Dialog boxes don't work with Xmonad.
(setq use-dialog-box nil)
;; --
;; (defalias 'yes-or-no-p 'y-or-n-p)
;; (setq use-short-answers t)
)
(use-package tool-bar :config (tool-bar-mode -1))
(use-package scroll-bar :config (scroll-bar-mode -1))
(use-package menu-bar
:doc "The menu bar is useful for discovering features that
exist in some modes, e.g Gnus, SQLi."
:bind (:map ctl-x-map ("w m" . menu-bar-open))
:config (menu-bar-mode -1))
(use-package appearance
:doc "`use-package' doesn't throw an error for non-existent packages"
:load-path "themes/"
:init
(add-to-list 'custom-theme-load-path
(expand-file-name "themes/"
user-emacs-directory))
:config
(let ((appearance-enable-time-based-theme-switching nil))
(appearance-init))
(load-theme 'ef-dark))
(use-package mode-line-config
:demand t
:load-path "etc/"
:config
(set-face-attribute 'mode-line-active nil :inherit 'mode-line)
(set-face-attribute 'mode-line-inactive nil :inherit 'mode-line)
:preface
(defun mode-line-config-flash-cleaner-line ()
(interactive)
(let ((mode-line-modes (list))
(mode-line-position nil)
(mode-line-config-hide-vc t)
(mode-line-buffer-identification nil)
(header-line-format (string-trim (pomodoro-status))))
(force-mode-line-update)
(sit-for 5)
(force-mode-line-update))))
(use-package fringe
:init
(defvar default-fringe-style (cons (floor (* 1.5 (frame-char-width)))
(frame-char-width))
"This needs to be defined because it's used elsewhere to
reset fringes back to the default after highlighting
something that requires immediate attention.")
(defun fringe-set-louder ()
(fringe-mode 20)
(set-face-attribute 'fringe nil :inverse-video t))
(defun fringe-restore-default ()
(fringe-mode default-fringe-style)
(set-face-attribute 'fringe nil :inverse-video nil))
(fringe-mode default-fringe-style))
(use-package quoted-scratch
:load-path "packages/rest/quoted-scratch"
:disabled t
:init
(add-hook 'after-init-hook #'quoted-scratch-refresh-quote-when-idle)
:config
(setq quoted-scratch-show-auroville-quality nil))
;;; Battery and Time display in the mode line
;;; ----------------------------------------------------------------------------
(use-package time
:demand t
:preface
:bind ( :map ctl-quote-map ("c t" . world-clock*) )
:init
(setq world-clock-timer-enable nil
world-clock-time-format "\n──────────────\n\t%A %d %B %R %Z\n")
(setq display-time-string-forms
'((propertize
(format " %s.%s.%s %s %s:%s "
(string-trim day) (string-trim month) (substring year -2) dayname 24-hours minutes)
'face 'bold))
display-time-default-load-average 1 ; 5 minute load avg
display-time-load-average-threshold 0.8 ; >80%
display-time-mail-string "")
(display-time-mode +1)
:preface
(defun world-clock* (&optional arg)
(interactive "P")
(if arg
(with-selected-date-time (world-clock))
(world-clock))))
(use-package battery
:disabled t
:demand t
:config
(setq battery-mode-line-format
(propertize "%b%p%% " 'face 'mode-line-battery-face))
(display-battery-mode +1)
;; (run-with-timer 60 60 #'battery-protection-notifications)
:preface
(defun battery-protection-pause ()
(interactive)
(put 'battery-protection-notifications
:enabler-timer
(run-with-timer 7200 nil
(lambda ()
(put 'battery-protection-notifications :paused nil)))))
(defun battery-protection-resume ()
(interactive)
(when-let ((timer (get 'battery-protection-notifications :enabler-timer)))
(cancel-timer timer)
(put 'battery-protection-notifications :enabler-timer nil)))
(defun battery-protection-notifications ()
(let* ((status (funcall battery-status-function))
(lowest-percentage 20)
(highest-percentage 101)
(percentage (string-to-number (alist-get ?p status)))
(charging-status (alist-get ?b status)))
(when (not (get 'battery-protection-notifications :enabler-timer))
(when (and (string= charging-status "+")
(< highest-percentage percentage))
(notifications-notify :title "Battery Protection"
:body "You need to remove the charger."))
(when (and (not (string= charging-status "+"))
(< percentage lowest-percentage))
(notifications-notify :title "Battery Protection"
:body "Start charging your battery."))))))
(use-package ibuffer
:bind (:map ctl-x-map ("C-b" . ibuffer-other-window) )
:config
(setq ibuffer-formats
'((mark modified read-only locked " "
(name 28 28 :left :elide) " "
(size 9 -1 :right) " "
(mode 16 -1 :left) " "
filename-and-process)
(mark " "
(name 36 36 :left) " | "
(filename-and-process 10 -1 :right)))))
(use-package ibuf-ext
:config
(setq ibuffer-saved-filter-groups
'(("Categorized"
("Org Mode" (mode . org-mode))
("IRC" (mode . erc-mode))
("*Auxiliary*" (name . "\\*.*\\*"))))))
;;; Utilities
;; ──────────────────────────────────────────────────────────────────
(use-package net-utils
:bind ( :map net-utils-mode-map ("G" . netutils--revert-buffer) )
:preface
(defun netutils--revert-buffer ()
"Revert buffer and get back to the same line number."
(interactive)
(let ((line (1+ (count-lines (point-min) (point))))
(buffer (buffer-name (current-buffer))))
(revert-buffer)
(add-hook 'after-revert-hook
(lambda ()
(forward-line line))))))
(use-package sql
:defer t
:bind ( :map sql-interactive-mode-map
("S-SPC" . upcase-last-symbol-and-space)
:map sql-mode-map
("S-SPC" . upcase-last-symbol-and-space) ))
(use-package wtf
:load-path "packages/lisp/"
:commands wtf-is)
(use-package tiny
:doc
"Provides `tiny-expand' to quickly generate linear sequences.
Syntax: m[<range start:=0>][<separator:= >]<range end>[Lisp expr]|[format expr]
Example: m1\n10(list x (sqrt x))|Square root of %d is %.2f"
:ensure t
:bind (("C-c C-;" . tiny-expand)))
(use-package copy-as-format
:ensure t
:preface
(advice-add 'copy-as-format
:around (lambda (orig-fn &rest _args)
(let ((current-prefix-arg '(4)))
(funcall orig-fn))))
:commands copy-as-format)
(use-package restclient
:doc "Restclient comes in handy a lot of times."
:defer t
:ensure t
:commands restclient
:mode ("\\.restclient\\'" . restclient-mode)
:config
(add-hook 'restclient-response-received-hook (lambda () (message "Done!"))))
(use-package verb
:ensure t
:after org
:config
(add-hook 'org-mode-hook
(lambda ()
(define-key org-mode-map
(kbd "C-c v")
verb-command-map))))
(use-package prodigy
:defer t
:bind ( :map ctl-quote-map ("s p" . prodigy) )
:ensure t
:config
(load-file (expand-file-name "etc/prodigy-service-defs.el"
user-emacs-directory))
;; Load definitions if they are kept in assets directory too
(let ((extra-service-defs-path (expand-file-name "prodigy-service-defs.el"
emacs-assets-directory)))
(when (file-exists-p extra-service-defs-path)
(load-file extra-service-defs-path))))
;;; Thanks to https://github.com/Wilfred
;;; ====================================
(use-package ag :ensure t :bind ("M-s M-a" . ag))
;; KEY BINDINGS
;; ──────────────────────────────────────────────────────────────────
(ffap-bindings)
(bind-keys :map ctl-period-map
("C-o" . goto-address-at-point)
("C-f" . ffap))
;; ──────────────────────────────────────────────────────────────────
(use-package tab-bar
:bind ( :map tab-prefix-map
("s" . tab-bar-new-scratch*)
("S" . tab-switcher) )
:doc
"This built-in package provides a way to keep a set of window
configurations around that can be switched to easily."
:config
(tab-bar-history-mode +1)
(setq tab-bar-show nil
tab-bar-tab-name-function #'tab-bar-tab-name-all)
:preface
(defun tab-bar-new-scratch* ()
(interactive)
(tab-new)
(switch-to-buffer "*scratch*")))
(use-package calendar
:defer t
:custom (calendar-date-style 'iso)
:bind (:map ctl-quote-map
("c c" . calendar))
:init
(add-hook 'calendar-today-visible-hook #'calendar-mark-today)
(setq
;; Weeks start on Monday.
calendar-week-start-day 1
;; Month header show the month of the year.
calendar-month-header
'(propertize (format "%s %d/%d" (calendar-month-name month) month year)
'font-lock-face 'calendar-month-header)))
(use-package holidays
:defer t
:config
(use-package german-holidays
:ensure t
:config
(->> holiday-german-holidays
(append calendar-holidays)
-distinct
(setq calendar-holidays))))
(use-package appt
:defer t
:preface
(defun show-appt-notifications (disp-fn &rest args)
"Show notifications for an appointment using default alert style."
(alert (format "In %s minutes: %s" (car args) (caddr args)) :title "Reminder")
(apply disp-fn args))
:init
(eval-after-load "org-mode"
'(appt-activate +1))
(add-hook 'org-agenda-finalize-hook
(lambda ()
(quietly (org-agenda-to-appt))))
:config
(setq appt-audible t
appt-display-duration 15)
(advice-add 'appt-disp-window :around #'show-appt-notifications))
(use-package xwidget
:custom (xwidget-webkit-cookie-file
(expand-file-name "webkit-cookies.txt" emacs-assets-directory))
:config
(add-to-list 'display-buffer-alist
'("\\*xwidget-webkit:" display-buffer-in-direction
(direction . right)
(window-width . 0.5))))
(use-package eww
:defer t
:custom ((eww-auto-rename-buffer 'title)
(eww-browse-url-new-window-is-tab nil))
:config
(add-hook 'eww-after-render-hook #'eww-readable)
:custom (eww-bookmarks-directory emacs-assets-directory))
(use-package browse-url
:defer t
:config
(setq browse-url-new-window-flag nil)
(cond
((executable-find "firefox")
(setq browse-url-browser-function 'browse-url-firefox))
((featurep 'xwidget-internal)
(setq browse-url-browser-function 'xwidget-webkit-browse-url))
((executable-find "chromium")
(setq browse-url-browser-function 'browse-url-chromium))
((executable-find "google-chrome")
(setq browse-url-browser-function 'browse-url-chrome))))
(use-package atomic-chrome
:ensure t
:init
(defvar atomic-chrome--saved-window-configuration nil)
(add-hook 'atomic-chrome-edit-mode-hook
(lambda ()
(setq atomic-chrome--saved-window-configuration (current-window-configuration))
(delete-other-windows)))
(add-hook 'atomic-chrome-edit-done-hook
(lambda ()
(when (window-configuration-p atomic-chrome--saved-window-configuration)
(set-window-configuration atomic-chrome--saved-window-configuration)))))
(use-package paren
:config
(setq show-paren-style 'parenthesis)
(setq show-paren-delay 0)
(show-paren-mode 1))
(use-package rainbow-mode :ensure t :defer t)
(use-package uniquify
:doc "Unique buffer names"
:delight t
:init
(setq uniquify-buffer-name-style 'post-forward
uniquify-separator " • "))
(use-package ialign
:doc "Very useful to get quick feedback for alignment with
`align.el'."
:ensure t
:bind (:map ctl-period-map
("C-a" . ialign)))
(use-package symbol-overlay
:ensure t
:bind ( :map global-map
("M-n" . symbol-overlay-put*)
("M-p" . symbol-overlay-put*)
:map symbol-overlay-map
("M-n" . symbol-overlay-jump-next)
("M-p" . symbol-overlay-jump-prev) )
:init
(advice-add 'symbol-overlay-jump-call :after #'flash-current-symbol)
:preface
(defvar symbol-overlay-remove-all-timer nil)
(defun symbol-overlay-remove-all-timer (buffer)
(when (timerp symbol-overlay-remove-all-timer)
(cancel-timer symbol-overlay-remove-all-timer))
(setq symbol-overlay-remove-all-timer
(run-with-timer 2
nil
(lambda ()
(with-current-buffer buffer
(call-interactively #'symbol-overlay-remove-all))))))
(defun symbol-overlay-put* ()
"Jump to the next or previous occurrence of symbol at point
after doing `symbol-overlay-put'."
(interactive)
(symbol-overlay-put)
(when-let ((command (lookup-key symbol-overlay-map
(this-command-keys))))
(call-interactively command)))
(defun flash-current-symbol (&rest _)
"Pulse highlight symbol at point."
(let ((bounds (bounds-of-thing-at-point 'symbol))
(pulse-delay 0.02))
(symbol-overlay-remove-all-timer (current-buffer))
(pulse-momentary-highlight-region (car bounds)
(cdr bounds)))))
(use-package crux
:ensure t
:commands (crux-swap-windows crux-transpose-windows)
:bind (("C-<backspace>" . crux-kill-line-backwards)
("S-<return>" . crux-switch-to-previous-buffer))
:hook (after-init . crux-reopen-as-root-mode))
;;; TEXT-EDITING, FOLDING and NAVIGATION
;; ─────────────────────────────────────────────────────────────────
(use-package elec-pair :init (electric-pair-mode +1))
(use-package wgrep :ensure t)
(use-package outline-minor-mode
:defer t
:custom ((outline-blank-line t))
:init
(delight 'outline-minor-mode "" "outline")
;; This minor mode uses selective display to hide text so it displays three
;; dots (ellipsis) like `selective-display'
;; https://www.emacswiki.org/emacs/OutlineMode
(set-display-table-slot standard-display-table
'selective-display
(string-to-vector " ... ")))
(use-package hideshow
:defer t
:delight hs-minor-mode
:bind ( :map hs-minor-mode-map
([backtab] . hs-toggle-hiding)
("C-c @ a" . my-toggle-hideshow-all)
("C-c @ s" . hs-show-block)
("C-c @ h" . hs-hide-block))
:init
(add-hook 'prog-mode-hook #'hs-minor-mode)
:config
(setq hs-set-up-overlay #'display-code-line-counts)
:preface
(defvar my-hs-hide nil "Current state of hideshow for toggling all.")
(defun my-toggle-hideshow-all ()
"Toggle hideshow all."
(interactive)
(setq my-hs-hide (not my-hs-hide))
(if my-hs-hide
(hs-hide-all)
(hs-show-all)))
(defun display-code-line-counts (ov)
(when-let ((line-count (and (eq 'code (overlay-get ov 'hs))
(count-lines (overlay-start ov)
(overlay-end ov)))))
(overlay-put ov
'display
(propertize (format " +%s " line-count)
'face 'highlight))
(overlay-put ov
'before-string
(propertize " "
'display
'(left-fringe right-arrow highlight))))))
(use-package wrap-region
:doc "Wrap region with custom chars."
:ensure t
:hook (after-init . wrap-region-mode)
:delight
:config
(wrap-region-add-wrappers
'(("=" "=" nil (org-mode))
("~" "~" nil (org-mode))))
(wrap-region-global-mode +1)
(wrap-region-remove-wrapper "<" 'org-mode))
(use-package selected
:delight selected-minor-mode
:ensure t
:config
(selected-global-mode +1))
(use-package repeat
:init
;; If a symbol property named `repeat-map' exists for a command and it's a
;; keymap, it's activate as a transient-map after command is executed.
(let ((inhibit-message t))
(repeat-mode +1))
:config
(setq repeat-exit-timeout 30)
:preface
(defmacro define-repeat-map (&rest bindings)
;; TODO: add a keyword argument to provide a name for the keymap instead of
;; the auto-generated name.
(declare (indent 0))
;; Use gensym just for the name of the symbol, let the generated
;; symbol be garbage collected. `intern' then creates a new symbol
;; that is used and remains valid globally.
(let ((keymap-symbol (intern (symbol-name (gensym "repeat-map--")))))
`(let* ((m (make-sparse-keymap)))
(dolist (binding (quote ,bindings))
(define-key m (kbd (car binding)) (cdr binding))
(put (cdr binding) 'repeat-map (quote ,keymap-symbol)))
(defvar ,keymap-symbol m)))))
(use-package misc
:bind ( :map ctl-period-map ("d" . duplicate-dwim) )
:custom ( duplicate-line-final-position -1
duplicate-region-final-position -1) )
(use-package select :init (setq select-enable-clipboard t))
(use-package simple
:doc "The great simple.el"
:demand t
:delight auto-fill-function
:bind (("M-q" . fill-or-unfill)
("M-[" . backward-delete-dwim)
:map ctl-period-map
("C-u" . delete-indentation)
:map ctl-quote-map
(":" . set-variable)
("s l" . list-processes)
("s >" . shell-command-on-region)
("s |" . shell-command-on-region)
("s s" . shell-command)
("s !" . shell-command)
("s a" . async-shell-command)
("s &" . async-shell-command)
("s ." . shell-command-from-region) )
:hook ((prog-mode hledger-mode) . comment-auto-fill)
:preface
(defun exchange-point-and-mark* (arg)
(interactive "P")
(exchange-point-and-mark (not arg)))
(defun shell-command-from-region (beg end)
"Runs selected region as a shell command."
(interactive "r")
(shell-command (buffer-substring-no-properties beg end)))
:config
(define-repeat-map ("C-u" . delete-indentation))
;; Multiple-cursors changes transient-mark-mode to (only only .. t),
;; if shift-select-mode is enabled.
(setq shift-select-mode nil)
;; Make text copied/cut from outside Emacs part of Emacs kill-ring on first
;; kill inside Emacs.
(setq kill-ring-max 1024
save-interprogram-paste-before-kill t
kill-do-not-save-duplicates t)
;; Temporary
;; ----------------------------------------------------------------------------
(defvar kill-ring-modifiers-freq-hashmap
(make-hash-table))
(add-variable-watcher 'kill-ring
(lambda (&rest _args)
(when this-command
(puthash this-command
(1+ (gethash this-command kill-ring-modifiers-freq-hashmap 0))
kill-ring-modifiers-freq-hashmap))))
(defun summarize-kill-ring-modifiers ()
(interactive)
(let ((items ()))
(maphash (lambda (k v) (push (cons k v) items)) kill-ring-modifiers-freq-hashmap)
(message-or-box (mapconcat (lambda (command-freq)
(format "%s: %s" (car command-freq) (cdr command-freq)))
(sort items (lambda (a b) (> (cdr a) (cdr b))))
"\n"))))
;; ----------------------------------------------------------------------------
(setq suggest-key-bindings t
extended-command-suggest-shorter nil)
(setq-default indent-tabs-mode nil)
(setq async-shell-command-buffer 'new-buffer
set-mark-command-repeat-pop t
column-number-mode t
size-indication-mode t)
(delight 'visual-line-mode nil "simple")
;; This BROKE multiple cursors! Multiple-cursor uses
;; `exchange-point-and-mark' and creates overlays for active region around
;; fake cursors. This advice was deactivating region after multiple-cursors
;; called `exchange-point-and-mark' for the first time which resulted in
;; strange behaviour when used after activating region.
;;
;; (add-function :after
;; (symbol-function #'exchange-point-and-mark)
;; (lambda (&rest _args) (deactivate-mark nil)))
(define-key global-map
[remap exchange-point-and-mark]
#'exchange-point-and-mark*)
(add-hook 'activate-mark-hook (lambda () (setq cursor-type (cons 'bar 4))))
(add-hook 'deactivate-mark-hook (lambda () (setq cursor-type t))))
(use-package visual-wrap
:init
(global-visual-wrap-prefix-mode +1))
(use-package apropos :config (setq apropos-do-all t))
(use-package shortdoc :bind ( :map help-map ("g" . shortdoc-display-group) ))
(use-package misc
:doc "Where simple ends, maybe misc.el begins"
:bind (("M-z" . zap-up-to-char)
("M-Z" . copy-from-above-command)))
(use-package savehist
:demand t
:config
(setq savehist-file (expand-file-name "var/savehist.el"
user-emacs-directory))
(setq savehist-save-minibuffer-history t
savehist-additional-variables
'( kill-ring command-history limit-usage kill-ring-modifiers-freq-hashmap ))
(savehist-mode +1)
;; https://emacs.stackexchange.com/a/4191/14967
;; Prevent `kill-ring' values from causing very long pauses while
;; shutting down Emacs by removing text properties from `kill-ring'
;; entries.
(add-hook 'kill-emacs-hook
(lambda ()
(setq kill-ring (mapcar 'substring-no-properties kill-ring)))))
(use-package vcursor
:bind ( :map ctl-m-map
("v" . vcursor-use-vcursor-map-quietly)
("V" . vcursor-toggle-copy)
("@" . vcursor-expand-region-expand) )
:custom (vcursor-key-bindings t)
:init
(add-hook 'vcursor-use-vcursor-map-hook
#'vcursor-toggle-vcursor-config-in-buffer)
:preface
(defun vcursor-use-vcursor-map-quietly ()
(interactive)
(require 'vcursor)
(quietly (call-interactively #'vcursor-use-vcursor-map)))
;; These two commands interact in a contrived way to fit exactly the workflow
;; that I need to copy regions present at a place in the buffer to the