Emacs config changes from the last few days

This commit is contained in:
Ian Keane 2023-11-30 12:57:59 -05:00
parent 1fae9f1514
commit 0db94f8ba4

View file

@ -1,5 +1,20 @@
#+title Ian's Emacs Config #+title Ian's Emacs Config
#+PROPERTY: header-args:emacs-lisp :tangle (if (eq system-type 'darwin) "~/dotfiles/guix/init.el" "~/.config/emacs/init.el") #+PROPERTY: header-args:emacs-lisp :tangle (if (eq system-type 'darwin) "~/dotfiles/guix/init.el" "~/.config/emacs/init.el")
#+EXPORT_FILE_NAME: ~/code/website/src/content/dotfiles/emacs.md
#+begin_src
+++
title = "Emacs Configuration"
author = ["Ian Keane"]
date = 2023-02-09
tags = ["Config", "Text editing"]
description = 'My emacs configuration.'
+++
#+end_src
* Preamble
My emacs configuration. It tangles to =.emacs.d/init.el= and exports to this markdown file on save. If you're viewing this in a repo, it's better to visit the website at <https://iankeane.srht.site/dotfiles>. If you are viewing this on the website and want the repo, you can find it at <https://sr.ht/~iankeane/dotfiles>. To see the hugo front-matter configuration, you'll have to view the raw code.
* First things first * First things first
** Literate Config Setup ** Literate Config Setup
@ -37,6 +52,26 @@ To get started, run =C-c C-v t=
:init :init
(savehist-mode)) (savehist-mode))
#+end_src #+end_src
** Straight
#+begin_src emacs-lisp
(defvar bootstrap-version)
(let ((bootstrap-file
(expand-file-name
"straight/repos/straight.el/bootstrap.el"
(or (bound-and-true-p straight-base-dir)
user-emacs-directory)))
(bootstrap-version 7))
(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))
(setq package-enable-at-startup nil)
#+end_src
** Environment-specific setup ** Environment-specific setup
#+begin_src emacs-lisp #+begin_src emacs-lisp
(setq IS-MACOS (eq system-type 'darwin)) (setq IS-MACOS (eq system-type 'darwin))
@ -79,9 +114,7 @@ To get started, run =C-c C-v t=
(ensure-directory "~/.config/emacs/video") (ensure-directory "~/.config/emacs/video")
(ensure-directory "~/.config/emacs/audio") (ensure-directory "~/.config/emacs/audio")
(setq deft-directory "~/notes/deft" (setq projectile-project-search-path '("~/code/")
org-roam-directory "~/notes/roam"
projectile-project-search-path '("~/code/")
empv-video-dir "~/.config/emacs/video" empv-video-dir "~/.config/emacs/video"
empv-audio-dir "~/.config/emacs/audio" empv-audio-dir "~/.config/emacs/audio"
backup-directory-alist `(("." . "~/.config/emacs/backups/")) backup-directory-alist `(("." . "~/.config/emacs/backups/"))
@ -91,14 +124,14 @@ To get started, run =C-c C-v t=
** Helper Functions ** Helper Functions
#+begin_src emacs-lisp #+begin_src emacs-lisp
(defun custom/eval-region-or-buffer () (defun ian/eval-region-or-buffer ()
"Eval the region if anything is selected, otherwise eval the whole buffer." "Eval the region if anything is selected, otherwise eval the whole buffer."
(interactive) (interactive)
(if mark-active (if mark-active
(eval-region (region-beginning) (region-end)) (eval-region (region-beginning) (region-end))
(eval-buffer))) (eval-buffer)))
(defun custom/conditional-imenu () (defun ian/conditional-imenu ()
"Call `consult-org-heading` in Org mode, otherwise `consult-imenu`." "Call `consult-org-heading` in Org mode, otherwise `consult-imenu`."
(interactive) (interactive)
(if (eq major-mode 'org-mode) (if (eq major-mode 'org-mode)
@ -107,8 +140,20 @@ To get started, run =C-c C-v t=
#+end_src #+end_src
* One-Line Includes * One-Line Includes
TODO: rename this section
#+begin_src emacs-lisp #+begin_src emacs-lisp
(use-package treemacs) (use-package treemacs)
;; Enable follow mode
;; Use treemacs-current-visibility function to expand backspace functionality
(setq treemacs--project-follow-delay 0)
(defun ian/treemacs-open-current-or-jump ()
"Find the current file and open treemacs if it's not open, otherwise jump
to the treemacs window"
(interactive)
(if
(not(eq (treemacs-current-visibility) 'visible))
(treemacs-find-file))
(treemacs-select-window))
#+end_src #+end_src
* Notes * Notes
@ -137,8 +182,6 @@ To get started, run =C-c C-v t=
(add-to-list 'org-structure-template-alist '("sh" . "src shell")) (add-to-list 'org-structure-template-alist '("sh" . "src shell"))
(add-to-list 'org-structure-template-alist '("el" . "src emacs-lisp")) (add-to-list 'org-structure-template-alist '("el" . "src emacs-lisp"))
(use-package org-make-toc
:hook (org-mode . org-make-toc-mode))
(add-to-list 'org-structure-template-alist '("py" . "src python")) (add-to-list 'org-structure-template-alist '("py" . "src python"))
(setq org-hide-emphasis-markers t) (setq org-hide-emphasis-markers t)
@ -146,6 +189,34 @@ To get started, run =C-c C-v t=
(use-package org-appear (use-package org-appear
:hook (org-mode . org-appear-mode)) :hook (org-mode . org-appear-mode))
(use-package org-roam
:ensure t
:custom
(org-roam-directory "~/notes/roam")
:config
;; If you're using a vertical completion framework, you might want a more informative completion interface
;; (setq org-roam-node-display-template (concat "${title:*} " (propertize "${tags:10}" 'face 'org-tag)))
(org-roam-db-autosync-mode))
(use-package deft
:commands (deft)
:config
(setq deft-directory "~/notes/deft"
deft-extensions '("org" "txt")
deft-recursive t))
(use-package ox-hugo
:after ox)
(use-package org-roam-ui
:after org-roam
:config
(setq 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 ox-gfm)
#+end_src #+end_src
* Basic Appearance and Behaviors * Basic Appearance and Behaviors
#+begin_src emacs-lisp #+begin_src emacs-lisp
@ -184,7 +255,7 @@ To get started, run =C-c C-v t=
;; Corrects (and improves) org-mode's native fontification. ;; Corrects (and improves) org-mode's native fontification.
(doom-themes-org-config)) (doom-themes-org-config))
(set-frame-font "DejaVu Sans Mono 14") (set-frame-font "DejaVu Sans Mono 17")
(use-package simple-modeline (use-package simple-modeline
:hook (after-init . simple-modeline-mode)) :hook (after-init . simple-modeline-mode))
@ -221,6 +292,17 @@ To get started, run =C-c C-v t=
;; If a popup does happen, don't resize windows to be equal-sized ;; If a popup does happen, don't resize windows to be equal-sized
(setq even-window-sizes nil) (setq even-window-sizes nil)
(setq whitespace-style '(trailing tabs newline tab-mark )) ; show tab characters
(setq indent-tabs-mode nil) ; tabs not spaces
(visual-line-mode)
#+end_src
** Tab bar
#+begin_src emacs-lisp
(use-package tab-bar-echo-area
:ensure
:config
(tab-bar-echo-area-mode 1)
(setq tab-bar-show nil))
#+end_src #+end_src
* Navigation * Navigation
** Helper Functions ** Helper Functions
@ -262,31 +344,36 @@ To get started, run =C-c C-v t=
#+end_src #+end_src
** Windows and Workspaces ** Windows and Workspaces
[[https://github.com/abo-abo/ace-window/issues/216][Credit]] for manual dispatch function
#+begin_src emacs-lisp #+begin_src emacs-lisp
(use-package persp-mode (defun ace-window-manual-dispatch (arg)
:diminish persp-mode) "Calls `ace-window' with ARG asking for the dispatch, even if `aw-dispatch-always' is nil.
(unless (equal persp-mode t) This could be useful to use the advanced commands"
(persp-mode)) (interactive "p")
(let ((aw-dispatch-always t))
(ace-window arg)
))
(use-package ace-window) (use-package ace-window)
(setq aw-keys '(?a ?s ?d ?f ?g ?h ?j ?k ?l)) (setq aw-keys '(?a ?s ?d ?f ?g ?h ?j ?k ?l))
(defvar aw-dispatch-alist (setq aw-dispatch-alist
'((?x aw-delete-window "Delete Window") '(
(?x aw-delete-window "Delete Window")
(?m aw-swap-window "Swap Windows") (?m aw-swap-window "Swap Windows")
(?M aw-move-window "Move Window") (?M aw-move-window "Move Window")
(?c aw-copy-window "Copy Window") ;; (?c aw-copy-window "Copy Window")
(?j aw-switch-buffer-in-window "Select Buffer") ;; (?j aw-switch-buffer-in-window "Select Buffer")
(?n aw-flip-window) ;; (?n aw-flip-window)
;;(?u aw-switch-buffer-other-window "Switch Buffer Other Window") ;; ;;
(?u aw-switch-buffer-other-window 'winner-undo) (?b aw-switch-buffer-other-window "Switch Buffer Other Window")
(?U aw-switch-buffer-other-window 'winner-redo) (?u winner-undo)
(?U winner-redo)
(?c aw-split-window-fair "Split Fair Window") (?c aw-split-window-fair "Split Fair Window")
(?v aw-split-window-vert "Split Vert Window") (?v aw-split-window-vert "Split Vert Window")
(?b aw-split-window-horz "Split Horz Window") (?H aw-split-window-horz "Split Horz Window")
(?o delete-other-windows "Delete Other Windows") (?o delete-other-windows "Delete Other Windows")
(?? aw-show-dispatch-help)) (?? aw-show-dispatch-help)))
"List of actions for `aw-dispatch-default'.") (setq aw-scope 'frame)
;; TODO: maybe put workspace controls in aw-dispatch? ;; TODO: Window width controls
#+end_src #+end_src
** Dired ** Dired
#+begin_src emacs-lisp #+begin_src emacs-lisp
@ -358,7 +445,7 @@ To get started, run =C-c C-v t=
;; Top level bindings ;; Top level bindings
"SPC" '(projectile-find-file :which-key "Find project file") "SPC" '(projectile-find-file :which-key "Find project file")
"<backspace>" '(treemacs-find-file :which-key "Find current file in sidebar") "<backspace>" '(ian/treemacs-open-current-or-jump :which-key "Find current file in sidebar") ; TODO or treemacs-select-window
"," '(+ivy/switch-workspace-buffer :which-key "Buffers (workspace)") "," '(+ivy/switch-workspace-buffer :which-key "Buffers (workspace)")
"/" '(consult-ripgrep :which-key "Search project") "/" '(consult-ripgrep :which-key "Search project")
":" '(execute-extended-command :which-key "M-x") ":" '(execute-extended-command :which-key "M-x")
@ -368,8 +455,9 @@ To get started, run =C-c C-v t=
"-" '(dired :which-key "Find Directory") "-" '(dired :which-key "Find Directory")
;; "*" '(counsel-locate :which-key "Fuzzy find file") ;; find-file? consult-locate? ;; "*" '(counsel-locate :which-key "Fuzzy find file") ;; find-file? consult-locate?
"d" '(docker :which-key "Docker") "d" '(docker :which-key "Docker")
"i" '(custom/conditional-imenu :which-key "Imenu") ;; consult-outline? "i" '(ian/conditional-imenu :which-key "Imenu") ;; consult-outline?
"w" '(ace-window :which-key "Window") "w" '(ace-window :which-key "Window")
"W" '(ace-window-manual-dispatch :which-key "Window (dispatch)")
;; Agenda ;; Agenda
"a" '(:ignore t :which-key "Agenda") "a" '(:ignore t :which-key "Agenda")
@ -402,7 +490,7 @@ To get started, run =C-c C-v t=
"cC" '(recompile :which-key "Recompile") "cC" '(recompile :which-key "Recompile")
"cd" '(+lookup/definition :which-key "Goto definition") "cd" '(+lookup/definition :which-key "Goto definition")
"cr" '(+lookup/references :which-key "Goto references") "cr" '(+lookup/references :which-key "Goto references")
"ce" '(custom/eval-region-or-buffer :which-key "Eval buffer/region") "ce" '(ian/eval-region-or-buffer :which-key "Eval buffer/region")
;; "cf" '(NOT A COMMAND (re-do) :which-key "Format buffer/region") ;; "cf" '(NOT A COMMAND (re-do) :which-key "Format buffer/region")
"ci" '(+lookup/implementations :which-key "Find implementations") "ci" '(+lookup/implementations :which-key "Find implementations")
"cj" '(lsp-ivy-workspace-symbol :which-key "Goto symbol (curr. workspace)") "cj" '(lsp-ivy-workspace-symbol :which-key "Goto symbol (curr. workspace)")
@ -537,7 +625,7 @@ To get started, run =C-c C-v t=
"nd" '(deft :which-key "Deft") "nd" '(deft :which-key "Deft")
"nt" '(org-todo-list :which-key "Todo list") "nt" '(org-todo-list :which-key "Todo list")
"nf" '(org-roam-node-find :which-key "Find node") "nf" '(org-roam-node-find :which-key "Find node")
"ng" '(org-roam-graph :which-key "Show graph") "ng" '(org-roam-ui-open :which-key "Show graph")
"nr" '(org-roam-buffer-toggle :which-key "Toggle roam buffer") "nr" '(org-roam-buffer-toggle :which-key "Toggle roam buffer")
"nb" '(org-roam-buffer-display-dedicated :which-key "Launch roam buffer") "nb" '(org-roam-buffer-display-dedicated :which-key "Launch roam buffer")
"ns" '(org-roam-db-sync :which-key "Sync database") "ns" '(org-roam-db-sync :which-key "Sync database")
@ -607,7 +695,6 @@ To get started, run =C-c C-v t=
"TAB s" '(+workspace/save :which-key "Save workspace") "TAB s" '(+workspace/save :which-key "Save workspace")
"TAB x" '(+workspace/kill-session :which-key "Delete session") "TAB x" '(+workspace/kill-session :which-key "Delete session")
)) ))
#+end_src #+end_src
* Project management * Project management
@ -799,6 +886,7 @@ All lisp-family languages
(lispyville-set-key-theme '(operators c-w additional))) (lispyville-set-key-theme '(operators c-w additional)))
#+end_src #+end_src
* Markups * Markups
** Markdown
#+begin_src emacs-lisp #+begin_src emacs-lisp
(use-package markdown-mode (use-package markdown-mode
:mode ("\\.md\\'" . markdown-mode)) :mode ("\\.md\\'" . markdown-mode))
@ -807,6 +895,25 @@ All lisp-family languages
(use-package json-mode) (use-package json-mode)
(use-package yaml-mode) (use-package yaml-mode)
#+end_src #+end_src
** Beancount
#+begin_src emacs-lisp
(defun beancount-tab-function ()
"Improved beancount tab ripped off from doom emacs"
(interactive)
(if (and outline-minor-mode (outline-on-heading-p))
(beancount-outline-cycle)
(indent-according-to-mode)))
(use-package beancount
:straight (beancount :type git :host github :repo "beancount/beancount-mode")
:mode ("\\.beancount\\'" . beancount-mode)
:hook (beancount-mode . outline-minor-mode)
:config
(evil-define-key 'normal 'beancount-mode-map (kbd "TAB") 'beancount-tab-function)
) ;; Bind the TAB key
(add-hook 'beancount-mode-hook #'flymake-bean-check-enable)
#+end_src
* Shells * Shells
** Enable fish completions ** Enable fish completions
Uses the external fish program to provide fish-style completions to eshell etc Uses the external fish program to provide fish-style completions to eshell etc
@ -935,15 +1042,21 @@ Uses the external fish program to provide fish-style completions to eshell etc
;; (require 'evil-org-agenda) ;; (require 'evil-org-agenda)
;; (evil-org-agenda-set-keys) ;; (evil-org-agenda-set-keys)
) )
(use-package evil-collection (use-package evil-collection
:after evil :after evil
:ensure t :ensure t
:diminish evil-collection-unimpaired-mode :diminish evil-collection-unimpaired-mode
:init
(setq evil-want-C-u-scroll t)
:config :config
(evil-collection-init) (evil-collection-init)
(setq evil-want-C-i-jump t (setq evil-want-C-i-jump t
evil-respect-visual-line-mode t)) evil-respect-visual-line-mode t))
(use-package evil-commentary
:config
(evil-commentary-mode))
#+end_src #+end_src
* Web browsing and youtube * Web browsing and youtube
#+begin_src emacs-lisp #+begin_src emacs-lisp