nixconfig/emacs/init.el

907 lines
26 KiB
EmacsLisp
Raw Normal View History

2023-11-15 16:09:47 +00:00
;;; init.el --- Description -*- lexical-binding: t; -*-
;;
;; Copyright (C) 2023 Daniel Ziltener
;;
;; Author: Daniel Ziltener <dziltener@lyrion.ch>
;; Maintainer: Daniel Ziltener <dziltener@lyrion.ch>
;; Created: November 13, 2023
;; Modified: November 13, 2023
;; Version: 0.0.1
2023-11-16 10:30:36 +00:00
;; Keywords: abbrev bib c calendar comm convenience data docs
;; emulations extensions faces files frames games hardware help
;; hypermedia i18n internal languages lisp local maint mail matching
;; mouse multimedia news outlines processes terminals tex tools unix
;; vc wp
2023-12-13 12:35:06 +00:00
;; Homepage: https://gitea.lyrion.ch/zilti/guixconfig
;; Package-Requires: ((emacs "29.1"))
2023-11-15 16:09:47 +00:00
;;
;; This file is not part of GNU Emacs.
;;
;;; Commentary:
;;
;; Description
;;
;;; Code:
2024-07-12 19:32:57 +00:00
;;; Requirements
2023-11-24 17:02:30 +00:00
;; Since I am using `cl-defun` in this init file, I need to require
;; `cl-macs`.
2023-11-20 00:59:52 +00:00
(require 'cl-macs)
2023-11-15 16:09:47 +00:00
2024-07-12 19:32:57 +00:00
;;; Early Variables
2023-12-13 11:46:11 +00:00
(setq custom-file "~/.config/emacs/custom.el")
2023-11-15 16:09:47 +00:00
(when (file-exists-p custom-file)
(load custom-file))
2023-12-13 11:46:11 +00:00
(defvar init-dir (file-name-directory (or load-file-name (buffer-file-name))))
2024-07-12 19:32:57 +00:00
;;; Package Management
;;;; Repositories
(require 'package)
(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t)
(package-initialize)
;;;; VC
;; This will be unnecessary starting at Emacs 30
(unless (package-installed-p 'vc-use-package)
(package-vc-install "https://github.com/slotThe/vc-use-package"))
(setopt use-package-always-ensure t)
(require 'vc-use-package)
;;; Personal Information Setup
2023-11-15 16:09:47 +00:00
(setq user-full-name "Daniel Ziltener"
user-mail-address "dziltener@lyrion.ch")
2023-11-24 17:02:30 +00:00
;; I use `pass` as password storage.
2023-11-15 16:09:47 +00:00
(auth-source-pass-enable)
2024-07-12 19:32:57 +00:00
;;; Package Management Configuration
2023-11-15 16:09:47 +00:00
;; See: https://github.com/radian-software/el-patch
(use-package el-patch)
2024-07-12 19:32:57 +00:00
;;;; Guix Management
(use-package guix
:after magit-popup)
2023-12-13 11:46:11 +00:00
2024-07-12 19:32:57 +00:00
;;; Helper Functions
2023-11-24 17:02:30 +00:00
(cl-defun conditional-keybind
(filter-fn target-fn
&optional (fail-fn #'self-insert-command))
"Creates a keybinding that checks `filter-fn`. If it succeeds,
`target-fn` is run, otherwise `fail-fn`. If no fail-fn is given,
`self-insert-command` is run instead.
`target-fn` and `fail-fn` must both be interactive."
2023-11-17 11:20:24 +00:00
(lambda (_prefix)
(interactive "P")
(if (funcall filter-fn)
(call-interactively target-fn)
2023-11-20 00:59:52 +00:00
(call-interactively fail-fn))))
2023-11-17 11:20:24 +00:00
2024-07-12 19:32:57 +00:00
;;; Emacs
2023-11-15 16:09:47 +00:00
(use-package emacs
2024-07-12 19:32:57 +00:00
:after org
2023-11-15 16:09:47 +00:00
:custom
(completion-cycle-threshold 10)
2023-11-22 22:27:09 +00:00
(display-time-mode t)
2023-11-16 10:30:36 +00:00
(enable-recursive-minibuffers t)
2023-11-16 11:09:43 +00:00
(enable-remote-dir-locals t)
2023-11-24 17:02:30 +00:00
(fill-column 100)
2023-11-15 16:09:47 +00:00
(global-hl-line-mode t)
2024-07-12 19:32:57 +00:00
(global-prettify-symbols-mode t)
2023-11-22 22:27:09 +00:00
(indent-tabs-mode nil)
2023-11-15 16:09:47 +00:00
(menu-bar-mode nil)
2023-11-22 22:27:09 +00:00
(minibuffer-prompt-properties (read-only t cursor-intangible t face minibuffer-prompt))
2024-07-12 19:32:57 +00:00
(native-comp-async-report-warnings-errors nil)
2024-10-03 15:23:45 +00:00
(display-warning-minimum-level :error)
(warning-suppress-types '(emacs))
2023-11-22 22:27:09 +00:00
(read-extended-command-predicate #'command-completion-default-include-p)
(recentf-mode t)
2024-07-12 19:32:57 +00:00
(pixel-scroll-precision-large-scroll-height 30)
2023-11-15 16:09:47 +00:00
(scroll-bar-mode nil)
2023-11-22 22:27:09 +00:00
(tab-always-indent 'complete)
2023-11-16 10:30:36 +00:00
(tool-bar-mode nil)
2024-07-12 19:32:57 +00:00
(newsticker-url-list-defaults nil)
(newsticker-url-list
'(("Tagesschau" "https://www.tagesschau.de/index~atom.xml" nil nil nil)
("NZZ Neuste" "https://www.nzz.ch/recent.rss" nil nil nil)
("SRF News" "https://www.srf.ch/news/bnf/rss/1646" nil nil nil)
("SRF Wissen" "https://www.srf.ch/bnf/rss/630" nil nil nil)
("Deutschlandfunk Nachrichten" "https://www.deutschlandfunk.de/nachrichten-100.rss" nil nil nil)
("Deutschlandfunk Wissen" "https://www.deutschlandfunk.de/wissen-106.rss" nil nil nil)
("RBB" "https://www.rbb24.de/aktuell/index.xml/feed=rss.xml" nil nil nil)
("Guix" "https://guix.gnu.org/feeds/blog.atom" nil nil nil)
("Mastering Emacs" "https://www.masteringemacs.org/feed" nil nil nil)
("Schiene.de" "https://www.schiene.de/feed/" nil nil nil)
("Anil Dash Blog" "https://www.anildash.com/feed.xml" nil nil nil)
("Karl Voit's Blog" "https://karl-voit.at/feeds/lazyblorg-all.atom_1.0.links-and-content.xml" nil nil nil)
("Vaxry's Blog" "https://blog.vaxry.net/feed" nil nil nil)))
2023-11-22 22:27:09 +00:00
:custom-face
2024-07-12 19:32:57 +00:00
(default ((t (:weight normal :height 110 :family "MonaspiceXe Nerd Font Mono"))))
(fixed-pitch ((t (:weight normal :height 110 :family "MonaspiceXe Nerd Font Mono"))))
(variable-pitch ((t (:weight normal :height 135 :family "MonaspiceXe Nerd Font Propo"))))
2023-11-16 10:30:36 +00:00
:hook
2023-11-16 11:09:43 +00:00
(minibuffer-setup . cursor-intangible-mode)
:config
2024-07-12 19:32:57 +00:00
(setq xref-backend-functions (list))
2023-11-24 17:02:30 +00:00
(advice-add 'risky-local-variable-p :override #'ignore)
2023-12-13 11:46:11 +00:00
(global-display-fill-column-indicator-mode t)
(pixel-scroll-precision-mode 1))
2023-11-15 16:09:47 +00:00
2024-07-12 19:32:57 +00:00
(defun set-buffer-variable-pitch ()
(interactive)
(variable-pitch-mode t)
(setq line-spacing 3)
(set-face-attribute 'org-table nil :inherit 'fixed-pitch)
(set-face-attribute 'org-code nil :inherit 'fixed-pitch)
(set-face-attribute 'org-block nil :inherit 'fixed-pitch)
;; investigate: this face does not exist
;;(set-face-attribute 'org-block-background nil :inherit 'fixed-pitch)
)
(use-package outline-minor
:ensure nil
:bind
(:map evil-normal-state-map
("zoc" . #'outline-cycle-buffer))
:hook
clojure-mode
scheme-mode
emacs-lisp-mode)
;;; Org Mode
2023-11-15 16:09:47 +00:00
(use-package org
2024-07-12 19:32:57 +00:00
:vc (:fetcher "https://git.savannah.gnu.org/git/emacs/org-mode.git" :rev "emacs-sync")
:preface
(defun cc/org-local-stuff ()
(setq-local visual-fill-column-center-text t))
2023-12-15 15:49:46 +00:00
:after visual-fill-column
2023-12-13 11:46:11 +00:00
:custom
(org-babel-load-languages '((emacs-lisp . t)
2024-07-12 19:32:57 +00:00
(scheme . t)
(shell . t)))
2023-11-15 16:09:47 +00:00
:hook
2023-11-22 23:09:24 +00:00
(org-mode . org-indent-mode)
2023-11-15 16:09:47 +00:00
(org-src-mode . hack-local-variables)
2023-12-13 11:46:11 +00:00
(org-mode . visual-line-mode)
2024-07-12 19:32:57 +00:00
(org-mode . set-buffer-variable-pitch)
2023-11-15 16:09:47 +00:00
:config
(setq org-directory "~/org")
2024-07-12 19:32:57 +00:00
;;(add-to-list 'org-modules 'collector)
)
2023-11-15 16:09:47 +00:00
(use-package org-roam
:custom
(org-roam-directory "~/org/roam")
:config
2023-12-13 11:46:11 +00:00
(org-roam-db-autosync-mode))
2023-11-15 16:09:47 +00:00
2023-11-22 23:09:24 +00:00
(use-package consult-notes
:config
(consult-notes-org-roam-mode t))
2023-11-22 22:27:09 +00:00
2023-11-15 16:09:47 +00:00
(use-package websocket
:after org-roam)
(use-package org-roam-ui
:after org-roam
:custom
(org-roam-ui-sync-theme t)
(org-roam-ui-follow t)
(org-roam-ui-update-on-save t)
(org-roam-ui-open-on-start t))
(use-package org-modern
:hook
2024-07-12 19:32:57 +00:00
(org-mode . org-modern-mode)
(org-agenda-finalize . org-modern-agenda))
2023-11-15 16:09:47 +00:00
(use-package org-rainbow-tags
:hook
(org-mode . org-rainbow-tags-mode))
2024-07-12 19:32:57 +00:00
;;; Design
2023-11-15 16:09:47 +00:00
(use-package color-theme-modern)
(use-package moe-theme)
(use-package catppuccin-theme
:custom
(catppuccin-flavor 'mocha)
(catppuccin-highlight-matches t)
(catppuccin-italic-comments t)
:custom-face
(font-lock-doc-face ((t (:inherit font-lock-comment-face
2023-11-17 02:22:38 +00:00
:foreground "#fab387"))))
2023-11-15 16:09:47 +00:00
:config
2023-11-22 22:27:09 +00:00
;;(load-theme 'catppuccin)
)
2023-11-15 16:09:47 +00:00
2023-12-13 11:46:11 +00:00
(use-package unicode-fonts
:config
(unicode-fonts-setup))
2023-11-15 16:09:47 +00:00
2023-12-15 12:41:21 +00:00
(set-frame-parameter nil 'alpha-background 90)
(add-to-list 'default-frame-alist '(alpha-background . 90))
2023-11-22 20:41:50 +00:00
2023-11-22 22:27:09 +00:00
(use-package lambda-line
2024-07-12 19:32:57 +00:00
:vc (:fetcher github :repo "lambda-emacs/lambda-line")
2023-11-22 22:27:09 +00:00
:custom
(lambda-line-icon-time t) ;; requires ClockFace font (see below)
2023-11-24 17:02:30 +00:00
(lambda-line-clockface-update-fontset "ClockFaceRect") ;; set clock icon
2023-11-22 22:27:09 +00:00
(lambda-line-position 'bottom) ;; Set position of status-line
(lambda-line-abbrev t) ;; abbreviate major modes
(lambda-line-hspace " ") ;; add some cushion
(lambda-line-prefix t) ;; use a prefix symbol
(lambda-line-prefix-padding nil) ;; no extra space for prefix
(lambda-line-status-invert nil) ;; no invert colors
(lambda-line-gui-ro-symbol "") ;; symbols
(lambda-line-gui-mod-symbol "")
2023-11-24 17:02:30 +00:00
(lambda-line-gui-rw-symbol "")
(lambda-line-vc-symbol "")
2023-11-22 22:27:09 +00:00
(lambda-line-space-top +.50) ;; padding on top and bottom of line
(lambda-line-space-bottom -.50)
(lambda-line-symbol-position 0.1) ;; adjust the vertical placement of symbol
:config
2023-11-24 17:02:30 +00:00
;; add evil indicator
(advice-add 'lambda-line-compose :around
(lambda (orig-fun status name primary tertiary secondary)
(funcall orig-fun
status
(concat name evil-mode-line-tag)
primary tertiary secondary)))
2023-11-22 22:27:09 +00:00
;; activate lambda-line
(lambda-line-mode)
2023-11-24 17:02:30 +00:00
(lambda-line-clockface-update-fontset "ClockFaceRect")
2023-11-22 22:27:09 +00:00
(customize-set-variable 'flymake-mode-line-counter-format '("" flymake-mode-line-error-counter flymake-mode-line-warning-counter flymake-mode-line-note-counter ""))
(customize-set-variable 'flymake-mode-line-format '(" " flymake-mode-line-exception flymake-mode-line-counters))
;; set divider line in footer
(when (eq lambda-line-position 'top)
(setq-default mode-line-format (list "%_"))
(setq mode-line-format (list "%_"))))
(use-package lambda-themes
2024-07-12 19:32:57 +00:00
:vc (:fetcher github :repo "lambda-emacs/lambda-themes")
2023-11-22 22:27:09 +00:00
:custom
(lambda-themes-set-italic-comments t)
(lambda-themes-set-italic-keywords t)
(lambda-themes-set-variable-pitch t)
2023-11-22 20:41:50 +00:00
:config
2023-11-22 22:27:09 +00:00
;; load preferred theme
(load-theme 'lambda-dark))
2023-11-22 20:41:50 +00:00
2024-07-12 19:32:57 +00:00
;;;; Long line handling
2023-12-15 15:14:07 +00:00
2023-12-13 11:46:11 +00:00
(use-package visual-fill-column
:custom
(visual-fill-column-enable-sensible-window-split t)
2023-12-15 15:14:07 +00:00
:hook
(prog-mode . visual-line-mode)
2024-07-12 19:32:57 +00:00
visual-line-mode
;; :config
;; (add-hook 'prog-mode-hook #'visual-line-mode)
;; (add-hook 'visual-line-mode-hook #'visual-fill-column-mode)
)
2023-12-13 11:46:11 +00:00
(use-package adaptive-wrap
2023-12-15 15:14:07 +00:00
:config
2023-12-15 15:40:27 +00:00
(setq-default adaptive-wrap-extra-indent 4)
2024-07-12 19:32:57 +00:00
;;(add-hook 'visual-line-mode-hook #'adaptive-wrap-prefix-mode)
2023-12-15 15:14:07 +00:00
:hook
(visual-line-mode . adaptive-wrap-prefix-mode))
2023-12-13 11:46:11 +00:00
2023-11-15 16:09:47 +00:00
(use-package password-store)
(use-package password-store-otp)
2024-07-12 19:32:57 +00:00
(use-package pass)
;;; Evil Mode
2023-11-15 16:09:47 +00:00
(use-package evil
:init
2023-11-24 17:02:30 +00:00
(setq evil-want-keybinding nil
evil-emacs-state-tag " 󰯸 "
evil-normal-state-tag " 󰰓 "
evil-visual-state-tag " 󰰬 "
evil-insert-state-tag " 󰰅 "
evil-motion-state-tag " 󰬔 "
evil-operator-state-tag " 󰰕 ")
2023-11-15 16:09:47 +00:00
:config
(evil-set-leader 'normal (kbd "<SPC>"))
(evil-set-leader 'normal (kbd "z") t)
2024-07-12 19:32:57 +00:00
(evil-ex-define-cmd "q" 'delete-frame)
2023-11-15 16:09:47 +00:00
(evil-mode 1)
:bind
(:map evil-normal-state-map
2023-11-17 02:22:38 +00:00
("<leader>f" . 'find-file)
("<leader>k" . 'kill-buffer)))
2023-11-15 16:09:47 +00:00
(use-package evil-collection
:after evil
:ensure t
2023-11-22 20:41:50 +00:00
:delight evil-collection-unimpaired-mode
2023-11-15 16:09:47 +00:00
:custom
(evil-collection-outline-bind-tab-p 1)
:commands evil-collection-init
:init
(evil-collection-init))
2024-07-12 19:32:57 +00:00
;;; Search, Completion, Execution
;;;; Preliminary Packages
2023-11-15 16:09:47 +00:00
(use-package savehist
2024-07-12 19:32:57 +00:00
:ensure nil
2023-11-15 16:09:47 +00:00
:init
(savehist-mode))
(use-package orderless
2023-11-16 10:30:36 +00:00
:after consult
2023-11-15 16:09:47 +00:00
:config
2023-11-16 11:52:31 +00:00
(with-eval-after-load 'eglot
(setq completion-category-defaults nil))
2023-11-23 22:45:40 +00:00
(setq completion-styles '(orderless basic)
2023-11-17 02:22:38 +00:00
completion-category-defaults nil
2023-11-23 22:45:40 +00:00
completion-category-overrides '((file (styles basic partial-completion)))))
2023-11-15 16:09:47 +00:00
2023-12-13 11:46:11 +00:00
(use-package embark-consult
:hook
2023-12-14 11:33:52 +00:00
(embark-collect-mode . consult-preview-at-point-mode)
2023-12-13 11:46:11 +00:00
:config
(require 'consult-flymake)
(require 'consult-xref)
2024-07-12 19:32:57 +00:00
:custom
(xref-show-xrefs-function #'consult-xref)
2023-11-15 16:09:47 +00:00
:bind
2023-11-17 02:22:38 +00:00
(:map evil-normal-state-map
("<leader><SPC>" . 'consult-find)
("<leader>gs" . 'consult-eglot-symbols)
("<leader>b" . 'consult-buffer)
("<leader>gb" . 'consult-project-buffer)
("<leader>g/" . 'consult-git-grep)
("<leader>/" . 'consult-grep)
2023-12-14 14:15:59 +00:00
("/" . 'consult-line))
("C-<SPC>" . 'embark-act)
("C-M-<return>" . 'embark-bindings))
2023-11-15 16:09:47 +00:00
2023-11-21 15:54:41 +00:00
(use-package wgrep
:config
(setq wgrep-auto-save-buffer t))
2023-11-15 16:09:47 +00:00
(use-package vertico
:commands
vertico-mode
:init
(vertico-mode))
(use-package marginalia
:commands
marginalia-mode
:init
(marginalia-mode))
(use-package nerd-icons-completion
:after marginalia
:commands
nerd-icons-completion-mode
:hook
(marginalia-mode-hook . nerd-icons-completion-marginalia-setup)
:init
(nerd-icons-completion-mode))
(use-package which-key
:commands
which-key-setup-minibuffer
:init
2024-07-12 19:32:57 +00:00
(which-key-setup-minibuffer)
:config
(which-key-mode t))
2023-11-15 16:09:47 +00:00
2024-07-12 19:32:57 +00:00
;;;; Code Completion
2023-11-15 16:09:47 +00:00
(use-package cape
2024-07-12 19:32:57 +00:00
:config
(require 'cape-char)
(require 'cape-keyword)
2023-12-13 11:46:11 +00:00
(defun my/capf ()
(setq completion-at-point-functions
(list (cape-capf-super
#'tempel-complete
#'cape-dabbrev
#'cape-file
#'cape-dict
#'cape-line
#'cape-emoji
#'cape-keyword))))
2024-07-12 19:32:57 +00:00
(defun my/eglot-capf ()
(setq completion-at-point-functions
(list (cape-capf-super
#'eglot-completion-at-point
#'tempel-complete
#'cape-dabbrev
#'cape-file
#'cape-dict
#'cape-line
#'cape-emoji
#'cape-keyword))))
(defun my/geiser-capf ()
(setq completion-at-point-functions
(list (apply #'cape-capf-super
(append geiser-capf--capfs
(list
#'tempel-complete
#'cape-dabbrev
#'cape-file
#'cape-dict
#'cape-line
#'cape-emoji
#'cape-keyword))))))
2023-12-13 11:46:11 +00:00
(advice-add 'eglot-completion-at-point :around #'cape-wrap-buster)
:hook
(org-mode . my/capf)
2024-07-12 19:32:57 +00:00
(prog-mode . my/capf)
(eglot-managed-mode . my/eglot-capf)
(geiser-mode . my/geiser-capf))
2023-11-15 16:09:47 +00:00
(defun my/corfu-combined-sort (candidates)
"Sort CANDIDATES using both display-sort-function and corfu-sort-function."
(let ((candidates
(let ((display-sort-func (corfu--metadata-get 'display-sort-function)))
(if display-sort-func
(funcall display-sort-func candidates)
candidates))))
(if corfu-sort-function
(funcall corfu-sort-function candidates)
candidates)))
(use-package corfu
:custom
(corfu-cycle t)
(corfu-preselect 'prompt)
(corfu-auto t)
(corfu-scroll-margin 5)
(corfu-quit-no-match 'separator)
(evil-collection-corfu-key-themes '(tab-n-go))
2023-12-13 11:46:11 +00:00
(corfu-popupinfo-delay '(0.1 . 0.5))
2023-11-15 16:09:47 +00:00
:config
(setq corfu-sort-override-function #'my/corfu-combined-sort)
2023-12-13 11:46:11 +00:00
(add-to-list 'savehist-additional-variables 'corfu-history)
2023-11-15 16:09:47 +00:00
:commands
global-corfu-mode
:init
2024-07-12 19:32:57 +00:00
(require 'corfu-popupinfo)
(require 'corfu-history)
2023-12-13 11:46:11 +00:00
(global-corfu-mode)
(corfu-popupinfo-mode 1)
(corfu-history-mode 1))
2023-11-15 16:09:47 +00:00
(use-package nerd-icons-corfu
:after corfu
:init
(add-to-list 'corfu-margin-formatters 'nerd-icons-corfu-formatter))
(use-package corfu-terminal
2023-11-16 10:30:36 +00:00
:if (not (display-graphic-p))
2023-11-15 16:09:47 +00:00
:after corfu
2023-11-24 17:02:30 +00:00
:hook
global-corfu-mode)
2023-11-15 16:09:47 +00:00
(use-package tempel)
2023-11-23 09:42:52 +00:00
(use-package xref-union
2024-07-12 19:32:57 +00:00
:custom
(xref-union-excluded-backends (lambda (b) (eq b #'etags--xref-backend)))
2023-11-23 09:42:52 +00:00
:hook
2024-07-12 19:32:57 +00:00
cider-mode)
2023-11-22 14:32:58 +00:00
2024-07-12 19:32:57 +00:00
;;; Basic Navigation
2023-11-15 16:09:47 +00:00
(use-package goto-chg
:bind
(:map evil-normal-state-map
2023-11-17 02:22:38 +00:00
("g," . 'goto-last-change)
("g;" . 'goto-last-change-reverse)))
2023-11-15 16:09:47 +00:00
2023-11-21 11:59:44 +00:00
(use-package evil-snipe
2024-07-12 19:32:57 +00:00
:after evil-easymotion
2023-11-21 11:59:44 +00:00
:custom
(evil-snipe-scope 'whole-visible)
(evil-snipe-repeat-scope 'whole-buffer)
(evil-snipe-spillover-scope 'whole-buffer)
2023-11-24 17:02:30 +00:00
(evil-snipe-tab-increment t)
2024-07-12 19:32:57 +00:00
:commands
evil-snipe-override-mode
:init
(evil-snipe-override-mode 1)
2023-11-21 11:59:44 +00:00
:hook
(magit-mode . turn-off-evil-snipe-override-mode)
2023-11-21 13:10:12 +00:00
;; See https://github.com/hlissner/evil-snipe/issues/95
;; :config
;; (evilem-define "gs" 'evil-snipe-repeat
;; :bind ((evil-snipe-scope 'buffer)
;; (evil-snipe-enable-highlight)
;; (evil-snipe-enable-incremental-highlight)))
)
2023-11-21 11:59:44 +00:00
(use-package evil-easymotion
2024-07-12 19:32:57 +00:00
:after evil
2023-11-21 11:59:44 +00:00
:config
(evilem-default-keybindings "<leader>"))
2024-07-12 19:32:57 +00:00
;;; Lisp Navigation and Editing
;;;; Helper Functions
2023-11-19 23:29:24 +00:00
(defun cc/move-sexp-backward ()
"Move balanced expression (sexp) to the right of point backward one sexp.
Point must be at the beginning of balanced expression (sexp)."
(interactive)
(transpose-sexps 1)
(forward-sexp -2))
(defun cc/move-sexp-forward ()
"Move balanced expression (sexp) to the right of point forward one sexp.
Point must be at the beginning of balanced expression (sexp)."
(interactive)
(forward-sexp 1)
(transpose-sexps 1)
(forward-sexp -1))
2023-12-13 15:29:25 +00:00
(defvar last-sexp nil)
(defun cc/clone-sexp ()
"Clone the sexp right after the cursor."
(interactive)
(call-interactively #'mark-sexp)
(call-interactively #'kill-ring-save)
(call-interactively #'evil-paste-before)
(call-interactively #'forward-char)
(call-interactively #'paredit-newline))
2023-12-14 16:35:16 +00:00
(defun cc/slurp-forward ()
"Slurps forward when the key is after the closing paren."
(interactive)
(call-interactively #'backward-char)
(call-interactively #'paredit-forward-slurp-sexp))
(defun cc/barf-forward ()
"Barfs forward even when the key is after the closing paren."
(interactive)
(call-interactively #'backward-char)
(call-interactively #'paredit-forward-barf-sexp))
2023-11-20 00:59:52 +00:00
(defun looking-at-opening-paren ()
(looking-at (rx (or "(" "{" "["))))
(defun being-past-closing-paren ()
2023-11-21 09:16:02 +00:00
(looking-back (rx (or ")" "}" "]"))))
2023-11-20 00:59:52 +00:00
2024-07-12 19:32:57 +00:00
;;;; Basic
2023-12-14 11:30:17 +00:00
2023-12-13 15:29:25 +00:00
(use-package paredit
2023-11-15 16:09:47 +00:00
:config
2024-07-12 19:32:57 +00:00
;; (add-hook 'clojure-ts-mode-hook #'paredit-mode)
;; (add-hook 'emacs-lisp-mode-hook #'paredit-mode)
;; (add-hook 'scheme-mode-hook #'paredit-mode)
2023-12-13 15:29:25 +00:00
(evil-define-key 'insert paredit-mode-map
2023-11-20 00:59:52 +00:00
(kbd "r") (conditional-keybind #'looking-at-opening-paren
2023-12-13 15:29:25 +00:00
#'paredit-raise-sexp)
(kbd "w") (conditional-keybind #'looking-at-opening-paren
2023-11-19 23:29:24 +00:00
#'cc/move-sexp-backward)
2023-11-20 00:59:52 +00:00
(kbd "s") (conditional-keybind #'looking-at-opening-paren
2023-11-19 23:29:24 +00:00
#'cc/move-sexp-forward)
2023-12-13 15:29:25 +00:00
(kbd "c") (conditional-keybind #'looking-at-opening-paren
2023-12-14 16:35:16 +00:00
#'cc/clone-sexp)
(kbd ">") (conditional-keybind #'being-past-closing-paren
#'cc/slurp-forward)
(kbd "<") (conditional-keybind #'being-past-closing-paren
2024-07-12 19:32:57 +00:00
#'cc/barf-forward))
:hook
clojure-ts-mode
clojure-mode
emacs-lisp-mode
scheme-mode)
2023-12-13 15:29:25 +00:00
2024-07-12 19:32:57 +00:00
;;;; Visual Aid
2023-11-17 02:22:38 +00:00
;; (use-package rainbow-delimiters
;; :hook
;; emacs-lisp-mode
;; scheme-mode)
2023-11-15 16:09:47 +00:00
2024-07-12 19:32:57 +00:00
;;; Programming
2023-11-15 16:09:47 +00:00
(use-package editorconfig
2023-11-22 20:41:50 +00:00
:delight editorconfig-mode
2023-11-15 16:09:47 +00:00
:commands
editorconfig-mode
:init
(editorconfig-mode 1))
2023-11-22 20:41:50 +00:00
(use-package flymake
2024-07-12 19:32:57 +00:00
:ensure nil
2023-11-22 20:41:50 +00:00
:delight '(:eval (cons "" (flymake--mode-line-counters))))
2023-11-16 10:30:36 +00:00
2023-11-15 16:09:47 +00:00
(use-package eglot
2024-07-12 19:32:57 +00:00
:ensure nil
2023-11-15 16:09:47 +00:00
:custom
(eglot-connect-timeout 90)
(eglot-autoshutdown t)
(eglot-report-progress t)
:config
2024-10-03 15:23:45 +00:00
;;(add-to-list 'eglot-server-programs '(scheme-mode . ("chicken-lsp-server")))
2023-11-15 16:09:47 +00:00
(setq-default eglot-workspace-configuration
2023-11-17 02:22:38 +00:00
'((clojure-lsp (maxCompletions . 300))))
2023-11-15 16:09:47 +00:00
:hook
2024-07-12 19:32:57 +00:00
(clojure-mode . eglot-ensure)
2023-11-15 16:44:10 +00:00
(eglot-managed-mode . (lambda ()
2023-11-17 02:22:38 +00:00
(add-hook 'before-save-hook
(lambda ()
(call-interactively #'eglot-format-buffer))
nil 'local)))
2024-07-12 19:32:57 +00:00
(eglot-managed-mode . eglot-inlay-hints-mode))
2023-11-15 16:09:47 +00:00
(use-package consult-eglot
:after (consult eglot))
2024-09-30 11:14:21 +00:00
(use-package dape
:custom
(dape-buffer-window-arrangement 'gud)
:hook
(kill-emacs . dape-breakpoint-save)
(after-init . dape-breakpoint-load)
(dape-compile . kill-buffer)
(dape-display-source . pulse-momentary-highlight-one-line))
2024-07-12 19:32:57 +00:00
;;;; Clojure
(use-package clojure-mode
2023-12-15 15:14:07 +00:00
:preface
(defun embark-eglot-rename (from to)
"Renames the symbol at point."
(interactive "sRename: \nsRename %s to: ")
(funcall-interactively #'eglot-rename to))
2023-12-14 11:30:17 +00:00
:delight ""
2024-07-12 19:32:57 +00:00
:after (embark cider)
2023-12-14 11:30:17 +00:00
:config
2023-12-15 15:14:07 +00:00
(defvar-keymap embark-clj-identifier-map
:parent embark-identifier-map
"c" #'embark-eglot-rename)
(add-to-list 'embark-keymap-alist '(identifier . embark-clj-identifier-map))
2023-12-14 11:30:17 +00:00
:hook
2024-07-12 19:32:57 +00:00
(clojure-mode . (lambda ()
(setq-local prettify-symbols-alist
'(("fn" . "λ")
("comp" . "")
("and" . "")
("or" . "")
("not" . "¬"))))))
2023-11-15 16:09:47 +00:00
(use-package cider
2024-07-12 19:32:57 +00:00
;;:elpaca (:host github :repo "clojure-emacs/cider" :tag "v1.12.0")
2023-11-22 20:41:50 +00:00
:delight (cider-mode '(:eval (concat "  [" (cider--modeline-info) "]")))
2023-11-15 16:09:47 +00:00
:config
(evil-define-key 'normal 'cider-mode-map
(kbd "<localleader>ce") #'cider-eval-sexp-at-point))
2024-07-12 19:32:57 +00:00
;;;; Scheme
2023-12-13 11:46:11 +00:00
(use-package geiser
:custom
(geiser-chicken-match-limit 200)
:config
2024-07-12 19:32:57 +00:00
(defalias 'run-geiser 'geiser))
2023-12-13 11:46:11 +00:00
2024-09-12 17:36:23 +00:00
;; (use-package paren-face
;; :hook
;; scheme-mode
;; emacs-lisp-mode
;; clojure-ts-mode
;; ;; :config
;; ;; (add-hook 'scheme-mode-hook #'paren-face-mode)
;; ;; (add-hook 'emacs-lisp-mode-hook #'paren-face-mode)
;; ;; (add-hook 'clojure-ts-mode-hook #'paren-face-mode)
;; )
2023-12-13 11:46:11 +00:00
(use-package highlight-parentheses
2024-07-12 19:32:57 +00:00
:custom
(highlight-parentheses-highlight-adjacent t)
(highlight-parentheses-colors '("yellow" "light gray" "dark gray" "dim gray"))
:hook
prog-mode
;; :config
;; (add-hook 'prog-mode-hook #'highlight-parentheses-mode)
)
2023-12-13 11:46:11 +00:00
2024-07-12 19:32:57 +00:00
;;;;; Chicken Scheme
2023-11-24 21:54:52 +00:00
(use-package scheme
2024-07-12 19:32:57 +00:00
:ensure nil
2023-11-24 21:54:52 +00:00
:hook
2023-12-15 12:41:21 +00:00
(scheme-mode . eglot-ensure)
(scheme-mode . (lambda ()
(setq-local prettify-symbols-alist
2024-07-12 19:32:57 +00:00
'(("lambda" . "λ")
("compose" . "")
("and" . "")
("or" . "")
("not" . "¬"))))))
2023-11-24 21:54:52 +00:00
2023-11-15 16:09:47 +00:00
(defun flymake-chicken-init ()
2024-07-12 19:32:57 +00:00
(add-hook flymake-diagnostic-functions
flymake-chicken-backend nil t)
2023-11-15 16:09:47 +00:00
(flymake-mode))
2023-12-13 11:46:11 +00:00
(use-package geiser-chicken)
2024-07-12 19:32:57 +00:00
;;;;; Guile
2023-12-02 23:30:51 +00:00
(use-package geiser-guile
:config
2023-12-02 08:59:40 +00:00
(when (executable-find "guix")
2023-12-02 23:30:51 +00:00
(add-to-list 'geiser-guile-load-path
(expand-file-name "~/.config/guix/current/share/guile/site/3.0"))))
2023-11-15 16:09:47 +00:00
;; (use-package flymake-chicken
;; :hook
;; ((scheme-mode . flymake-chicken-init)
;; (scheme-mode . flymake-mode))
;; :custom
;; (flycheck-global-modes '(not scheme-mode))
;; :config
;; (add-hook 'flymake-diagnostic-functions #'flymake-chicken-backend nil t))
2024-07-12 19:32:57 +00:00
;;; Other Languages
2023-11-24 17:02:30 +00:00
(use-package zig-mode
:hook
(zig-mode . eglot-ensure)
:mode ("\\.zig\\'" . zig-mode))
2024-07-12 19:32:57 +00:00
(use-package nix-mode
:mode ("\\.nix\\'" . nix-mode))
2023-11-15 16:09:47 +00:00
;; (use-package lsp-tailwindcss
;; :init
;; (setq lsp-tailwindcss-add-on-mode t
;; lsp-tailwindcss-experimental-class-regex ["\"([^\"]*)\""])
;; :config
;; (add-to-list 'lsp-tailwindcss-major-modes 'clojurescript-ts-mode)
;; (add-to-list 'lsp-tailwindcss-major-modes 'clojurec-ts-mode))
(use-package dhall-mode
:mode "\\.dhall\'"
:hook
((dhall-mode . lsp)))
2024-07-12 19:32:57 +00:00
;;; Version Control
;;;; Git
2023-11-15 16:09:47 +00:00
2024-08-21 15:30:52 +00:00
;; The following snippet is a convenience function for git-commit to add the ticket number, if found
;; in the branch name, to the commit message.
2024-08-30 09:27:10 +00:00
(defun add-git-commit-ticket-id-from-branch ()
"A git-commit-mode-hook which inserts the first consecutive
sequence of at least 3 digits in the current branch name at
the beginning of the commit message buffer (in square
brackets)."
(when-let ((branch (magit-get-current-branch)))
(when (string-match "\\([[:digit:]]\\{3,\\}\\)" branch)
(let ((prefix (format "[T-%s] \n" (match-string 1 branch))))
(goto-char (point-min))
(insert prefix)
(forward-char -1)))))
(add-hook 'git-commit-mode-hook 'add-git-commit-ticket-id-from-branch)
2024-08-21 15:30:52 +00:00
2024-07-12 19:32:57 +00:00
;; Magit requires 'transient' >= 0.5.0, but due to bad defaults, Emacs' package manager refuses to
;; upgrade this and other built-in packages to higher releases from GNU Elpa.
(use-package transient
:init
(progn (unload-feature 'transient t)
(require 'transient)))
2024-09-05 17:44:18 +00:00
2024-07-12 19:32:57 +00:00
;; To fix this, you have to add this to your init file:
;; (setq package-install-upgrade-built-in t)
;; You must also make sure the updated version is loaded, by evaluating the `progn` form below.
2023-11-15 16:09:47 +00:00
(use-package magit
2024-07-12 19:32:57 +00:00
:after magit-popup
:init
(progn (unload-feature 'transient t)
(require 'transient)))
(use-package hl-todo)
2023-11-15 16:09:47 +00:00
(use-package magit-todos
2024-07-12 19:32:57 +00:00
:after (magit hl-todo)
2023-11-15 16:09:47 +00:00
:hook
(magit-mode . magit-todos-mode))
2024-07-12 19:32:57 +00:00
(use-package magit-popup)
2023-11-15 16:09:47 +00:00
(use-package forge
:after magit
2024-09-05 17:44:18 +00:00
:custom
2024-09-07 07:52:01 +00:00
(forge-alist '(("github.com" "api.github.com" "github.com" forge-github-repository)
("gitlab.com" "gitlab.com/api/v4" "gitlab.com" forge-gitlab-repository)
("dev.bevuta.com" "dev.bevuta.com/api/v4" "dev.bevuta.com" forge-gitlab-repository)
("codeberg.org" "codeberg.org/api/v1" "codeberg.org" forge-gitea-repository)
2024-09-30 00:51:03 +00:00
("forgejo.lyrion.ch:7920" "forgejo.lyrion.ch/api/v1" "forgejo.lyrion.ch" forge-gitea-repository)
2024-09-07 07:52:01 +00:00
("git.sr.ht" nil "git.sr.ht" forge-srht-repository)))
2023-11-15 16:09:47 +00:00
:config
2023-11-16 10:30:36 +00:00
(advice-add 'magit :after (lambda (&rest _args)
2023-11-17 02:22:38 +00:00
(call-interactively #'forge-pull))))
2023-11-15 16:09:47 +00:00
(use-package git-gutter
2024-07-12 19:32:57 +00:00
:hook
prog-mode
;; :config
;; (add-hook 'prog-mode-hook #'git-gutter-mode)
)
;;; File Formats
;;;; Beancount
(use-package beancount
:vc (:fetcher github :repo "beancount/beancount-mode"))
;;;; Asciidoc
(use-package adoc-mode
:hook
(adoc-mode . visual-line-mode)
(adoc-mode . (lambda () (setq-local visual-fill-column-center-text t))))
2023-11-15 16:09:47 +00:00
2024-07-12 19:32:57 +00:00
;;; LaTeX
2023-11-15 16:09:47 +00:00
;; https://github.com/politza/pdf-tools/#known-problems
2023-11-16 10:30:36 +00:00
(add-hook 'TeX-after-compilation-finished-functions
2023-11-17 02:22:38 +00:00
#'TeX-revert-document-buffer)
2023-11-15 16:09:47 +00:00
2024-07-12 19:32:57 +00:00
;;; Communication
;;;; E-Mail
(use-package gnus
:custom
(message-send-mail-function 'message-send-mail-with-sendmail)
(sendmail-program "msmtp")
(message-sendmail-f-is-evil t)
(message-sendmail-extra-arguments '("--read-envelope-from")))
(use-package piem
:vc (piem :url "https://git.kyleam.com/piem"))
(use-package git-email
:vc (:fetcher codeberg :repo "martianh/git-email")
:after (magit piem)
:init
(require 'git-email-magit)
(require 'git-email-gnus)
(require 'git-email-piem))
(use-package notmuch)
(use-package consult-notmuch)
;;;; IRC
2023-11-27 16:52:54 +00:00
(use-package rcirc
2024-07-12 19:32:57 +00:00
:ensure nil
2023-12-14 11:30:17 +00:00
:after password-store
2023-11-15 16:09:47 +00:00
:custom
2023-11-27 16:52:54 +00:00
(rcirc-server-alist
`(("liberachat.irc.lyrion.ch"
:server-alias "irc.libera.chat"
2023-11-27 10:24:47 +00:00
:port 6697
:nick "zilti"
2023-11-27 16:52:54 +00:00
:full-name "Daniel Ziltener"
:user-name "zilti/irc.libera.chat"
:password ,(password-store-get "Privat/Soju")
:encryption tls
:channels ("#chicken")))
`(("oftc.irc.lyrion.ch"
:server-alias "irc.oftc.net"
2023-11-17 02:22:38 +00:00
:port 6697
:nick "zilti"
2023-11-27 16:52:54 +00:00
:full-name "Daniel Ziltener"
:user-name "zilti/irc.oftc.net"
:password ,(password-store-get "Privat/Soju")
:encryption tls
:channels ()))))
2023-11-15 16:09:47 +00:00
2024-09-12 17:36:23 +00:00
2024-07-12 19:32:57 +00:00
;;; Wrapping Up
2024-09-24 00:28:31 +00:00
;; (use-package envrc
;; :config
;; (envrc-global-mode))
(use-package direnv
2023-12-13 11:46:11 +00:00
:config
2024-09-24 00:28:31 +00:00
(direnv-mode))
2023-12-13 11:46:11 +00:00
2023-11-15 16:09:47 +00:00
(provide 'init)
;;; init.el ends here