Move things around in org mode file

This commit is contained in:
James Dixon 2025-05-25 23:18:25 -04:00
parent 095fec1364
commit 0c60b9346c
2 changed files with 529 additions and 455 deletions

View File

@ -1,10 +1,10 @@
;;; init.el -- EMACS -*- lexical-binding: t -*- ;;; init.el -*- lexical-binding: t -*-
;;; ;;;
;;; Author: James Dixon <notjamesdixon@gmail.com> ;;; Author: James Dixon <notjamesdixon@gmail.com>
;;; Maintainer: James Dixon <notjamesdixon@gmail.com> ;;; Maintainer: James Dixon <notjamesdixon@gmail.com>
;;; ;;;
;;; Commentary: ;;; Commentary:
;;; My Literate Emacs Config ;;; My Emacs Config
;;; ;;;
;;; Code: ;;; Code:
@ -42,9 +42,9 @@
;; Show paren differently ;; Show paren differently
(setq show-paren-delay 0.1 (setq show-paren-delay 0.1
show-paren-highlight-openparen t show-paren-highlight-openparen t
show-paren-when-point-inside-paren t show-paren-when-point-inside-paren t
show-paren-when-point-in-periphery t) show-paren-when-point-in-periphery t)
;;; Comment Settings ;;; Comment Settings
(setq comment-multi-line t) (setq comment-multi-line t)
@ -54,8 +54,8 @@
;;; Memory Limits and Performance ;;; Memory Limits and Performance
;; Undo/Redo ;; Undo/Redo
(setq undo-limit (* 13 160000) (setq undo-limit (* 13 160000)
undo-strong-limit (* 13 240000) undo-strong-limit (* 13 240000)
undo-outer-limit (* 13 24000000)) undo-outer-limit (* 13 24000000))
;; Garbage Collection ;; Garbage Collection
(setq gc-cons-threshold-original gc-cons-threshold) (setq gc-cons-threshold-original gc-cons-threshold)
@ -88,10 +88,10 @@
(setq history-length 300) (setq history-length 300)
(setq savehist-save-minibuffer-history t) ;; Default (setq savehist-save-minibuffer-history t) ;; Default
(setq savehist-additional-variables (setq savehist-additional-variables
'(kill-ring ; clipboard '(kill-ring ; clipboard
register-alist ; macros register-alist ; macros
mark-ring global-mark-ring ; marks mark-ring global-mark-ring ; marks
search-ring regexp-search-ring)) ; searches search-ring regexp-search-ring)) ; searches
;; savehist is an Emacs feature that preserves the minibuffer history between sessions ;; savehist is an Emacs feature that preserves the minibuffer history between sessions
(add-hook 'after-init-hook #'savehist-mode) (add-hook 'after-init-hook #'savehist-mode)
;; save-place-mode enables Emacs to remember the last location within a file ;; save-place-mode enables Emacs to remember the last location within a file
@ -110,34 +110,6 @@
;; Auto-refresh buffers when files on disk change. ;; Auto-refresh buffers when files on disk change.
(global-auto-revert-mode t) (global-auto-revert-mode t)
(define-minor-mode clean-trailing-whitespace-mode
"Tidy up trailing whitespace with `delete-trailing-whitespace' before saving."
:lighter " ctsv"
(if clean-trailing-whitespace-mode
(add-hook 'before-save-hook #'delete-trailing-whitespace nil t)
(remove-hook 'before-save-hook #'delete-trailing-whitespace t)))
(define-minor-mode clean-all-whitespace-mode
"Tidy up *all* whitespace with `whitespace-cleanup' before saving."
:lighter " casv"
(if clean-trailing-whitespace-mode
(add-hook 'before-save-hook #'whitespace-cleanup nil t)
(remove-hook 'before-save-hook #'whitespace-cleanup t)))
(define-minor-mode check-parens-save-mode
"Check the balance of parens with `check-parens' before saving."
:lighter " cpns"
(if check-parens-save-mode
(add-hook 'before-save-mode #'check-parens nil t)
(remove-hook 'before-save-mode #'check-parens t)))
;;; Minor Mode Hooks
;; (add-hook 'prog-mode #'clean-all-whitespace-mode)
;; (add-hook 'org-mode #'clean-all-whitespace-mode)
;;
;; (add-hook 'emacs-lisp-mode #'check-parens-save-mode)
;; (add-hook 'emacs-lisp-mode #'outline-minor-mode)
;;; Custom Tab Settings ;;; Custom Tab Settings
;; https://dougie.io/emacs/indentation/ ;; https://dougie.io/emacs/indentation/
;; Create a variable for our preferred tab width ;; Create a variable for our preferred tab width
@ -180,6 +152,34 @@
;; Make the backspace properly erase the tab instead of removing 1 space at a time. ;; Make the backspace properly erase the tab instead of removing 1 space at a time.
(setq backward-delete-char-untabify-method 'hungry) (setq backward-delete-char-untabify-method 'hungry)
(define-minor-mode clean-trailing-whitespace-mode
"Tidy up trailing whitespace with `delete-trailing-whitespace' before saving."
:lighter " ctsv"
(if clean-trailing-whitespace-mode
(add-hook 'before-save-hook #'delete-trailing-whitespace nil t)
(remove-hook 'before-save-hook #'delete-trailing-whitespace t)))
(define-minor-mode clean-all-whitespace-mode
"Tidy up *all* whitespace with `whitespace-cleanup' before saving."
:lighter " casv"
(if clean-trailing-whitespace-mode
(add-hook 'before-save-hook #'whitespace-cleanup nil t)
(remove-hook 'before-save-hook #'whitespace-cleanup t)))
(define-minor-mode check-parens-save-mode
"Check the balance of parens with `check-parens' before saving."
:lighter " cpns"
(if check-parens-save-mode
(add-hook 'before-save-mode #'check-parens nil t)
(remove-hook 'before-save-mode #'check-parens t)))
;;; Minor Mode Hooks
;; (add-hook 'prog-mode #'clean-all-whitespace-mode)
;; (add-hook 'org-mode #'clean-all-whitespace-mode)
;;
;; (add-hook 'emacs-lisp-mode #'check-parens-save-mode)
;; (add-hook 'emacs-lisp-mode #'outline-minor-mode)
;; https://stackoverflow.com/questions/6286579/emacs-shell-mode-how-to-send-region-to-shell/7053298#7053298 ;; https://stackoverflow.com/questions/6286579/emacs-shell-mode-how-to-send-region-to-shell/7053298#7053298
(defun shell-region (start end) (defun shell-region (start end)
"Execute region START to END in an inferior shell." "Execute region START to END in an inferior shell."
@ -193,10 +193,10 @@
`I` ignore binary files; `E` extended regular expressions; `r` recursive" `I` ignore binary files; `E` extended regular expressions; `r` recursive"
(interactive) (interactive)
(let* ((grep-flags "-inrEI --color=always -C3") (let* ((grep-flags "-inrEI --color=always -C3")
(search-term (read-string (format "Recursive regex search with grep %s: " grep-flags))) (search-term (read-string (format "Recursive regex search with grep %s: " grep-flags)))
(search-path (directory-file-name (expand-file-name (read-directory-name "directory: ")))) (search-path (directory-file-name (expand-file-name (read-directory-name "directory: "))))
(default-directory (file-name-as-directory search-path)) (default-directory (file-name-as-directory search-path))
(grep-command (concat grep-program " " grep-flags " " search-term " " search-path))) (grep-command (concat grep-program " " grep-flags " " search-term " " search-path)))
(compilation-start grep-command 'grep-mode (lambda (mode) "*grep*") nil))) (compilation-start grep-command 'grep-mode (lambda (mode) "*grep*") nil)))
;; Open External Terminal Emulator ;; Open External Terminal Emulator
@ -257,15 +257,15 @@
(defvar bootstrap-version) (defvar bootstrap-version)
(let ((bootstrap-file (let ((bootstrap-file
(expand-file-name (expand-file-name
"straight/repos/straight.el/bootstrap.el" "straight/repos/straight.el/bootstrap.el"
(or (bound-and-true-p straight-base-dir) (or (bound-and-true-p straight-base-dir)
user-emacs-directory))) user-emacs-directory)))
(bootstrap-version 7)) (bootstrap-version 7))
(unless (file-exists-p bootstrap-file) (unless (file-exists-p bootstrap-file)
(with-current-buffer (with-current-buffer
(url-retrieve-synchronously (url-retrieve-synchronously
"https://raw.githubusercontent.com/radian-software/straight.el/develop/install.el" "https://raw.githubusercontent.com/radian-software/straight.el/develop/install.el"
'silent 'inhibit-cookies) 'silent 'inhibit-cookies)
(goto-char (point-max)) (goto-char (point-max))
(eval-print-last-sexp))) (eval-print-last-sexp)))
(load bootstrap-file nil 'nomessage)) (load bootstrap-file nil 'nomessage))
@ -294,9 +294,9 @@
(setq evil-ex-visual-char-range t) (setq evil-ex-visual-char-range t)
(setq evil-disable-insert-state-bindings t) (setq evil-disable-insert-state-bindings t)
(setq evil-insert-state-cursor '(box "violet") (setq evil-insert-state-cursor '(box "violet")
evil-normal-state-cursor '(box "yellow") evil-normal-state-cursor '(box "yellow")
evil-visual-state-cursor '(hollow "#1aa5db") evil-visual-state-cursor '(hollow "#1aa5db")
evil-emacs-state-cursor '(box "cyan")) evil-emacs-state-cursor '(box "cyan"))
(setq evil-want-keybinding nil) (setq evil-want-keybinding nil)
(setq evil-want-integration t) (setq evil-want-integration t)
:config :config
@ -432,21 +432,27 @@
;;; Vanilla Emacs Keybinds ;;; Vanilla Emacs Keybinds
(global-set-key (kbd "C-c i") (lambda () (interactive) (find-file (concat user-emacs-directory "/init.org")))) (global-set-key (kbd "C-c i") (lambda () (interactive) (find-file (concat user-emacs-directory "/init.org"))))
(global-set-key (kbd "C-c d") (lambda () (interactive) (find-file (getenv "DOTFILES")))) (global-set-key (kbd "C-c d") (lambda () (interactive) (find-file (getenv "DOTFILES"))))
(global-set-key (kbd "C-c g") (lambda () (interactive) (find-file (concat (getenv "DOTFILES") "/config/emacs/.config/emacs/init.el"))))
;; more ergo keybind for switching to normal<->emacs state ;; more ergo keybind for switching to normal<->emacs state
(global-set-key (kbd "C-;") (kbd "C-z")) (global-set-key (kbd "C-;") (kbd "C-z"))
(add-hook 'python-mode-hook ;;; Better discoverability for key mappings (which-key)
(lambda () (set (make-local-variable 'compile-command) ;; https://github.com/justbur/emacs-which-key
(format "python3 %s" (file-name-nondirectory buffer-file-name))))) ;; builtin to emacs > 30.1
(use-package which-key
:straight t
:init (which-key-mode 1))
;; https://www.gnu.org/software/emacs/manual/html_node/emacs/Dired.html ;;; Better help menus (helpful)
(use-package dired ;; https://github.com/Wilfred/helpful
:straight nil (use-package helpful
:commands (dired dired-jump) :straight t
:config :bind
(setq dired-dwim-target t)) (("C-c C-d" . helpful-at-point) ; Lookup the symbol at point
("C-h f" . helpful-callable) ; Describe a function
("C-h v" . helpful-variable) ; Describe a variable
("C-h k" . helpful-key) ; Describe a key binding
("C-h x" . helpful-command))) ; Describe a command
;; Org mode (organization outline framework) ;; Org mode (organization outline framework)
(straight-use-package '(org :type built-in)) ;; use builtin org (straight-use-package '(org :type built-in)) ;; use builtin org
@ -490,13 +496,20 @@
:init (setq markdown-command "multimarkdown") :init (setq markdown-command "multimarkdown")
(setq markdown-fontify-code-blocks-natively t) ; Make code block syntax highlighted (setq markdown-fontify-code-blocks-natively t) ; Make code block syntax highlighted
:bind(:map markdown-mode-map :bind(:map markdown-mode-map
("C-c C-e" . markdown-do))) ("C-c C-e" . markdown-do)))
;; Magit (intuitive git interface) ;; Magit (intuitive git interface)
;; https://magit.vc/ ;; https://magit.vc/
(use-package magit (use-package magit
:straight t) :straight t)
;; https://www.gnu.org/software/emacs/manual/html_node/emacs/Dired.html
(use-package dired
:straight nil
:commands (dired dired-jump)
:config
(setq dired-dwim-target t))
;; Fancy, polished and modernized dired ;; Fancy, polished and modernized dired
;; https://github.com/alexluigit/dirvish ;; https://github.com/alexluigit/dirvish
;; https://github.com/alexluigit/dirvish/blob/main/docs/CUSTOMIZING.org#sample-config ;; https://github.com/alexluigit/dirvish/blob/main/docs/CUSTOMIZING.org#sample-config
@ -512,45 +525,45 @@
(dirvish-peek-mode) (dirvish-peek-mode)
(dirvish-side-follow-mode) (dirvish-side-follow-mode)
(setq dirvish-mode-line-format (setq dirvish-mode-line-format
'(:left (sort symlink) :right (omit yank index))) '(:left (sort symlink) :right (omit yank index)))
(setq dirvish-attributes ; The order *MATTERS* for some attributes (setq dirvish-attributes ; The order *MATTERS* for some attributes
'(vc-state subtree-state nerd-icons collapse git-msg file-time file-size) '(vc-state subtree-state nerd-icons collapse git-msg file-time file-size)
dirvish-side-attributes dirvish-side-attributes
'(vc-state nerd-icons collapse file-size)) '(vc-state nerd-icons collapse file-size))
(setq dirvish-large-directory-threshold 20000) (setq dirvish-large-directory-threshold 20000)
:bind :bind
(("C-c -" . dirvish-side) (("C-c -" . dirvish-side)
:map dirvish-mode-map ; Dirvish inherits `dired-mode-map' :map dirvish-mode-map ; Dirvish inherits `dired-mode-map'
(";" . dired-up-directory) ; So you can adjust `dired' bindings here (";" . dired-up-directory) ; So you can adjust `dired' bindings here
("?" . dirvish-dispatch) ; [?] a helpful cheatsheet ("?" . dirvish-dispatch) ; [?] a helpful cheatsheet
("a" . dirvish-setup-menu) ; [a]ttributes settings:`t' toggles mtime, `f' toggles fullframe, etc. ("a" . dirvish-setup-menu) ; [a]ttributes settings:`t' toggles mtime, `f' toggles fullframe, etc.
("f" . dirvish-file-info-menu) ; [f]ile info ("f" . dirvish-file-info-menu) ; [f]ile info
("o" . dirvish-quick-access) ; [o]pen `dirvish-quick-access-entries' ("o" . dirvish-quick-access) ; [o]pen `dirvish-quick-access-entries'
("s" . dirvish-quicksort) ; [s]ort flie list ("s" . dirvish-quicksort) ; [s]ort flie list
("r" . dirvish-history-jump) ; [r]ecent visited ("r" . dirvish-history-jump) ; [r]ecent visited
("l" . dirvish-ls-switches-menu) ; [l]s command flags ("l" . dirvish-ls-switches-menu) ; [l]s command flags
("v" . dirvish-vc-menu) ; [v]ersion control commands ("v" . dirvish-vc-menu) ; [v]ersion control commands
("*" . dirvish-mark-menu) ("*" . dirvish-mark-menu)
("y" . dirvish-yank-menu) ("y" . dirvish-yank-menu)
("N" . dirvish-narrow) ("N" . dirvish-narrow)
("^" . dirvish-history-last) ("^" . dirvish-history-last)
("TAB" . dirvish-subtree-toggle) ("TAB" . dirvish-subtree-toggle)
("M-f" . dirvish-history-go-forward) ("M-f" . dirvish-history-go-forward)
("M-b" . dirvish-history-go-backward) ("M-b" . dirvish-history-go-backward)
("M-e" . dirvish-emerge-menu))) ("M-e" . dirvish-emerge-menu)))
;; https://github.com/doomemacs/themes ;; https://github.com/doomemacs/themes
(use-package doom-themes (use-package doom-themes
:straight t :straight t
:config) :config)
;; (load-theme 'doom-badger t)) ;; (load-theme 'doom-badger t))
;; (load-theme 'doom-ir-black t)) ;; (load-theme 'doom-ir-black t))
;; Doom Modeline - much easier on the eyes ;; Doom Modeline - much easier on the eyes
;; https://github.com/seagle0128/doom-modeline ;; https://github.com/seagle0128/doom-modeline
(use-package doom-modeline (use-package doom-modeline
:straight t :straight t
:hook (after-init . doom-modeline-mode)) :hook (after-init . doom-modeline-mode))
;; Sticky headers for programming modes ;; Sticky headers for programming modes
;; https://github.com/alphapapa/topsy.el ;; https://github.com/alphapapa/topsy.el
@ -561,47 +574,52 @@
;; Highlights TODOs and other configured keywords in buffer ;; Highlights TODOs and other configured keywords in buffer
;; https://github.com/tarsius/hl-todo ;; https://github.com/tarsius/hl-todo
(use-package hl-todo (use-package hl-todo
:straight t :straight t
:hook (prog-mode . hl-todo-mode) :hook (prog-mode . hl-todo-mode)
:config :config
(setq hl-todo-highlight-punctuation ":" (setq hl-todo-highlight-punctuation ":"
hl-todo-keyword-faces hl-todo-keyword-faces
`(("TODO" warning bold) `(("TODO" warning bold)
("FIXME" error bold) ("FIXME" error bold)
("HACK" font-lock-constant-face bold) ("HACK" font-lock-constant-face bold)
("REVIEW" font-lock-keyword-face bold) ("REVIEW" font-lock-keyword-face bold)
("NOTE" success bold) ("NOTE" success bold)
("DEPRECATED" font-lock-doc-face bold)))) ("DEPRECATED" font-lock-doc-face bold))))
; TODO: look into todo integrations ; TODO: look into todo integrations
;; Colorize color names in buffers ;; Colorize color names in buffers
;; https://github.com/emacsmirror/rainbow-mode ;; https://github.com/emacsmirror/rainbow-mode
(use-package rainbow-mode (use-package rainbow-mode
:straight t) :straight t)
;; Rainbow Delimiters - who doesn't love colors ;; Rainbow Delimiters - who doesn't love colors
;; https://github.com/Fanael/rainbow-delimiters ;; https://github.com/Fanael/rainbow-delimiters
(use-package rainbow-delimiters (use-package rainbow-delimiters
:straight t :straight t
:init (add-hook 'prog-mode-hook #'rainbow-delimiters-mode)) :init (add-hook 'prog-mode-hook #'rainbow-delimiters-mode))
;; Git Gutter -- sidebar / fringe indicators of changes ;; Git Gutter -- sidebar / fringe indicators of changes
;; https://github.com/emacsorphanage/git-gutter ;; https://github.com/emacsorphanage/git-gutter
(use-package git-gutter (use-package git-gutter
:hook (prog-mode . git-gutter-mode) :hook (prog-mode . git-gutter-mode)
:straight t :straight t
:config :config
(setq git-gutter:update-interval 0.2)) (setq git-gutter:update-interval 0.2))
;; TODO: disable this in terminal mode ;; TODO: disable this in terminal mode
;; highlights the modified region (yank/kill) ;; highlights the modified region (yank/kill)
;; https://github.com/minad/goggles ;; https://github.com/minad/goggles
(use-package goggles (use-package goggles
:straight t :straight t
:hook ((prog-mode org-mode) . goggles-mode) :hook ((prog-mode org-mode) . goggles-mode)
:config :config
(goggles-define yank evil-paste-after) ; make pasting from evil mode highlighted (goggles-define yank evil-paste-after) ; make pasting from evil mode highlighted
(setq-default goggles-pulse t)) (setq-default goggles-pulse t))
;; NYAN x inf
;; https://github.com/TeMPOraL/nyan-mode
(use-package nyan-mode
:straight t)
;;; Mini-buffer improvements (fido, orderless, marginalia) ;;; Mini-buffer improvements (fido, orderless, marginalia)
;; Let's try [icomplete / fido / ido] mode for a while. ;; Let's try [icomplete / fido / ido] mode for a while.
@ -659,7 +677,7 @@
(advice-add #'register-preview :override #'consult-register-window) (advice-add #'register-preview :override #'consult-register-window)
(setq register-preview-delay 0.5) (setq register-preview-delay 0.5)
(setq xref-show-xrefs-function #'consult-xref (setq xref-show-xrefs-function #'consult-xref
xref-show-definitions-function #'consult-xref)) xref-show-definitions-function #'consult-xref))
;; corfu: mini completion ui ;; corfu: mini completion ui
;;https://github.com/minad/corfu ;;https://github.com/minad/corfu
@ -701,30 +719,12 @@
;; useful beyond Corfu. ;; useful beyond Corfu.
(read-extended-command-predicate #'command-completion-default-include-p)) (read-extended-command-predicate #'command-completion-default-include-p))
;;; Better discoverability for key mappings (which-key)
;; https://github.com/justbur/emacs-which-key
;; builtin to emacs > 30.1
(use-package which-key
:straight t
:init (which-key-mode 1))
;;; Better help menus (helpful)
;; https://github.com/Wilfred/helpful
(use-package helpful
:straight t
:bind
(("C-c C-d" . helpful-at-point) ; Lookup the symbol at point
("C-h f" . helpful-callable) ; Describe a function
("C-h v" . helpful-variable) ; Describe a variable
("C-h k" . helpful-key) ; Describe a key binding
("C-h x" . helpful-command))) ; Describe a command
;; Syntax checking ;; Syntax checking
;; https://www.flycheck.org/en/latest/languages.html ;; https://www.flycheck.org/en/latest/languages.html
;; https://github.com/flycheck/flycheck ;; https://github.com/flycheck/flycheck
(use-package flycheck (use-package flycheck
:straight t :straight t
:init (add-hook 'after-init-hook #'global-flycheck-mode)) :init (global-flycheck-mode))
;;; External code formatting tool integration (format-all) ;;; External code formatting tool integration (format-all)
;; https://github.com/lassik/emacs-format-all-the-code ;; https://github.com/lassik/emacs-format-all-the-code
@ -743,6 +743,15 @@
:config :config
(global-whitespace-cleanup-mode)) (global-whitespace-cleanup-mode))
(use-package compile
:straight nil
:config
(setq compilation-scroll-output t))
(add-hook 'python-mode-hook
(lambda () (set (make-local-variable 'compile-command)
(format "python3 %s" (file-name-nondirectory buffer-file-name)))))
;; Abbrevs and Snippets ;; Abbrevs and Snippets
;; URLs ;; URLs
(define-abbrev global-abbrev-table "mygh" "https://github.com/lemonase") (define-abbrev global-abbrev-table "mygh" "https://github.com/lemonase")
@ -773,30 +782,25 @@
:straight t :straight t
:init) :init)
;; LSP Modes
(use-package eglot (use-package eglot
:straight nil :straight nil
:defer t :defer t
:hook ((python-mode . eglot-ensure) :hook ((python-mode . eglot-ensure)
(go-mode . eglot-ensure))) (go-mode . eglot-ensure)))
;; Allow flycheck errors to show with eglot
;;https://github.com/flycheck/flycheck-eglot
;; (use-package flycheck-eglot
;; :straight t
;; :after (flycheck eglot)
;; :config
;; (global-flycheck-eglot-mode 1))
;;; Extra Language Modes
;; Lua mode ;; Lua mode
(use-package lua-mode (use-package lua-mode
:straight t) :straight t)
;;; Other misc modes (docker, gptel, load-env-vars, csv-mode)
(use-package docker
:straight t
:defer t)
(use-package dockerfile-mode
:straight t
:defer t)
(use-package csv-mode
:straight t
:defer t)
;; JavaScript ;; JavaScript
(use-package js (use-package js
:defer t :defer t
@ -834,10 +838,28 @@
(package-install 'json-mode)) (package-install 'json-mode))
(setq-default major-mode (setq-default major-mode
(lambda () ; guess major mode from file name (lambda () ; guess major mode from file name
(unless buffer-file-name (unless buffer-file-name
(let ((buffer-file-name (buffer-name))) (let ((buffer-file-name (buffer-name)))
(set-auto-mode))))) (set-auto-mode)))))
;;; Extra Language Modes
;; docker
(use-package docker
:straight t
:defer t)
(use-package dockerfile-mode
:straight t
:defer t)
;; csv
(use-package csv-mode
:straight t
:defer t)
;; vimrc
(use-package vimrc-mode
:straight t)
;; Local Environment File ;; Local Environment File
(use-package load-env-vars (use-package load-env-vars
@ -846,7 +868,7 @@
(defvar my-env-file "~/.local/.env" "Local environment file.") (defvar my-env-file "~/.local/.env" "Local environment file.")
(let ((my-env-file "~/.local/.env")) (let ((my-env-file "~/.local/.env"))
(if (file-exists-p my-env-file) (if (file-exists-p my-env-file)
(load-env-vars my-env-file))) (load-env-vars my-env-file)))
;; LLM support (must configure with api keys) ;; LLM support (must configure with api keys)
;; (use-package gptel ;; (use-package gptel
@ -866,12 +888,12 @@
(set-frame-font "Cascadia Code 12" nil t) (set-frame-font "Cascadia Code 12" nil t)
(let ((xlist (let ((xlist
'( '(
"C:/Program Files/PowerShell/7/pwsh.exe" "C:/Program Files/PowerShell/7/pwsh.exe"
"~/AppData/Local/Microsoft/WindowsApps/pwsh.exe" "~/AppData/Local/Microsoft/WindowsApps/pwsh.exe"
"C:/Windows/System32/WindowsPowerShell/v1.0/powershell.exe" "C:/Windows/System32/WindowsPowerShell/v1.0/powershell.exe"
)) ))
xfound) xfound)
(setq xfound (seq-some (lambda (x) (if (file-exists-p x) x nil)) xlist)) (setq xfound (seq-some (lambda (x) (if (file-exists-p x) x nil)) xlist))
(when xfound (setq explicit-shell-file-name xfound)))) (when xfound (setq explicit-shell-file-name xfound))))
@ -897,31 +919,18 @@
;; xah-lee functions ;; xah-lee functions
;; http://xahlee.info/index.html ;; http://xahlee.info/index.html
(defun x-open-in-vscode () (defun open-in-vscode ()
"Open current file or dir in vscode." "Open current file or dir in vscode."
(interactive) (interactive)
(let ((xpath (if buffer-file-name buffer-file-name (expand-file-name default-directory)))) (let ((xpath (if buffer-file-name buffer-file-name (expand-file-name default-directory))))
(message "path is %s" xpath) (message "path is %s" xpath)
(cond (cond
((eq system-type 'darwin) ((eq system-type 'darwin)
(shell-command (format "open -a Visual\\ Studio\\ Code.app %s" (shell-quote-argument xpath)))) (shell-command (format "open -a Visual\\ Studio\\ Code.app %s" (shell-quote-argument xpath))))
((eq system-type 'windows-nt) ((eq system-type 'windows-nt)
(shell-command (format "code.cmd %s" (shell-quote-argument xpath)))) (shell-command (format "code.cmd %s" (shell-quote-argument xpath))))
((eq system-type 'gnu/linux) ((eq system-type 'gnu/linux)
(shell-command (format "code %s" (shell-quote-argument xpath))))))) (shell-command (format "code %s" (shell-quote-argument xpath)))))))
(defun x-open-in-terminal ()
"Open the current dir in a new terminal window."
(interactive)
(cond
((eq system-type 'windows-nt)
(shell-command (concat "wt -d " (shell-quote-argument (expand-file-name default-directory)))))
((eq system-type 'darwin)
(shell-command (concat "open -a iTerm " (shell-quote-argument (expand-file-name default-directory)))))
((eq system-type 'gnu/linux)
(let ((process-connection-type nil)) (start-process "" nil "x-terminal-emulator" (concat "--working-directory=" default-directory))))
((eq system-type 'berkeley-unix)
(let ((process-connection-type nil)) (start-process "" nil "x-terminal-emulator" (concat "--working-directory=" default-directory))))))
;;; Buffer local variables - ask to save/tangle. ;;; Buffer local variables - ask to save/tangle.
;; Local Variables: ;; Local Variables:

View File

@ -1,37 +1,36 @@
#+TITLE: Emacs Literate Config #+TITLE: Emacs Literate Config
#+AUTHOR: James Dixon #+AUTHOR: James Dixon
* My Literate Emacs with EVIL * Emacs Config
Made with +evil+ love
** Prelude and Initial Comments ** Prelude and Initial Comments
Initial comment prelude to appease the commnent gods. Initial comment prelude to appease the commnent gods.
#+begin_src emacs-lisp :tangle "init.el" #+begin_src emacs-lisp :tangle "init.el"
;;; init.el -- EMACS -*- lexical-binding: t -*- ;;; init.el -*- lexical-binding: t -*-
;;; ;;;
;;; Author: James Dixon <notjamesdixon@gmail.com> ;;; Author: James Dixon <notjamesdixon@gmail.com>
;;; Maintainer: James Dixon <notjamesdixon@gmail.com> ;;; Maintainer: James Dixon <notjamesdixon@gmail.com>
;;; ;;;
;;; Commentary: ;;; Commentary:
;;; My Literate Emacs Config ;;; My Emacs Config
;;; ;;;
;;; Code: ;;; Code:
#+end_src #+end_src
** Setting User and Email ** Setting User and Email
We set this for use later on with email and other packages. We set this for later use with git, email and other misc. packages.
#+begin_src emacs-lisp :tangle "init.el" #+begin_src emacs-lisp :tangle "init.el"
(setq user-full-name "James Dixon") (setq user-full-name "James Dixon")
(setq user-mail-address "notjamesdixon@gmail.com") (setq user-mail-address "notjamesdixon@gmail.com")
#+end_src #+end_src
** Sensible Defaults ** More Sensible Defaults
These are things what I would consider more sensible defaults for emacs.
*** UI Settings *** UI Settings
- Setting UTF-8 encoding for language - Setting UTF-8 encoding for language
@ -78,9 +77,9 @@ These are things what I would consider more sensible defaults for emacs.
;; Show paren differently ;; Show paren differently
(setq show-paren-delay 0.1 (setq show-paren-delay 0.1
show-paren-highlight-openparen t show-paren-highlight-openparen t
show-paren-when-point-inside-paren t show-paren-when-point-inside-paren t
show-paren-when-point-in-periphery t) show-paren-when-point-in-periphery t)
;;; Comment Settings ;;; Comment Settings
(setq comment-multi-line t) (setq comment-multi-line t)
@ -96,8 +95,8 @@ Undo and Garbage Collection Limits Upgrade
;;; Memory Limits and Performance ;;; Memory Limits and Performance
;; Undo/Redo ;; Undo/Redo
(setq undo-limit (* 13 160000) (setq undo-limit (* 13 160000)
undo-strong-limit (* 13 240000) undo-strong-limit (* 13 240000)
undo-outer-limit (* 13 24000000)) undo-outer-limit (* 13 24000000))
;; Garbage Collection ;; Garbage Collection
(setq gc-cons-threshold-original gc-cons-threshold) (setq gc-cons-threshold-original gc-cons-threshold)
@ -107,7 +106,7 @@ Undo and Garbage Collection Limits Upgrade
(setq read-extended-command-predicate #'command-completion-default-include-p) (setq read-extended-command-predicate #'command-completion-default-include-p)
#+end_src #+end_src
** Theme and Font *** Set Default Theme and Font
#+begin_src emacs-lisp :tangle "init.el" #+begin_src emacs-lisp :tangle "init.el"
;;; Theme (Default) ;;; Theme (Default)
@ -118,7 +117,7 @@ Undo and Garbage Collection Limits Upgrade
;; (load-theme 'modus-operandi t) ;; (load-theme 'modus-operandi t)
#+end_src #+end_src
** File History, Saving, Reverting and Backups *** File History, Saving, Reverting and Backups
#+begin_src emacs-lisp :tangle "init.el" #+begin_src emacs-lisp :tangle "init.el"
;;; File History, Saving and Reverting ;;; File History, Saving and Reverting
@ -138,10 +137,10 @@ Undo and Garbage Collection Limits Upgrade
(setq history-length 300) (setq history-length 300)
(setq savehist-save-minibuffer-history t) ;; Default (setq savehist-save-minibuffer-history t) ;; Default
(setq savehist-additional-variables (setq savehist-additional-variables
'(kill-ring ; clipboard '(kill-ring ; clipboard
register-alist ; macros register-alist ; macros
mark-ring global-mark-ring ; marks mark-ring global-mark-ring ; marks
search-ring regexp-search-ring)) ; searches search-ring regexp-search-ring)) ; searches
;; savehist is an Emacs feature that preserves the minibuffer history between sessions ;; savehist is an Emacs feature that preserves the minibuffer history between sessions
(add-hook 'after-init-hook #'savehist-mode) (add-hook 'after-init-hook #'savehist-mode)
;; save-place-mode enables Emacs to remember the last location within a file ;; save-place-mode enables Emacs to remember the last location within a file
@ -161,48 +160,13 @@ Undo and Garbage Collection Limits Upgrade
(global-auto-revert-mode t) (global-auto-revert-mode t)
#+end_src #+end_src
** Basic Minor Modes and Hooks *** Tab and Indent Settings
Adding some basic minor modes for ease of adding as hooks.
*** Whitespace and Parens
Cleaning up whitespace and checking balanced parens are something that should be handled automatically.
#+begin_src emacs-lisp :tangle "init.el"
(define-minor-mode clean-trailing-whitespace-mode
"Tidy up trailing whitespace with `delete-trailing-whitespace' before saving."
:lighter " ctsv"
(if clean-trailing-whitespace-mode
(add-hook 'before-save-hook #'delete-trailing-whitespace nil t)
(remove-hook 'before-save-hook #'delete-trailing-whitespace t)))
(define-minor-mode clean-all-whitespace-mode
"Tidy up *all* whitespace with `whitespace-cleanup' before saving."
:lighter " casv"
(if clean-trailing-whitespace-mode
(add-hook 'before-save-hook #'whitespace-cleanup nil t)
(remove-hook 'before-save-hook #'whitespace-cleanup t)))
(define-minor-mode check-parens-save-mode
"Check the balance of parens with `check-parens' before saving."
:lighter " cpns"
(if check-parens-save-mode
(add-hook 'before-save-mode #'check-parens nil t)
(remove-hook 'before-save-mode #'check-parens t)))
;;; Minor Mode Hooks
;; (add-hook 'prog-mode #'clean-all-whitespace-mode)
;; (add-hook 'org-mode #'clean-all-whitespace-mode)
;;
;; (add-hook 'emacs-lisp-mode #'check-parens-save-mode)
;; (add-hook 'emacs-lisp-mode #'outline-minor-mode)
#+end_src
** Tab and Indent Settings
Tabs are horribly confusing to deal with in Emacs and some programming minor modes Tabs are horribly confusing to deal with in Emacs and some programming minor modes
really do not help simplify the situation. This is what works for now... really do not help simplify the situation.
This works somewhat, but need a quick way to change indent/tab settings in a buffer.
**** Custom Tab Settings
#+begin_src emacs-lisp :tangle "init.el" #+begin_src emacs-lisp :tangle "init.el"
;;; Custom Tab Settings ;;; Custom Tab Settings
@ -248,11 +212,44 @@ really do not help simplify the situation. This is what works for now...
(setq backward-delete-char-untabify-method 'hungry) (setq backward-delete-char-untabify-method 'hungry)
#+end_src #+end_src
** Custom Enhanced Defuns *** Whitespace and Parens
Better functions for some of the defaults. Cleaning up whitespace and checking balanced parens are something that should be handled automatically.
#+begin_src emacs-lisp :tangle "init.el"
(define-minor-mode clean-trailing-whitespace-mode
"Tidy up trailing whitespace with `delete-trailing-whitespace' before saving."
:lighter " ctsv"
(if clean-trailing-whitespace-mode
(add-hook 'before-save-hook #'delete-trailing-whitespace nil t)
(remove-hook 'before-save-hook #'delete-trailing-whitespace t)))
(define-minor-mode clean-all-whitespace-mode
"Tidy up *all* whitespace with `whitespace-cleanup' before saving."
:lighter " casv"
(if clean-trailing-whitespace-mode
(add-hook 'before-save-hook #'whitespace-cleanup nil t)
(remove-hook 'before-save-hook #'whitespace-cleanup t)))
(define-minor-mode check-parens-save-mode
"Check the balance of parens with `check-parens' before saving."
:lighter " cpns"
(if check-parens-save-mode
(add-hook 'before-save-mode #'check-parens nil t)
(remove-hook 'before-save-mode #'check-parens t)))
;;; Minor Mode Hooks
;; (add-hook 'prog-mode #'clean-all-whitespace-mode)
;; (add-hook 'org-mode #'clean-all-whitespace-mode)
;;
;; (add-hook 'emacs-lisp-mode #'check-parens-save-mode)
;; (add-hook 'emacs-lisp-mode #'outline-minor-mode)
#+end_src
*** Better Builtin Functions
=Enhanced= functions for some of the defaults.
*** Vanilla Emacs Improvements
#+begin_src emacs-lisp :tangle "init.el" #+begin_src emacs-lisp :tangle "init.el"
;; https://stackoverflow.com/questions/6286579/emacs-shell-mode-how-to-send-region-to-shell/7053298#7053298 ;; https://stackoverflow.com/questions/6286579/emacs-shell-mode-how-to-send-region-to-shell/7053298#7053298
@ -268,10 +265,10 @@ Better functions for some of the defaults.
`I` ignore binary files; `E` extended regular expressions; `r` recursive" `I` ignore binary files; `E` extended regular expressions; `r` recursive"
(interactive) (interactive)
(let* ((grep-flags "-inrEI --color=always -C3") (let* ((grep-flags "-inrEI --color=always -C3")
(search-term (read-string (format "Recursive regex search with grep %s: " grep-flags))) (search-term (read-string (format "Recursive regex search with grep %s: " grep-flags)))
(search-path (directory-file-name (expand-file-name (read-directory-name "directory: ")))) (search-path (directory-file-name (expand-file-name (read-directory-name "directory: "))))
(default-directory (file-name-as-directory search-path)) (default-directory (file-name-as-directory search-path))
(grep-command (concat grep-program " " grep-flags " " search-term " " search-path))) (grep-command (concat grep-program " " grep-flags " " search-term " " search-path)))
(compilation-start grep-command 'grep-mode (lambda (mode) "*grep*") nil))) (compilation-start grep-command 'grep-mode (lambda (mode) "*grep*") nil)))
;; Open External Terminal Emulator ;; Open External Terminal Emulator
@ -328,7 +325,7 @@ Better functions for some of the defaults.
(advice-add 'evil-yank :around 'hl-yank-advice) (advice-add 'evil-yank :around 'hl-yank-advice)
#+end_src #+end_src
** Here be Packages ** Emacs lisp packages
*** Bootstrap straight.el *** Bootstrap straight.el
#+begin_src emacs-lisp :tangle "init.el" #+begin_src emacs-lisp :tangle "init.el"
@ -336,18 +333,18 @@ Better functions for some of the defaults.
;; bootstrap straight.el package manager ;; bootstrap straight.el package manager
(defvar bootstrap-version) (defvar bootstrap-version)
(let ((bootstrap-file (let ((bootstrap-file
(expand-file-name (expand-file-name
"straight/repos/straight.el/bootstrap.el" "straight/repos/straight.el/bootstrap.el"
(or (bound-and-true-p straight-base-dir) (or (bound-and-true-p straight-base-dir)
user-emacs-directory))) user-emacs-directory)))
(bootstrap-version 7)) (bootstrap-version 7))
(unless (file-exists-p bootstrap-file) (unless (file-exists-p bootstrap-file)
(with-current-buffer (with-current-buffer
(url-retrieve-synchronously (url-retrieve-synchronously
"https://raw.githubusercontent.com/radian-software/straight.el/develop/install.el" "https://raw.githubusercontent.com/radian-software/straight.el/develop/install.el"
'silent 'inhibit-cookies) 'silent 'inhibit-cookies)
(goto-char (point-max)) (goto-char (point-max))
(eval-print-last-sexp))) (eval-print-last-sexp)))
(load bootstrap-file nil 'nomessage)) (load bootstrap-file nil 'nomessage))
(setq package-install-upgrade-built-in t) (setq package-install-upgrade-built-in t)
@ -355,7 +352,7 @@ Better functions for some of the defaults.
*** Use PATH from shell environment *** Use PATH from shell environment
Emacs does not properly pick up PATH from shell environment. Emacs does not properly pick up PATH from shell environment on macOS (or Windows).
#+begin_src emacs-lisp :tangle "init.el" #+begin_src emacs-lisp :tangle "init.el"
;;; Set Emacs path == shell path (exec-path-from-shell) ;;; Set Emacs path == shell path (exec-path-from-shell)
@ -367,9 +364,10 @@ Emacs does not properly pick up PATH from shell environment.
(exec-path-from-shell-initialize)) (exec-path-from-shell-initialize))
#+end_src #+end_src
*** Use EVIL *** Setup Keybinds
**** Evil
Set settings as well as load EVIL and complementary packages. Set initial evil settings as well as adding complementary evil packages.
#+begin_src emacs-lisp :tangle "init.el" #+begin_src emacs-lisp :tangle "init.el"
;;; EVIL Config :: Vi/Vim Emulation++ (evil-mode) ;;; EVIL Config :: Vi/Vim Emulation++ (evil-mode)
@ -386,9 +384,9 @@ Set settings as well as load EVIL and complementary packages.
(setq evil-ex-visual-char-range t) (setq evil-ex-visual-char-range t)
(setq evil-disable-insert-state-bindings t) (setq evil-disable-insert-state-bindings t)
(setq evil-insert-state-cursor '(box "violet") (setq evil-insert-state-cursor '(box "violet")
evil-normal-state-cursor '(box "yellow") evil-normal-state-cursor '(box "yellow")
evil-visual-state-cursor '(hollow "#1aa5db") evil-visual-state-cursor '(hollow "#1aa5db")
evil-emacs-state-cursor '(box "cyan")) evil-emacs-state-cursor '(box "cyan"))
(setq evil-want-keybinding nil) (setq evil-want-keybinding nil)
(setq evil-want-integration t) (setq evil-want-integration t)
:config :config
@ -439,7 +437,11 @@ Set settings as well as load EVIL and complementary packages.
(evil-define-key '(normal visual) 'global (kbd "C-a C--") 'evil-numbers/dec-at-pt-incremental)) (evil-define-key '(normal visual) 'global (kbd "C-a C--") 'evil-numbers/dec-at-pt-incremental))
#+end_src #+end_src
*** General Prefix/Leader Keybinds **** Evil Keybinds : General
Keybinds grouped varying degrees of organization.
Prefix / leader key of <SPC>.
#+begin_src emacs-lisp :tangle "init.el" #+begin_src emacs-lisp :tangle "init.el"
;; Custom Evil Keybinds ;; Custom Evil Keybinds
@ -524,38 +526,51 @@ Set settings as well as load EVIL and complementary packages.
;; Custom Ex commands ;; Custom Ex commands
(evil-ex-define-cmd "Format" 'format-all-region-or-buffer) ;; format-all-code (evil-ex-define-cmd "Format" 'format-all-region-or-buffer) ;; format-all-code
#+end_src
**** Emacs Global Keybinds
#+begin_src emacs-lisp :tangle "init.el"
;;; Vanilla Emacs Keybinds ;;; Vanilla Emacs Keybinds
(global-set-key (kbd "C-c i") (lambda () (interactive) (find-file (concat user-emacs-directory "/init.org")))) (global-set-key (kbd "C-c i") (lambda () (interactive) (find-file (concat user-emacs-directory "/init.org"))))
(global-set-key (kbd "C-c d") (lambda () (interactive) (find-file (getenv "DOTFILES")))) (global-set-key (kbd "C-c d") (lambda () (interactive) (find-file (getenv "DOTFILES"))))
(global-set-key (kbd "C-c g") (lambda () (interactive) (find-file (concat (getenv "DOTFILES") "/config/emacs/.config/emacs/init.el"))))
;; more ergo keybind for switching to normal<->emacs state ;; more ergo keybind for switching to normal<->emacs state
(global-set-key (kbd "C-;") (kbd "C-z")) (global-set-key (kbd "C-;") (kbd "C-z"))
#+end_src #+end_src
*** Compile Mode **** More helpful Help and Key Menus
It can be difficult to memorize key binds... `which-key` helps greatly by giving a transient pop-up buffer.
`helpful` is also a great package that changes the look and layout of the interactive help buffers in Emacs
as well as adding supplemental information. The result is a better experience with help menus all around.
#+begin_src emacs-lisp :tangle "init.el" #+begin_src emacs-lisp :tangle "init.el"
(add-hook 'python-mode-hook ;;; Better discoverability for key mappings (which-key)
(lambda () (set (make-local-variable 'compile-command) ;; https://github.com/justbur/emacs-which-key
(format "python3 %s" (file-name-nondirectory buffer-file-name))))) ;; builtin to emacs > 30.1
(use-package which-key
:straight t
:init (which-key-mode 1))
;;; Better help menus (helpful)
;; https://github.com/Wilfred/helpful
(use-package helpful
:straight t
:bind
(("C-c C-d" . helpful-at-point) ; Lookup the symbol at point
("C-h f" . helpful-callable) ; Describe a function
("C-h v" . helpful-variable) ; Describe a variable
("C-h k" . helpful-key) ; Describe a key binding
("C-h x" . helpful-command))) ; Describe a command
#+end_src #+end_src
*** Dired *** Configure Modes
**** Org Mode (org-mode)
Builtin Emacs directory editor Org mode. Cut my life into pizzas. This is my plastic fork!1 |dmb|
#+begin_src emacs-lisp :tangle "init.el"
;; https://www.gnu.org/software/emacs/manual/html_node/emacs/Dired.html
(use-package dired
:straight nil
:commands (dired dired-jump)
:config
(setq dired-dwim-target t))
#+end_src
*** Org (org-mode)
#+begin_src emacs-lisp :tangle "init.el" #+begin_src emacs-lisp :tangle "init.el"
;; Org mode (organization outline framework) ;; Org mode (organization outline framework)
@ -593,7 +608,9 @@ Builtin Emacs directory editor
;; :straight t) ;; :straight t)
#+end_src #+end_src
*** Markdown Mode (markdown-mode) **** Markdown Mode (markdown-mode)
Markdown is not supported filetype with Emacs, must use package.
#+begin_src emacs-lisp :tangle "init.el" #+begin_src emacs-lisp :tangle "init.el"
;;; Markdown support for emacs ;;; Markdown support for emacs
@ -604,10 +621,12 @@ Builtin Emacs directory editor
:init (setq markdown-command "multimarkdown") :init (setq markdown-command "multimarkdown")
(setq markdown-fontify-code-blocks-natively t) ; Make code block syntax highlighted (setq markdown-fontify-code-blocks-natively t) ; Make code block syntax highlighted
:bind(:map markdown-mode-map :bind(:map markdown-mode-map
("C-c C-e" . markdown-do))) ("C-c C-e" . markdown-do)))
#+end_src #+end_src
*** Magit (git mode) **** Magit (git)
It is magit. Git UI in Emacs.
#+begin_src emacs-lisp :tangle "init.el" #+begin_src emacs-lisp :tangle "init.el"
;; Magit (intuitive git interface) ;; Magit (intuitive git interface)
@ -616,7 +635,22 @@ Builtin Emacs directory editor
:straight t) :straight t)
#+end_src #+end_src
*** Dirvish (fancy/modern dired) **** Dired Mode
Builtin Emacs directory editor
#+begin_src emacs-lisp :tangle "init.el"
;; https://www.gnu.org/software/emacs/manual/html_node/emacs/Dired.html
(use-package dired
:straight nil
:commands (dired dired-jump)
:config
(setq dired-dwim-target t))
#+end_src
**** Dirvish (fancy/modern dired)
This package makes `dired` look completely different (in a good way).
#+begin_src emacs-lisp :tangle "init.el" #+begin_src emacs-lisp :tangle "init.el"
;; Fancy, polished and modernized dired ;; Fancy, polished and modernized dired
@ -634,103 +668,115 @@ Builtin Emacs directory editor
(dirvish-peek-mode) (dirvish-peek-mode)
(dirvish-side-follow-mode) (dirvish-side-follow-mode)
(setq dirvish-mode-line-format (setq dirvish-mode-line-format
'(:left (sort symlink) :right (omit yank index))) '(:left (sort symlink) :right (omit yank index)))
(setq dirvish-attributes ; The order *MATTERS* for some attributes (setq dirvish-attributes ; The order *MATTERS* for some attributes
'(vc-state subtree-state nerd-icons collapse git-msg file-time file-size) '(vc-state subtree-state nerd-icons collapse git-msg file-time file-size)
dirvish-side-attributes dirvish-side-attributes
'(vc-state nerd-icons collapse file-size)) '(vc-state nerd-icons collapse file-size))
(setq dirvish-large-directory-threshold 20000) (setq dirvish-large-directory-threshold 20000)
:bind :bind
(("C-c -" . dirvish-side) (("C-c -" . dirvish-side)
:map dirvish-mode-map ; Dirvish inherits `dired-mode-map' :map dirvish-mode-map ; Dirvish inherits `dired-mode-map'
(";" . dired-up-directory) ; So you can adjust `dired' bindings here (";" . dired-up-directory) ; So you can adjust `dired' bindings here
("?" . dirvish-dispatch) ; [?] a helpful cheatsheet ("?" . dirvish-dispatch) ; [?] a helpful cheatsheet
("a" . dirvish-setup-menu) ; [a]ttributes settings:`t' toggles mtime, `f' toggles fullframe, etc. ("a" . dirvish-setup-menu) ; [a]ttributes settings:`t' toggles mtime, `f' toggles fullframe, etc.
("f" . dirvish-file-info-menu) ; [f]ile info ("f" . dirvish-file-info-menu) ; [f]ile info
("o" . dirvish-quick-access) ; [o]pen `dirvish-quick-access-entries' ("o" . dirvish-quick-access) ; [o]pen `dirvish-quick-access-entries'
("s" . dirvish-quicksort) ; [s]ort flie list ("s" . dirvish-quicksort) ; [s]ort flie list
("r" . dirvish-history-jump) ; [r]ecent visited ("r" . dirvish-history-jump) ; [r]ecent visited
("l" . dirvish-ls-switches-menu) ; [l]s command flags ("l" . dirvish-ls-switches-menu) ; [l]s command flags
("v" . dirvish-vc-menu) ; [v]ersion control commands ("v" . dirvish-vc-menu) ; [v]ersion control commands
("*" . dirvish-mark-menu) ("*" . dirvish-mark-menu)
("y" . dirvish-yank-menu) ("y" . dirvish-yank-menu)
("N" . dirvish-narrow) ("N" . dirvish-narrow)
("^" . dirvish-history-last) ("^" . dirvish-history-last)
("TAB" . dirvish-subtree-toggle) ("TAB" . dirvish-subtree-toggle)
("M-f" . dirvish-history-go-forward) ("M-f" . dirvish-history-go-forward)
("M-b" . dirvish-history-go-backward) ("M-b" . dirvish-history-go-backward)
("M-e" . dirvish-emerge-menu))) ("M-e" . dirvish-emerge-menu)))
#+end_src #+end_src
*** Theme and Highlight (doom-themes) **** Extra Themes, Colorschemes, Highlight and Random Effects
Change the look and feel of Emacs.
#+begin_src emacs-lisp :tangle "init.el" #+begin_src emacs-lisp :tangle "init.el"
;; https://github.com/doomemacs/themes ;; https://github.com/doomemacs/themes
(use-package doom-themes (use-package doom-themes
:straight t :straight t
:config) :config)
;; (load-theme 'doom-badger t)) ;; (load-theme 'doom-badger t))
;; (load-theme 'doom-ir-black t)) ;; (load-theme 'doom-ir-black t))
;; Doom Modeline - much easier on the eyes ;; Doom Modeline - much easier on the eyes
;; https://github.com/seagle0128/doom-modeline ;; https://github.com/seagle0128/doom-modeline
(use-package doom-modeline (use-package doom-modeline
:straight t :straight t
:hook (after-init . doom-modeline-mode)) :hook (after-init . doom-modeline-mode))
;; Sticky headers for programming modes ;; Sticky headers for programming modes
;; https://github.com/alphapapa/topsy.el ;; https://github.com/alphapapa/topsy.el
(use-package topsy (use-package topsy
:straight t) :straight t)
;; :hook (prog-mode . topsy-mode)) ;; :hook (prog-mode . topsy-mode))
;; Highlights TODOs and other configured keywords in buffer ;; Highlights TODOs and other configured keywords in buffer
;; https://github.com/tarsius/hl-todo ;; https://github.com/tarsius/hl-todo
(use-package hl-todo (use-package hl-todo
:straight t :straight t
:hook (prog-mode . hl-todo-mode) :hook (prog-mode . hl-todo-mode)
:config :config
(setq hl-todo-highlight-punctuation ":" (setq hl-todo-highlight-punctuation ":"
hl-todo-keyword-faces hl-todo-keyword-faces
`(("TODO" warning bold) `(("TODO" warning bold)
("FIXME" error bold) ("FIXME" error bold)
("HACK" font-lock-constant-face bold) ("HACK" font-lock-constant-face bold)
("REVIEW" font-lock-keyword-face bold) ("REVIEW" font-lock-keyword-face bold)
("NOTE" success bold) ("NOTE" success bold)
("DEPRECATED" font-lock-doc-face bold)))) ("DEPRECATED" font-lock-doc-face bold))))
; TODO: look into todo integrations ; TODO: look into todo integrations
;; Colorize color names in buffers ;; Colorize color names in buffers
;; https://github.com/emacsmirror/rainbow-mode ;; https://github.com/emacsmirror/rainbow-mode
(use-package rainbow-mode (use-package rainbow-mode
:straight t) :straight t)
;; Rainbow Delimiters - who doesn't love colors ;; Rainbow Delimiters - who doesn't love colors
;; https://github.com/Fanael/rainbow-delimiters ;; https://github.com/Fanael/rainbow-delimiters
(use-package rainbow-delimiters (use-package rainbow-delimiters
:straight t :straight t
:init (add-hook 'prog-mode-hook #'rainbow-delimiters-mode)) :init (add-hook 'prog-mode-hook #'rainbow-delimiters-mode))
;; Git Gutter -- sidebar / fringe indicators of changes ;; Git Gutter -- sidebar / fringe indicators of changes
;; https://github.com/emacsorphanage/git-gutter ;; https://github.com/emacsorphanage/git-gutter
(use-package git-gutter (use-package git-gutter
:hook (prog-mode . git-gutter-mode) :hook (prog-mode . git-gutter-mode)
:straight t :straight t
:config :config
(setq git-gutter:update-interval 0.2)) (setq git-gutter:update-interval 0.2))
;; TODO: disable this in terminal mode ;; TODO: disable this in terminal mode
;; highlights the modified region (yank/kill) ;; highlights the modified region (yank/kill)
;; https://github.com/minad/goggles ;; https://github.com/minad/goggles
(use-package goggles (use-package goggles
:straight t :straight t
:hook ((prog-mode org-mode) . goggles-mode) :hook ((prog-mode org-mode) . goggles-mode)
:config :config
(goggles-define yank evil-paste-after) ; make pasting from evil mode highlighted (goggles-define yank evil-paste-after) ; make pasting from evil mode highlighted
(setq-default goggles-pulse t)) (setq-default goggles-pulse t))
;; NYAN x inf
;; https://github.com/TeMPOraL/nyan-mode
(use-package nyan-mode
:straight t)
#+end_src #+end_src
*** Minibuffer Completion *** Completion
**** Minibuffer Completion Packages
Minibuffer defaults are pretty rough out of the box. Completion is there, but the UX is pretty bad...
These packages (vertico, orderless, marginalia) give better UX for minibuffer as well as ease of customization.
#+begin_src emacs-lisp :tangle "init.el" #+begin_src emacs-lisp :tangle "init.el"
;;; Mini-buffer improvements (fido, orderless, marginalia) ;;; Mini-buffer improvements (fido, orderless, marginalia)
@ -767,33 +813,36 @@ Builtin Emacs directory editor
(use-package consult (use-package consult
:straight t :straight t
:bind ( :bind (
("C-x M-:" . consult-complex-command) ;; orig. repeat-complex-command ("C-x M-:" . consult-complex-command) ;; orig. repeat-complex-command
("C-x b" . consult-buffer) ;; orig. switch-to-buffer ("C-x b" . consult-buffer) ;; orig. switch-to-buffer
("C-x 4 b" . consult-buffer-other-window) ;; orig. switch-to-buffer-other-window ("C-x 4 b" . consult-buffer-other-window) ;; orig. switch-to-buffer-other-window
("C-x 5 b" . consult-buffer-other-frame) ;; orig. switch-to-buffer-other-frame ("C-x 5 b" . consult-buffer-other-frame) ;; orig. switch-to-buffer-other-frame
("C-x t b" . consult-buffer-other-tab) ;; orig. switch-to-buffer-other-tab ("C-x t b" . consult-buffer-other-tab) ;; orig. switch-to-buffer-other-tab
("C-x r b" . consult-bookmark) ;; orig. bookmark-jump ("C-x r b" . consult-bookmark) ;; orig. bookmark-jump
("C-x p b" . consult-project-buffer) ;; orig. project-switch-to-buffer ("C-x p b" . consult-project-buffer) ;; orig. project-switch-to-buffer
;; Custom M-# bindings for fast register access ;; Custom M-# bindings for fast register access
("M-#" . consult-register-load) ("M-#" . consult-register-load)
("M-'" . consult-register-store) ;; orig. abbrev-prefix-mark (unrelated) ("M-'" . consult-register-store) ;; orig. abbrev-prefix-mark (unrelated)
("C-M-#" . consult-register) ("C-M-#" . consult-register)
;; Other custom bindings ;; Other custom bindings
("M-y" . consult-yank-pop) ;; orig. yank-pop ("M-y" . consult-yank-pop) ;; orig. yank-pop
;; Minibuffer history ;; Minibuffer history
:map minibuffer-local-map :map minibuffer-local-map
("M-s" . consult-history) ;; orig. next-matching-history-element ("M-s" . consult-history) ;; orig. next-matching-history-element
("M-r" . consult-history)) ;; orig. previous-matching-history-element ("M-r" . consult-history)) ;; orig. previous-matching-history-element
:hook (completion-list-mode . consult-preview-at-point-mode) :hook (completion-list-mode . consult-preview-at-point-mode)
:init :init
(advice-add #'register-preview :override #'consult-register-window) (advice-add #'register-preview :override #'consult-register-window)
(setq register-preview-delay 0.5) (setq register-preview-delay 0.5)
(setq xref-show-xrefs-function #'consult-xref (setq xref-show-xrefs-function #'consult-xref
xref-show-definitions-function #'consult-xref)) xref-show-definitions-function #'consult-xref))
#+end_src #+end_src
*** Completion At Point (in main buffers) **** Completion At Point (in main buffers)
Completion at point usually happens in main buffers, the main concern of `corfu` and `cape` is providing the UI elements.
Most of the functionality for completion comes from other functions within Emacs as far as I understand.
#+begin_src emacs-lisp :tangle "init.el" #+begin_src emacs-lisp :tangle "init.el"
;; corfu: mini completion ui ;; corfu: mini completion ui
@ -837,29 +886,10 @@ Builtin Emacs directory editor
(read-extended-command-predicate #'command-completion-default-include-p)) (read-extended-command-predicate #'command-completion-default-include-p))
#+end_src #+end_src
*** Better and More Helpful Menus *** Programming Languages
**** Syntax Checking and Formatting
#+begin_src emacs-lisp :tangle "init.el" Basic syntax checking and formatting.
;;; Better discoverability for key mappings (which-key)
;; https://github.com/justbur/emacs-which-key
;; builtin to emacs > 30.1
(use-package which-key
:straight t
:init (which-key-mode 1))
;;; Better help menus (helpful)
;; https://github.com/Wilfred/helpful
(use-package helpful
:straight t
:bind
(("C-c C-d" . helpful-at-point) ; Lookup the symbol at point
("C-h f" . helpful-callable) ; Describe a function
("C-h v" . helpful-variable) ; Describe a variable
("C-h k" . helpful-key) ; Describe a key binding
("C-h x" . helpful-command))) ; Describe a command
#+end_src
*** Syntax Checking and Formatting
#+begin_src emacs-lisp :tangle "init.el" #+begin_src emacs-lisp :tangle "init.el"
;; Syntax checking ;; Syntax checking
@ -867,7 +897,7 @@ Builtin Emacs directory editor
;; https://github.com/flycheck/flycheck ;; https://github.com/flycheck/flycheck
(use-package flycheck (use-package flycheck
:straight t :straight t
:init (add-hook 'after-init-hook #'global-flycheck-mode)) :init (global-flycheck-mode))
;;; External code formatting tool integration (format-all) ;;; External code formatting tool integration (format-all)
;; https://github.com/lassik/emacs-format-all-the-code ;; https://github.com/lassik/emacs-format-all-the-code
@ -887,7 +917,24 @@ Builtin Emacs directory editor
(global-whitespace-cleanup-mode)) (global-whitespace-cleanup-mode))
#+end_src #+end_src
*** Abbrevs and Snippets **** Compile Mode
Compile the interpreters and interpret the compilers.
#+begin_src emacs-lisp :tangle "init.el"
(use-package compile
:straight nil
:config
(setq compilation-scroll-output t))
(add-hook 'python-mode-hook
(lambda () (set (make-local-variable 'compile-command)
(format "python3 %s" (file-name-nondirectory buffer-file-name)))))
#+end_src
**** Abbrevs and Snippets
Abbreviations and Snippets simply allow for less typing and more output.
#+begin_src emacs-lisp :tangle "init.el" #+begin_src emacs-lisp :tangle "init.el"
;; Abbrevs and Snippets ;; Abbrevs and Snippets
@ -921,37 +968,36 @@ Builtin Emacs directory editor
:init) :init)
#+end_src #+end_src
*** Extra Language Modes **** LSP
Add language server protocol using eglot. Installing LSP servers is a separate process.
#+begin_src emacs-lisp :tangle "init.el" #+begin_src emacs-lisp :tangle "init.el"
;; LSP Modes
(use-package eglot (use-package eglot
:straight nil :straight nil
:defer t :defer t
:hook ((python-mode . eglot-ensure) :hook ((python-mode . eglot-ensure)
(go-mode . eglot-ensure))) (go-mode . eglot-ensure)))
;;; Extra Language Modes ;; Allow flycheck errors to show with eglot
;;https://github.com/flycheck/flycheck-eglot
;; (use-package flycheck-eglot
;; :straight t
;; :after (flycheck eglot)
;; :config
;; (global-flycheck-eglot-mode 1))
#+end_src
**** Additional Language Settings
More setup for languages beyond LSP
#+begin_src emacs-lisp :tangle "init.el"
;; Lua mode ;; Lua mode
(use-package lua-mode (use-package lua-mode
:straight t) :straight t)
;;; Other misc modes (docker, gptel, load-env-vars, csv-mode)
(use-package docker
:straight t
:defer t)
(use-package dockerfile-mode
:straight t
:defer t)
(use-package csv-mode
:straight t
:defer t)
#+end_src
*** Additional Language Settings
#+begin_src emacs-lisp :tangle "init.el"
;; JavaScript ;; JavaScript
(use-package js (use-package js
:defer t :defer t
@ -989,13 +1035,40 @@ Builtin Emacs directory editor
(package-install 'json-mode)) (package-install 'json-mode))
(setq-default major-mode (setq-default major-mode
(lambda () ; guess major mode from file name (lambda () ; guess major mode from file name
(unless buffer-file-name (unless buffer-file-name
(let ((buffer-file-name (buffer-name))) (let ((buffer-file-name (buffer-name)))
(set-auto-mode))))) (set-auto-mode)))))
#+end_src #+end_src
*** Local Environment Variables **** Misc Config Language Settings
More obscure langauges (or configuration modes)
#+begin_src emacs-lisp :tangle "init.el"
;;; Extra Language Modes
;; docker
(use-package docker
:straight t
:defer t)
(use-package dockerfile-mode
:straight t
:defer t)
;; csv
(use-package csv-mode
:straight t
:defer t)
;; vimrc
(use-package vimrc-mode
:straight t)
#+end_src
*** Integrate External Tools
**** Local Environment Variables
Pick up local environment variables (if that file exists)
#+begin_src emacs-lisp :tangle "init.el" #+begin_src emacs-lisp :tangle "init.el"
;; Local Environment File ;; Local Environment File
@ -1005,10 +1078,12 @@ Builtin Emacs directory editor
(defvar my-env-file "~/.local/.env" "Local environment file.") (defvar my-env-file "~/.local/.env" "Local environment file.")
(let ((my-env-file "~/.local/.env")) (let ((my-env-file "~/.local/.env"))
(if (file-exists-p my-env-file) (if (file-exists-p my-env-file)
(load-env-vars my-env-file))) (load-env-vars my-env-file)))
#+end_src #+end_src
*** LLM Support **** LLM Support
Setup LLMs here (at some point)
#+begin_src emacs-lisp :tangle "init.el" #+begin_src emacs-lisp :tangle "init.el"
;; LLM support (must configure with api keys) ;; LLM support (must configure with api keys)
@ -1021,8 +1096,11 @@ Builtin Emacs directory editor
;; (gptel-make-openai "OpenAI" :stream t :key gptel-api-key) ;; (gptel-make-openai "OpenAI" :stream t :key gptel-api-key)
#+end_src #+end_src
** Windows (win32)
*** Windows / Win32 Specifics *** Windows / Win32 Specifics
Those things that are just for Windows, specially for Windows operating systems.
#+begin_src emacs-lisp :tangle "init.el" #+begin_src emacs-lisp :tangle "init.el"
;; for Win32 ;; for Win32
(when (eq system-type 'windows-nt) (when (eq system-type 'windows-nt)
@ -1033,12 +1111,12 @@ Builtin Emacs directory editor
(set-frame-font "Cascadia Code 12" nil t) (set-frame-font "Cascadia Code 12" nil t)
(let ((xlist (let ((xlist
'( '(
"C:/Program Files/PowerShell/7/pwsh.exe" "C:/Program Files/PowerShell/7/pwsh.exe"
"~/AppData/Local/Microsoft/WindowsApps/pwsh.exe" "~/AppData/Local/Microsoft/WindowsApps/pwsh.exe"
"C:/Windows/System32/WindowsPowerShell/v1.0/powershell.exe" "C:/Windows/System32/WindowsPowerShell/v1.0/powershell.exe"
)) ))
xfound) xfound)
(setq xfound (seq-some (lambda (x) (if (file-exists-p x) x nil)) xlist)) (setq xfound (seq-some (lambda (x) (if (file-exists-p x) x nil)) xlist))
(when xfound (setq explicit-shell-file-name xfound)))) (when xfound (setq explicit-shell-file-name xfound))))
@ -1064,31 +1142,18 @@ Builtin Emacs directory editor
;; xah-lee functions ;; xah-lee functions
;; http://xahlee.info/index.html ;; http://xahlee.info/index.html
(defun x-open-in-vscode () (defun open-in-vscode ()
"Open current file or dir in vscode." "Open current file or dir in vscode."
(interactive) (interactive)
(let ((xpath (if buffer-file-name buffer-file-name (expand-file-name default-directory)))) (let ((xpath (if buffer-file-name buffer-file-name (expand-file-name default-directory))))
(message "path is %s" xpath) (message "path is %s" xpath)
(cond (cond
((eq system-type 'darwin) ((eq system-type 'darwin)
(shell-command (format "open -a Visual\\ Studio\\ Code.app %s" (shell-quote-argument xpath)))) (shell-command (format "open -a Visual\\ Studio\\ Code.app %s" (shell-quote-argument xpath))))
((eq system-type 'windows-nt) ((eq system-type 'windows-nt)
(shell-command (format "code.cmd %s" (shell-quote-argument xpath)))) (shell-command (format "code.cmd %s" (shell-quote-argument xpath))))
((eq system-type 'gnu/linux) ((eq system-type 'gnu/linux)
(shell-command (format "code %s" (shell-quote-argument xpath))))))) (shell-command (format "code %s" (shell-quote-argument xpath)))))))
(defun x-open-in-terminal ()
"Open the current dir in a new terminal window."
(interactive)
(cond
((eq system-type 'windows-nt)
(shell-command (concat "wt -d " (shell-quote-argument (expand-file-name default-directory)))))
((eq system-type 'darwin)
(shell-command (concat "open -a iTerm " (shell-quote-argument (expand-file-name default-directory)))))
((eq system-type 'gnu/linux)
(let ((process-connection-type nil)) (start-process "" nil "x-terminal-emulator" (concat "--working-directory=" default-directory))))
((eq system-type 'berkeley-unix)
(let ((process-connection-type nil)) (start-process "" nil "x-terminal-emulator" (concat "--working-directory=" default-directory))))))
#+end_src #+end_src
*** Misc Windows Dotfiles Setup *** Misc Windows Dotfiles Setup