-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.el
More file actions
594 lines (507 loc) · 18.2 KB
/
Copy pathconfig.el
File metadata and controls
594 lines (507 loc) · 18.2 KB
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
(require 'package)
(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t)
(add-to-list 'package-archives '("melpa-stable" . "https://stable.melpa.org/packages/") t)
(setq package-archive-priorities
'(("gnu" . 30)
("nongnu" . 20)
("melpa-stable" . 10)
("melpa" . 0)))
(setq package-install-upgrade-built-in t)
(package-initialize)
(require 'use-package)
(setq use-package-always-ensure t)
;; Local libraries under ~/.config/emacs/lisp/
(add-to-list 'load-path (expand-file-name "lisp" user-emacs-directory))
(use-package exec-path-from-shell
:demand t
:config
;; GUI sessions on macOS lack the login shell PATH;
;; batch and terminal sessions already inherit it.
(when (memq window-system '(mac ns))
(exec-path-from-shell-initialize)))
(use-package tramp
:ensure nil
:defer t
:init
(require 'tramp-cache)
(add-to-list
'tramp-connection-properties
(list (rx bos "/" (or "ssh" "scp") ":")
"login-args"
'(("-o" "SetEnv=TERM=dumb")
("-l" "%u") ("-p" "%p") ("%c")
("-e" "none") ("%h"))))
;; uv tool installs (basedpyright-langserver, ruff) land in
;; ~/.local/bin, absent from the non-interactive SSH PATH on the
;; remote hosts.
(add-to-list 'tramp-remote-path "/home/codingquark/.local/bin" t))
(use-package emacs
:init
;; Remove UI clutter
(menu-bar-mode -1)
(tool-bar-mode -1)
(scroll-bar-mode -1)
;; Startup configuration
(setq inhibit-startup-message t)
(setq initial-scratch-message nil)
(setq initial-buffer-choice
(lambda ()
(require 'denote-journal)
(denote-journal-new-or-existing-entry)))
(defun cq-kill-initial-scratch-buffer ()
"Kill the unused initial scratch buffer."
(when-let* ((buffer (get-buffer "*scratch*")))
(kill-buffer buffer)))
(add-hook 'emacs-startup-hook #'cq-kill-initial-scratch-buffer)
)
(defconst cq-omarchy-integration-file
(expand-file-name "omarchy.el" user-emacs-directory)
"Host-provided Omarchy integration shim, when available.")
(use-package server
:ensure nil
:init
;; Omarchy's local hooks expect the standard Unix socket. Keep TCP on
;; regular hosts for remote emacsclient access.
(setq server-use-tcp
(not (file-readable-p cq-omarchy-integration-file)))
:config
(unless (or noninteractive (server-running-p))
(server-start)))
(unless (file-readable-p cq-omarchy-integration-file)
(use-package modus-themes
:bind (("<f5>" . modus-themes-toggle))
:init
(load-theme 'modus-vivendi)))
(use-package lin
:custom
(lin-face 'lin-blue)
:config
(lin-global-mode 1))
(defconst cq-variable-pitch-font "Charter"
"Font family used by variable-pitch faces.")
(when (find-font (font-spec :family cq-variable-pitch-font))
;; Reading-oriented modes like elfeed-show rely on `variable-pitch`.
(set-face-attribute 'variable-pitch nil :family cq-variable-pitch-font))
(when (or (string= system-name "muon.local") (string= system-name "photon"))
(set-face-attribute 'default nil :font "IBM Plex Mono" :height 160))
(use-package emacs
:init
(setq-default mode-line-format
'("%*"
(:eval (when (file-remote-p default-directory) "@"))
" "
mode-line-buffer-identification
"%e"
"%[" "%n" "%]"
erc-modified-channels-object
mode-line-format-right-align
(vc-mode (" " vc-mode))
(flymake-mode (" " flymake-mode-line-counters))
" "
mode-name
" L%l:C%c")))
(use-package emacs
:init
;; Indentation
(setq-default indent-tabs-mode nil)
(setq-default tab-width 2)
;; File management
(setq backup-directory-alist '(("." . "~/.config/emacs/backups")))
(setq auto-save-file-name-transforms '((".*" "~/.config/emacs/auto-save-list/" t)))
;; Visual aids
(show-paren-mode 1)
;; macOS compatibility
(setq dired-use-ls-dired nil)
:hook ((dired-mode . auto-revert-mode)
(prog-mode . auto-revert-mode)
(text-mode . auto-revert-mode))
;; Better keybindings
:bind
("C-x C-b" . ibuffer))
(use-package dired
:ensure nil
:hook ((dired-mode . denote-dired-mode)
(dired-mode . dired-hide-details-mode)))
(use-package vertico
:init
(vertico-mode 1)
:bind (:map vertico-map
("RET" . vertico-directory-enter)
("DEL" . vertico-directory-delete-char)
("M-DEL" . vertico-directory-delete-word))
:hook (rfn-eshadow-update-overlay . vertico-directory-tidy))
(use-package orderless
:custom
(completion-styles '(orderless basic))
(completion-category-defaults nil)
(completion-category-overrides '((file (styles partial-completion)))))
(use-package prescient
:config
(prescient-persist-mode 1))
(use-package vertico-prescient
:after (vertico prescient)
:custom
(vertico-prescient-enable-filtering nil)
:config
(vertico-prescient-mode 1))
(use-package marginalia
:init
(marginalia-mode 1))
(use-package consult
:bind (("C-s" . consult-line)
("C-x b" . consult-buffer)
("C-x 4 b" . consult-buffer-other-window)
("M-y" . consult-yank-pop)
("M-g g" . consult-goto-line)
("M-g i" . consult-imenu)
("M-s g" . consult-grep)
("M-s r" . consult-ripgrep)))
(use-package embark
:bind (("C-." . embark-act)
("C-;" . embark-dwim)
("C-h B" . embark-bindings))
:init
(setq prefix-help-command #'embark-prefix-help-command))
(use-package embark-consult
:after (embark consult)
:hook (embark-collect-mode . consult-preview-at-point-mode))
(use-package corfu
:init
(global-corfu-mode 1)
:custom
;; Explicit-only completion: popup on TAB / C-M-i, never on idle.
(corfu-auto nil)
(corfu-cycle t))
(use-package which-key
:init
(which-key-mode 1)
:custom
(which-key-idle-delay 0.5))
(use-package helpful
:bind (([remap describe-command] . helpful-command)
([remap describe-function] . helpful-callable)
([remap describe-key] . helpful-key)
([remap describe-symbol] . helpful-symbol)
([remap describe-variable] . helpful-variable)))
(use-package savehist
:ensure nil
:init
(savehist-mode 1))
(use-package recentf
:ensure nil
:init
(recentf-mode 1)
:custom
(recentf-max-saved-items 200))
(use-package saveplace
:ensure nil
:init
(save-place-mode 1))
(use-package winner
:ensure nil
:init
(winner-mode 1))
(use-package magit
:bind (("C-x g" . magit-status)))
(use-package magit-delta
:after magit
:hook (magit-mode . magit-delta-mode))
(use-package gptel
:commands (gptel gptel-send gptel-menu gptel-tools)
:custom
(gptel-default-mode 'org-mode)
(gptel-model 'Qwen/Qwen3.8-27B)
:config
(gptel-make-openai "OpenRouter"
:host "openrouter.ai"
:endpoint "/api/v1/chat/completions"
:stream t
:key gptel-api-key
:models '((z-ai/glm-5.3-flash :request-params (:reasoning (:effort "high")))
(deepseek/deepseek-v4-flash-0731 :request-params (:reasoning (:effort "high")))))
(gptel-make-openai "Gluon"
:protocol "http"
:host "gluon.home.arpa:8001"
:endpoint "/v1/chat/completions"
:stream t
:key "sk-noop"
:models '(Qwen/Qwen3.8-27B))
(setq gptel-backend (gptel-get-backend "Gluon")))
(add-to-list 'load-path
(expand-file-name "lisp/gptel-prompts" user-emacs-directory))
(use-package gptel-prompts
:ensure nil
:after (gptel)
:demand t
:config
(gptel-prompts-update)
(gptel-prompts-add-update-watchers))
(use-package gptel-magit
:after (gptel magit)
:hook (magit-mode . gptel-magit-install)
:config
(defun cq-gptel-magit--forward-if-string (cb response info)
(when (stringp response)
(funcall cb response info)))
(defun cq-gptel-magit--request-advice (orig-fn prompt &rest args)
(let* ((cb (plist-get args :callback))
(wrapped (apply-partially #'cq-gptel-magit--forward-if-string cb))
(args (plist-put args :stream nil))
(args (plist-put args :callback wrapped)))
(apply orig-fn prompt args)))
(advice-add 'gptel-magit--request :around #'cq-gptel-magit--request-advice))
(use-package erc
:ensure nil
:commands (erc erc-tls cq-erc-libera)
:custom
(erc-nick "codingquark")
(erc-user-full-name "codingquark")
(erc-server "irc.libera.chat")
(erc-port 6697)
(erc-prompt-for-password nil)
(erc-use-auth-source-for-nickserv-password t)
(erc-autojoin-timing 'ident)
(erc-autojoin-channels-alist '(("Libera.Chat" "#emacs")))
(erc-hide-list '("JOIN" "PART" "QUIT" "NICK"))
(erc-track-exclude-types '("JOIN" "PART" "QUIT" "NICK" "MODE"
"324" "329" "332" "333" "353" "477"))
(erc-kill-buffer-on-part t)
(erc-kill-queries-on-quit t)
(erc-kill-server-buffer-on-quit t)
(erc-fill-function 'erc-fill-static)
(erc-fill-static-center 18)
:config
(require 'erc-services)
(require 'erc-match)
(erc-services-mode 1)
(erc-match-mode 1)
(erc-track-mode 1)
(erc-autojoin-mode 1)
(add-hook 'erc-mode-hook (lambda () (display-line-numbers-mode -1)))
(defun cq-erc-libera ()
"Connect to Libera.Chat over TLS, reading creds from auth-source."
(interactive)
(erc-tls :server "irc.libera.chat" :port 6697
:nick erc-nick :full-name erc-user-full-name)))
(defvar cq-terminal-notifier
(executable-find "terminal-notifier")
"Path to terminal-notifier, or nil if unavailable.")
(defun cq-erc-notify (title message)
"Post a macOS notification with TITLE and MESSAGE via terminal-notifier."
(when cq-terminal-notifier
(call-process cq-terminal-notifier nil 0 nil
"-title" (format "ERC: %s" title)
"-message" message
"-group" "emacs-erc"
"-sender" "org.gnu.Emacs")))
(defun cq-erc-notify-match (match-type nickuserhost message)
"Notify on `erc-match' hits for current-nick and keywords."
(when (and (memq match-type '(current-nick keyword))
(not (get-buffer-window (current-buffer) 'visible)))
(let ((nick (car (split-string (or nickuserhost "") "!"))))
(cq-erc-notify (format "%s in %s" nick (buffer-name))
message))))
(defun cq-erc-notify-query (proc parsed)
"Notify when a private message lands in a query buffer.
Returns nil so ERC keeps processing the message normally."
(let* ((nick (car (erc-parse-user (erc-response.sender parsed))))
(target (car (erc-response.command-args parsed)))
(msg (erc-response.contents parsed)))
(when (and target
(erc-current-nick-p target)
(not (erc-current-nick-p nick)))
(let ((buf (erc-get-buffer nick proc)))
(unless (and buf (get-buffer-window buf 'visible))
(cq-erc-notify (format "PM from %s" nick) msg)))))
nil)
(with-eval-after-load 'erc-match
(add-hook 'erc-text-matched-hook #'cq-erc-notify-match))
(with-eval-after-load 'erc
(add-hook 'erc-server-PRIVMSG-functions #'cq-erc-notify-query))
(defvar cq-elfeed-feeds-file
(expand-file-name "elfeed-feeds.el" user-emacs-directory)
"Path to the personal Elfeed feed list.")
(use-package elfeed
:bind (("C-c f" . elfeed)
("C-c F" . cq-open-elfeed-feeds-file))
:custom
(elfeed-db-directory (expand-file-name "elfeed" user-emacs-directory))
(elfeed-search-filter "@2-months-ago +unread")
:config
;; Keep subscriptions outside the main config to make feed edits low-friction.
(load cq-elfeed-feeds-file 'noerror 'nomessage)
(defun cq-open-elfeed-feeds-file ()
"Open the Elfeed subscriptions file."
(interactive)
(find-file cq-elfeed-feeds-file)))
(defconst cq-reading-list-file
(expand-file-name
"Documents/notes/20230206T124634--reading-list__lists_productivity.org"
"~")
"Denote note used as the reading-list capture target.")
(use-package org-capture
:ensure nil
:demand t
:config
(add-to-list 'org-capture-templates
`("w" "Web page for reading list" entry
(file+headline ,cq-reading-list-file "Reading list")
"* TODO %:description\n:PROPERTIES:\n:CAPTURED: %U\n:URL: %:link\n:END:\n\n%:annotation\n\n#+begin_quote\n%i\n#+end_quote\n\n%?"
:empty-lines 1)))
(use-package org-protocol
:ensure nil
:demand t
:custom
(org-protocol-default-template-key "w"))
(use-package denote
:hook (text-mode . denote-fontify-links-mode-maybe)
:bind (
("C-c n n" . denote)
("C-c n D" . cq-open-denote-directory)
("C-c n N" . denote-type)
("C-c n i" . denote-link)
("C-c n I" . denote-add-links)
("C-c n b" . denote-backlinks)
("C-c n f b" . denote-find-backlink)
("C-c n r" . denote-rename-file)
("C-c n R" . denote-rename-file-using-front-matter)
;; ("C-c n ." . cq-insert-time-stamp)
)
:custom
(denote-directory "~/Documents/notes")
(denote-infer-keywords t)
(denote-sort-keywords t)
(denote-file-type 'text)
(denote-prompts '(title keywords))
:config
(setq crm-separator ",")
(defun cq-open-denote-directory ()
(interactive)
(revert-buffer (dired denote-directory)))
(defun cq-insert-time-stamp ()
"Insert a timestamp with a newline character."
(interactive)
(insert (current-time-string))
(newline)))
(use-package denote-journal
:after denote
:bind
(("C-c n j" . denote-journal-new-or-existing-entry))
:custom
(denote-journal-title-format 'day-date-month-year))
(use-package denote-menu
:after denote)
(use-package olivetti
:config
(setq olivetti-body-width 80))
(use-package markdown-mode
:custom
(markdown-command "pandoc")
:mode (("README\\.md\\'" . gfm-mode)
("\\.md\\'" . markdown-mode)
("\\.markdown\\'" . markdown-mode)))
(use-package cq-home-assistant
:ensure nil
:demand t
:config
(keymap-set global-map "C-c h" cq-home-assistant-prefix-map))
;; Require eglot before the :custom keyword is processed: with :ensure
;; nil use-package defers its require until after :custom, and the
;; value would then be silently skipped by custom-theme-set-variables.
(require 'eglot)
(defun cq-python-eglot-server (&optional _interactive _project)
"Return the basedpyright command for local or TRAMP Python buffers."
(list (if (file-remote-p default-directory)
;; uv installs this server here on electron and tau. Use an
;; absolute path because their non-interactive SSH PATH omits it.
"/home/codingquark/.local/bin/basedpyright-langserver"
"basedpyright-langserver")
"--stdio"))
(use-package eglot
:ensure nil
:custom
(eglot-workspace-configuration
'(:rust-analyzer (:check (:command "clippy"))))
:config
;; Prefer basedpyright even when another Python server is installed.
(add-to-list 'eglot-server-programs
'((python-mode python-ts-mode) . cq-python-eglot-server)))
(defun cq-eglot-disable-python-inlay-hints ()
"Keep Eglot inlay hints off initially in Python buffers."
(when (and (eglot-managed-p)
(derived-mode-p 'python-base-mode))
(eglot-inlay-hints-mode -1)))
(add-hook 'eglot-managed-mode-hook
#'cq-eglot-disable-python-inlay-hints)
(defun cq-eglot-format-on-save ()
"Toggle Eglot formatting before save in Rust buffers."
(if (eglot-managed-p)
(when (derived-mode-p 'rust-ts-mode)
(add-hook 'before-save-hook #'eglot-format-buffer nil t))
(remove-hook 'before-save-hook #'eglot-format-buffer t)))
(add-hook 'eglot-managed-mode-hook #'cq-eglot-format-on-save)
(use-package lua-mode
:mode "\\.lua\\'"
:hook (lua-mode . eglot-ensure)
:config
(setq lua-indent-level 2))
(use-package rust-ts-mode
:ensure nil
:mode "\\.rs\\'"
:hook (rust-ts-mode . eglot-ensure))
;; python-base-mode is the shared parent of python-mode and
;; python-ts-mode, so one hook covers both, locally and over TRAMP.
(use-package python
:ensure nil
:hook (python-base-mode . eglot-ensure))
;; Tree-sitter: let `treesit-install-language-grammar' find the Python
;; grammar, and remap python-mode only when that grammar is ready.
(add-to-list 'treesit-language-source-alist
'(python "https://github.com/tree-sitter/tree-sitter-python"))
(when (treesit-language-available-p 'python)
(add-to-list 'major-mode-remap-alist '(python-mode . python-ts-mode)))
(use-package flymake-ruff)
;; Ruff lint diagnostics in local Python buffers only: flymake-ruff
;; reads the local pyproject.toml, so it must not run on remote files.
(defun cq-flymake-ruff-local-python ()
"Load flymake-ruff in local Python file buffers only."
(when (and (buffer-file-name)
(not (file-remote-p (buffer-file-name))))
(flymake-ruff-load)))
(add-hook 'python-base-mode-hook #'cq-flymake-ruff-local-python)
;; Configure Ruff for explicit `M-x apheleia-format-buffer' calls.
;; Do not enable apheleia-mode: Python formatting is never automatic.
(use-package apheleia
:commands apheleia-format-buffer
:config
(setf (alist-get 'python-mode apheleia-mode-alist) '(ruff-isort ruff)
(alist-get 'python-ts-mode apheleia-mode-alist) '(ruff-isort ruff)))
;; pytest runner. python-mode and python-ts-mode inherit this base map.
;; Pin to regular MELPA because the stable archive currently advertises
;; a python-pytest tarball that is no longer available.
(use-package python-pytest
:pin melpa
:after python
:bind (:map python-base-mode-map
("C-c p" . python-pytest)))
(use-package projectile
:init
(setq projectile-dynamic-mode-line nil)
(setq-default projectile--mode-line "")
:config
(projectile-mode +1)
(define-key projectile-mode-map (kbd "s-p") 'projectile-command-map)
(setq projectile-project-search-path
'("~/workspace" "~/.config" "~/Projects" "~/Work")))
;; Group ibuffer buffers by Projectile project root. Each open
;; project gets its own section (named "Projectile: <name>"), and
;; buffers without a project fall into the default group. Rebuilds
;; the groups every time an ibuffer window is created.
(use-package ibuffer-projectile
:after projectile
:hook (ibuffer-mode . ibuffer-projectile-set-filter-groups))
(when (file-readable-p cq-omarchy-integration-file)
(mapc #'disable-theme custom-enabled-themes)
(load cq-omarchy-integration-file nil 'nomessage)
;; Avoid switching away from the Omarchy-managed theme independently.
(global-unset-key (kbd "<f5>")))