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)
;; No thanks
(setq inhibit-startup-message t) ; Disable startup message
(scroll-bar-mode -1) ; Disable visible scrollbar
(tool-bar-mode -1) ; Disable the toolbar
(tooltip-mode -1) ; Disable tooltips
(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
;; Disable startup message
(setq inhibit-startup-message t)
;; Don't ask about running processes on exit
(setq confirm-kill-processes nil)
;; Visible bell
(setq visible-bell t)
; Font - Does nothing if mixed-pitch package is used
;(set-face-attribute 'default nil :font "ibm plex mono light" :height 100)
;; Write external customizations to /dev/null
(setq-default custom-file null-device)
;; Make ESC quit prompts
(global-set-key (kbd "<escape>") 'keyboard-escape-quit)
;; Disable some GUI options
(menu-bar-mode -1)
(scroll-bar-mode -1)
(tool-bar-mode -1)
(tooltip-mode -1)
;; paren/bracket pairs
(show-paren-mode t)
(setq-default show-paren-style 'parenthesis)
(electric-pair-mode 1)
;; Fringe width
(set-fringe-mode 10)
;; 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
(add-hook 'emacs-startup-hook
@ -34,27 +41,32 @@
(time-subtract after-init-time before-init-time)))
gcs-done)))
;; Change the user-emacs-directory to keep ~/.emacs.d clean
(setq user-emacs-directory (expand-file-name "~/.cache/emacs/")
;; ESC behaves like C-g
(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))
;; Store autosaves in cache dir instead of littering all over the filesystem
;; Store autosaves in $XDG_CACHE_HOME
(setq auto-save-file-name-transforms
`((".*" "~/.cache/emacs/autosave/" t)))
;; No annoying Windows errors
;; Default encoding
(set-default-coding-systems 'utf-8)
;; Disable suspend-frame shortcut
(define-key global-map "\C-z" nil)
;; More reasonable keybinds for resizing windows
(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-<down>") 'shrink-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-progressive-speed nil) ; acceleration
(setq mouse-wheel-follow-mouse 't) ; scroll window under cursor
@ -77,10 +89,12 @@
conf-mode-hook))
(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)
(add-hook 'prog-mode-hook #'display-fill-column-indicator-mode)
;;; PACKAGE MANAGEMENT:
;; Install and load straight.el
(defvar bootstrap-version)
(let ((bootstrap-file
@ -95,77 +109,15 @@
(eval-print-last-sexp)))
(load bootstrap-file nil 'nomessage))
;;;;;;;;;;;;;; Not needed when using straight.el ;;;;;;;;;;;;;;
;; Initialize package sources
;(require 'package)
;(setq package-archives '(("melpa" . "https://melpa.org/packages/")
; ("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
;; use-package
(straight-use-package 'use-package)
;; Make use-package use straight.el
;; use-package/straight integration
(use-package straight
:custom (straight-use-package-by-default t))
;; Theme
(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)
;;; PACKAGES:
;; Automatically set paths to the new user-emacs-directory
(use-package no-littering)
@ -175,7 +127,7 @@
:hook ((text-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
:init (which-key-mode)
:config
@ -368,7 +320,6 @@
(use-package consult-yasnippet)
;; Alternate completion style
(use-package orderless
:init
;; Configure a custom style dispatcher (see the Consult wiki)
@ -379,7 +330,6 @@
completion-category-overrides '((file (styles partial-completion)))))
;; Contextual actions
(use-package marginalia
:config
(marginalia-mode))
@ -403,9 +353,8 @@
:hook
(embark-collect-mode . consult-preview-at-point-mode))
;; Org-mode
;;; ORG-MODE:
; No line numbers in org-mode
(dolist (mode '(org-mode-hook))
(add-hook mode (lambda () (display-line-numbers-mode 0))))
@ -418,6 +367,54 @@
(use-package org-appear
: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
;:hook
;(org-mode . mixed-pitch-mode)
@ -427,14 +424,76 @@
(set-face-attribute 'variable-pitch nil :font "DejaVu Sans" :height 100))
;(add-hook 'mixed-pitch-mode-hook #'solaire-mode-reset)
(use-package org-superstar
:hook
(org-mode . org-superstar-mode)
;; Icons
(use-package all-the-icons)
;; 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
(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
(use-package lsp-mode
:init
(setq lsp-keymap-prefix "C-c l")
@ -490,29 +549,7 @@
(setq lsp-ui-peek-peek-height 25)
(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
(use-package dap-mode
:after lsp-mode
:commands dap-debug
@ -544,52 +581,29 @@
(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
(use-package flycheck
:hook (lsp-mode . flycheck-mode)
:config
(setq flycheck-python-flake8-executable "flake8"))
;; 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))
;;; Languages/Tools
;; Highlighting/Formatting
;; Format on save
(use-package apheleia
:init
(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
:config
(global-tree-sitter-mode)
(add-hook 'tree-sitter-after-on-hook #'tree-sitter-hl-mode))
(use-package tree-sitter-langs
:after tree-sitter)
(use-package tree-sitter-langs)
;; C/C++
(setq dap-lldb-debug-program '("/usr/bin/lldb-vscode"))
(setq-default c-default-style "k&r")
(setq-default c-basic-offset 2)
@ -604,13 +618,11 @@
;; Golang
(use-package go-mode
:config
(add-hook 'before-save-hook #'lsp-organize-imports))
;; (use-package go-mode
;; :config
;; (add-hook 'before-save-hook #'lsp-organize-imports))
;; JavaScript/TypeScript, HTML, CSS
;; JavaScript/TypeScript, Web
(setq css-indent-level 2)
(setq css-indent-offset 2)
(setq js-indent-level 2)
@ -677,20 +689,16 @@
:bind ("C-c C-n" . jsdoc))
;; LaTeX
;(use-package lsp-latex)
;'(setq lsp-tex-server 'digestif)
;; OpenGL / GLSL
(use-package glsl-mode)
;; Protocol Buffers
;; (use-package protobuf-mode)
(use-package protobuf-mode)
;; Python
(setq dap-python-debugger 'debugpy)
(use-package lsp-pyright
@ -717,7 +725,6 @@
(conda-env-activate-for-buffer)))))
;; Rust
(use-package rustic
:ensure
:bind (:map rustic-mode-map
@ -732,7 +739,7 @@
("C-c C-c e" . lsp-rust-analyzer-expand-macro)
("C-c C-c d" . dap-hydra)
("C-c C-c h" . lsp-ui-doc-glance)))
:config
;; :config
;; uncomment for less flashiness
;; (setq lsp-eldoc-hook nil)
;; (setq lsp-enable-symbol-highlighting nil)
@ -751,11 +758,9 @@
;; (add-hook 'before-save-hook 'lsp-format-buffer nil t))
;; TOML config files
(use-package toml-mode)
;; Zig
(use-package zig-mode
:config
(add-to-list 'lsp-language-id-configuration '(zig-mode . "zig"))
@ -765,19 +770,4 @@
:major-modes '(zig-mode)
: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

View file

Before

Width:  |  Height:  |  Size: 282 KiB

After

Width:  |  Height:  |  Size: 282 KiB