-
Notifications
You must be signed in to change notification settings - Fork 0
/
init-backup
938 lines (754 loc) · 36.7 KB
/
init-backup
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
;; -*- coding: utf-8 -*-
;;; init.el --- Where all the magic begins
;;
;; Part of the Emacs Starter Kit
;;
;; This is the first thing to get loaded.
;;,-----------------------------
;;| Technomancy's recommendation
;;`-----------------------------
;; This avoids many
;; [common](https://glyph.twistedmatrix.com/2015/11/editor-malware.html)
;; [problems](https://github.com/melpa/melpa/issues/2342) with `package.el`, and
;; it allows you to seamlessly roll back upgrades which introduce breaking
;; changes as well as guaranteeing that all machines you work on share the same
;; versions.
;; in:
;; /media/dgm/blue/documents/programming/emacs/CoolEmacsGuys/technomancy/emacs-starter-kit/README.markdown
;; where it says "ini.el", it originally says "my-autoload.el".
;; (defun pnh-reinit-libs ()
;; (interactive)
;; (let ((generated-autoload-file (concat user-emacs-directory "init.el")))
;; (dolist (d (directory-files (concat user-emacs-directory "lib") t "^[^\.]"))
;; (dolist (f (directory-files d t "\\.el$"))
;; (byte-compile-file f))
;; (update-directory-autoloads d))))
;; (dolist (l (directory-files (concat user-emacs-directory "lib") nil "^[^\.]"))
;; (add-to-list 'load-path (concat user-emacs-directory "lib/" l))
;; (autoload (internl) (concat l ".el")))
;; (when (not (file-exists-p (concat user-emacs-directory "init.el")))
;; (pnh-reinit-libs))
;; (load (concat user-emacs-directory "init.el"))
;; DGM: I've commented out because I've created the "lib" directory BUT I don't know what is meant to be in the
;; "my-autoload.el" file
;; But this produces this:
;; Warning (initialization): An error occurred while loading ‘/home/dgm/.emacs.d/init.el’:
;; error: Recursive load, /home/dgm/.emacs.d/init.el, /home/dgm/.emacs.d/init.el, /home/dgm/.emacs.d/init.el, /home/dgm/.emacs.d/init.el, /home/dgm/.emacs.d/init.el
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; John Wiegley's setup tweaked
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(when (string= (system-name) "lenovo")
(setq package-native-compile t))
(defconst emacs-start-time (current-time))
(defvar file-name-handler-alist-old file-name-handler-alist)
(setq package-enable-at-startup nil
file-name-handler-alist nil
message-log-max 16384
gc-cons-threshold 402653184 ;; 402.653.184
gc-cons-percentage 0.6
auto-window-vscroll nil)
;;; original bit by JW (though with =gc-cons-percentage= on)
;;; Alphapapa suggests 10 or 100MB (100000000) at most.
;;; Another use says 300\MBOX{}
;;; Originally, I found that 3000000 (3 MB) was okay
(add-hook 'after-init-hook
`(lambda ()
(setq file-name-handler-alist file-name-handler-alist-old
gc-cons-threshold (* 2 1000 1000)) ;; originally 10MB or 10000000 or 10.000.000
;; originally. This setting is by DW
;;gc-cons-percentage 0.1)
(garbage-collect)) t)
;; DW: Now set the garbage collection threshold lower. 2MB
;; (setq gc-cons-threshold (* 5 1000 1000))
;; Added by Package.el. This must come before configurations of
;; installed packages. Don't delete this line. If you don't want it,
;; just comment it out by adding a semicolon to the start of the line.
;; You may delete these explanatory comments.
;; However, I comment it out because with emacs 27 we get a message
;; saying this is not needed any more.
;; (package-initialize)
;; (require 'cl) ;; deprecated
(require 'cl-lib)
(require 'ffap)
(require 'ansi-color)
;;; DGM on 5th August 2019 trying to fix <(file-error
;;; "https://elpa.gnu.org/packages/archive-contents" "Bad Request")>
;;; Tip from:
;;; https://www.reddit.com/r/emacs/comments/cdei4p/failed_to_download_gnu_archive_bad_request/
;;; Apparently it is a bug in emacs
(setq gnutls-algorithm-priority "NORMAL:-VERS-TLS1.3")
;;; Tip 1 from Ambrevar's init.el
;; I guess responsiveness is improved by a low gc-cons-threshold, but
;; speed is improved by a high gc-cons-threshold.
;; from: https://www.reddit.com/r/emacs/comments/55ork0/is_emacs_251_noticeably_slower_than_245_on_windows/
;;; Speed up init.
;;Temporarily reduce garbage collection during startup. Inspect `gcs-done'.
;; (defun ambrevar/reset-gc-cons-threshold ()
;; (setq gc-cons-threshold (car (get 'gc-cons-threshold 'standard-value))))
;; ;; 511 (setq gc-cons-threshold (* 64 1024 1024))
;; ;;(setq gc-cons-threshold (* 64 1024 1024))
;; (setq gc-cons-threshold 800000)
;; (add-hook 'after-init-hook 'ambrevar/reset-gc-cons-threshold)
;; ;;Temporarily disable the file name handler.
;; (setq default-file-name-handler-alist file-name-handler-alist)
;; (setq file-name-handler-alist nil)
;; (defun ambrevar/reset-file-name-handler-alist ()
;; (setq file-name-handler-alist
;; (append default-file-name-handler-alist
;; file-name-handler-alist))
;; (cl-delete-duplicates file-name-handler-alist :test 'equal))
;; (add-hook 'after-init-hook 'ambrevar/reset-file-name-handler-alist)
;; (setq gc-cons-percentage 0.1)
;; ;(run-with-idle-timer 5 t #'garbage-collect)
;; (setq garbage-collection-messages t)
;;; Tip 2 from Ambrevar's init.el
;;; Avoid the "loaded old bytecode instead of newer source" pitfall.
(setq load-prefer-newer t)
(setq dotfiles-dir (file-name-directory (or (buffer-file-name) load-file-name)))
(setq dotfiles-dir (file-name-directory (or load-file-name (buffer-file-name))))
(setq autoload-file (concat dotfiles-dir "loaddefs.el"))
;; (setq package-user-dir (concat dotfiles-dir "elpa")) ;; if enabled
;; this with exwm, then it blocks emacs
;; original config about custom-file
;; (setq custom-file (concat dotfiles-dir "custom.el"))
;; (add-to-list 'load-path (expand-file-name
;; "lisp" (expand-file-name
;; "org" (expand-file-name
;; "src" dotfiles-dir))))
;; daviwil's alternative. Apparently, he got it from Ambrevar too!
;; Keep customization settings in a temporary file (thanks Ambrevar!)
(setq custom-file
(if (boundp 'server-socket-dir)
(expand-file-name "custom.el" server-socket-dir)
(expand-file-name (format "emacs-custom-%s.el" (user-uid)) temporary-file-directory)))
(load custom-file t)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; use-package ;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;From https://github.com/danielmai/.emacs.d/blob/master/init.el
;;; Set up package. Originally in =starter-kit.org= but when I
;;; downloaded everything anew from the github repository =use-package=
;;; didn't work until I moved this here.
;;; DGM on 2 Oct 2019: changing all http's to https as per: https://www.reddit.com/r/emacs/comments/aug9in/failed_to_verify_signature_archivecontentssig/
;;; DGM on 6 nov 2019: added this line to be able to load emacs or else
;;; I had a signature fail message. I have to solve this
;;; (setq package-check-signature nil)
;; We require the <package.el> package to bring in the environment all the package management functions
(require 'package)
(setq package-archives '(
("melpa" . "https://melpa.org/packages/")
("org" . "https://orgmode.org/elpa/")
("gnu" . "https://elpa.gnu.org/packages/")))
;; From DW. In the very first load, check if there is a package archive cloned
;; in your computer. Unless the archive exists, refresh the package list so that
;; future calls to packages functions know which packages you're referring to.
(unless package-archive-contents
(package-refresh-contents))
;; Initialise the packages, avoiding a re-initialisation?
(when (boundp 'package-pinned-packages)
(setq package-pinned-packages
'((org-plus-contrib . "org"))))
;; Emacs 27: Warning (package): Unnecessary call to ‘package-initialize’ in init
;; file. Typically this initializes the package system and preprares it to be
;; used.
;; (package-initialize)
;;; Add support to package.el for pre-filtering available packages
(defvar package-filter-function nil
"Optional predicate function used to internally filter packages used by package.el.
The function is called with the arguments PACKAGE VERSION ARCHIVE, where
PACKAGE is a symbol, VERSION is a vector as produced by `version-to-list', and
ARCHIVE is the string name of the package archive.")
(defadvice package--add-to-archive-contents
(around filter-packages (package archive) activate)
"Add filtering of available packages using `package-filter-function', if non-nil."
(when (or (null package-filter-function)
(funcall package-filter-function
(car package)
(funcall (if (fboundp 'package-desc-version)
'package--ac-desc-version
'package-desc-vers)
(cdr package))
archive))
ad-do-it))
(defvar melpa-exclude-packages
;; '(slime magit)
'()
"Don't install Melpa versions of these packages.")
;; Don't take Melpa versions of certain packages
(setq package-filter-function
(lambda (package version archive)
(and
(not (memq package '(eieio)))
(or (not (string-equal archive "melpa"))
(not (memq package melpa-exclude-packages))))))
;; Make sure `use-package' is available (used to configure the rest of the packages)
;; Bootstrap use-package
;; Install use-package if it's not already installed.
(unless (or (package-installed-p 'use-package)
(package-installed-p 'diminish))
(package-refresh-contents)
(package-install 'use-package)
(package-install 'diminish))
;; Configure `use-package' prior to loading it.
(setq use-package-enable-imenu-support t)
(setq use-package-minimum-reported-time 0)
(setq use-package-verbose t)
(setq use-package-compute-statistics t)
;; From use-package README
(eval-when-compile
(require 'use-package))
(setq-default use-package-minimum-reported-time 0)
(setq use-package-minimum-reported-time 0)
(eval-and-compile (setq-default use-package-verbose t))
(eval-and-compile (setq use-package-verbose t))
(setq use-package-always-ensure t) ;; The :ensure keyword causes the package(s) to be installed automatically if not already present on your system
;; Other options from Prot(eval-and-compile
;; (setq use-package-always-ensure nil)
;; (setq use-package-always-defer nil)
;; (setq use-package-always-demand nil)
;; (setq use-package-expand-minimally nil)
;; More Prot Stuff
;; The following is VERY IMPORTANT. Write hooks using their real name
;; instead of a shorter version: after-init ==> `after-init-hook'.
;;
;; This is to empower help commands with their contextual awareness,
;; such as `describe-symbol'.
;; (setq use-package-hook-name-suffix nil)
;;; Garbage collection the automated way
;;; my system collapsed when I used it!!
;; (use-package gcmh
;; :ensure t
;; :init
;; (gcmh-mode 1))
(use-package bind-key)
;; tip from https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=810640
(setq tramp-ssh-controlmaster-options nil)
(setq-default tramp-ssh-controlmaster-options nil)
;; tramp package from
;; https://github.com/danielmai/.emacs.d/blob/master/config.org
;; TRAMP (Transparent Remote Access, Multiple Protocols) is a package for editing remote files, similar to AngeFtp or efs. Whereas the others use FTP to connect to the remote host and to transfer the files, TRAMP uses a remote shell connection (rlogin, telnet, ssh). It can transfer the files using rcp or a similar program, or it can encode the file contents (using uuencode or base64) and transfer them right through the shell connection.
;; Tramp was formerly called RCP or rcp.el.
(use-package tramp
:defer t)
;; Do this to quicken startup:
;; https://emacs.stackexchange.com/questions/14708/debugging-slowness-in-init-file-not-hostname-related
;; because I was getting the startup process tripped until I did this.
;;;;;;;;;; commented out by dgm on January the 10th as i rather go for
;;;;;;;;;;;; the nil option
;;;;;;;;;;;; (setq tramp-ssh-controlmaster-options "")
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; async ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; activate for all packages. Advised in Helm's wiki
;; also, uncle dave says: Lets us use asynchronous processes wherever
;; possible, pretty useful.
(use-package async
:init (dired-async-mode 1)
:config
(setq async-bytecomp-allowed-packages '(all))
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; exwm
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Sacha says: (server-start) permits the use of emacsclient,
;; emacsclient, and org-protocol.
;; emacs --daemon, which starts a server automatically but with --daemon, Emacs doesn't start off
;; in a graphical environment.
;; dgm comments out on Nov 13th 2019 to try and stop emacs from
;; creating new frames
;; (server-start)
(require 'server)
(or (server-running-p) (server-start))
;; When stating the client from .xinitrc, =save-buffer-kill-terminal= will =force-kill= Emacs before it can run through =kill-emacs-hook=.
(global-set-key (kbd "C-x C-c") 'save-buffers-kill-emacs)
;; (defun efs/exwm-update-class ()
;; (exwm-workspace-rename-buffer exwm-class-name))
;; :init
;; (load "/home/dgm/.emacs.d/src/ambrevar/functions.el")
(use-package exwm
:config
(require 'exwm-config)
;; (require 'exwm-systemtray)
(require 'exwm-randr)
(exwm-enable))
;; (use-package exwm-edit)
;; Check for start-up errors. See =~/.profile=
(let ((error-logs (directory-files "~" t "errors.*log$")))
(when error-logs
(warn "Error during system startup. See %s." (mapconcat 'identity error-logs ", "))
(when (daemonp)
;; Non-daemon Emacs already brings up the *Warning* buffer.
(setq initial-buffer-choice
(lambda () (get-buffer "*Warnings*"))))))
(use-package delight)
;;; changed to <nil> on March, 15th, 2021
;;; debug options from https://github.com/ch11ng/exwm/wiki
(setq debug-on-error nil)
;; (setq debug-on-quit t)
(setq edebug-all-forms nil)
;; ;; Common Lisp compatability
(require 'cl-lib)
;; ;; Temporary workaround for eshell bug in 24.3.1
;; ;; http://zpcat.blogspot.com/2013/08/configure-eshell-mode-after-upgrade.html
(require 'esh-mode)
;; ;; Package Locations
(if (fboundp 'normal-top-level-add-subdirs-to-load-path)
(let* ((my-lisp-dir "~/.emacs.d/")
(default-directory my-lisp-dir))
;; (setq load-path (cons my-lisp-dir load-path))
(normal-top-level-add-subdirs-to-load-path)))
;; ;; Load up Org Mode and Babel
;; ;; load up the main file
;; ;; org-mode windmove compatibility
(require 'org)
(org-babel-load-file (expand-file-name "starter-kit.org" dotfiles-dir))
;; This tells Emacs to open all .org files in org-mode (http://sachachua.com/blog/2007/12/emacs-getting-things-done-with-org-basic/)
(add-to-list 'auto-mode-alist '("\\.org$" . org-mode))
;;; Higher garbage collection threshold
;; (setq gc-cons-threshold 20000000)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;; The Power of UTF8 ;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Enable UTF-8 by default. From: lopez-ibanez.eu/dotemacs.html
(prefer-coding-system 'utf-8)
;;; other stuff from https://github.com/izahn/emacs-starter-kit
;;; kjh says that setting this coding system prevents emacs from choking on melpa file listings
;;; see also https://masteringemacs.org/article/working-coding-systems-unicode-emacs
(set-default-coding-systems 'utf-8)
(set-terminal-coding-system 'utf-8)
(set-keyboard-coding-system 'utf-8)
;; backwards compatibility as default-buffer-file-coding-system
;; is deprecated in 23.2. (Petersen's way. I commented it out now and
;; leave it as it was originally)
;; (if (boundp 'buffer-file-coding-system)
;; (setq-default buffer-file-coding-system 'utf-8)
;; (setq default-buffer-file-coding-system 'utf-8))
;; originally I had (setq buffer-file-coding-system 'utf-8)
(setq default-buffer-file-coding-system 'utf-8)
(setq buffer-file-coding-system 'utf-8)
(setq-default buffer-file-coding-system 'utf-8)
;; Treat clipboard input as UTF-8 string first; compound text next, etc.
;; (setq x-select-request-type '(UTF8_STRING COMPOUND_TEXT TEXT STRING))
;; next version as in Sacha Chua's dotfiles
(when (display-graphic-p)
(setq x-select-request-type '(UTF8_STRING COMPOUND_TEXT TEXT STRING)))
;; UTF-8 as default encoding (permanently choose a encoding system in
;; emacs for opening and saving). See http://ergoemacs.org/emacs/emacs_encoding_decoding_faq.html
(set-language-environment 'utf-8)
(setq locale-coding-system 'utf-8)
(unless (eq system-type 'windows-nt)
(set-selection-coding-system 'utf-8))
;; DGM on 4 October 2019 following Bern Hansen
(setq default-process-coding-system '(utf-8-unix . utf-8-unix))
;; DGM on 3 December 2020: default input method
;; tip from: https://emacs.stackexchange.com/questions/418/setting-and-activating-the-default-input-method
(setq default-input-method "spanish-prefix")
(defvar use-default-input-method t)
(make-variable-buffer-local 'use-default-input-method)
(defun activate-default-input-method ()
(interactive)
(if use-default-input-method
(activate-input-method default-input-method)
(inactivate-input-method)))
(add-hook 'after-change-major-mode-hook 'activate-default-input-method)
(add-hook 'minibuffer-setup-hook 'activate-default-input-method)
(defun inactivate-default-input-method ()
(setq use-default-input-method nil))
(add-hook 'c-mode-hook 'inactivate-default-input-method)
(add-hook 'prog-mode-hook 'inactivate-default-input-method)
;;;;;;; dgm on 13 December 2018 to try and not get the conflict with utf-8-emacs
;; from https://stackoverflow.com/questions/24904208/emacs-windows-org-mode-encoding
;; (modify-coding-system-alist 'file "" 'utf-8-unix) ;; this is the line that the guys in stackoverflow say fix everything
;; (setq coding-system-for-read 'utf-8)
;; (setq coding-system-for-write 'utf-8)
;;; Tuhdo's setup for the records
;; (set-terminal-coding-system 'utf-8)
;; (set-keyboard-coding-system 'utf-8)
;; (set-language-environment "UTF-8")
;; (prefer-coding-system 'utf-8)
;; Note in =starter-kit-org.org= there are two more lines on the coding system for the org mode case.
;; other stuff from
;; https://superuser.com/questions/410100/how-to-make-emacs-accept-utf-8-from-the-keyboard
;; (setq default-process-coding-system '(utf-8-unix . utf-8-unix))
;; (setq default-sendmail-coding-system 'utf-8-unix)
;;;;;;;;;;;;;;;;;;;;;;;;;;; PATH ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; https://github.com/purcell/exec-path-from-shell
(use-package exec-path-from-shell)
(setq-default exec-path-from-shell-arguments nil)
(setq exec-path-from-shell-arguments nil)
(setq exec-path-from-shell-check-startup-files t)
(when (memq window-system '(mac ns x))
(exec-path-from-shell-initialize))
;;;;;;;;;;;;;;;;;;;;;;;;
;; Autoloads: Dropbox ;;
;;;;;;;;;;;;;;;;;;;;;;;;
;; Autostart Dropbox
(call-process-shell-command "(sleep 10s && ~/.dropbox-dist/dropboxd) &" nil 0)
;;;;;;;;;;;;;;;;;;;;;
;; Local variables ;;
;;;;;;;;;;;;;;;;;;;;;
;; From https://alhassy.github.io/init/
;; Let's always load local variables that we've marked as safe. ( I tend to use loads of such locals! )
(setq enable-local-variables :safe)
;; This buffer is for text that is not saved, and for Lisp evaluation.
;; To create a file, visit it with <open> and enter text in its buffer.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; ambrevar stuff
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Emacs config
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Prerequisites
;; (let ((minver "26.1"))
;; (when (version< emacs-version minver)
;; (error "Your Emacs is too old -- this config requires v%s or higher" minver)))
;; ;;; Speed up init.
;; ;;; Temporarily reduce garbage collection during startup. Inspect `gcs-done'.
;; (defun ambrevar/reset-gc-cons-threshold ()
;; (setq gc-cons-threshold (car (get 'gc-cons-threshold 'standard-value))))
;; (setq gc-cons-threshold (* 64 1024 1024))
;; (add-hook 'after-init-hook 'ambrevar/reset-gc-cons-threshold)
;; ;;; Temporarily disable the file name handler.
;; (setq default-file-name-handler-alist file-name-handler-alist)
;; (setq file-name-handler-alist nil)
;; (defun ambrevar/reset-file-name-handler-alist ()
;; (setq file-name-handler-alist
;; (append default-file-name-handler-alist
;; file-name-handler-alist))
;; (cl-delete-duplicates file-name-handler-alist :test 'equal))
;; (add-hook 'after-init-hook 'ambrevar/reset-file-name-handler-alist)
;; ;;; Avoid the "loaded old bytecode instead of newer source" pitfall.
;; (setq load-prefer-newer t)
;; ;;; Store additional config in a 'lisp' subfolder and add it to the load path so
;; ;;; that `require' can find the files.
;; ;;; This must be done before moving `user-emacs-directory'.
;; (add-to-list 'load-path (expand-file-name "lisp/" user-emacs-directory))
;; ;;; Move user-emacs-directory so that user files don't mix with cache files.
;; (setq user-emacs-directory "~/.cache/emacs/")
;; ;;; Site Lisp folder for local packages and development.
;; ;; We need to roll it out manually since we want it first in the `load-path',
;; ;; while `normal-top-level-add-subdirs-to-load-path' appends it to the very end.
;; (defun ambrevar/package-refresh-load-path (path)
;; "Add every non-hidden sub-folder of PATH to `load-path'."
;; (when (file-directory-p path)
;; (dolist (dir (directory-files path t "^[^\\.]"))
;; (when (file-directory-p dir)
;; (setq load-path (add-to-list 'load-path dir))
;; (dolist (subdir (directory-files dir t "^[^\\.]"))
;; (when (file-directory-p subdir)
;; (setq load-path (add-to-list 'load-path subdir))))))))
;; (let ((site-lisp (expand-file-name "site-lisp/" "~/.local/share/emacs/")))
;; (add-to-list 'load-path site-lisp)
;; (ambrevar/package-refresh-load-path site-lisp))
;; ;;; Local config. See below for an example usage.
;; (load "local-before" t)
;; (require 'functions)
;; (require 'main)
;; ;; (require 'visual)
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;; Assembly
;; (push 'nasm-mode package-selected-packages)
;; ;;; ChangeLog
;; (defun ambrevar/change-log-set-indent-rules ()
;; (setq tab-width 2 left-margin 2))
;; (add-hook 'change-log-mode-hook 'ambrevar/change-log-set-indent-rules)
;; ;;; Diff
;; ;;; TODO: In diff-mode, both `[[` and `C-M-a` do not go back to previous index
;; ;;; once they are at the beginning of an index.
;; (nconc package-selected-packages '(ztree))
;; ;;; Dired
;; ;;; Dired is loaded after init.el, so configure it only then.
;; ;;; TODO: Improve dired-du:
;; ;;; - Hangs when the `ls` time format is changed.
;; ;;; - Cache recursive results.
;; (nconc package-selected-packages '(dired-du))
;; (with-eval-after-load 'dired (require 'init-dired))
;; ;;; Daemons.
;; (nconc package-selected-packages '(daemons))
;; ;;; Eshell
;; ;;; Extend completion.
;; (nconc package-selected-packages '(fish-completion bash-completion
;; pcomplete-extension pcmpl-args pcmpl-git))
;; (nconc package-selected-packages '(esh-autosuggest))
;; (with-eval-after-load 'eshell (require 'init-eshell))
;; (autoload 'ambrevar/eshell-or-new-session "eshell")
;; ;;; Expand region.
;; (nconc package-selected-packages '(expand-region))
;; (when (require 'expand-region nil t)
;; (global-set-key (kbd "C-=") 'er/expand-region))
;; ;;; Helm
;; (nconc package-selected-packages '(helm helm-descbinds helm-ls-git))
;; (when (require 'helm-config nil t) (require 'init-helm))
;; ;;; Highlight
;; (nconc package-selected-packages '(hl-todo))
;; (when (require 'hl-todo nil t)
;; (add-to-list 'hl-todo-keyword-faces `("REVIEW" . ,(alist-get "TODO" hl-todo-keyword-faces nil nil 'equal)))
;; (global-hl-todo-mode)
;; ;; (global-set-key (kbd "M-s M-o") 'hl-todo-occur)
;; (define-key hl-todo-mode-map (kbd "M-s t") 'hl-todo-occur))
;; ;;; Iedit
;; (nconc package-selected-packages '(iedit))
;; (when (require 'iedit nil t)
;; (global-set-key (kbd "C-;") 'iedit-mode))
;; ;;; Image
;; ;;; TODO: Disable white frame.
;; ;;; I think it's the cursor.
;; ;;; Evil-mode reverts cursor changes.
;; ;; (set-face-foreground 'cursor "black")
;; ;;; TODO: Implement other sxiv features:
;; ;;; - Gamma
;; ;;; - Marks
;; ;;; - Gallery
;; ;;; TODO: Is it possible to display an image fullscreen?
;; ;;; TODO: Image+: Dot no auto-adjust animated files
;; ;;; https://github.com/mhayashi1120/Emacs-imagex/issues/10
;; ;;; TODO: Image+: Restore animation state
;; ;;; https://github.com/mhayashi1120/Emacs-imagex/issues/9
;; ;; (nconc package-selected-packages '(image+))
;; ;; (with-eval-after-load 'image
;; ;; (setq image-animate-loop t)
;; ;; (add-hook 'image-mode-hook 'image-toggle-animation)
;; ;; (require 'image+ nil t))
;; ;;; Indentation engine fix.
;; ;; (require 'smiext "init-smiext")
;; ;;; Indentation style guessing.
;; ;; (nconc 'package-selected-packages '(dtrt-indent))
;; ;;; Info-colors
;; ;; (nconc 'package-selected-packages '(info-colors))
;; (when (require 'info-colors nil t)
;; (add-hook 'Info-selection-hook 'info-colors-fontify-node))
;; ;;; Lisp
;; (nconc package-selected-packages '(lispy lispyville rainbow-delimiters geiser slime))
;; (with-eval-after-load 'lisp-mode (require 'init-lisp))
;; (setq geiser-repl-history-filename (expand-file-name "geiser_history" user-emacs-directory))
;; ;;; Magit
;; ;;; Magit can be loaded just-in-time.
;; ;; (nconc package-selected-packages '(magit magit-todos))
;; ;; (with-eval-after-load 'magit
;; ;; (setq auto-revert-mode-text "")
;; ;; (set-face-foreground 'magit-branch-remote "orange red")
;; ;; (setq git-commit-summary-max-length fill-column)
;; ;; ;; Customize what to fold by default.
;; ;; ;; (push (cons [* commitbuf] 'hide) magit-section-initial-visibility-alist)
;; ;; ;; Avoid conflict with WM.
;; ;; (define-key magit-mode-map (kbd "s-<tab>") nil)
;; ;; (setq magit-diff-refine-hunk 'all)
;; ;; (when (require 'magit-todos nil t)
;; ;; ;; REVIEW: Default scanner does not work on Guix because Git needs be compiled with PCRE.
;; ;; (setq magit-todos-scanner #'magit-todos--scan-with-find|grep)
;; ;; (magit-todos-mode)))
;; ;; (when (fboundp 'magit-status)
;; ;; (global-set-key (kbd "C-x g") 'magit-status))
;; ;;; Mail
;; ;;; mu4e is usually site-local and not part of ELPA.
;; (when (or (fboundp 'mu4e)
;; (delq nil (mapcar (lambda (path) (string-match "/mu4e/\\|/mu4e$" path)) load-path)))
;; ;; (nconc package-selected-packages '(mu4e-maildirs-extension))
;; (nconc package-selected-packages '(helm-mu)))
;; (with-eval-after-load 'mu4e
;; ;; mu4e-conversation must be enabled here.
;; ;; REVIEW: https://github.com/djcb/mu/issues/1258
;; (when (require 'mu4e-conversation nil t)
;; (global-mu4e-conversation-mode)
;; ;; (setq mu4e-debug t)
;; (setq mu4e-headers-show-threads nil
;; mu4e-headers-include-related nil)
;; ;; For testing purposes:
;; ;; (set-face-background mu4e-conversation-sender-1 "#335533")
;; ;; (set-face-background mu4e-conversation-sender-2 "#553333")
;; ;; (set-face-background mu4e-conversation-sender-3 "#333355")
;; ;; (set-face-background mu4e-conversation-sender-4 "#888855")
;; ;; (setq mu4e-conversation-print-function 'mu4e-conversation-print-tree)
;; (add-hook 'mu4e-conversation-hook 'flyspell-mode)
;; ;; (add-hook
;; ;; 'mu4e-conversation-before-send-hook
;; ;; (lambda ()
;; ;; (setq mu4e-compose-signature-auto-include nil)))
;; (add-hook
;; 'mu4e-conversation-after-send-hook
;; (lambda ()
;; (let ((mu4e-get-mail-command "mbsync ambrevar-sent peneidhardt-sent"))
;; (mu4e-update-mail-and-index 'run-in-background))))
;; (add-hook 'mu4e-view-mode-hook 'auto-fill-mode))
;; (require 'init-mu4e))
;; (autoload 'ambrevar/mu4e-headers "mu4e")
;; ;;; Makefile
;; (with-eval-after-load 'make-mode (require 'init-makefile))
;; ;;; Markdown
;; (nconc package-selected-packages '(markdown-mode))
;; (with-eval-after-load 'markdown-mode (require 'init-markdown))
;; ;;; Org-mode
;; (nconc package-selected-packages '(org-plus-contrib org-bullets helm-org-contacts)) ; org-plus contains latest Org mode.
;; (with-eval-after-load 'org (require 'init-org))
;; (autoload 'ambrevar/org-switch-agenda-file "org")
;; (autoload 'ambrevar/org-switch-agenda-file-other-window "org")
;; ;;; Packaging
;; (nconc package-selected-packages '(esup package-lint))
;; ;;; Pass
;; (nconc package-selected-packages '(helm-pass))
;; ;;; PDF
;; ;;; pdf-tools requires poppler built with cairo support.
;; ;;; We cannot defer loading as `pdf-tools-install' is required for PDF
;; ;;; association.
;; ;;; REVIEW: `save-place' does not seem to work with pdf-tools.
;; ;;; See https://github.com/politza/pdf-tools/issues/18.
;; ;;; TODO: windmove fails when selecting text and then moving up/down.
;; ;;; It only fails in Evil mode.
;; (nconc package-selected-packages '(pdf-tools))
;; (when (require 'pdf-tools nil t)
;; ;; (setq pdf-view-midnight-colors '("#ffffff" . "#000000"))
;; (setq pdf-view-midnight-colors '("#ff9900" . "#0a0a12" )) ; Amber
;; (add-hook 'pdf-view-mode-hook 'pdf-view-midnight-minor-mode)
;; (pdf-tools-install t t t))
;; ;;; Python
;; (with-eval-after-load 'python (require 'init-python))
;; ;;; Rainbow-mode
;; (nconc package-selected-packages '(rainbow-mode))
;; (when (require 'rainbow-mode nil t)
;; (dolist (hook '(css-mode-hook html-mode-hook sass-mode-hook))
;; (add-hook hook 'rainbow-mode)))
;; ;;; Screencast
;; ;; (nconc package-selected-packages '(camcorder))
;; (with-eval-after-load 'camcorder
;; (setq camcorder-output-directory (expand-file-name "temp" "~")
;; camcorder-gif-output-directory camcorder-output-directory)
;; (setq camcorder-recording-command '("recordmydesktop" " --fps 10 --no-sound --windowid " window-id " -o " file))
;; (add-to-list 'camcorder-gif-conversion-commands '("ffmpeg-slow" "ffmpeg -i " input-file " -vf 'fps=10,scale=1024:-1:flags=lanczos' " gif-file)))
;; (nconc package-selected-packages '(gif-screencast keycast))
;; (with-eval-after-load 'gif-screencast
;; (define-key gif-screencast-mode-map (kbd "<f8>") 'gif-screencast-toggle-pause)
;; (define-key gif-screencast-mode-map (kbd "<f9>") 'gif-screencast-stop))
;; ;;; Shell
;; (with-eval-after-load 'sh-script (require 'init-sh))
;; ;;; Arch Linux PKGBUILD
;; (add-to-list 'auto-mode-alist '("PKGBUILD" . sh-mode))
;; ;;; Gentoo
;; (add-to-list 'auto-mode-alist '("\\.ebuild\\'" . sh-mode))
;; (add-to-list 'auto-mode-alist '("\\.eclass\\'" . sh-mode))
;; (add-to-list 'auto-mode-alist '("package\\.accept_keywords" . sh-mode))
;; (add-to-list 'auto-mode-alist '("package\\.mask" . sh-mode))
;; (add-to-list 'auto-mode-alist '("package\\.use" . sh-mode))
;; ;;; If we ever need to edit exotic shell configs:
;; ;; (nconc package-selected-packages '(fish-mode rc-mode))
;; ;;; Srt (subtitles)
;; (add-to-list 'auto-mode-alist '("\\.srt\\'" . text-mode))
;; ;;; StackExchange
;; (nconc package-selected-packages '(sx))
;; (nconc package-selected-packages '(strace-mode))
;; (nconc package-selected-packages '(synosaurus))
;; ;;; Syntax checking
;; (nconc package-selected-packages '(flycheck helm-flycheck))
;; (when (require 'flycheck nil t) (require 'init-flycheck))
;; ;;; System packages
;; (nconc package-selected-packages '(helm-system-packages))
;; (global-set-key (kbd "C-x c #") 'helm-system-packages)
;; ;;; Terminal
;; (with-eval-after-load 'term
;; ;; (require 'init-term)
;; (setq term-buffer-maximum-size 0))
;; ;;; Torrent
;; (nconc package-selected-packages '(transmission))
;; (with-eval-after-load 'transmission
;; ;; `transmission' will fail to start and will not run any hook if the daemon
;; ;; is not up yet.
;; ;; We need to advice the function :before to guarantee it starts.
;; (defun ambrevar/transmission-start-daemon ()
;; (unless (member "transmission-da"
;; (mapcar
;; (lambda (pid) (alist-get 'comm (process-attributes pid)))
;; (list-system-processes)))
;; (call-process "transmission-daemon")
;; (sleep-for 1)))
;; (advice-add 'transmission :before 'ambrevar/transmission-start-daemon)
;; (setq transmission-refresh-modes '(transmission-mode transmission-files-mode transmission-info-mode transmission-peers-mode)
;; transmission-refresh-interval 1))
;; ;;; Translator
;; (nconc package-selected-packages '(google-translate))
;; (when (require 'google-translate nil t)
;; (require 'google-translate-default-ui)
;; ;; (global-set-key "\C-ct" 'google-translate-at-point)
;; ;; (global-set-key "\C-cT" 'google-translate-query-translate)
;; (defun ambrevar/google-translate-line ()
;; "Translate current line and insert result after it, separated by ' = '."
;; (interactive)
;; (let* ((langs (google-translate-read-args nil nil))
;; (source-language (car langs))
;; (target-language (cadr langs))
;; text
;; result)
;; (end-of-line)
;; (just-one-space)
;; (setq text (buffer-substring-no-properties
;; (line-beginning-position) (line-end-position)))
;; (setq result (with-temp-buffer
;; (google-translate-translate
;; source-language target-language
;; text
;; 'current-buffer)
;; (buffer-string))
;; (insert "= " result)))))
;; ;;; Web forms.
;; ;;; Remove auto-fill in web edits because wikis and forums do not like it.
;; ;;; This works for qutebrowser, but may need changes for other browsers.
;; (defun ambrevar/browser-edit ()
;; (when (require 'with-editor nil t) (with-editor-mode))
;; (text-mode)
;; (auto-fill-mode -1))
;; (add-to-list 'auto-mode-alist `(,(concat (getenv "BROWSER") "-editor-*") . ambrevar/browser-edit))
;; ;;; Wgrep
;; (nconc package-selected-packages '(wgrep-helm wgrep-pt))
;; (when (require 'wgrep nil t)
;; ;; TODO: wgrep-face is not so pretty.
;; (set-face-attribute 'wgrep-face nil :inherit 'ediff-current-diff-C :foreground 'unspecified :background 'unspecified :box nil))
;; ;;; Window manager
;; (nconc package-selected-packages '(exwm helm-exwm))
;; (nconc package-selected-packages '(pulseaudio-control))
;; (with-eval-after-load 'pulseaudio-control
;; ;; REVIEW: Upstream should set path dynamically.
;; ;; https://github.com/flexibeast/pulseaudio-control/issues/7
;; (setq pulseaudio-control-pactl-path (executable-find "pactl")
;; pulseaudio-control-volume-step "2%"))
;; (when (require 'exwm nil t) (require 'init-exwm))
;; ;;; Yasnippet
;; (nconc package-selected-packages '(yasnippet))
;; (nconc package-selected-packages '(youtube-dl))
;; (with-eval-after-load 'youtube-dl
;; (setq youtube-dl-directory "~/temp"))
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;; Finalization
;; ;;; Don't let `customize' clutter my config.
;; (setq custom-file
;; (if (boundp 'server-socket-dir)
;; (expand-file-name "custom.el" server-socket-dir)
;; (expand-file-name (format "emacs-custom-%s.el" (user-uid)) temporary-file-directory)))
;; (load custom-file t)
;; ;;; Local config. You can use it to set system specific variables, such as the
;; ;;; external web browser or the geographical coordinates:
;; ;;
;; ;; (setq calendar-latitude 20.2158)
;; ;; (setq calendar-longitude 105.938)
;; (load "local-after" t)
;; Ambrevar's stuff (from his init)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; commented out by dgm on 5 nov
;;2018 when trying to write a ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; starter-kit-helm file
;;;;;;;;;;;;; helm
;;(require 'helm)
;;(require 'helm-config)
;;(nconc package-selected-packages '(helm helm-descbinds helm-ls-git))
;; (when (require 'helm-config nil t) (require 'init-helm))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;; other helm-related stuff
;; commented out as flyspell makes email work very slowly and I don't
;; know if this bit of code is messing around
;;; Syntax checking
;; (nconc package-selected-packages '(flycheck helm-flycheck))
;; (when (require 'flycheck nil t) (require 'init-flycheck))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; commented out by dgm on
;;; 5 nov 2018
;;; System packages
;;;;;;;;;;;; (nconc package-selected-packages '(helm-system-packages))
;;;;;;;;;;;; (global-set-key (kbd "C-x c #") 'helm-system-packages)
;;;;;;;;;;;;;;;;;;;;;;;; commented out by dgm on 6 nov 2018
;;; Org-mode
;;(nconc package-selected-packages '(org-plus-contrib org-bullets helm-org-contacts)) ; org-plus contains latest Org mode.
;;(with-eval-after-load 'org (require 'init-org))
;;;;;;;;;;;;;;;;;;; mu4e ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Following advice for reading advanced emails (with complicated
;; images) from /media/dgm/blue/documents/elibrary/computing/Linux/linuxFormat/tips/emacs2-email-video-246February2019.pdf
;; (setq mu4e-html2text-command "iconv -c -t utf-8 | pandoc -f html -t plain")
(put 'magit-diff-edit-hunk-commit 'disabled nil)