nixos-dotfiles

nixos-dotfiles

https://git.tonybtw.com/nixos-dotfiles.git git://git.tonybtw.com/nixos-dotfiles.git
6,190 bytes raw
1
;;; config.el --- Configuration -*- lexical-binding: t -*-
2
3
(when (file-directory-p "/run/current-system/sw/lib")
4
  (add-to-list 'treesit-extra-load-path "/run/current-system/sw/lib"))
5
6
(setq epg-pinentry-mode 'loopback)
7
8
(add-hook 'org-mode-hook 'visual-line-mode)
9
10
(defun rc/get-default-font ()
11
  (cond
12
   ((eq system-type 'windows-nt) "Consolas-13")
13
   ((eq system-type 'gnu/linux) "Iosevka Nerd Font-24")))
14
15
(add-to-list 'default-frame-alist `(font . ,(rc/get-default-font)))
16
17
(tool-bar-mode 0)
18
(menu-bar-mode 0)
19
(scroll-bar-mode 0)
20
(column-number-mode 1)
21
(show-paren-mode 1)
22
(global-display-line-numbers-mode 1)
23
24
(setq-default c-basic-offset 4
25
              c-default-style '((java-mode . "java")
26
                                (awk-mode . "awk")
27
                                (other . "bsd")))
28
29
(add-hook 'c-mode-hook (lambda ()
30
                         (interactive)
31
                         (c-toggle-comment-style -1)))
32
33
(add-hook 'rust-mode-hook
34
          (lambda ()
35
            (setq-local eglot-workspace-configuration
36
                        '(:rust-analyzer
37
                          (:cargo (:allFeatures t)
38
                           :rustfmt (:extraArgs ["--edition" "2021"]))))
39
            (add-hook 'before-save-hook 'eglot-format-buffer nil t)))
40
41
(add-hook 'before-save-hook 'delete-trailing-whitespace)
42
43
(require 'dired-x)
44
(require 'dired-aux)
45
(setq dired-omit-files
46
      (concat dired-omit-files "\\|^\\..+$"))
47
(setq-default dired-dwim-target t)
48
(setq dired-listing-switches "-alh")
49
50
(setq-default indent-tabs-mode nil)
51
(setq-default tab-width 4)
52
(setq make-backup-files nil)
53
(setq auto-save-default nil)
54
55
(defvar my/base-dir "/home/tony")
56
57
(defun my/set-base-dir ()
58
  "Set the root directory for searches."
59
  (interactive)
60
  (setq my/base-dir (read-directory-name "Set base directory: " my/base-dir))
61
  (message "Search root set to: %s" my/base-dir))
62
63
(defun my/consult-fd ()
64
  "Find files from base dir."
65
  (interactive)
66
  (let ((default-directory my/base-dir))
67
    (consult-fd)))
68
69
(defun my/fzf-find-file ()
70
  "Find files from base dir using fzf."
71
  (interactive)
72
  (let ((default-directory my/base-dir))
73
    (fzf-find-file)))
74
75
(defun my/affe-find ()
76
  "Find files from base dir using affe (async fuzzy)."
77
  (interactive)
78
  (affe-find my/base-dir))
79
80
(load (expand-file-name "telescope.el" user-emacs-directory))
81
82
(defun my/telescope-find-files ()
83
  "Find files from base dir using telescope."
84
  (interactive)
85
  (telescope-find-files my/base-dir))
86
87
(defun my/consult-ripgrep ()
88
  "Ripgrep from base dir."
89
  (interactive)
90
  (consult-ripgrep my/base-dir))
91
92
(defun my/consult-ripgrep-symbol ()
93
  "Ripgrep symbol at point from base dir."
94
  (interactive)
95
  (consult-ripgrep my/base-dir (thing-at-point 'symbol t)))
96
97
(defun my/find-emacs-config ()
98
  "Find files in emacs config dir."
99
  (interactive)
100
  (let ((default-directory "/home/tony/.emacs.d/"))
101
    (consult-fd)))
102
103
(defun my/switch-project ()
104
  "Pick a project from ~/repos, set base-dir, open dired."
105
  (interactive)
106
  (let* ((repos-dir "~/repos/")
107
         (dirs (seq-filter
108
                (lambda (f) (file-directory-p (expand-file-name f repos-dir)))
109
                (directory-files repos-dir nil "^[^.]")))
110
         (chosen (completing-read "Project: " dirs nil t)))
111
    (when chosen
112
      (let ((project-dir (expand-file-name chosen repos-dir)))
113
        (setq my/base-dir project-dir)
114
        (dired project-dir)
115
        (message "Base dir: %s" project-dir)))))
116
117
(defun my/vterm-here ()
118
  "Open vterm in current window."
119
  (interactive)
120
  (let ((default-directory (or (and buffer-file-name (file-name-directory buffer-file-name))
121
                               default-directory))
122
        (display-buffer-alist nil))  ; bypass all display rules
123
    (pop-to-buffer-same-window (vterm "*vterm*"))))
124
125
(setq display-buffer-alist
126
      '(("\\*xref\\*\\|\\*compilation\\*\\|\\*grep\\*"
127
         (display-buffer-reuse-window display-buffer-below-selected)
128
         (window-height . 0.35))))
129
130
(defun my/close-popup-window ()
131
  "Close windows showing xref, compilation, grep, or help buffers."
132
  (interactive)
133
  (dolist (win (window-list))
134
    (when (string-match-p "\\*xref\\*\\|\\*compilation\\*\\|\\*grep\\*\\|\\*Help\\*"
135
                          (buffer-name (window-buffer win)))
136
      (delete-window win))))
137
138
(defun my/reformat-parenthesized-content ()
139
  "Reformat comma-separated content inside parentheses to multiple lines."
140
  (interactive)
141
  (let* ((line (thing-at-point 'line t))
142
         (inside (and (string-match "(\\([^)]+\\))" line)
143
                      (match-string 1 line))))
144
    (if (not inside)
145
        (message "No content found inside parentheses")
146
      (let* ((prefix (and (string-match "^\\(.*?\\)(" line)
147
                          (match-string 1 line)))
148
             (suffix (and (string-match ")\\(.*\\)$" line)
149
                          (match-string 1 line)))
150
             (parts (split-string inside "," t "[ \t]*"))
151
             (new-lines (list (concat prefix "("))))
152
        (dotimes (i (length parts))
153
          (let ((part (nth i parts)))
154
            (if (< i (1- (length parts)))
155
                (push (concat "        " part ",") new-lines)
156
              (push (concat "        " part) new-lines))))
157
        (push (concat "    )" (string-trim-right suffix)) new-lines)
158
        (setq new-lines (nreverse new-lines))
159
        (beginning-of-line)
160
        (kill-line 1)
161
        (insert (mapconcat 'identity new-lines "\n") "\n")))))
162
163
(add-hook 'prog-mode-hook
164
          (lambda ()
165
            (modify-syntax-entry ?- "w")
166
            (modify-syntax-entry ?_ "w")))
167
168
(require 'erc)
169
(require 'erc-services)
170
(erc-services-mode 1)
171
172
(setq erc-nick "tonybtw"
173
      erc-user-full-name "tony"
174
      erc-prompt-for-nickserv-password nil
175
      erc-nickserv-identify-mode 'autodetect
176
      erc-use-auth-source-for-nickserv-password t)
177
178
(setq erc-autojoin-channels-alist
179
      '(("znc.tonybtw.com" "#technicalrenaissance")))
180
181
(defun my/erc-connect-libera ()
182
  "Connect to Libera.Chat via ZNC bouncer."
183
  (interactive)
184
  (erc-tls :server "192.168.86.113"
185
           :port 6697
186
           :nick "tonybtw"
187
           :user "tony/libera"
188
           :password (read-passwd "ZNC password: ")))