-
Notifications
You must be signed in to change notification settings - Fork 1
/
init.el
2248 lines (1841 loc) · 77 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
;; ######################################## INSTALL PACKAGES ######################################
(require 'package)
(add-to-list 'package-archives
'("melpa" . "http://melpa.org/packages/") t)
(add-to-list 'package-archives
'("melpa-stable" . "https://stable.melpa.org/packages/"))
(add-to-list 'package-archives
'("org" . "http://orgmode.org/elpa/") t) ;; for newest version of org mode
(package-initialize)
(when (not package-archive-contents)
(package-refresh-contents))
; Bootstrap `use-package'
(unless (package-installed-p 'use-package)
(package-refresh-contents)
(package-install 'use-package))
(unless (package-installed-p `better-defaults) (package-install `better-defaults))
(unless (package-installed-p `material-theme) (package-install `material-theme))
(unless (package-installed-p `auto-complete) (package-install `auto-complete))
;; automate package updating. It is silly to do this manually.
;; (use-package auto-package-update
;; :custom
;; (auto-package-update-interval 31)
;; (auto-package-update-delete-old-versions t)
;; (auto-package-update-prompt-before-update t)
;; (auto-package-update-show-preview t)
;; :config
;; (auto-package-update-maybe))
;; ##################################### BASIC CUSTOMIZATION ######################################
(setq inhibit-startup-message t) ;; hide the startup message
;; (load-theme 'material t) ;; load material theme
;; (global-linum-mode t) ;; enable line numbers globally
(set-default 'truncate-lines t) ;; do not wrap
(prefer-coding-system 'utf-8) ;; use UTF-8
;;### Shell configuration
(use-package exec-path-from-shell
:init
(setenv "SHELL" "/bin/zsh")
:ensure t
:if (memq window-system '(mac ns x))
:config
(setq exec-path-from-shell-variables '("PATH" "GOPATH" "PYTHONPATH"))
(exec-path-from-shell-initialize))
;;### Faked full screen
(use-package maxframe
:ensure t)
(defvar my-fullscreen-p t "Check if fullscreen is on or off")
(defun my-toggle-fullscreen ()
(interactive)
(setq my-fullscreen-p (not my-fullscreen-p))
(if my-fullscreen-p
(restore-frame)
(maximize-frame)))
;; (global-set-key (kbd "M-RET") 'toggle-frame-fullscreen) ;; conflicts with an auctex command to insert an \item in a list.
;;### Turn on font-locking or syntax highlighting
(global-font-lock-mode t)
;;### font size in the modeline
(set-face-attribute 'mode-line nil :height 140)
;; set default coding of buffers
(setq default-buffer-file-coding-system 'utf-8-unix)
;; Switch from tabs to spaces for indentation
;; Set the indentation level to 4.
(setq-default indent-tabs-mode nil)
(setq-default tab-width 4)
;;### hippie-expand M-/
(global-set-key [remap dabbrev-expand] 'hippie-expand)
;; GUI related settings
(if (display-graphic-p)
(progn
;; Removed some UI elements
;; (menu-bar-mode -1)
(tool-bar-mode -1)
(scroll-bar-mode -1)
;; Show battery status
(display-battery-mode 1)))
;; Hey, stop being a whimp and learn the Emacs keybindings!
;; ;; Set copy+paste
;; (cua-mode t)
;; (setq cua-auto-tabify-rectangles nil) ;; Don't tabify after rectangle commands
;; (transient-mark-mode 1) ;; No region when it is not highlighted
;; (setq cua-keep-region-after-copy t) ;; Standard Windows behaviour
;; REMOVE THE SCRATCH BUFFER AT STARTUP
;; Makes *scratch* empty.
;; (setq initial-scratch-message "")
;; Removes *scratch* from buffer after the mode has been set.
;; (defun remove-scratch-buffer ()
;; (if (get-buffer "*scratch*")
;; (kill-buffer "*scratch*")))
;; (add-hook 'after-change-major-mode-hook 'remove-scratch-buffer)
;; Disable the C-z sleep/suspend key
;; See http://stackoverflow.com/questions/28202546/hitting-ctrl-z-in-emacs-freezes-everything
(global-unset-key (kbd "C-z"))
;; Disable the C-x C-b key, use helm (C-x b) instead
(global-unset-key (kbd "C-x C-b"))
;; Make copy and paste use the same clipboard as emacs.
(setq select-enable-primary t
select-enable-clipboard t)
(setq display-time-default-load-average nil)
(setq display-time-day-and-date t display-time-24hr-format t)
(display-time-mode t)
;; dired-icon-mode
(add-hook 'dired-mode-hook 'dired-icon-mode)
;; replace dired with dirvish
(dirvish-override-dired-mode)
;; Revert Dired and other buffers after changes to files in directories on disk.
;; Source: [[https://www.youtube.com/watch?v=51eSeqcaikM&list=PLEoMzSkcN8oNmd98m_6FoaJseUsa6QGm2&index=2][Dave Wilson]]
(setq global-auto-revert-non-file-buffers t)
;; customize powerline
;; (line above the command line at the bottom of the screen)
(use-package powerline
:ensure t)
(require 'powerline)
(powerline-default-theme)
;; Add line numbers.
;; (global-nlinum-mode t)
;; highlight current line
(global-hl-line-mode +1)
(set-face-background hl-line-face "#1c1f26")
(set-face-attribute 'mode-line nil :height 360)
;; List recently opened files.
(recentf-mode 1)
;; Revert buffers when the underlying file has changed.
(global-auto-revert-mode 1)
;; Save history going back 25 commands.
;; Use M-p to get previous command used in the minibuffer.
;; Use M-n to move to next command.
(setq history-length 25)
(savehist-mode 1)
;; Save place in a file.
(save-place-mode 1)
;; sets monday to be the first day of the week in calendar
(setq calendar-week-start-day 1)
;; save emacs backups in a different directory
;; (some build-systems build automatically all files with a prefix, and .#something.someending breakes that)
(setq backup-directory-alist '(("." . "~/.emacsbackups")))
;; Enable show-paren-mode (to visualize paranthesis) and make it possible to delete things we have marked
(show-paren-mode 1)
(delete-selection-mode 1)
;; use y or n instead of yes or no
(defalias 'yes-or-no-p 'y-or-n-p)
;; These settings enables using the same configuration file on multiple platforms.
;; Note that windows-nt includes [[https://www.gnu.org/software/emacs/manual/html_node/elisp/System-Environment.html][windows 10]].
(defconst *is-a-mac* (eq system-type 'darwin))
(defconst *is-a-linux* (eq system-type 'gnu/linux))
(defconst *is-windows* (eq system-type 'windows-nt))
(defconst *is-cygwin* (eq system-type 'cygwin))
(defconst *is-unix* (not *is-windows*))
;; See this [[http://ergoemacs.org/emacs/emacs_hyper_super_keys.html][ for more information.]]
;; set keys for Apple keyboard, for emacs in OS X
;; Source http://xahlee.info/emacs/emacs/emacs_hyper_super_keys.html
(setq mac-command-modifier 'meta) ; make cmd key do Meta
(setq mac-option-modifier 'super) ; make option key do Super.
(setq mac-control-modifier 'control) ; make Control key do Control
(setq mac-function-modifier 'hyper) ; make Fn key do Hyper. Only works on Apple produced keyboards.
(setq mac-right-command-modifier 'hyper)
;; Switch to previous buffer
(define-key global-map (kbd "s-<left>") 'previous-buffer)
;; Switch to next buffer
(define-key global-map (kbd "s-<right>") 'next-buffer)
;; Minibuffer history keybindings
;; The calling up of a previously issued command in the minibuffer with ~M-p~ saves times.
(autoload 'edit-server-maybe-dehtmlize-buffer "edit-server-htmlize" "edit-server-htmlize" t)
(autoload 'edit-server-maybe-htmlize-buffer "edit-server-htmlize" "edit-server-htmlize" t)
(add-hook 'edit-server-start-hook 'edit-server-maybe-dehtmlize-buffer)
(add-hook 'edit-server-done-hook 'edit-server-maybe-htmlize-buffer)
(define-key minibuffer-local-map (kbd "M-p") 'previous-complete-history-element)
(define-key minibuffer-local-map (kbd "M-n") 'next-complete-history-element)
(define-key minibuffer-local-map (kbd "<up>") 'previous-complete-history-element)
(define-key minibuffer-local-map (kbd "<down>") 'next-complete-history-element)
;; Bibtex configuration
(defconst blaine/bib-libraries (list "/Users/blaine/Documents/global.bib"))
;; Combined with emacs-mac, this gives good PDF quality for [[https://www.aidanscannell.com/post/setting-up-an-emacs-playground-on-mac/][retina display]].
(setq pdf-view-use-scaling t)
;; PDF default page width behavior
(setq-default pdf-view-display-size 'fit-page)
;; Set delay in the matching parenthesis to zero.
(setq show-paren-delay 0)
(show-paren-mode t)
;; rainbow-delimiters
(use-package rainbow-delimiters)
(add-hook 'prog-mode-hook 'rainbow-delimiters-mode)
(set-face-attribute 'rainbow-delimiters-unmatched-face nil
:foreground "magenta"
:inherit 'error
:box t)
;; ############################## Package Configurations ################################
;;## A
;;### auto-complete
;; do default config for auto-complete
(require 'auto-complete)
(require 'auto-complete-config)
(ac-config-default)
(global-auto-complete-mode t)
(ac-flyspell-workaround)
;;;### auto-complete-auctex.el --- auto-completion for auctex
;; Copyright (C) 2012 Christopher Monsanto
;; Author: Christopher Monsanto <[email protected]>
;; Version: 1.0
;; Package-Requires: ((yasnippet "0.6.1") (auto-complete "1.4"))
;; 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:
;; You can install this by (require 'auto-complete-auctex).
;; Feel free to contribute better documentation!
;;;#### Code:
(require 'tex)
(require 'latex)
(eval-when-compile
(require 'auto-complete)
(require 'yasnippet))
(defvar ac-auctex-arg-lookup-table
'((TeX-arg-define-macro . ("\\MacroName"))
(TeX-arg-counter . ("Counter"))
(TeX-arg-define-counter . ("\\CounterName"))
(TeX-arg-file . ("Filename"))
(TeX-arg-bibliography . ("Filename"))
(TeX-arg-bibstyle . ("Style"))
(TeX-arg-environment . ("Environment"))
(TeX-arg-define-environment . ("EnvironmentName"))
(TeX-arg-size . ("(w, h)"))
(TeX-arg-ref . ("Name"))
(TeX-arg-index . ("Index"))
(TeX-arg-define-label . ("Label"))
(LaTeX-arg-usepackage . (["opt1,..."] "Package"))
(LaTeX-env-label . nil)
(LaTeX-amsmath-env-aligned . (["htbp!"]))
(LaTeX-amsmath-env-alignat . (["# Columns"]))
(LaTeX-env-array . (["bct"] "lcrpmb|"))
(LaTeX-env-item . nil)
(LaTeX-env-document . nil)
(LaTeX-env-figure . (["htbp!"]))
(LaTeX-env-contents . ("Filename"))
(LaTeX-env-minipage . (["htbp!"] "Width"))
(LaTeX-env-list . ("Label" "\\itemsep,\\labelsep,..."))
(LaTeX-env-picture . ("(w, h)" "(x, y)"))
(LaTeX-env-tabular* . ("Width" ["htbp!"] "lcrpmb|><"))
(LaTeX-env-bib . ("WidestLabel"))
(TeX-arg-conditional . ([""]))
(2 . ("" ""))
(3 . ("" "" ""))
(4 . ("" "" "" ""))
(5 . ("" "" "" "" ""))
(6 . ("" "" "" "" "" ""))
(7 . ("" "" "" "" "" "" ""))
(8 . ("" "" "" "" "" "" "" ""))
(9 . ("" "" "" "" "" "" "" "" "")))
"Anything not in this table defaults to '(\"\")")
(defun ac-auctex-expand-arg-info (arg-info)
(loop for item in arg-info
append (cond
((or (stringp item) (and (vectorp item) (stringp (elt item 0))))
(list item))
((vectorp item)
(loop for item-2 in (or (assoc-default (or (car-safe (elt item 0)) (elt item 0))
ac-auctex-arg-lookup-table 'equal) '(""))
collect [item-2]))
(t
(or (assoc-default (or (car-safe item) item) ac-auctex-arg-lookup-table) '(""))))))
(defun ac-auctex-snippet-arg (n arg)
(let* ((opt (vectorp arg))
(item (if opt (elt arg 0) arg))
(m (if (vectorp arg) (1+ n) n))
(var (format "${%s}" item)))
(list (1+ m)
(if opt
(concat (format "${[") var "]}")
(concat "{" var "}")))))
;;;#### Macros
;;
(defun ac-auctex-expand-args (str env)
(yas/expand-snippet (ac-auctex-macro-snippet (assoc-default str env))))
(defun ac-auctex-macro-snippet (arg-info)
(let ((count 1))
(apply 'concat (loop for item in (ac-auctex-expand-arg-info arg-info)
collect (destructuring-bind (n val)
(ac-auctex-snippet-arg count item)
(setq count n)
val)))))
(defun ac-auctex-macro-candidates ()
(let ((comlist (if TeX-symbol-list
(mapcar (lambda (item)
(or (car-safe (car item)) (car item)))
TeX-symbol-list))))
(all-completions ac-prefix comlist)))
(defun ac-auctex-macro-action ()
(yas/expand-snippet (ac-auctex-macro-snippet (assoc-default candidate TeX-symbol-list))))
(ac-define-source auctex-macros
'((init . TeX-symbol-list)
(candidates . ac-auctex-macro-candidates)
(action . ac-auctex-macro-action)
(requires . 0)
(symbol . "m")
(prefix . "\\\\\\([a-zA-Z]*\\)\\=")))
;;;#### Symbols
(defun ac-auctex-symbol-candidates ()
(all-completions ac-prefix (mapcar 'cadr LaTeX-math-default)))
(defun ac-auctex-symbol-action ()
(re-search-backward candidate)
(delete-region (1- (match-beginning 0)) (match-end 0))
(if (texmathp)
(progn
(insert "\\" candidate)
(yas/expand-snippet (ac-auctex-macro-snippet (assoc-default candidate TeX-symbol-list))))
(insert "$\\" candidate "$")
(backward-char)
(yas/expand-snippet (ac-auctex-macro-snippet (assoc-default candidate TeX-symbol-list)))))
(defun ac-auctex-symbol-document (c)
(let* ((cl (assoc c (mapcar 'cdr LaTeX-math-default)))
(decode (if (nth 2 cl) (char-to-string (decode-char 'ucs (nth 2 cl))) ""))
(st (nth 1 cl))
(hs (if (listp st) (mapconcat 'identity st " ") st)))
(and decode (concat hs " == " decode))))
(ac-define-source auctex-symbols
'((init . LaTeX-math-mode)
(candidates . ac-auctex-symbol-candidates)
(document . ac-auctex-symbol-document)
(action . ac-auctex-symbol-action)
(requires . 0)
(symbol . "s")
(prefix . "\\\\\\([a-zA-Z]*\\)\\=")))
;;;#### Environments
(defvar ac-auctex-environment-prefix "beg")
(defun ac-auctex-environment-candidates ()
(let ((envlist (mapcar (lambda (item) (concat ac-auctex-environment-prefix (car item)))
LaTeX-environment-list)))
(all-completions ac-prefix envlist)))
(defun ac-auctex-environment-action ()
(re-search-backward candidate)
(delete-region (1- (match-beginning 0)) (match-end 0))
(let ((candidate (substring candidate (length ac-auctex-environment-prefix))))
(yas/expand-snippet (format "\\begin{%s}%s\n$0\n\\end{%s}"
candidate
(ac-auctex-macro-snippet (assoc-default candidate LaTeX-environment-list))
candidate))))
(ac-define-source auctex-environments
'((init . LaTeX-environment-list)
(candidates . ac-auctex-environment-candidates)
(action . ac-auctex-environment-action)
(requires . 0)
(symbol . "e")
(prefix . "\\\\\\([a-zA-Z]*\\)\\=")))
;;;#### Refs
(defun ac-auctex-label-candidates ()
(all-completions ac-prefix (mapcar 'car LaTeX-label-list)))
(ac-define-source auctex-labels
'((init . LaTeX-label-list)
(candidates . ac-auctex-label-candidates)
(requires . 0)
(symbol . "r")
(prefix . "\\\\ref{\\([^}]*\\)\\=")))
;;;#### Bibs
(defun ac-auctex-bib-candidates ()
(all-completions ac-prefix (mapcar 'car LaTeX-bibitem-list)))
(ac-define-source auctex-bibs
`((init . LaTeX-bibitem-list)
(candidates . ac-auctex-bib-candidates)
(requires . 0)
(symbol . "b")
(prefix . ,(concat "\\\\cite"
"\\(?:"
"\\[[^]]*\\]"
"\\)?"
"{\\([^},]*\\)"
"\\="))))
;;;#### Setup
(defun ac-auctex-setup ()
(setq ac-sources (append
'(ac-source-auctex-symbols
ac-source-auctex-macros
ac-source-auctex-environments
ac-source-auctex-labels
ac-source-auctex-bibs)
ac-sources)))
(add-to-list 'ac-modes 'latex-mode)
(add-hook 'LaTeX-mode-hook 'ac-auctex-setup)
(provide 'auto-complete-auctex)
;;; auto-complete-auctex.el ends here
;; indent with spaces instead of tabs for pep8 compatibility
(setq tab-width 4)
(setq-default indent-tabs-mode nil)
;; atomic-chrome, used to interact with GhostText extension for Google Chrome.
(use-package atomic-chrome)
(atomic-chrome-start-server)
(setq atomic-chrome-default-major-mode 'python-mode)
(setq atomic-chrome-extension-type-list '(ghost-text))
;;(atomic-chrome-start-httpd)
(setq atomic-chrome-server-ghost-text-port 4001)
(setq atomic-chrome-url-major-mode-alist
'(("github\\.com" . gfm-mode)
("overleaf.com" . latex-mode)
("750words.com" . latex-mode)))
; Select the style of opening the editing buffer by atomic-chrome-buffer-open-style.
; full: Open in the selected window.
; split: Open in the new window by splitting the selected window (default).
; frame: Create a new frame and window in it. Must be using some windowing pacakge.
(setq atomic-chrome-buffer-open-style 'split)
;; awesome-tabs
;; I love awesome-tabs; some people do not.
;; cd ~/latex-emacs29/manual-packages
;; git clone --depth=1 https://github.com/manateelazycat/awesome-tab.git
(use-package awesome-tab
:load-path "~/latex-emacs29/manual-packages/awesome-tab"
:config
(awesome-tab-mode t))
(global-set-key (kbd "s-1") 'awesome-tab-select-visible-tab)
(global-set-key (kbd "s-2") 'awesome-tab-select-visible-tab)
(global-set-key (kbd "s-3") 'awesome-tab-select-visible-tab)
(global-set-key (kbd "s-4") 'awesome-tab-select-visible-tab)
(global-set-key (kbd "s-5") 'awesome-tab-select-visible-tab)
(global-set-key (kbd "s-6") 'awesome-tab-select-visible-tab)
(global-set-key (kbd "s-7") 'awesome-tab-select-visible-tab)
(global-set-key (kbd "s-8") 'awesome-tab-select-visible-tab)
(global-set-key (kbd "s-9") 'awesome-tab-select-visible-tab)
(global-set-key (kbd "s-0") 'awesome-tab-select-visible-tab)
;; avy
;; Navigate buffer after selecting all sites starting with the same one or two letters.
;; After entering the avy command in the minibuffer, selected sites will be highlighted but they will be indexed with letters.
;; Enter a letter to go to a desired site.
;; See https://github.com/abo-abo/avy for documentation.
;;
(use-package avy
:ensure t
:bind ("M-s" . avy-goto-char)
("M-d" . avy-goto-char-2)
("M-g f" . avy-goto-line)
("M-g w" . avy-goto-word-1)
)
;;## B
;;### bibtex-mode related
;; Fetch bibtex for the given DOI. Insert at point, which should be in your global.bib file.
;; Needs code to reformat the bibtex key.
;;
;; https://www.anghyflawn.net/blog/2014/emacs-give-a-doi-get-a-bibtex-entry/
(defun get-bibtex-from-doi (doi)
"Get a BibTeX entry from the DOI"
(interactive "MDOI: ")
(let ((url-mime-accept-string "text/bibliography;style=bibtex"))
(with-current-buffer
(url-retrieve-synchronously
(format "http://dx.doi.org/%s"
(replace-regexp-in-string "http://dx.doi.org/" "" doi)))
(switch-to-buffer (current-buffer))
(goto-char (point-max))
(setq bibtex-entry
(buffer-substring
(string-match "@" (buffer-string))
(point)))
(kill-buffer (current-buffer))))
(insert (decode-coding-string bibtex-entry 'utf-8))
(define-key bibtex-mode-map (kbd "C-c C-b") 'get-bibtex-from-doi)
(bibtex-fill-entry))
;; I want run the above function to define it upon entry into a Bibtex file.
(add-hook
'bibtex-mode-hook
(lambda ()
(get-bibtex-from-doi nil)))
;; Hook to add imenu to menubar in bibtex mode
;; http://www.jonathanleroux.org/bibtex-mode.html
(add-hook
'bibtex-mode-hook
(lambda ()
(imenu-add-to-menubar "Imenu")))
;; Fetch bibtex information from DOI.
;; Source https://chainsawriot.com/postmannheim/2022/12/13/aoe13.html
;; Copy the DOI from Firefox (or any source)
;; 1. Go back to emacs (By C . e)
;; 2. Run the custom command: M-x add-doi and paste yank the DOI (C-y)
;; 3. Auto: Fetch the BIBTEX
;; 4. from Crossref
;; 5. Auto: Add it into “~/dev/dotfiles/bib.bib”
;; 6. Save it
(defun add-doi ()
(interactive)
(progn
(setq doi-to-query (read-string "DOI "))
(find-file "~/Documents/global.bib")
(end-of-buffer)
(doi-insert-bibtex doi-to-query)
)
)
(use-package biblio
:config
(setq-default
biblio-bibtex-use-autokey t
bibtex-autokey-name-year-separator ""
bibtex-autokey-year-title-separator ""
bibtex-autokey-year-length 4
bibtex-autokey-titlewords 7
bibtex-autokey-titleword-length -1 ;; -1 means exactly one
bibtex-autokey-titlewords-stretch 0
bibtex-autokey-titleword-separator ""
bibtex-autokey-titleword-case-convert 'upcase)
)
;; ** D
;; Getting pretty icons
(use-package all-the-icons)
(use-package dashboard
;; :after (all-the-icons dashboard-hackernews helm-system-packages)
:ensure t
:init
(dashboard-setup-startup-hook)
:custom
(dashboard-banner-logo-title "Let's get stuff done!")
(dashboard-startup-banner 'logo)
(dashboard-center-content t)
(dashboard-set-navigator t)
;; (dashboard-navigator-buttons '((("⤓" " Install system package" " Install system package" (lambda (&rest _) (helm-system-packages))))))
(dashboard-set-heading-icons t)
(dashboard-set-file-icons t)
(dashboard-items '((projects . 10)
(recents . 15)
(hackernews . 5))))
(use-package dashboard-hackernews
:ensure t)
;;# ** Dired related
(use-package dired-subtree :ensure t
:after dired
:config
(bind-key "<tab>" #'dired-subtree-toggle dired-mode-map)
(bind-key "<backtab>" #'dired-subtree-cycle dired-mode-map))
;; ** E
;; *** ef-theme
(use-package ef-themes
:ensure t)
;; If you like two specific themes and want to switch between them, you
;; can specify them in `ef-themes-to-toggle' and then invoke the command
;; `ef-themes-toggle'. All the themes are included in the variable
;; `ef-themes-collection'.
(setq ef-themes-to-toggle '(ef-summer ef-winter))
;; Make customisations that affect Emacs faces BEFORE loading a theme
;; (any change needs a theme re-load to take effect).
(setq ef-themes-headings ; read the manual's entry or the doc string
'((0 . (variable-pitch light 1.9))
(1 . (variable-pitch light 1.8))
(2 . (variable-pitch regular 1.7))
(3 . (variable-pitch regular 1.6))
(4 . (variable-pitch regular 1.5))
(5 . (variable-pitch 1.4)) ; absence of weight means `bold'
(6 . (variable-pitch 1.3))
(7 . (variable-pitch 1.2))
(t . (variable-pitch 1.1))))
;; They are nil by default...
(setq ef-themes-mixed-fonts t
ef-themes-variable-pitch-ui t)
;; Disable all other themes to avoid awkward blending:
(mapc #'disable-theme custom-enabled-themes)
;; Load the theme of choice:
(load-theme 'ef-cyprus :no-confirm)
;; The themes we provide:
;;
;; Light: `ef-day', `ef-light', `ef-spring', `ef-summer'.
;; Dark: `ef-autumn', `ef-dark', `ef-night', `ef-winter'.
;;
;; Also those which are optimized for deuteranopia (red-green color
;; deficiency): `ef-deuteranopia-dark', `ef-deuteranopia-light'.
;; We also provide these commands, but do not assign them to any key:
;;
;; - `ef-themes-toggle'
;; - `ef-themes-select'
;; - `ef-themes-load-random'
;; - `ef-themes-preview-colors'
;; - `ef-themes-preview-colors-current'#+END_SRC
;; *** Electric-pair mode. Add matching pairs of quotes and parentheses.
(electric-pair-mode)
;; *** electric-spacing
;; An emacs minor-mode to automatically add spacing around [[https://github.com/xwl/electric-spacing][operators] in math expressions.].
;; Backspace over the whitespaces to remove them when none are permitted.
(use-package electric-spacing
:ensure t)
;; git clone https://github.com/walmes/electric-spacing.git into ~/latex-emacs29/manual-packages
;; byte-compile with (byte-compile-file "~/latex-emacs29/manual-packages/electric-spacing/electric-spacing.el")
;; byte-compile with (byte-compile-file "~/latex-emacs29/manual-packages/electric-spacing/electric-spacing-r.el")
(add-to-list 'load-path "~/latex-emacs29/manual-packages/electric-spacing")
(require 'electric-spacing-r)
(add-hook 'ess-mode-hook #'electric-spacing-mode)
;; restrict to limited number of modes to keep it out of the minibuffer
(defvar my-electic-pair-modes '(python-mode julia-mode org-mode latex-mode))
(defun my-inhibit-electric-pair-mode (char)
(not (member major-mode my-electic-pair-modes)))
(setq electric-pair-inhibit-predicate #'my-inhibit-electric-pair-mode)
;; *** Emojis
(use-package emojify
:init
(add-hook 'after-init-hook #'global-emojify-mode))
;; ** F
;; *** FlySpell (spell checking)
(dolist (flyspellmodes '(text-mode-hook
org-mode-hook
latex-mode-hook))
(add-hook flyspellmodes 'turn-on-flyspell))
;; comments and strings in code
(add-hook 'prog-mode-hook 'flyspell-prog-mode)
;; sets american english as defult
(setq ispell-dictionary "american")
;; let us cycle american english (best written english) and norwegian
(defun change-dictionary ()
(interactive)
(ispell-change-dictionary (if (string-equal ispell-current-dictionary "american")
"norsk"
"american")))
;; helm functionality for flyspell. To make it more user friendly
;; (use-package helm-flyspell
;; :after flyspell
;; :init
;; ;; Disable standard keys for flyspell correct, and make my own for helm.
;; (define-key flyspell-mode-map (kbd "C-.") nil)
;; (define-key flyspell-mode-map (kbd "C-,") #'helm-flyspell-correct))
;; *** Focus
;; Highlights the current section or function.
(use-package focus)
;; ** G
;; ** H
;; *** Helm
;; Use ivy or helm but not both.
;; (use-package helm
;; :after (projectile helm-projectile)
;;
;; :init
;; (helm-mode 1)
;; (projectile-mode +1)
;; (helm-projectile-on)
;; (helm-adaptive-mode 1)
;; ;; hide uninteresting buffers from buffer list
;; (add-to-list 'helm-boring-buffer-regexp-list (rx "magit-"))
;; (add-to-list 'helm-boring-buffer-regexp-list (rx "*helm"))
;;
;; :custom
;; (helm-M-x-fuzzy-match t)
;; (projectile-completion-system 'helm)
;; (helm-split-window-in-side-p t)
;;
;; :bind
;; (("M-x" . helm-M-x)
;; ("C-x C-f" . helm-find-files)
;; ;; get the awesome buffer list instead of the standard stuff
;; ("C-x b" . helm-mini)))
;;
;;;; *** helm-system-packages
;;;;(use-package helm-system-packages
;;;; :after helm)
;;
;;;; *** Helm-bibtex
;;;; Can only use helm-bitex or ivy-bibtex
;;;; See https://github.com/tmalsburg/helm-bibtex for extensive documentation and configuration.
;;(use-package helm-bibtex
;; :ensure t
;; :config
;; (setq bibtex-completion-library-path '("~/0labeledPapers" "~/0bookaLabeled"))
;; (setq bibtex-completion-pdf-field "File")
;; (setq bibtex-completion-notes-path '("~/0labeledPapers/notes" "~/0papersLabeled/notes"))
;; (setq org-cite-follow-processor 'helm-bibtex-org-cite-follow)
;; (setq bibtex-completion-display-formats
;; '((article . "${=has-pdf=:1}${=has-note=:1} ${=type=:3} ${year:4} ${author:36} ${title:*} ${journal:40}")
;; (inbook . "${=has-pdf=:1}${=has-note=:1} ${=type=:3} ${year:4} ${author:36} ${title:*} Chapter ${chapter:32}")
;; (incollection . "${=has-pdf=:1}${=has-note=:1} ${=type=:3} ${year:4} ${author:36} ${title:*} ${booktitle:40}")
;; (inproceedings . "${=has-pdf=:1}${=has-note=:1} ${=type=:3} ${year:4} ${author:36} ${title:*} ${booktitle:40}")
;; (t . "${=has-pdf=:1}${=has-note=:1} ${=type=:3} ${year:4} ${author:36} ${title:*}")))
;; (setq bibtex-completion-additional-search-fields '(keywords))
;; (setq bibtex-completion-pdf-symbol "⌘")
;; (setq bibtex-completion-notes-symbol "✎")
;; (setq bibtex-completion-pdf-open-function
;; (lambda (fpath)
;; (call-process "open" nil 0 nil "-a" "/Applications/Skim.app" fpath)))
;; (setq bibtex-completion-find-additional-pdfs t)
;; (setq bibtex-completion-browser-function
;; (lambda (url _) (start-process "firefox" "*firefox*" "firefox" url)))
;; (setq bibtex-completion-format-citation-functions
;; '((org-mode . bibtex-completion-format-citation-org-title-link-to-PDF)
;; (latex-mode . bibtex-completion-format-citation-cite)
;; (markdown-mode . bibtex-completion-format-citation-pandoc-citeproc)
;; (default . bibtex-completion-format-citation-default)))
;; (setq bibtex-completion-additional-search-fields '(tags))
;;)
;;
;;;; (require 'helm-config)
;;;;
;;(global-set-key (kbd "<menu>") 'helm-command-prefix)
;;
;;(define-key helm-command-map "b" 'helm-bibtex)
;;(define-key helm-command-map "B" 'helm-bibtex-with-local-bibliography)
;;(define-key helm-command-map "n" 'helm-bibtex-with-notes)
;;(define-key helm-command-map (kbd "<menu>") 'helm-resume)
;;
;;(defun helm-bibtex-my-publications (&optional arg)
;; "Search BibTeX entries authored by “Blaine Mooers”.
;;
;;With a prefix ARG, the cache is invalidated and the bibliography reread."
;; (interactive "P")
;; (helm-bibtex arg nil "Blaine Mooers"))
;;
;;;; Bind this search function to Ctrl-x p:
;;(global-set-key (kbd "C-x p") 'helm-bibtex-my-publications)
;;
;;;;
;;(helm-add-action-to-source
;; "Open annotated PDF (if present)" 'helm-bibtex-open-annotated-pdf
;; helm-source-bibtex 1)
;;
;;(helm-delete-action-from-source "Insert BibTeX key" helm-source-bibtex)
;;(helm-add-action-to-source "Insert BibTeX key" 'helm-bibtex-insert-key helm-source-bibtex 0)
;;
;;(helm-bibtex-helmify-action bibtex-completion-<action> helm-bibtex-<action>)
;;
;;;; (setq tmalsburg-pdf-watch
;;;; (file-notify-add-watch bibtex-completion-library-path
;;;; '(change)
;;;; (lambda (event) (bibtex-completion-candidates))))
;;
;; ** I
;;
;; *** ivy
;; Use ivy or helm but not both.
(use-package ivy
:ensure t
:init
(ivy-mode 1)
(global-set-key "\C-s" 'swiper)
(unbind-key "S-SPC" ivy-minibuffer-map)
(setq ivy-height 15
ivy-use-virtual-buffers t
ivy-count-format "(%d/%d) "
ivy-use-selectable-prompt t))
(use-package ivy-bibtex
:ensure t)
;;## L
;;### LanguageTool
;; I downloaded Language Tool and installed it in ~/.languagetool.
;; source: https://github.com/PillFall/languagetool.el
(use-package languagetool
:ensure t
:defer t
:commands (languagetool-check
languagetool-clear-suggestions
languagetool-correct-at-point
languagetool-correct-buffer
languagetool-set-language
languagetool-server-mode
languagetool-server-start
languagetool-server-stop)
:config
(setq languagetool-java-arguments '("-Dfile.encoding=UTF-8")
languagetool-console-command "~/.languagetool/languagetool-commandline.jar"
languagetool-server-command "~/.languagetool/languagetool-server.jar"))
(setq languagetool-java-arguments '("-Dfile.encoding=UTF-8"))
(setq languagetool-console-command "~/.languagetool/languagetool-commandline.jar"
languagetool-server-command "~/.languagetool/languagetool-server.jar")
;;### LaTeX helpher functions
;;#### M-x description
;; Converts a selected list into a description list.
;; The elements of the list must begin with a dash.
;; The terms to be inserted into the square brackets
;; have to be added after running the function.
(defun description (beg end)
"wrap the active region in an 'itemize' environment,
converting hyphens at the beginning of a line to \item"
(interactive "r")
(save-restriction
(narrow-to-region beg end)
(beginning-of-buffer)
(insert "\\begin{description}\n")
(while (re-search-forward "^- " nil t)
(replace-match "\\\\item[ ]"))
(end-of-buffer)
(insert "\\end{description}\n")))
;;#### M-x enumerate
;; Converts a selected list into an enumerated list.
;; The elements of the list must begin with a dash.
(defun enumerate (beg end)
"wrap the active region in an 'itemize' environment,
converting hyphens at the beginning of a line to \item"
(interactive "r")
(save-restriction
(narrow-to-region beg end)
(beginning-of-buffer)
(insert "\\begin{enumerate}\n")
(while (re-search-forward "^- " nil t)
(replace-match "\\\\item "))
(end-of-buffer)
(insert "\\end{enumerate}\n")))
;;#### M-x itemize
;; Converts a selected list into an itemized list.
;; The elements of the list must begin with a dash.
;; A similar function could be made to make an enumerated list
;; and a description list.
;; Source: \url{https://tex.stackexchange.com/questions/118958/emacsauctex-prevent-region-filling-when-inserting-itemize}
(defun itemize (beg end)
"wrap the active region in an 'itemize' environment,
converting hyphens at the beginning of a line to \item"