-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.el
1241 lines (1007 loc) · 43.8 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
;; -*- lexical-binding: t -*-
(when (version< emacs-version "25.1")
(error "This configuration requires GNU Emacs 25.1 or newer, but you're running %s" emacs-version))
(require 'package)
(let* ((no-ssl (and (memq system-type '(windows-nt ms-dos))
(not (gnutls-available-p))))
(proto (if no-ssl "http" "https")))
(add-to-list 'package-archives (cons "melpa" (concat proto "://melpa.org/packages/")) t)
(add-to-list 'package-archives (cons "org" (concat proto "://orgmode.org/elpa/")) t))
(package-initialize)
(defvar lmintmate/packages '(color-theme-modern
counsel
dired-icon
dired-recent
free-keys
jump-char
no-littering
parent-mode
rainbow-mode
toc-org
transpose-frame
try
undo-fu
vimrc-mode
;; emacs 24.4 and above
auto-minor-mode
elisp-demos
ivy-rich
markdown-mode
org-cliplink
;; emacs 25.1 and above
el-patch
ryo-modal
helpful
ivy-prescient)
"Core packages")
(setq package-selected-packages lmintmate/packages)
;; Packages to be installed only when a certain executable is on the path
(when (executable-find "git")
(add-to-list 'package-selected-packages 'magit))
;; Packages for use only on my Linux system
(when (eq system-type 'gnu/linux)
(add-to-list 'package-selected-packages 'trashed))
;; Packages that require emacs versions above 25.1
(unless (version< emacs-version "25.2")
(add-to-list 'package-selected-packages 'minions))
;; Packages that require emacs versions 26.1 and above
(unless (version< emacs-version "26.1")
(add-to-list 'package-selected-packages 'org-superstar))
;; GNU ELPA keyring package for versions below 26.3
(when (version< emacs-version "26.3" )
(add-to-list 'package-selected-packages 'gnu-elpa-keyring-update))
(unless package-archive-contents
(message "%s" "Refreshing package database...")
(package-refresh-contents))
(when (fboundp 'package-install-selected-packages)
(package-install-selected-packages))
;; enforce installing the latest version of org mode
(unless (file-expand-wildcards (concat package-user-dir "/org-[0-9]*"))
(if (y-or-n-p "Do you want to install the latest version of org-mode?")
(package-install (elt (cdr (assoc 'org package-archive-contents)) 0))
(message "The latest version of org-mode wasn't installed.")))
(add-to-list 'package-selected-packages 'org)
(defun package-upgrade-all ()
"Upgrade all packages automatically without showing *Packages* buffer."
(interactive)
(package-refresh-contents)
(let (upgrades)
(cl-flet ((get-version (name where)
(let ((pkg (cadr (assq name where))))
(when pkg
(package-desc-version pkg)))))
(dolist (package (mapcar #'car package-alist))
(let ((in-archive (get-version package package-archive-contents)))
(when (and in-archive
(version-list-< (get-version package package-alist)
in-archive))
(push (cadr (assq package package-archive-contents))
upgrades)))))
(if upgrades
(when (yes-or-no-p
(message "Upgrade %d package%s (%s)? "
(length upgrades)
(if (= (length upgrades) 1) "" "s")
(mapconcat #'package-desc-full-name upgrades ", ")))
(save-window-excursion
(dolist (package-desc upgrades)
(let ((old-package (cadr (assq (package-desc-name package-desc)
package-alist))))
(package-install package-desc)
(package-delete old-package)))))
(message "All packages are up to date"))))
(prefer-coding-system 'utf-8)
(set-default-coding-systems 'utf-8)
(set-terminal-coding-system 'utf-8)
(set-keyboard-coding-system 'utf-8)
(setq no-littering-etc-directory
(expand-file-name "config/" user-emacs-directory))
(setq no-littering-var-directory
(expand-file-name "data/" user-emacs-directory))
(require 'no-littering)
;; set frame
(when (eq system-type 'windows-nt)
(setq default-frame-alist '((top . 5) (left . 220) (width . 80) (height . 30))))
(tool-bar-mode -1)
(if (eq system-type 'windows-nt)
(if (member "DejaVu Sans Mono" (font-family-list))
(set-face-attribute 'default nil :family "DejaVu Sans Mono" :height 140)
(set-face-attribute 'default nil :family "Consolas" :height 140))
(set-face-attribute 'default nil :family "DejaVu Sans Mono" :height 140))
(when (eq system-type 'windows-nt)
(set-face-attribute 'fixed-pitch nil :family "Consolas" :height 140))
(load-theme 'blue-mood t t)
(enable-theme 'blue-mood)
(set-face-attribute 'fringe nil :background "DodgerBlue4")
(set-face-attribute 'font-lock-negation-char-face nil :foreground "tomato")
(set-face-attribute 'font-lock-variable-name-face nil :foreground "tomato")
(set-face-attribute 'font-lock-doc-face nil :foreground "cyan" :inherit 'unspecified)
(set-face-attribute 'highlight nil :background "#235c94")
(set-face-attribute 'secondary-selection nil :background "#235c94" :foreground nil :inherit 'unspecified)
(set-face-attribute 'package-status-built-in nil :inherit font-lock-comment-face)
(set-face-attribute 'package-status-dependency nil :inherit font-lock-builtin-face)
(set-face-attribute 'package-status-installed nil :inherit font-lock-function-name-face)
(set-face-attribute 'vc-edited-state nil :background "tomato1" :foreground "black" :box '(:line-width 2 :color "tomato1"))
;; setting so that hl-line-mode won't affect syntax coloring
(set-face-foreground 'highlight nil)
(set-face-attribute 'mode-line nil :background "grey75" :foreground "black" :box '(:line-width 2 :color "grey75"))
(set-face-attribute 'mode-line-inactive nil :background "grey30" :foreground "grey80" :box '(:line-width 2 :color "grey30"))
(set-face-attribute 'mode-line-highlight nil :box '(:line-width 1 :color "grey20"))
(set-face-attribute 'mode-line-buffer-id nil :weight 'normal :foreground nil :background nil)
(set-face-attribute 'vertical-border nil :foreground (face-attribute 'fringe :background))
(setq lisp-directory (concat user-emacs-directory "lisp"))
(unless (file-directory-p lisp-directory) (make-directory lisp-directory))
;; in addition to greek.el, also download the byte-compiled greek.elc
(unless (file-exists-p (expand-file-name "greek.el" lisp-directory))
(url-copy-file "http://myria.math.aegean.gr/~atsol/emacs-unicode/greek.el" (expand-file-name "greek.el" lisp-directory)))
(unless (file-exists-p (expand-file-name "greek.elc" lisp-directory))
(url-copy-file "http://myria.math.aegean.gr/~atsol/emacs-unicode/greek.elc" (expand-file-name "greek.elc" lisp-directory)))
;; byte-compile .el files after downloading them
(unless (file-exists-p (expand-file-name "lacarte.el" lisp-directory))
(url-copy-file "https://www.emacswiki.org/emacs/download/lacarte.el" (expand-file-name "lacarte.el" lisp-directory)))
(unless (file-exists-p (expand-file-name "lacarte.elc" lisp-directory))
(byte-compile-file (expand-file-name "lacarte.el" lisp-directory)))
(unless (file-exists-p (expand-file-name "elispfl.el" lisp-directory))
(url-copy-file "https://raw.githubusercontent.com/lmintmate/elispfl/master/elispfl.el" (expand-file-name "elispfl.el" lisp-directory)))
(unless (file-exists-p (expand-file-name "elispfl.elc" lisp-directory))
(byte-compile-file (expand-file-name "elispfl.el" lisp-directory)))
(add-to-list 'load-path lisp-directory)
;; load elisp file, use byte compiled version (.elc) if it exists
(load "greek")
(require 'lacarte)
(global-set-key (kbd "\C-c.") 'lacarte-execute-menu-command)
(require 'elispfl)
(with-eval-after-load 'elisp-mode
(elispfl-mode))
;; Highlight face name by the face itself
(setq elispfl-face-use-itself t)
(setq inhibit-startup-screen t)
(unless (executable-find "fortune")
(unless (file-exists-p (concat user-emacs-directory "apofthegmata.txt"))
(url-copy-file "https://gitlab.com/snippets/1870200/raw" (concat user-emacs-directory "apofthegmata.txt")))
(require 'cookie1)
(defun lmintmate/cookie-insert (phrase-file &optional count startmsg endmsg)
(setq phrase-file (cookie-check-file phrase-file))
(let ((cookie-vector (cookie-snarf phrase-file startmsg endmsg)))
(cookie-shuffle-vector cookie-vector)
(let ((start (point)))
(cookie1 (min (- (length cookie-vector) 1) (or count 1)) cookie-vector)
(fill-region-as-paragraph start (point) nil)))))
(if (executable-find "fortune")
(setq initial-scratch-message
(with-temp-buffer
(shell-command "fortune" t)
(let ((comment-start ";;"))
(comment-region (point-min) (point-max)))
(concat (buffer-string))))
(if (file-exists-p (concat user-emacs-directory "apofthegmata.txt"))
(setq initial-scratch-message
(with-temp-buffer
(lmintmate/cookie-insert
(concat user-emacs-directory "apofthegmata.txt"))
(let ((comment-start ";;"))
(comment-region (point-min) (point-max)))
(concat (buffer-string) "\n")))
(setq initial-scratch-message (concat ";; Είς οιωνός άριστος, αμύνεσθαι περί πάτρης." "\n"))))
(defun display-startup-echo-area-message ()
(message "Καλωσήλθες!"))
(setq calendar-week-start-day 1
calendar-day-name-array ["Κυριακή" "Δευτέρα" "Τρίτη" "Τετάρτη"
"Πέμπτη" "Παρασκευή" "Σάββατο"]
calendar-month-name-array ["Ιανουάριος" "Φεβρουάριος" "Μάρτιος"
"Απρίλιος" "Μάιος" "Ιούνιος"
"Ιούλιος" "Αύγουστος" "Σεπτέμβριος"
"Οκτώβριος" "Νοέμβριος" "Δεκέμβριος"])
(setq default-input-method "el_GR")
(global-set-key (kbd "C-/") 'toggle-input-method)
(defun reverse-input-method (input-method)
"Build the reverse mapping of single letters from INPUT-METHOD."
(interactive
(list (read-input-method-name "Use input method (default current): ")))
(if (and input-method (symbolp input-method))
(setq input-method (symbol-name input-method)))
(let ((current current-input-method)
(modifiers '(nil (control) (meta) (control meta))))
(when input-method
(activate-input-method input-method))
(when (and current-input-method quail-keyboard-layout)
(dolist (map (cdr (quail-map)))
(let* ((to (car map))
(from (quail-get-translation
(cadr map) (char-to-string to) 1)))
(when (and (characterp from) (characterp to))
(dolist (mod modifiers)
(define-key local-function-key-map
(vector (append mod (list from)))
(vector (append mod (list to)))))))))
(when input-method
(activate-input-method current))))
(reverse-input-method 'el_GR)
(defun start-from-new-line ()
(interactive)
(move-end-of-line nil)
(newline)
(indent-for-tab-command))
(defun start-from-new-top-line ()
(interactive)
(previous-line)
(start-from-new-line))
(defun lmintmate/insert ()
"Kill active region if active"
(interactive)
(if mark-active (kill-region (region-beginning) (region-end))))
(defun lmintmate/append ()
"Do not go to the next line when at the end of the current line"
(interactive)
(unless (eolp) (forward-char)))
(defun sk/remove-mark ()
"Deactivate the region"
(interactive)
(if (use-region-p)
(deactivate-mark)))
(defun lmintmate/mark-line (&optional arg)
(interactive "p")
(if (not mark-active)
(progn
(beginning-of-line)
(push-mark)
(setq mark-active t)))
(forward-line arg))
(defun lmintmate/kill-ring-save-line-trim ()
"Copy current line in kill-ring, trimming begining spaces and tabs"
(interactive)
(beginning-of-line)
(kill-ring-save (progn (skip-chars-forward " \t") (point))
(line-beginning-position 2))
(beginning-of-line))
(defun selection/kill-ring-save ()
"kill-ring-save the active region but don't do anything if there's no active region"
(interactive)
(if (use-region-p)
(kill-ring-save (region-beginning) (region-end))
(message "Used selection/kill-ring-save while no active region")))
(defun selection/kill-region ()
"Kill the active region but don't do anything if there's no active region"
(interactive)
(if (use-region-p)
(kill-region (region-beginning) (region-end))
(message "Used selection/kill-region while no active region")))
(defun lmintmate/toggle-case-char-under-point ()
"Toggle the case of char under point. Afterwards moves to the next char."
(interactive)
(let ((char (following-char)))
(if (eq char (upcase char))
(insert-char (downcase char) 1 t)
(insert-char (upcase char) 1 t)))
(delete-char 1 nil))
(defun lmintmate/toggle-ryo-modes ()
"Deactivate a potentially marked region, toggle input method if enabled and disable overwrite-mode if enabled before toggling ryo-modal-mode"
(interactive)
(sk/remove-mark)
(unless (eq current-input-method nil)
(toggle-input-method))
(overwrite-mode -1)
(ryo-modal-mode 'toggle))
(defun lmintmate/silently-toggle-overwrite-mode ()
"Silently toggle overwrite-mode"
(interactive)
(overwrite-mode 'toggle))
(ryo-modal-keys
;; Movement
("i" lmintmate/insert :name "Insert" :exit t)
("a" lmintmate/append :first (lmintmate/insert) :name "Append" :exit t)
("b" backward-word)
("w" forward-word)
("f" jump-char-forward)
("F" jump-char-backward)
("j" next-line)
("k" previous-line)
("h" backward-char)
("l" forward-char)
("<backspace>" backward-char)
("A" move-end-of-line :name "Append at end of line" :exit t)
("I" move-beginning-of-line :name "Insert at beginning of line" :exit t)
("g g" beginning-of-buffer)
("G" end-of-buffer)
("e" mark-whole-buffer)
("^" back-to-indentation)
("0" move-beginning-of-line)
("$" move-end-of-line)
;; Editing
("." ryo-modal-repeat)
("y" selection/kill-ring-save)
("Y" lmintmate/kill-ring-save-line-trim)
("p" yank)
("`" lmintmate/toggle-case-char-under-point)
("<S-return>" start-from-new-top-line)
("<return>" start-from-new-line)
("o" start-from-new-line :name "Open new line below and insert" :exit t)
("O" start-from-new-top-line :name "Open new line above and insert" :exit t)
("u" undo-fu-only-undo :norepeat t)
("C-r" undo-fu-only-redo :norepeat t)
("r" lmintmate/silently-toggle-overwrite-mode :exit t)
("d" selection/kill-region)
("D" kill-whole-line)
("c w" kill-word :name "Kill word" :exit t)
("c $" kill-line :name "Kill from point until end of line" :exit t)
("S" kill-line :first '(move-beginning-of-line) :name "Substitute line" :exit t)
("c f" zap-to-char)
("c t" zap-up-to-char)
("v" set-mark-command :name "Begin marking a region" :norepeat t)
("V" lmintmate/mark-line :name "Begin marking whole lines")
("C" comment-dwim :norepeat t)
("J" join-line)
;; Other
("s" save-buffer :norepeat t))
(ryo-modal-keys
(:norepeat t)
("1" "M-1")
("2" "M-2")
("3" "M-3")
("4" "M-4")
("5" "M-5")
("6" "M-6")
("7" "M-7")
("8" "M-8")
("9" "M-9"))
(add-hook 'text-mode-hook 'ryo-modal-mode)
(add-hook 'prog-mode-hook 'ryo-modal-mode)
(global-set-key (kbd "C-'") 'ryo-modal-mode)
(global-set-key (kbd "<escape>") 'lmintmate/toggle-ryo-modes)
(add-hook 'input-method-activate-hook (lambda () (ryo-modal-mode -1)))
(setq djcb-modal-cursor-type 'box)
(setq djcb-overwrite-cursor-type 'hbar)
(setq lmintmate/emacs-editing-cursor-type 'bar)
(setq djcb-emacs-other-cursor-type 'box)
(defun djcb-set-cursor-according-to-mode ()
"change cursor type according to modes."
(cond
(ryo-modal-mode
(setq cursor-type djcb-modal-cursor-type))
(overwrite-mode
(setq cursor-type djcb-overwrite-cursor-type))
((or (derived-mode-p 'prog-mode) (derived-mode-p 'text-mode))
(setq cursor-type lmintmate/emacs-editing-cursor-type))
(t
(setq cursor-type djcb-emacs-other-cursor-type))))
(add-hook 'ryo-modal-mode-hook 'djcb-set-cursor-according-to-mode)
(setq ryo-modal-cursor-color nil)
(defface modal-state-tag
'((t :foreground "black"
:background "#4f94cd"
:box (:line-width 2 :color "#4f94cd")))
"Face for the Modal state tag"
:group 'my-state-tags)
(defface overwrite-state-tag
'((t :foreground "black"
:background "tomato"
:box (:line-width 2 :color "tomato")))
"Face for the Overwrite state tag"
:group 'my-state-tags)
(defface emacs-state-tag
'((t :foreground "black"
:background "MediumPurple2"
:box (:line-width 2 :color "MediumPurple2")))
"Face for the Emacs state tag"
:group 'my-state-tags)
(defun add-ryo-modeline-status (&rest _)
(interactive)
(let ((win (frame-selected-window)))
(unless (minibuffer-window-active-p win)
(add-to-list 'mode-line-format '(:eval (cond (ryo-modal-mode
(propertize " MODAL " 'face 'modal-state-tag))
(overwrite-mode
(propertize " OVWRT " 'face 'overwrite-state-tag))
(t
(propertize " EMACS " 'face 'emacs-state-tag))))))))
(add-hook 'window-configuration-change-hook 'add-ryo-modeline-status)
;; Needed so that it'll show up on all major modes, including help buffers and ibuffer
(add-hook 'after-change-major-mode-hook 'add-ryo-modeline-status)
(setq ring-bell-function 'ignore)
(setq use-dialog-box nil)
(setq custom-file (no-littering-expand-etc-file-name "custom.el"))
(setq frame-title-format
'((:eval (if (buffer-file-name)
(abbreviate-file-name (buffer-file-name))
"%b"))
(:eval (if (buffer-modified-p)
" [+]"))
" - Emacs " emacs-version))
(setq auto-save-default nil)
(setq make-backup-files nil)
(setq create-lockfiles nil)
(setq delete-by-moving-to-trash t)
(delete-selection-mode 1)
(setq sentence-end-double-space nil)
(unless (display-graphic-p)
(menu-bar-mode -1))
(global-set-key [f8] 'toggle-menu-bar-mode-from-frame)
(set-face-attribute 'window-divider nil :foreground "gray75")
(set-face-attribute 'window-divider-first-pixel nil :foreground "gray95")
(set-face-attribute 'window-divider-last-pixel nil :foreground "gray55")
(add-hook 'window-divider-mode-hook (lambda () (scroll-bar-mode 'toggle)))
(global-set-key [f10] 'window-divider-mode)
(global-set-key [f9] 'toggle-frame-maximized)
(setq frame-inhibit-implied-resize t)
(add-hook 'text-mode-hook 'visual-line-mode)
(add-to-list 'auto-minor-mode-alist '("\\.te?xt\\'" . goto-address-mode))
(when (version< emacs-version "26.0.50" )
(defun my-kill-buffer ()
"Kill current buffer without prompting"
(interactive)
(kill-buffer (current-buffer))))
(if (version<= "26.0.50" emacs-version )
(global-set-key "\C-ck" 'kill-current-buffer)
(global-set-key "\C-ck" 'my-kill-buffer))
(define-key global-map "\M-o" 'other-window)
(when (fboundp 'windmove-default-keybindings)
(windmove-default-keybindings))
(setq windmove-wrap-around t)
(when (version<= "26.0.50" emacs-version )
(setq mouse-drag-and-drop-region t))
;; (define-key evil-emacs-state-map "\C-cz" 'zap-up-to-char)
(when (fboundp 'display-line-numbers-mode)
(setq-default display-line-numbers nil)
(defun noct:relative ()
(setq-local display-line-numbers 'relative))
(defun noct:line-number-relative ()
(setq-local display-line-numbers-current-absolute nil)))
(when (fboundp 'display-line-numbers-mode)
(add-hook 'text-mode-hook #'noct:relative)
(add-hook 'text-mode-hook #'noct:line-number-relative)
(add-hook 'prog-mode-hook #'noct:relative)
(add-hook 'prog-mode-hook #'noct:line-number-relative))
(when (fboundp 'display-line-numbers-mode)
(add-hook 'lisp-interaction-mode-hook (lambda () (display-line-numbers-mode -1))))
(when (fboundp 'display-line-numbers-mode)
(with-eval-after-load 'display-line-numbers
(set-face-attribute 'line-number-current-line nil :inherit font-lock-comment-face)))
(setq-default help-window-select t)
(setq disabled-command-function nil)
(setq custom-safe-themes t)
(defadvice load-theme (before clear-previous-themes activate)
"Clear existing theme settings instead of layering them"
(mapc #'disable-theme custom-enabled-themes))
(setq custom-unlispify-tag-names nil)
(global-set-key (kbd "C-x r d") 'bookmark-delete)
(defun d/download-file (&optional url name)
"Download a file from url to specified path."
(interactive)
(let* ((file-url (or url (read-from-minibuffer "URL: ")))
(file-name
(or name
(counsel-find-file
(file-name-nondirectory file-url)))))
(url-copy-file file-url file-name)))
(defun d/switch-to-scratch ()
"Switch to scratch buffer."
(interactive)
(switch-to-buffer "*scratch*"))
(global-set-key (kbd "\C-cs") 'd/switch-to-scratch)
(defun spacemacs/dos2unix ()
"Converts the current buffer to UNIX file format."
(interactive)
(set-buffer-file-coding-system 'undecided-unix nil))
(defun spacemacs/unix2dos ()
"Converts the current buffer to DOS file format."
(interactive)
(set-buffer-file-coding-system 'undecided-dos nil))
(defun lmintmate/rename-file (filename &optional new-filename)
"Rename FILENAME to NEW-FILENAME.
When NEW-FILENAME is not specified, asks user for a new name.
Also renames associated buffers (if any exists) and updates recentf list."
(interactive "f")
(when (and filename (file-exists-p filename))
(let* ((is-dir (file-directory-p filename))
(short-name
(if is-dir
(file-name-base (directory-file-name filename))
(file-name-nondirectory filename)))
(new-filename
(if new-filename new-filename
(read-file-name
(format "Rename %s to: " short-name)))))
;; Rename filename to new-filename and error if new-filename already
;; exists. `dired-rename-file' handles renaming of directories and files.
;; It updates the name of all associated buffers.
(dired-rename-file filename new-filename nil)
;; Update recentf list.
(when (fboundp 'recentf-add-file)
(seq-map
(lambda (fp)
(recentf-add-file
(concat new-filename (string-remove-prefix filename fp)))
(recentf-remove-if-non-kept fp))
(seq-filter
(lambda (fp)
(string-prefix-p filename fp))
recentf-list)))
;; Inform user about tremendous success.
(message "%s '%s' successfully renamed to '%s'"
(if is-dir "Directory" "File")
short-name
(file-name-nondirectory new-filename)))))
(defun lmintmate/rename-current-buffer-file (&optional arg)
"Rename the current buffer and the file it is visiting.
If the buffer isn't visiting a file, ask if it should
be saved to a file, or just renamed.
If called without a prefix argument, the prompt is
initialized with the current directory instead of filename."
(interactive "P")
(let* ((name (buffer-name))
(filename (buffer-file-name)))
(if (and filename (file-exists-p filename))
;; the buffer is visiting a file
(let* ((dir (file-name-directory filename))
(new-name (read-file-name "New name: " (if arg dir filename))))
(cond ((get-buffer new-name)
(error "A buffer named '%s' already exists!" new-name))
(t
(let ((dir (file-name-directory new-name)))
(when (and (not (file-exists-p dir))
(yes-or-no-p
(format "Create directory '%s'?" dir)))
(make-directory dir t)))
(rename-file filename new-name 1)
(rename-buffer new-name)
(set-visited-file-name new-name)
(set-buffer-modified-p nil)
(when (fboundp 'recentf-add-file)
(recentf-add-file new-name)
(recentf-remove-if-non-kept filename))
(message "File '%s' successfully renamed to '%s'"
name (file-name-nondirectory new-name)))))
;; the buffer is not visiting a file
(let ((key))
(while (not (memq key '(?s ?r)))
(setq key (read-key (propertize
(format
(concat "Buffer '%s' is not visiting a file: "
"[s]ave to file or [r]ename buffer?")
name)
'face 'minibuffer-prompt)))
(cond ((eq key ?s) ; save to file
;; this allows for saving a new empty (unmodified) buffer
(unless (buffer-modified-p) (set-buffer-modified-p t))
(save-buffer))
((eq key ?r) ; rename buffer
(let ((new-name (read-string "New buffer name: ")))
(while (get-buffer new-name)
;; ask to rename again, if the new buffer name exists
(if (yes-or-no-p
(format (concat "A buffer named '%s' already exists: "
"Rename again?")
new-name))
(setq new-name (read-string "New buffer name: "))
(keyboard-quit)))
(rename-buffer new-name)
(message "Buffer '%s' successfully renamed to '%s'"
name new-name)))
;; ?\a = C-g, ?\e = Esc and C-[
((memq key '(?\a ?\e)) (keyboard-quit))))))))
(require 'parent-mode)
(defun parent-mode-display ()
"Display this buffer's mode hierarchy."
(interactive)
(let ((ls (parent-mode-list major-mode)))
(princ ls)))
(defun dabbrev-completion-all-buffers ()
(interactive)
(setq current-prefix-arg '(16))
(call-interactively 'dabbrev-completion))
(define-key text-mode-map (kbd "C-n") 'dabbrev-completion-all-buffers)
(define-key prog-mode-map (kbd "C-n") 'dabbrev-completion-all-buffers)
(setq dabbrev-abbrev-skip-leading-regexp "~")
(require 'recentf)
(recentf-mode 1)
(setq recentf-exclude '(".*-autoloads\\.el\\'"
"[/\\]\\elpa/"
"bookmark"
))
(define-key global-map "\M-[" 'transpose-frame)
(define-key global-map "\M-]" 'rotate-frame)
(require 'ibuffer)
(global-set-key (kbd "C-x C-b") 'ibuffer)
(autoload 'ibuffer "ibuffer" "List buffers." t)
(setq ibuffer-saved-filter-groups
'(("default"
("Dired" (mode . dired-mode))
("Org" (derived-mode . org-mode))
("Text" (name . "^.*txt$"))
("Markdown" (derived-mode . markdown-mode))
("Emacs Lisp" (mode . emacs-lisp-mode))
("Help" (or (derived-mode . help-mode)
(derived-mode . helpful-mode)
(derived-mode . elisp-refs-mode)
(derived-mode . apropos-mode)))
("Info" (derived-mode . Info-mode))
("Custom" (derived-mode . Custom-mode))
("Scratch" (name . "*scratch*"))
("Git" (derived-mode . magit-mode))
("Other"
(or
(name . "^\\*")))
)))
(add-hook 'ibuffer-mode-hook
(lambda ()
(ibuffer-auto-mode 1)
(ibuffer-switch-to-saved-filter-groups "default")))
(setq ibuffer-show-empty-filter-groups nil)
;; Use human readable Size column instead of original one
(define-ibuffer-column size-h
(:name "Size" :inline t)
(cond
((> (buffer-size) 1000000) (format "%7.1fM" (/ (buffer-size) 1000000.0)))
((> (buffer-size) 100000) (format "%7.0fk" (/ (buffer-size) 1000.0)))
((> (buffer-size) 1000) (format "%7.1fk" (/ (buffer-size) 1000.0)))
(t (format "%8d" (buffer-size)))))
;; Modify the default ibuffer-formats
(setq ibuffer-formats
'((mark modified read-only " "
(name 18 18 :left :elide)
" "
(size-h 9 -1 :right)
" "
(mode 16 16 :left :elide)
" "
filename-and-process)))
(add-hook 'dired-mode-hook 'dired-icon-mode)
(setq dired-icon-image-size 32)
(dired-recent-mode 1)
(add-hook 'dired-mode-hook 'auto-revert-mode)
(setq auto-revert-verbose nil)
(setq dired-listing-switches "-alh --group-directories-first")
(add-hook 'dired-mode-hook 'dired-sort-toggle-or-edit)
(add-hook 'dired-mode-hook 'dired-hide-details-mode)
(setq dired-dwim-target t)
(require 'org)
(if (require 'toc-org nil t)
(add-hook 'org-mode-hook 'toc-org-mode)
(warn "toc-org not found"))
(require 'org-mouse)
(define-key org-mode-map [remap org-mouse-down-mouse] 'mouse-drag-region)
(when (package-installed-p 'org-cliplink)
(define-key org-mode-map (kbd "\C-cl") 'org-cliplink))
(define-key org-mode-map (kbd "\C-cd") 'org-toggle-link-display)
;; for functions
(defun +org-link--helpfn:face (link)
(let ((fn (intern link)))
(if (fboundp fn)
'org-link
'error)))
(defun +org-link--helpfn:follow (link)
(let ((fn (intern link)))
(if (require 'helpful nil :no-error)
(helpful-callable fn)
(describe-function fn))))
(org-link-set-parameters
"helpfn"
:face
#'+org-link--helpfn:face
:follow
#'+org-link--helpfn:follow)
;; for variables
(defun +org-link--helpvar:face (link)
(if (boundp (intern link)) 'org-link 'error))
(defun +org-link--helpvar:follow (link)
(let ((var (intern link)))
(if (require 'helpful nil :noerror)
(helpful-variable var)
(describe-variable var))))
(org-link-set-parameters
"helpvar"
:face
#'+org-link--helpvar:face
:follow
#'+org-link--helpvar:follow)
(define-key org-mode-map (kbd "\C-ce") 'org-emphasize)
(define-key org-mode-map (kbd "\C-c.") nil)
(require 'org-superstar)
(add-hook 'org-mode-hook 'org-superstar-mode)
(when (eq system-type 'windows-nt)
(setq inhibit-compacting-font-caches t))
(if (eq system-type 'windows-nt)
(setq org-superstar-headline-bullets-list
'("➊" "➋" "➌"))
(setq org-superstar-headline-bullets-list
'("🅐" "🅑" "🅒")))
;; completely hide the leading stars
(setq org-superstar-remove-leading-stars t)
(setq org-ellipsis "↪")
(set-face-attribute 'org-ellipsis nil :foreground "cyan3" :underline 'unspecified)
(setq org-todo-keywords
'((sequence "TODO(t)" "CURRENTLY(c)" "SOMEDAY(s)" "CANCELLED(x)" "DONE(d)")))
(setq org-superstar-special-todo-items t)
(setq org-superstar-todo-bullet-alist '(("TODO" . ?➽)
("CURRENTLY" . ?⌛)
("SOMEDAY" . ?⏱)
("CANCELLED" . ?✘)
("DONE" . ?✓)))
(setq org-fontify-done-headline t)
(set-face-attribute 'org-done nil :foreground "PaleGreen" :strike-through t :weight 'bold)
(set-face-attribute 'org-headline-done nil :foreground "LightSalmon" :strike-through t)
(setq org-special-ctrl-a/e t)
(setq org-ctrl-k-protect-subtree t)
(define-key org-mode-map (kbd "C-'") nil)
(ryo-modal-major-mode-keys
'org-mode
("<return>" org-return)
("c $" org-kill-line :name "Like kill-line but for org" :exit t)
("S" org-kill-line :first '(org-beginning-of-line) :name "Substitute line in org mode" :exit t)
("0" org-beginning-of-line)
("$" org-end-of-line))
;; Make windmove work in org-mode:
(add-hook 'org-shiftup-final-hook 'windmove-up)
(add-hook 'org-shiftleft-final-hook 'windmove-left)
(add-hook 'org-shiftdown-final-hook 'windmove-down)
(add-hook 'org-shiftright-final-hook 'windmove-right)
(setq org-footnote-auto-adjust t)
(setq org-return-follows-link t)
(setq org-level-color-stars-only t)
(set-face-attribute 'org-level-2 nil :foreground "gold" :weight 'bold :inherit 'unspecified)
(set-face-attribute 'org-level-3 nil :foreground "cyan3" :weight 'bold :inherit 'unspecified)
(set-face-attribute 'org-block nil :foreground "whitesmoke" :inherit 'unspecified)
(defun my-org-html-postamble (plist)
(format "Last update : %s" (format-time-string "%a %d/%m/%Y")))
(setq org-html-postamble 'my-org-html-postamble)
(when (version<= "9.2" (org-version))
(require 'org-tempo)
(add-to-list 'org-structure-template-alist '("el" . "src emacs-lisp"))
(add-to-list 'org-structure-template-alist '("o" . "src org"))
(add-to-list 'org-structure-template-alist '("vim" . "src vim"))
(add-to-list 'org-structure-template-alist '("sh" . "src sh"))
(add-to-list 'org-tempo-keywords-alist '("t" . "title")))
(setq org-use-speed-commands
(lambda () (and (looking-at org-outline-regexp) (looking-back "^\**"))))
(push '(org-goto . tree) org-show-context-detail)
(setq org-adapt-indentation nil)
(defun modi/org-in-any-block-p ()
"Return non-nil if the point is in any Org block.
The Org block can be *any*: src, example, verse, etc., even any
Org Special block.
This function is heavily adapted from `org-between-regexps-p'."
(save-match-data
(let ((pos (point))
(case-fold-search t)
(block-begin-re "^[[:blank:]]*#\\+begin_\\(?1:.+?\\)\\(?: .*\\)*$")
(limit-up (save-excursion (outline-previous-heading)))
(limit-down (save-excursion (outline-next-heading)))
beg end)
(save-excursion
;; Point is on a block when on BLOCK-BEGIN-RE or if
;; BLOCK-BEGIN-RE can be found before it...
(and (or (org-in-regexp block-begin-re)
(re-search-backward block-begin-re limit-up :noerror))
(setq beg (match-beginning 0))
;; ... and BLOCK-END-RE after it...
(let ((block-end-re (concat "^[[:blank:]]*#\\+end_"
(match-string-no-properties 1)
"\\( .*\\)*$")))
(goto-char (match-end 0))
(re-search-forward block-end-re limit-down :noerror))
(> (setq end (match-end 0)) pos)
;; ... without another BLOCK-BEGIN-RE in-between.
(goto-char (match-beginning 0))
(not (re-search-backward block-begin-re (1+ beg) :noerror))
;; Return value.
(cons beg end))))))
(defun modi/org-split-block ()
"Sensibly split the current Org block at point.
If the point is anywhere on the line, but not at the beginning of the line
(BOL), go to the end of the line, and then split the block.
Otherwise (if point is at BOL), split the block exactly at that point."
(interactive)
(if (modi/org-in-any-block-p)
(save-match-data
(save-restriction
(widen)
(let ((case-fold-search t)
(at-bol (bolp))
block-start
block-end)
(save-excursion
(re-search-backward "^\\(?1:[[:blank:]]*#\\+begin_.+?\\)\\(?: .*\\)*$" nil nil 1)
(setq block-start (match-string-no-properties 0))
(setq block-end (replace-regexp-in-string
"begin_" "end_" ;Replaces "begin_" with "end_", "BEGIN_" with "END_"
(match-string-no-properties 1))))
;; Go to the end of current line, if not at the BOL
(unless at-bol
(end-of-line 1))
(insert (concat (if at-bol "" "\n")
block-end
"\n\n"
block-start
(if at-bol "\n" "")))
;; Go to the line before the inserted "#+begin_ .." line
(beginning-of-line (if at-bol -1 0)))))
(message "Point is not in an Org block")))
(ivy-mode 1)
(counsel-mode 1)