Move custom emacs files to XDG_DATA_DIR, format init.el

This commit is contained in:
Andrew Scott 2023-06-11 23:55:07 -04:00
parent 0b715d6a2d
commit 04f26cd3ea
Signed by: a
GPG key ID: 7CD5A5977E4931C1
37 changed files with 176 additions and 186 deletions

View file

@ -1,29 +1,36 @@
; Disable package.el early so it won't start loading packages before init is loaded ;;; init.el --- GNU Emacs Initialization File
;;; OPTIONS:
;; Disable package.el (interferes with straight.el)
(setq package-enable-at-startup nil) (setq package-enable-at-startup nil)
;; No thanks ;; Disable startup message
(setq inhibit-startup-message t) ; Disable startup message (setq inhibit-startup-message t)
(scroll-bar-mode -1) ; Disable visible scrollbar
(tool-bar-mode -1) ; Disable the toolbar ;; Don't ask about running processes on exit
(tooltip-mode -1) ; Disable tooltips (setq confirm-kill-processes nil)
(set-fringe-mode 10) ; Add come extra space to the left/right sides
(menu-bar-mode -1) ; Disable the menu bar
(setq-default custom-file null-device) ; Write customizations not in this file to the null device (AKA stop littering in my init.el)
(setq confirm-kill-processes nil) ; Stop asking about running processes on exit
;; Visible bell ;; Visible bell
(setq visible-bell t) (setq visible-bell t)
; Font - Does nothing if mixed-pitch package is used ;; Write external customizations to /dev/null
;(set-face-attribute 'default nil :font "ibm plex mono light" :height 100) (setq-default custom-file null-device)
;; Make ESC quit prompts ;; Disable some GUI options
(global-set-key (kbd "<escape>") 'keyboard-escape-quit) (menu-bar-mode -1)
(scroll-bar-mode -1)
(tool-bar-mode -1)
(tooltip-mode -1)
;; paren/bracket pairs ;; Fringe width
(show-paren-mode t) (set-fringe-mode 10)
(setq-default show-paren-style 'parenthesis)
(electric-pair-mode 1) ;; Disable suspend-frame shortcut
(define-key global-map "\C-z" nil)
;; Font (does nothing if mixed-pitch is used)
;; (set-face-attribute 'default nil :font "ibm plex mono light" :height 100)
;; Profile emacs startup ;; Profile emacs startup
(add-hook 'emacs-startup-hook (add-hook 'emacs-startup-hook
@ -34,27 +41,32 @@
(time-subtract after-init-time before-init-time))) (time-subtract after-init-time before-init-time)))
gcs-done))) gcs-done)))
;; Change the user-emacs-directory to keep ~/.emacs.d clean ;; ESC behaves like C-g
(setq user-emacs-directory (expand-file-name "~/.cache/emacs/") (global-set-key (kbd "<escape>") 'keyboard-escape-quit)
;; Parenthesis/bracket pairs
(show-paren-mode t)
(setq-default show-paren-style 'parenthesis)
(electric-pair-mode 1)
;; Relocate emacs-user-directory to $XDG_DATA_HOME
(setq user-emacs-directory (expand-file-name "~/.local/share/emacs/")
url-history-file (expand-file-name "url/history" user-emacs-directory)) url-history-file (expand-file-name "url/history" user-emacs-directory))
;; Store autosaves in cache dir instead of littering all over the filesystem ;; Store autosaves in $XDG_CACHE_HOME
(setq auto-save-file-name-transforms (setq auto-save-file-name-transforms
`((".*" "~/.cache/emacs/autosave/" t))) `((".*" "~/.cache/emacs/autosave/" t)))
;; No annoying Windows errors ;; Default encoding
(set-default-coding-systems 'utf-8) (set-default-coding-systems 'utf-8)
;; Disable suspend-frame shortcut
(define-key global-map "\C-z" nil)
;; More reasonable keybinds for resizing windows ;; More reasonable keybinds for resizing windows
(global-set-key (kbd "S-C-<left>") 'shrink-window-horizontally) (global-set-key (kbd "S-C-<left>") 'shrink-window-horizontally)
(global-set-key (kbd "S-C-<right>") 'enlarge-window-horizontally) (global-set-key (kbd "S-C-<right>") 'enlarge-window-horizontally)
(global-set-key (kbd "S-C-<down>") 'shrink-window) (global-set-key (kbd "S-C-<down>") 'shrink-window)
(global-set-key (kbd "S-C-<up>") 'enlarge-window) (global-set-key (kbd "S-C-<up>") 'enlarge-window)
;; scrolling ;; Scrolling
(setq mouse-wheel-scroll-amount '(4 ((shift) . 1))) ; 1: lines to scroll, 2: while holding shift (setq mouse-wheel-scroll-amount '(4 ((shift) . 1))) ; 1: lines to scroll, 2: while holding shift
(setq mouse-wheel-progressive-speed nil) ; acceleration (setq mouse-wheel-progressive-speed nil) ; acceleration
(setq mouse-wheel-follow-mouse 't) ; scroll window under cursor (setq mouse-wheel-follow-mouse 't) ; scroll window under cursor
@ -77,10 +89,12 @@
conf-mode-hook)) conf-mode-hook))
(add-hook mode (lambda () (display-line-numbers-mode 1)))) (add-hook mode (lambda () (display-line-numbers-mode 1))))
;; Show vertical line at column 80 in prog-mode ;; Line width indicator
(setq-default fill-column 80) (setq-default fill-column 80)
(add-hook 'prog-mode-hook #'display-fill-column-indicator-mode) (add-hook 'prog-mode-hook #'display-fill-column-indicator-mode)
;;; PACKAGE MANAGEMENT:
;; Install and load straight.el ;; Install and load straight.el
(defvar bootstrap-version) (defvar bootstrap-version)
(let ((bootstrap-file (let ((bootstrap-file
@ -95,77 +109,15 @@
(eval-print-last-sexp))) (eval-print-last-sexp)))
(load bootstrap-file nil 'nomessage)) (load bootstrap-file nil 'nomessage))
;;;;;;;;;;;;;; Not needed when using straight.el ;;;;;;;;;;;;;;
;; Initialize package sources
;(require 'package)
;(setq package-archives '(("melpa" . "https://melpa.org/packages/") ;; use-package
; ("org" . "https://orgmode.org/elpa/")
; ("elpa" . "https://elpa.gnu.org/packages/")))
;(package-initialize)
;(unless package-archive-contents
; (package-refresh-contents))
;; Initialize use-package on non-Linux platforms
;(unless (package-installed-p 'use-package)
; (package-install 'use-package))
;(require 'use-package)
;(setq use-package-always-ensure t)
;;;;;;;;;;;;;;
;; Install use-package
(straight-use-package 'use-package) (straight-use-package 'use-package)
;; Make use-package use straight.el ;; use-package/straight integration
(use-package straight (use-package straight
:custom (straight-use-package-by-default t)) :custom (straight-use-package-by-default t))
;; Theme ;;; PACKAGES:
(setq custom-safe-themes t)
;; (use-package everforest
;; :straight (:type git :repo "https://git.sr.ht/~theorytoe/everforest-theme"))
(add-to-list 'custom-theme-load-path
(expand-file-name "custom/themes/everforest-theme" user-emacs-directory))
(load-theme 'everforest-hard-dark t)
;; Help distinguish work buffers from others like sidebars and terminal
;; (use-package solaire-mode
;; :init
;; (solaire-global-mode t))
;; Icons
(use-package all-the-icons)
;; Modeline
(use-package minions
:hook (doom-modeline-mode . minions-mode)
(simple-modeline-mode . minions-mode))
(use-package doom-modeline
:init (doom-modeline-mode)
:custom
(doom-modeline-height 32)
;(doom-modeline-bar-width .75)
(doom-modeline-window-width-limit fill-column)
(doom-modeline-lsp t)
(doom-modeline-minor-modes t)
(doom-modeline-persp-name nil)
(doom-modeline-buffer-file-name-style 'truncate-upto-project)
(doom-modeline-major-mode-icon t)
(doom-modeline-major-mode-color-icon t)
(doom-modeline-enable-word-count t)
(doom-modeline-env-version t)
(doom-modeline-env-load-string "..."))
;; Don't remind me about some minor modes
(use-package diminish)
;; Automatically set paths to the new user-emacs-directory ;; Automatically set paths to the new user-emacs-directory
(use-package no-littering) (use-package no-littering)
@ -175,7 +127,7 @@
:hook ((text-mode . ws-butler-mode) :hook ((text-mode . ws-butler-mode)
(prog-mode . ws-butler-mode))) (prog-mode . ws-butler-mode)))
;; Overview of keybindings available based on prefix keys ;; Keybindings overview by prefix key
(use-package which-key (use-package which-key
:init (which-key-mode) :init (which-key-mode)
:config :config
@ -368,7 +320,6 @@
(use-package consult-yasnippet) (use-package consult-yasnippet)
;; Alternate completion style ;; Alternate completion style
(use-package orderless (use-package orderless
:init :init
;; Configure a custom style dispatcher (see the Consult wiki) ;; Configure a custom style dispatcher (see the Consult wiki)
@ -379,7 +330,6 @@
completion-category-overrides '((file (styles partial-completion))))) completion-category-overrides '((file (styles partial-completion)))))
;; Contextual actions ;; Contextual actions
(use-package marginalia (use-package marginalia
:config :config
(marginalia-mode)) (marginalia-mode))
@ -403,9 +353,8 @@
:hook :hook
(embark-collect-mode . consult-preview-at-point-mode)) (embark-collect-mode . consult-preview-at-point-mode))
;; Org-mode ;;; ORG-MODE:
; No line numbers in org-mode
(dolist (mode '(org-mode-hook)) (dolist (mode '(org-mode-hook))
(add-hook mode (lambda () (display-line-numbers-mode 0)))) (add-hook mode (lambda () (display-line-numbers-mode 0))))
@ -418,6 +367,54 @@
(use-package org-appear (use-package org-appear
:hook (org-mode . org-appear-mode)) :hook (org-mode . org-appear-mode))
(use-package org-superstar
:hook
(org-mode . org-superstar-mode)
:config
(setq org-superstar-special-todo-items t))
;;; APPEARANCE:
;; Theme
(setq custom-safe-themes t)
(add-to-list 'custom-theme-load-path
(expand-file-name "custom/themes/everforest-theme" user-emacs-directory))
(load-theme 'everforest-hard-dark t)
;; (use-package everforest
;; :straight (:type git :repo "https://git.sr.ht/~theorytoe/everforest-theme"))
;; Better distinction between work buffers and others
;; (use-package solaire-mode
;; :init
;; (solaire-global-mode t))
;; Modeline
(use-package minions
:hook (doom-modeline-mode . minions-mode)
(simple-modeline-mode . minions-mode))
(use-package doom-modeline
:init (doom-modeline-mode)
:custom
(doom-modeline-height 32)
;(doom-modeline-bar-width .75)
(doom-modeline-window-width-limit fill-column)
(doom-modeline-lsp t)
(doom-modeline-minor-modes t)
(doom-modeline-persp-name nil)
(doom-modeline-buffer-file-name-style 'truncate-upto-project)
(doom-modeline-major-mode-icon t)
(doom-modeline-major-mode-color-icon t)
(doom-modeline-enable-word-count t)
(doom-modeline-env-version t)
(doom-modeline-env-load-string "..."))
;; Font
(use-package mixed-pitch (use-package mixed-pitch
;:hook ;:hook
;(org-mode . mixed-pitch-mode) ;(org-mode . mixed-pitch-mode)
@ -427,14 +424,76 @@
(set-face-attribute 'variable-pitch nil :font "DejaVu Sans" :height 100)) (set-face-attribute 'variable-pitch nil :font "DejaVu Sans" :height 100))
;(add-hook 'mixed-pitch-mode-hook #'solaire-mode-reset) ;(add-hook 'mixed-pitch-mode-hook #'solaire-mode-reset)
(use-package org-superstar ;; Icons
:hook (use-package all-the-icons)
(org-mode . org-superstar-mode)
;; Hide some minor modes
(use-package diminish)
;;; PROJECT MANAGEMENT:
;; Git
(use-package magit
:bind ("C-M-;" . magit-status)
:commands (magit-status magit-get-current-branch)
:custom
(magit-display-buffer-function #'magit-display-buffer-same-window-except-diff-v1))
;; Treemacs
(use-package treemacs
:bind
(:map global-map
("M-0" . treemacs-select-window)
("C-x t 1" . treemacs-delete-other-windows)
("C-x t t" . treemacs)
("C-x t B" . treemacs-bookmark)
("C-x t C-t" . treemacs-find-file)
("C-x t M-t" . treemacs-find-tag)))
(use-package lsp-treemacs
:config :config
(setq org-superstar-special-todo-items t)) (lsp-treemacs-sync-mode 1))
;;; UTILITIES:
;; Text completion
(use-package company
:config
(global-company-mode 1)
(setq company-global-modes '(not gud-mode))
(setq company-global-modes '(not comint-mode))
:custom
(company-idle-delay 0)
(company-minimum-prefix-length 1)
(company-tooltip-align-annotations t)
:bind
(:map company-active-map
("RET" . nil)
("[return]" . nil)
("TAB" . company-complete-selection)
("<tab>" . company-complete-selection)
("C-n" . company-select-next)
("C-p" . company-select-previous)))
;; Templating
(use-package yasnippet
:bind
("C-c y s" . yas-insert-snippet)
("C-c y v" . yas-visit-snippet-file)
:config
(yas-reload-all)
(add-to-list 'yas-snippet-dirs
(expand-file-name "custom/snippets" user-emacs-directory))
:hook
(prog-mode . yas-minor-mode)
(tex-mode . yas-minor-mode)
(latex-mode . yas-minor-mode))
(use-package yasnippet-snippets)
;;; LANGUAGE SUPPORT:
;; LSP ;; LSP
(use-package lsp-mode (use-package lsp-mode
:init :init
(setq lsp-keymap-prefix "C-c l") (setq lsp-keymap-prefix "C-c l")
@ -490,29 +549,7 @@
(setq lsp-ui-peek-peek-height 25) (setq lsp-ui-peek-peek-height 25)
(lsp-ui-doc-show)) (lsp-ui-doc-show))
;; Text completion
(use-package company
:config
(global-company-mode 1)
(setq company-global-modes '(not gud-mode))
(setq company-global-modes '(not comint-mode))
:custom
(company-idle-delay 0)
(company-minimum-prefix-length 1)
(company-tooltip-align-annotations t)
:bind
(:map company-active-map
("RET" . nil)
("[return]" . nil)
("TAB" . company-complete-selection)
("<tab>" . company-complete-selection)
("C-n" . company-select-next)
("C-p" . company-select-previous)))
;; Debugging ;; Debugging
(use-package dap-mode (use-package dap-mode
:after lsp-mode :after lsp-mode
:commands dap-debug :commands dap-debug
@ -544,52 +581,29 @@
(use-package realgud-lldb) (use-package realgud-lldb)
;; Treemacs
(use-package treemacs
:bind
(:map global-map
("M-0" . treemacs-select-window)
("C-x t 1" . treemacs-delete-other-windows)
("C-x t t" . treemacs)
("C-x t B" . treemacs-bookmark)
("C-x t C-t" . treemacs-find-file)
("C-x t M-t" . treemacs-find-tag)))
(use-package lsp-treemacs
:config
(lsp-treemacs-sync-mode 1))
;; Syntax checking ;; Syntax checking
(use-package flycheck (use-package flycheck
:hook (lsp-mode . flycheck-mode) :hook (lsp-mode . flycheck-mode)
:config :config
(setq flycheck-python-flake8-executable "flake8")) (setq flycheck-python-flake8-executable "flake8"))
;; Git ;; Format on save
(use-package magit
:bind ("C-M-;" . magit-status)
:commands (magit-status magit-get-current-branch)
:custom
(magit-display-buffer-function #'magit-display-buffer-same-window-except-diff-v1))
;;; Languages/Tools
;; Highlighting/Formatting
(use-package apheleia (use-package apheleia
:init :init
(apheleia-global-mode +1)) (apheleia-global-mode +1))
(use-package reformatter ;; required for zig fmt
:after zig-mode)
;; Syntax parsing/highlighting (use native tree-sitter on emacs 29+)
(use-package tree-sitter (use-package tree-sitter
:config :config
(global-tree-sitter-mode) (global-tree-sitter-mode)
(add-hook 'tree-sitter-after-on-hook #'tree-sitter-hl-mode)) (add-hook 'tree-sitter-after-on-hook #'tree-sitter-hl-mode))
(use-package tree-sitter-langs (use-package tree-sitter-langs)
:after tree-sitter)
;; C/C++ ;; C/C++
(setq dap-lldb-debug-program '("/usr/bin/lldb-vscode")) (setq dap-lldb-debug-program '("/usr/bin/lldb-vscode"))
(setq-default c-default-style "k&r") (setq-default c-default-style "k&r")
(setq-default c-basic-offset 2) (setq-default c-basic-offset 2)
@ -604,13 +618,11 @@
;; Golang ;; Golang
(use-package go-mode
:config
(add-hook 'before-save-hook #'lsp-organize-imports))
;; (use-package go-mode ;; JavaScript/TypeScript, Web
;; :config
;; (add-hook 'before-save-hook #'lsp-organize-imports))
;; JavaScript/TypeScript, HTML, CSS
(setq css-indent-level 2) (setq css-indent-level 2)
(setq css-indent-offset 2) (setq css-indent-offset 2)
(setq js-indent-level 2) (setq js-indent-level 2)
@ -677,20 +689,16 @@
:bind ("C-c C-n" . jsdoc)) :bind ("C-c C-n" . jsdoc))
;; LaTeX ;; LaTeX
;(use-package lsp-latex) ;(use-package lsp-latex)
;'(setq lsp-tex-server 'digestif) ;'(setq lsp-tex-server 'digestif)
;; OpenGL / GLSL ;; OpenGL / GLSL
(use-package glsl-mode) (use-package glsl-mode)
;; Protocol Buffers ;; Protocol Buffers
(use-package protobuf-mode)
;; (use-package protobuf-mode)
;; Python ;; Python
(setq dap-python-debugger 'debugpy) (setq dap-python-debugger 'debugpy)
(use-package lsp-pyright (use-package lsp-pyright
@ -717,7 +725,6 @@
(conda-env-activate-for-buffer))))) (conda-env-activate-for-buffer)))))
;; Rust ;; Rust
(use-package rustic (use-package rustic
:ensure :ensure
:bind (:map rustic-mode-map :bind (:map rustic-mode-map
@ -732,7 +739,7 @@
("C-c C-c e" . lsp-rust-analyzer-expand-macro) ("C-c C-c e" . lsp-rust-analyzer-expand-macro)
("C-c C-c d" . dap-hydra) ("C-c C-c d" . dap-hydra)
("C-c C-c h" . lsp-ui-doc-glance))) ("C-c C-c h" . lsp-ui-doc-glance)))
:config ;; :config
;; uncomment for less flashiness ;; uncomment for less flashiness
;; (setq lsp-eldoc-hook nil) ;; (setq lsp-eldoc-hook nil)
;; (setq lsp-enable-symbol-highlighting nil) ;; (setq lsp-enable-symbol-highlighting nil)
@ -751,11 +758,9 @@
;; (add-hook 'before-save-hook 'lsp-format-buffer nil t)) ;; (add-hook 'before-save-hook 'lsp-format-buffer nil t))
;; TOML config files ;; TOML config files
(use-package toml-mode) (use-package toml-mode)
;; Zig ;; Zig
(use-package zig-mode (use-package zig-mode
:config :config
(add-to-list 'lsp-language-id-configuration '(zig-mode . "zig")) (add-to-list 'lsp-language-id-configuration '(zig-mode . "zig"))
@ -765,19 +770,4 @@
:major-modes '(zig-mode) :major-modes '(zig-mode)
:server-id 'zls))) :server-id 'zls)))
;; Templating
(use-package yasnippet
:bind
("C-c y s" . yas-insert-snippet)
("C-c y v" . yas-visit-snippet-file)
:config
(yas-reload-all)
(add-to-list 'yas-snippet-dirs
(expand-file-name "custom/snippets" user-emacs-directory))
:hook
(prog-mode . yas-minor-mode)
(tex-mode . yas-minor-mode)
(latex-mode . yas-minor-mode))
(use-package yasnippet-snippets)
;;; End init.el ;;; End init.el

View file

Before

Width:  |  Height:  |  Size: 282 KiB

After

Width:  |  Height:  |  Size: 282 KiB