-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.el
1815 lines (1557 loc) · 63.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
;; emacs built with:
;; ./configure --with-cairo --with-xwidgets --with-x-toolkit=gtk3 --without-compress-install --with-native-compilation --with-json --with-tree-sitter --with-imagemagick
(setq package-archives '(("gnu" . "https://elpa.gnu.org/packages/")
("melpa" . "https://melpa.org/packages/")))
(package-initialize)
(let ((emacs-git "~/.emacs.d/git"))
(mapc (lambda (x)
(add-to-list 'load-path (expand-file-name x emacs-git)))
(delete ".." (directory-files emacs-git))))
(when (not (package-installed-p 'use-package)) (package-refresh-contents) (package-install 'use-package))
(require 'use-package)
(use-package quelpa-use-package
:ensure t)
(use-package treesit-auto
:ensure t
:config
(global-treesit-auto-mode))
(setq treesit-auto-install 'prompt)
(setq treesit-font-lock-level 4)
(defun treesit-reindent()
(interactive)
; if no selection, reindent the whole buffer. otherwise, reindent the selection.
(if (use-region-p)
(treesit-indent-region (region-beginning) (region-end))
(treesit-indent-region (point-min) (point-max)))
)
; map the reindent function to a key
(global-set-key (kbd "C-M-\\") 'treesit-reindent)
(require 'cl) ; to compensate for a bug in prog-mode in Emacs 24.5
;; set local package locations
(unless (file-directory-p "~/.emacs.d/lisp")
(make-directory "~/.emacs.d/lisp"))
(add-to-list 'load-path "~/.emacs.d/lisp")
(defvar bootstrap-version)
(let ((bootstrap-file
(expand-file-name "straight/repos/straight.el/bootstrap.el" user-emacs-directory))
(bootstrap-version 6))
(unless (file-exists-p bootstrap-file)
(with-current-buffer
(url-retrieve-synchronously
"https://raw.githubusercontent.com/radian-software/straight.el/develop/install.el"
'silent 'inhibit-cookies)
(goto-char (point-max))
(eval-print-last-sexp)))
(load bootstrap-file nil 'nomessage))
;;; Appearance Settings
(tool-bar-mode -1)
(menu-bar-mode -1)
(use-package obsidian-theme
:ensure t
:config
(enable-theme 'obsidian)
(set-face-attribute 'mode-line-active nil
:foreground "medium spring green"
:background "#132024"))
(use-package nerd-icons
:ensure t)
(use-package all-the-icons
:ensure t)
(use-package nerd-icons-dired
:ensure t
:config
(add-hook 'dired-mode-hook 'nerd-icons-dired-mode))
(use-package doom-modeline
:ensure t
:init (doom-modeline-mode 1)
:config
(setq doom-modeline-icon t))
(global-hl-line-mode 1)
;; underline the current line
(set-face-attribute hl-line-face nil)
(add-to-list 'default-frame-alist
'(font . "DejaVu Sans Mono-10"))
(setq inhibit-startup-screen t)
(setq-default show-trailing-whitespace t)
(fringe-mode '(20 . 20))
(defun my-after-init-hook ()
(if (file-directory-p "~/org/org-docs")
(find-file "~/org/org-docs/index.org")
(find-file "~/org/work.org"))
(show-all))
(add-hook 'after-init-hook 'my-after-init-hook)
(global-unset-key (kbd "C-x C-z")) ;; get rid of automatically suspending frame!
(use-package delight
:ensure t
:config
(delight '((company-box-mode nil "company-box")
(company-mode nil "company")
(yas-minor-mode nil "yasnippet")
(smartparens-mode nil "smartparens")
(helm-mode nil "helm")
(flyspell-mode nil "flyspell")
(undo-tree-mode nil "undo-tree")
(highlight-symbol-mode nil "highlight-symbol")
(flycheck-mode nil "flycheck")
(lsp-mode nil "lsp-mode")
(eldoc-mode nil "eldoc")
(abbrev-mode nil "abbrev"))))
;;; General Configuration
(global-unset-key (kbd "C-x C-c"))
(setq gc-cons-threshold 100000000)
(use-package gcmh
:ensure t
:config
(gcmh-mode 1))
(setq read-process-output-max (* 1024 1024))
(use-package exec-path-from-shell
:ensure t
:config
(exec-path-from-shell-initialize))
(use-package gnu-elpa-keyring-update
:ensure t)
(setq ring-bell-function 'ignore)
(setq-default tab-width 4) ; set tab to appear like 2 spaces
(add-to-list 'display-buffer-alist
'("." nil (reusable-frames . t)))
(setq enable-local-eval 't)
(global-set-key (kbd "<XF86Tools>") 'kill-region)
(global-set-key (kbd "<XF86Launch5>") 'kill-ring-save)
(global-set-key (kbd "<XF86Launch6>") 'yank)
(global-set-key (kbd "C-s-o") 'other-window)
(global-set-key (kbd "C-s-p") (lambda () (interactive) (other-window -1)))
(setq ediff-split-window-function 'split-window-horizontally)
(use-package diff-hl
:ensure t
:config
(global-diff-hl-mode)
(diff-hl-flydiff-mode))
(use-package drag-stuff
:ensure t)
(add-to-list 'drag-stuff-except-modes 'org-mode)
(drag-stuff-global-mode 1)
(drag-stuff-define-keys)
(setq
backup-by-copying t ; don't clobber symlinks
backup-directory-alist
'(("." . "~/.saves")) ; don't litter my fs tree
delete-old-versions t
kept-new-versions 6
kept-old-versions 2
create-lockfiles nil
version-control t) ; use versioned backups
(defun download-file-to-directory (url filename)
(interactive (list (read-string "URL: ")
(read-string "File name: ")))
(let ((buffer (url-retrieve-synchronously url)))
(save-excursion
(set-buffer buffer)
(goto-char (point-min))
(re-search-forward "^$" nil 'move)
(forward-char)
(delete-region (point-min) (point))
(write-file filename))
(kill-buffer buffer)))
;; (use-package dtrt-indent
;; :ensure t
;; :config
;; (dtrt-indent-global-mode))
(use-package bpr
:ensure t
:config
(setq bpr-show-progress nil))
(use-package undo-tree
:ensure t)
(global-undo-tree-mode)
(setq undo-tree-history-directory-alist '(("." . "~/.emacs.d/.undo")))
(use-package evil
:ensure t
:init
(setq evil-want-fine-undo t)
:config
(evil-mode))
(evil-set-initial-state 'term-mode 'emacs)
(evil-set-undo-system 'undo-tree)
;; (use-package evil
;; :ensure t)
;; (evil-mode 1)
;; (setq evil-want-fine-undo t)
;; (evil-set-initial-state 'term-mode 'emacs)
;; (evil-set-undo-system 'undo-tree)
(use-package eyebrowse
:ensure t
:config
(eyebrowse-mode)
(eyebrowse-setup-opinionated-keys))
(add-to-list 'default-frame-alist '(close-inner-windows . nil))
(defun my/close-frame-function(frame)
(if (frame-parameter nil 'close-inner-windows)
(dolist (window (window-list))
(let ((buffer (window-buffer window)))
(when (< (length (get-buffer-window-list buffer nil t)) 2)
(kill-buffer buffer))))))
(global-set-key (kbd "C-<tab>") 'other-frame)
(add-hook 'delete-frame-functions 'my/close-frame-function)
(defun my/toggle-fixed-window()
(interactive)
(cond
((and (window-fixed-size-p)
(window-dedicated-p))
(setq window-fixed-size nil)
(set-window-dedicated-p (selected-window) nil)
(window-preserve-size (selected-window) nil)
(message "Window is now resizable"))
((and (not (window-fixed-size-p))
(not (window-dedicated-p)))
(setq window-fixed-size t)
(set-window-dedicated-p (selected-window) t)
(window-preserve-size (selected-window) t)
(message "Window is now fixed"))
((window-dedicated-p)
(setq window-fixed-size t)
(window-preserve-size (selected-window) t)
(message "Window is now fixed. Be careful, originally dedicated."))
(t
(message "Could not toggle window state"))))
(global-set-key (kbd "C-c t") 'my/toggle-fixed-window)
(defun prompt-save-daemon (frame)
(when (and (member terminal-frame (visible-frame-list))
(< (length (visible-frame-list)) 3))
(save-some-buffers)))
(add-hook 'delete-frame-functions 'prompt-save-daemon)
(defun my/set-eyebrowse-frame-title()
(interactive)
(let*
((window-configs (eyebrowse--get 'window-configs))
(current-config (assq (eyebrowse--get 'current-slot) window-configs))
(window-tag (car (last current-config)))
title
(index (-elem-index (assq (eyebrowse--get 'current-slot) window-configs) window-configs))
(curr-count (car (nth index window-configs)))
(first-count (caar window-configs))
(last-count (caar (last window-configs))))
(if (= (length window-tag) 0)
(setq title (concat (number-to-string (car current-config)) "@emacs"))
(setq title (concat (car (last current-config)) "@emacs")))
(if (equal curr-count first-count)
(set-frame-name (concat title " >"))
(if (equal curr-count last-count)
(set-frame-name (concat "< " title))
(set-frame-name (concat "< " title " >")))))
(force-mode-line-update))
(add-hook 'eyebrowse-post-window-switch-hook 'my/set-eyebrowse-frame-title)
(defun my/move-ws-left()
(interactive)
(let*
((window-configs (eyebrowse--get 'window-configs))
(index (-elem-index (assq (eyebrowse--get 'current-slot) window-configs) window-configs))
(curr-count (car (nth index window-configs)))
(first-count (caar window-configs)))
(if (equal curr-count first-count)
(eyebrowse-switch-to-window-config (1- first-count))
(eyebrowse-prev-window-config nil))))
(defun rename-ws(tag)
(interactive "MWorkspace Name: ")
(eyebrowse-rename-window-config (eyebrowse--get 'current-slot) tag)
(my/set-eyebrowse-frame-title))
(defun my/move-ws-right ()
(interactive)
(let*
((window-configs (eyebrowse--get 'window-configs))
(index (-elem-index (assq (eyebrowse--get 'current-slot) window-configs) window-configs))
(curr-count (car (nth index window-configs)))
(last-count (caar (last window-configs))))
(if (equal curr-count last-count)
(eyebrowse-switch-to-window-config (1+ last-count))
(eyebrowse-next-window-config nil))))
(define-key eyebrowse-mode-map (kbd "C-<") 'my/move-ws-left)
(define-key eyebrowse-mode-map (kbd "C->") 'my/move-ws-right)
; stolen from https://emacs.stackexchange.com/questions/31646/how-to-paste-with-indent
(defun yank-with-indent ()
(interactive)
(let ((indent
(buffer-substring-no-properties (line-beginning-position) (line-end-position))))
(message indent)
(yank)
(save-excursion
(save-restriction
(narrow-to-region (mark t) (point))
(pop-to-mark-command)
(replace-string "\n" (concat "\n" indent))
(widen)))))
;; (use-package hideshowvis
;; :ensure t)
(defun my/hs-minor-mode-hook ()
(define-key hs-minor-mode-map (kbd "C-c h h") 'hs-hide-block)
(define-key hs-minor-mode-map (kbd "C-c h s") 'hs-show-block))
;; (add-hook 'hs-minor-mode-hook 'my/hs-minor-mode-hook)
;; (add-hook 'prog-mode-hook #'hs-minor-mode)
;; (add-hook 'prog-mode-hook #'hideshowvis-enable)
(use-package origami
:ensure t
:bind (("<XF86Launch7>" . origami-toggle-node)
("C-<XF86Launch7>" . origami-open-all-nodes))
:config
(global-origami-mode))
(defun my/make-frame-on-monitor ()
(interactive)
; run transparent_window.py in the background
(let
((display-buffer-alist
(list
(cons
"\\*Async Shell Command\\*"
(cons #'display-buffer-no-window nil))))
(default-frame-alist (cl-pushnew '(fullscreen . maximized) default-frame-alist)))
(unwind-protect
(progn
(async-shell-command "python3 ~/.emacs.d/scripts/transparent_window.py" nil nil)
(call-interactively 'make-frame-on-monitor))
(progn
(set-process-query-on-exit-flag (get-buffer-process "*Async Shell Command*") nil)
(kill-buffer "*Async Shell Command*")))))
(global-set-key (kbd "s-f") 'my/make-frame-on-monitor)
(put 'dired-find-alternate-file 'disabled nil)
(setq dired-dwim-target t)
(setq dired-mouse-drag-files t)
(set-face-foreground 'dired-directory "aqua")
(setq dired-listing-switches "-lha")
(use-package openwith
:ensure t
:config
(setq openwith-associations
'(("\\.\\(mp4\\|mp3\\|webm\\|avi\\|flv\\|mov\\mkv\\wav\\xlsx\\doc\\deb\\)$"
"xdg-open" (file))))
(openwith-mode +1))
(use-package helm
:ensure t)
;(require 'helm-config) ; helm-config is part of the helm package
(helm-mode 1)
(setq helm-display-header-line nil)
(add-hook 'after-make-frame-functions (lambda (foo) (set-face-attribute 'helm-source-header nil :height 0.1)))
(set-face-attribute 'helm-source-header nil :height 0.1)
(helm-autoresize-mode 1)
(setq helm-autoresize-max-height 30)
(setq helm-autoresize-min-height 30)
(setq helm-split-window-in-side-p t)
(setq helm-buffer-skip-remote-checking t)
(setq helm-frame-background-color "#202527")
(setq helm-display-buffer-width 90)
; taken from default helm-core.el
(defun my/helm-display-buffer-in-own-frame (buffer &optional resume)
"Display Helm buffer BUFFER in a separate frame.
Function suitable for `helm-display-function',
`helm-completion-in-region-display-function' and/or
`helm-show-completion-default-display-function'.
See `helm-display-buffer-height' and `helm-display-buffer-width'
to configure frame size.
Note that this feature is available only with emacs-25+.
Note also it is not working properly in helm nested session with emacs
version < emacs-28."
(cl-assert (and (fboundp 'window-absolute-pixel-edges)
(fboundp 'frame-geometry))
nil "Helm buffer in own frame is only available starting at emacs-25+")
(if (not (display-graphic-p))
;; Fallback to default when frames are not usable.
(helm-default-display-buffer buffer)
(setq helm--buffer-in-new-frame-p t)
(let* ((parent (selected-frame))
(frame-pos (frame-position parent))
(parent-left (car frame-pos))
(parent-top (cdr frame-pos))
(pos (window-absolute-pixel-position))
(half-screen-size (/ (display-pixel-height x-display-name) 2))
(frame-info (frame-geometry))
(prmt-size (length helm--prompt))
(line-height (frame-char-height))
tab-bar-mode
(new-frame-alist
(if resume
(buffer-local-value 'helm--last-frame-parameters
(get-buffer buffer))
`((width . ,helm-display-buffer-width)
(height . ,helm-display-buffer-height)
(tool-bar-lines . 0)
;; (left . ,(- (car pos)
;; (* (frame-char-width)
;; (if (< (- (point) (point-at-bol)) prmt-size)
;; (- (point) (point-at-bol))
;; prmt-size))))
;; Try to put frame at the best possible place.
;; Frame should be below point if enough
;; place, otherwise above point and
;; current line should not be hidden
;; by helm frame.
;; (top . ,(if (> (cdr pos) half-screen-size)
;; ;; Above point
;; (- (cdr pos)
;; ;; add 2 lines to make sure there is always a gap
;; (* (+ helm-display-buffer-height 2) line-height)
;; ;; account for title bar height too
;; (cddr (assq 'title-bar-size frame-info)))
;; ;; Below point
;; (+ (cdr pos) line-height)))
;; (left . ,(+ parent-left (/ (* (frame-char-width parent) (frame-width parent)) 4)))
;; (top . ,(+ parent-top (/ (* (frame-char-width parent) (frame-height parent)) 6)))
;; (left . ,(+ parent-left (/ (- (* (frame-char-width parent) (frame-width parent)) ,helm-display-buffer-width) 2)))
(left . ,(+ parent-left (/ (- (* (frame-char-width parent) (frame-width parent)) (* (frame-char-width parent) helm-display-buffer-width)) 2)))
;; (left . ,(+ parent-left (/ (* (frame-char-width parent) (frame-width parent)) 4)))
(top . ,(+ parent-top (/ (* (frame-char-width parent) (frame-height parent)) 6)))
(title . "Helm")
(undecorated . ,helm-use-undecorated-frame-option)
(background-color . ,(or helm-frame-background-color
(face-attribute 'default :background)))
(foreground-color . ,(or helm-frame-foreground-color
(face-attribute 'default :foreground)))
(alpha . ,(or helm-frame-alpha 100))
(font . ,(assoc-default 'font (frame-parameters)))
(vertical-scroll-bars . nil)
(menu-bar-lines . 0)
(fullscreen . nil)
(visibility . ,(null helm-display-buffer-reuse-frame))
(minibuffer . t))))
display-buffer-alist)
;; Display minibuffer above or below only in initial session,
;; not on a session triggered by action, this way if user have
;; toggled minibuffer and header-line manually she keeps this
;; setting in next action.
(unless (or helm--executing-helm-action resume)
;; Add the hook inconditionally, if
;; helm-echo-input-in-header-line is nil helm-hide-minibuffer-maybe
;; will have anyway no effect so no need to remove the hook.
(add-hook 'helm-minibuffer-set-up-hook 'helm-hide-minibuffer-maybe)
;; (with-helm-buffer
;; (setq-local helm-echo-input-in-header-line
;; (not (> (cdr pos) half-screen-size))))
)
(helm-display-buffer-popup-frame buffer new-frame-alist)
;; When frame size have been modified manually by user restore
;; it to default value unless resuming or not using
;; `helm-display-buffer-reuse-frame'.
;; This have to be done AFTER raising the frame otherwise
;; minibuffer visibility is lost until next session.
(unless (or resume (not helm-display-buffer-reuse-frame))
(set-frame-size helm-popup-frame
helm-display-buffer-width
helm-display-buffer-height)))
(helm-log-run-hook "my/helm-display-buffer-in-own-frame" 'helm-window-configuration-hook)))
; taken from https://www.reddit.com/r/emacs/comments/jj269n/display_helm_frames_in_the_center_of_emacs/
(defun my-helm-display-frame-center (buffer &optional resume)
"Display `helm-buffer' in a separate frame which centered in
parent frame."
(if (not (display-graphic-p))
;; Fallback to default when frames are not usable.
(helm-default-display-buffer buffer)
(setq helm--buffer-in-new-frame-p t)
(let* ((parent (selected-frame))
(frame-pos (frame-position parent))
(parent-left (car frame-pos))
(parent-top (cdr frame-pos))
(width (/ (frame-width parent) 2))
(height (/ (frame-height parent) 3))
;; (width (max (/ (frame-width parent) 2) 300))
;; (height (max (/ (frame-height parent) 3) 200))
tab-bar-mode
(default-frame-alist
(if resume
(buffer-local-value 'helm--last-frame-parameters
(get-buffer buffer))
`((parent . ,parent)
(width . ,width)
(height . ,height)
(undecorated . ,helm-use-undecorated-frame-option)
(left-fringe . 0)
(right-fringe . 0)
(tool-bar-lines . 0)
(line-spacing . 0)
(desktop-dont-save . t)
(no-special-glyphs . t)
(inhibit-double-buffering . t)
(tool-bar-lines . 0)
(left . ,(+ parent-left (/ (* (frame-char-width parent) (frame-width parent)) 4)))
(top . ,(+ parent-top (/ (* (frame-char-width parent) (frame-height parent)) 6)))
(title . "Helm")
(vertical-scroll-bars . nil)
(menu-bar-lines . 0)
(fullscreen . nil)
(visibility . ,(null helm-display-buffer-reuse-frame))
;; (internal-border-width . ,(if IS-MAC 1 0))
)))
display-buffer-alist)
;; (set-face-background 'internal-border (face-foreground 'default))
;; (raise-frame)
(helm-display-buffer-popup-frame buffer default-frame-alist))
;; (unless (bound-and-true-p 'helm-popup-frame)
;; (setq helm-popup-frame (selected-frame)))
;; (select-frame-set-input-focus (selected-frame)))
;; (select-frame-set-input-focus helm-popup-frame)
;; (select-frame-set-input-focus )
(helm-log-run-hook "my-helm-display-frame-center" 'helm-window-configuration-hook)))
(setq helm-display-function 'my/helm-display-buffer-in-own-frame
helm-display-buffer-reuse-frame t
helm-use-undecorated-frame-option t)
;; (setq helm-display-function 'my-helm-display-frame-center)
;; (add-hook 'helm-major-mode-hook
;; (lambda ()
;; (message "enter helm")))
(use-package helm-lsp
:ensure t)
(define-key lsp-mode-map [remap xref-find-apropos] #'helm-lsp-workspace-symbol)
(customize-set-variable 'helm-ff-lynx-style-map t)
(define-key helm-map (kbd "<left>") 'helm-previous-source)
(define-key helm-map (kbd "<right>") 'helm-next-source)
(global-set-key (kbd "M-x") 'helm-M-x)
(global-set-key (kbd "C-x C-f") 'helm-find-files)
(global-set-key (kbd "C-x b") 'helm-mini)
(use-package helm-system-packages
:ensure t)
(use-package direnv
:ensure t
:config
(direnv-mode))
(setenv "TERM" "xterm-256color")
(use-package multi-term
:ensure t
:bind ([escape] . term-send-esc)
:config
(yas-minor-mode -1)
(set-face-foreground 'term-color-blue "deep sky blue"))
(defun my-compile-libvterm ()
(make-directory "~/.emacs.d/.vterm" t)
(if (file-directory-p "~/.emacs.d/.vterm/emacs-libvterm")
(shell-command "cd ~/.emacs.d/.vterm/emacs-libvterm && git pull origin master")
(shell-command "cd ~/.emacs.d/.vterm && git clone https://github.com/akermu/emacs-libvterm.git"))
(async-shell-command "cd ~/.emacs.d/.vterm/emacs-libvterm && git pull origin master && mkdir build -p build && cd build && cmake .. && make -j"))
(unless (file-exists-p "~/.emacs.d/.vterm/emacs-libvterm")
(my-compile-libvterm))
(add-to-list 'load-path "~/.emacs.d/.vterm/emacs-libvterm")
(require 'vterm)
(add-to-list 'evil-emacs-state-modes 'vterm-mode)
(use-package multi-vterm
:ensure t)
(defun my/vterm-hook()
(define-key vterm-mode-map (kbd "<escape>") (lambda ()
(interactive)
(vterm-send-key "<escape>")))
(setq show-trailing-whitespace nil)
(set-process-query-on-exit-flag (get-buffer-process (current-buffer)) nil)
(set-face-foreground 'term-color-blue "deep sky blue"))
(add-hook 'vterm-mode-hook 'my/vterm-hook)
(defun rename-term (name)
(interactive "sRename terminal to: ")
(rename-buffer (concat "*term* " name)))
(defun rename-new-term (name)
(interactive "sNew terminal name: ")
(multi-vterm)
(rename-term name))
(defun kill-all-term ()
(interactive)
(with-temp-buffer
(dolist (buff (buffer-list))
(let ((buff-name (buffer-name buff))
(buff-mode (buffer-local-value 'major-mode buff)))
(when (equal (buffer-local-value 'major-mode buff) 'vterm-mode)
(kill-buffer buff))))))
(global-set-key (kbd "s-t") 'multi-vterm)
(global-set-key (kbd "s-T") 'rename-new-term)
(use-package highlight-symbol
:ensure t)
(add-hook 'prog-mode-hook 'highlight-symbol-mode)
(use-package comment-dwim-2
:ensure t)
(global-set-key (kbd "M-;") 'comment-dwim-2)
(global-set-key (kbd "C-c i") 'clone-indirect-buffer)
(defun narrow-and-rename-region (new-buff-name)
(interactive "s")
(let ((beg (region-beginning))
(end (region-end)))
(deactivate-mark)
(save-restriction
(clone-indirect-buffer new-buff-name t)
(narrow-to-region beg end))))
(global-set-key (kbd "C-c n") 'narrow-and-rename-region)
(defun narrow-and-rename-defun (new-buff-name)
(interactive "s")
(save-restriction
(clone-indirect-buffer new-buff-name t)
(narrow-to-defun)))
(global-set-key (kbd "C-c d") 'narrow-and-rename-defun)
(defun narrow-and-rename-page (new-buff-name)
(interactive "s")
(save-restriction
(clone-indirect-buffer new-buff-name t)
(narrow-to-page)))
; from http://stackoverflow.com/questions/3035337/in-emacs-can-you-evaluate-an-emacs-lisp-expression-and-replace-it-with-the-resul
(defun replace-last-sexp ()
(interactive)
(let ((value (eval (preceding-sexp))))
(kill-sexp -1)
(insert (format "%S" value))))
(defun uniquify-all-lines-region (start end)
"find duplicate lines in region start to end keeping first occurance."
(interactive "*r")
(save-excursion
(let ((lines) (end (copy-marker end)))
(goto-char start)
(while (and (< (point) (marker-position end))
(not (eobp)))
(let ((line (buffer-substring-no-properties
(line-beginning-position) (line-end-position))))
(if (member line lines)
(delete-region (point) (progn(forward-line 1) (point)))
(push line lines)
(forward-line 1)))))))
(put 'narrow-to-region 'disabled nil)
(require 'ansi-color)
(defun display-ansi-colors ()
(interactive)
(ansi-color-apply-on-region (point-min) (point-max)))
;;; LaTeX Configuration
(defun my-latex-mode-hook ()
(visual-line-mode)
(flyspell-mode)
(flyspell-buffer))
(add-hook 'latex-mode-hook 'my-latex-mode-hook)
;;; Org Configuration
(with-eval-after-load 'org
(add-to-list 'org-modules 'org-habit t))
(use-package ob-ipython
:ensure t)
(setq org-log-done 'time)
(use-package plantuml-mode
:ensure t
:init
(setq plantuml-jar-path "/usr/share/plantuml/plantuml.jar")
(setq org-plantuml-jar-path plantuml-jar-path))
(org-babel-do-load-languages
'org-babel-load-languages
'((python . t)
(ipython . t)
(ditaa . t)
(plantuml . t)
(ruby . t)
(shell . t)
(elixir . t)
(latex . t)))
(add-hook 'org-babel-after-execute-hook 'org-redisplay-inline-images)
(setq org-image-actual-width 800)
(setq org-export-preserve-breaks t)
(setq org-confirm-babel-evaluate nil)
(setq org-src-fontify-natively t)
(setq org-time-clocksum-use-effort-durations t)
(setq org-blank-before-new-entry
'((heading . nil)
(plain-list-item . nil)))
(setq org-html-head "<link rel=\"stylesheet\" type=\"text/css\" href=\"http://www.pirilampo.org/styles/readtheorg/css/htmlize.css\"/>\n<link rel=\"stylesheet\" type=\"text/css\" href=\"http://www.pirilampo.org/styles/readtheorg/css/readtheorg.css\"/>\n\n<script src=\"https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js\"></script>\n<script src=\"https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js\"></script>\n<script type=\"text/javascript\" src=\"https://unpkg.com/sticky-table-headers\"></script>\n<script type=\"text/javascript\" src=\"http://www.pirilampo.org/styles/readtheorg/js/readtheorg.js\"></script>")
(setq org-latex-inputenc-alist '(("utf8" . "utf8x")))
(use-package centered-window
:ensure t)
(defun centered-window-on-switch ()
(interactive)
(if (and (not (or (window-in-direction 'left) (window-in-direction 'right))) (bound-and-true-p centered-window-mode-set))
(unless (bound-and-true-p centered-window-mode)
(progn
(centered-window-mode-toggle)))
(if (bound-and-true-p centered-window-mode)
(progn
(centered-window-mode-toggle)))))
(add-hook 'window-configuration-change-hook 'centered-window-on-switch)
(defun toggle-centered-window ()
(interactive)
(unless (boundp 'centered-window-mode-set)
(make-local-variable 'centered-window-mode-set)
(setq centered-window-mode-set nil))
(setq centered-window-mode-set (not centered-window-mode-set))
(centered-window-on-switch))
(global-set-key (kbd "<XF86Launch9>") 'toggle-centered-window)
(defun copy-org-to-clipboard ()
(interactive)
(save-excursion
(let ((buff (current-buffer)))
(with-temp-buffer
(insert-buffer-substring buff)
(org-mode)
(goto-char 0)
(org-show-all)
(if (not (org-at-heading-p))
(progn
(org-next-visible-heading 1)
(kill-region (point-min) (point))))
(while (not (eobp))
(let ((num-spaces (- (org-current-level) 1)))
(delete-char num-spaces)
(insert-char (char-from-name "SPACE") (* num-spaces 2))
(forward-line 1)
(while (not (or (eobp) (org-at-heading-p)))
(progn
(if (not (eolp))
(insert-char (char-from-name "SPACE") (+ (* num-spaces 2) 2)))
(forward-line 1)))))
(clipboard-kill-region (point-min) (point-max))))))
(use-package emacsql-sqlite-builtin
:ensure t)
(use-package org-roam
:ensure t
:init
(setq org-roam-v2-ack t)
:custom
(org-roam-directory "~/orgroam")
(org-roam-completion-everywhere t)
(org-roam-mode-sections (list 'org-roam-backlinks-section
'org-roam-reflinks-section))
:config
(org-roam-setup))
;; (setq org-agenda-files
;; `(,(concat (file-name-as-directory org-roam-directory) "20220927084753-daily_habits.org")))
;; (setq org-agenda-prefix-format '(
;; (agenda . " %-12T")))
;; (setq org-agenda-remove-tags t)
(use-package org-roam-ui
:ensure t
:config
(setq org-roam-ui-sync-theme t
org-roam-ui-follow t
org-roam-ui-open-on-start nil
org-roam-ui-update-on-save t)
(setq org-roam-capture-templates
'(("d" "default" plain "%?"
:if-new
(file+head
"%<%Y%m%d%H%M%S>-${slug}.org" "\n#+title: ${title}\n#+author: %n\n#+lastmod: [%<%Y-%m-%d %a %H:%M>]\n#+categories[]:\n#+draft: true\n#+ROAM_TAGS:\n#+PROPERTY: header-args :dir \"%<%Y%m%d%H%M%S>-${slug}\"\n#+hugo_bundle: %<%Y%m%d%H%M%S>-${slug}\n#+export_file_name: _index.md\n")
:unnarrowed t))))
(defun xwidget-webkit-get-url-buffer (url)
"Returns xwidget buffer that points to URL, nil if none."
(interactive)
(when-let* ((r (lambda (x)
(when x (replace-regexp-in-string "http\\(s\\|\\)://" "" x))))
(fnd (seq-find
(lambda (x)
(string= (concat (funcall r url) "/")
(funcall r (xwidget-webkit-uri x))))
xwidget-list)))
(xwidget-buffer fnd)))
(defun xwidget-webkit-url-get-create (url &optional buffer-name)
"Opens existing xwidget buffer, if it exists for the given URL,
or creates new session. Optionally, BUFFER-NAME can be set"
(interactive (list (or (thing-at-point 'url)
(car (browse-url-interactive-arg "xwidget url: ")))))
(require 'xwidget)
(or (xwidget-webkit-get-url-buffer url)
(progn (xwidget-webkit-browse-url url :new-session)
(let ((buf xwidget-webkit-last-session-buffer))
(run-with-timer
1 nil
(lambda (buf buffer-name)
(with-current-buffer buf
(rename-buffer (or buffer-name (concat "*xwidget " url "*")))))
buf buffer-name)
buf))))
(defun org-roam-toggle-ui-xwidget ()
(interactive)
(let* ((url (concat "http://localhost:" (number-to-string org-roam-ui-port)))
(buf (or (xwidget-webkit-get-url-buffer
(concat "localhost:" (number-to-string org-roam-ui-port)))
(xwidget-webkit-url-get-create url "*org-roam-ui*"))))
(if-let ((win (get-buffer-window buf)))
(delete-window win)
(switch-to-buffer-other-window buf))))
(add-hook 'org-roam-capture-new-node-hook
(lambda ()
(message "Created node %s" (buffer-file-name))
(make-directory (file-name-sans-extension (buffer-file-name)))))
(setq time-stamp-active t
time-stamp-start "#\\+lastmod:[ \t]*"
time-stamp-end "$"
time-stamp-format "[%04Y-%02m-%02d %a %H:%M]")
(add-hook 'before-save-hook 'time-stamp nil)
(defun my/org-roam-work-only (node)
(interactive)
(let ((tags (org-roam-node-tags node)))
(member "work" tags)))
(defun my/org-roam-personal-only (node)
(interactive)
(let ((tags (org-roam-node-tags node)))
(member "personal" tags)))
(defun my/org-roam-web-only (node)
(interactive)
(let ((tags (org-roam-node-tags node)))
(member "web" tags)))
(defun org-get-all-website-pages ()
(org-roam-db-query
[:select file :from nodes :inner :join tags :on (= nodes:id tags:node_id) :where (= tags:tag "web")]))
(setq org-website-path "/home/kota/kota_dev_ws/personal_blog/personal_blog/content/posts")
(defun org-generate-website ()
(interactive)
(dolist (source-file-arr (org-get-all-website-pages))
(let* ((source-file (car source-file-arr))
(target-file
(concat (file-name-as-directory org-website-path)
(car (last (file-name-split source-file))))))
(if (file-exists-p target-file)
(delete-file target-file))
(copy-file source-file target-file))))
(setq org-hugo-base-dir "/home/kota/kota_dev_ws/personal_blog/personal_blog")
(setq org-hugo-default-section-directory "posts")
(defun org-generate-hugo ()
(interactive)
(dolist (source-file-arr (org-get-all-website-pages))
(let ((source-file (car source-file-arr)))
(message "exporting %s" source-file)
(org-hugo--export-file-to-md source-file))))
(use-package adaptive-wrap
:ensure t)
(defun split-horizontal-center-window ()
(interactive)
(if (bound-and-true-p centered-window-mode)
(progn
(centered-window-mode-toggle)
(split-window-horizontally)
(centered-window-mode-toggle))
(split-window-horizontally)))
(global-set-key (kbd "C-x 3") 'split-horizontal-center-window)
(use-package org-download
:ensure t)
(defun my/org-mode-hook ()
(visual-line-mode)
(toggle-centered-window)
(org-indent-mode t)
(org-download-enable)
(setq org-confirm-babel-evaluate nil)
(define-key evil-insert-state-map (kbd "S-<left>") nil)
(define-key evil-insert-state-map (kbd "S-<right>") nil)
(local-set-key [?\s-e] 'org-latex-export-to-pdf))
(add-hook 'org-mode-hook 'my/org-mode-hook)
(setq org-todo-keywords
'((seqeunce "TODO" "STARTED" "PAUSED" "|" "DONE" "CANCELED")))
(setq org-todo-keyword-faces
'(("TODO" . "white smoke")
("STARTED" . "SeaGreen1")
("PAUSED" . "pink1")
("DONE" . "SteelBlue1")
("CANCELED" . "grey58")))
(require 'ox-latex)
(setq org-latex-pdf-process
'("pdflatex -shell-escape -interaction nonstopmode -output-directory %o %f"
"pdflatex -shell-escape -interaction nonstopmode -output-directory %o %f"))
(setq org-latex-listings 'minted)
(add-to-list 'org-latex-classes
'("hitec"
"\\documentclass{hitec}
\\usepackage{graphicx}
\\usepackage{graphicx}
\\usepackage[hidelinks]{hyperref}
\\usepackage{parskip}
\\usepackage{pstricks}
\\usepackage{textcomp}
\\usepackage[tikz]{bclogo}
\\usepackage{listings}
\\usepackage{fancyvrb}
\\usepackage{xcolor}
\\definecolor{LightGray}{gray}{0.9}
%% \\usepackage[bgcolor=LightGray]{minted}
\\usepackage{minted}
\\usemintedstyle{monokai}
\\presetkeys{bclogo}{ombre=true,epBord=3,couleur = blue!15!white,couleurBord = red,arrondi = 0.2,logo=\bctrombone}{}
\\usetikzlibrary{patterns}
\\company{Skylla Technologies}
[NO-DEFAULT-PACKAGES]
[NO-PACKAGES]"
("\\section{%s}" . "\\section*{%s}")
("\\subsection{%s}" . "\\subsection*{%s}")
("\\subsubsection{%s}" . "\\subsubsection*{%s}")
("\\paragraph{%s}" . "\\paragraph*{%s}")
("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
(setq org-latex-default-class "hitec")
(use-package ox-hugo
:ensure t
:after ox)
;;; Project Configuration
(use-package skeletor
:ensure t)
(use-package projectile
:ensure t
:config
(setq projectile-switch-project-action 'projectile-dired)
(define-key projectile-mode-map (kbd "C-c p") 'projectile-command-map)
(setq projectile-globally-ignored-directories