emacs.d/init.el

595 lines
18 KiB
EmacsLisp
Raw Normal View History

2022-05-13 17:04:23 -04:00
;;; Init --- Emacs settings
;;; Commentary:
;;; Code:
2022-08-03 00:37:37 -04:00
;; set up local directory
(add-to-list 'load-path (expand-file-name "lisp" user-emacs-directory))
(setq-default flycheck-emacs-lisp-load-path 'inherit)
2022-05-03 18:30:29 -04:00
;; set up straight.el
(defvar bootstrap-version)
(let ((bootstrap-file
(expand-file-name "straight/repos/straight.el/bootstrap.el" user-emacs-directory))
(bootstrap-version 5))
(unless (file-exists-p bootstrap-file)
(with-current-buffer
(url-retrieve-synchronously
"https://raw.githubusercontent.com/raxod502/straight.el/develop/install.el"
'silent 'inhibit-cookies)
(goto-char (point-max))
(eval-print-last-sexp)))
(load bootstrap-file nil 'nomessage))
;; set up use-package
(straight-use-package 'use-package)
2022-05-03 18:30:29 -04:00
;; set a bunch of varibles
(setq user-full-name "d_m"
user-mail-address "d_m@plastic-idolatry.com"
straight-use-package-by-default t
package-enable-at-startup nil
straight-vc-git-default-protocol 'https
2022-05-03 18:54:16 -04:00
load-path (cons (concat user-emacs-directory "lisp") load-path)
2022-05-03 18:30:29 -04:00
inhibit-startup-screen t
org-directory "~/org/"
line-move-visual nil
create-lockfiles nil
make-backup-files nil
column-number-mode t
scroll-error-top-bottom t
show-paren-delay 0.5
column-number-mode t
diff-switches "-u"
large-file-warning-threshold nil
sentence-end-double-space nil
mode-line-compact nil
company-idle-delay nil
company-tooltip-idle-delay nil
dired-kill-when-opening-new-dired-buffer t
read-minibuffer-restore-windows t
frame-background-mode 'dark)
2022-07-18 11:53:05 -04:00
;; show matching parenthesis
;(show-paren-mode 1)
2022-05-03 18:30:29 -04:00
;; turn off UI various gizmos
(set-face-attribute 'mode-line nil :box nil)
(when (fboundp 'scroll-bar-mode) (scroll-bar-mode -1))
(when (fboundp 'tool-bar-mode) (tool-bar-mode -1))
(when (fboundp 'menu-bar-mode) (menu-bar-mode -1))
(blink-cursor-mode 0)
;; disable annoying ring-bell when backspace key
;; is pressed in certain situations
2022-07-18 11:53:05 -04:00
(setq ring-bell-function 'ignore)
2022-05-03 18:30:29 -04:00
;; use utf-8
(prefer-coding-system 'utf-8)
2022-07-18 11:53:05 -04:00
(set-language-environment "UTF-8")
(set-default-coding-systems 'utf-8)
2022-05-03 18:30:29 -04:00
;; prioritized list of fonts to try
(defvar my/fonts
'("PragmataPro Mono Liga"
"PragmataPro Mono"
"PragmataPro Liga"
"PragmataPro"
"Iosevka"
"JetBrains Mono"
"Fira Code"))
;; default size to use when loading fonts
(defvar my/font-size 16)
;; see if a given font exists
(defun my/has-font (font)
(member font (font-family-list)))
;; load the first font found (if any)
(defun my/load-first-font (fonts)
(let ((font (seq-find #'my/has-font fonts)))
(when font
(let* ((size (number-to-string my/font-size))
(name (concat font " " size)))
(set-frame-font name nil t)))))
;; set transparency percentage
(defun my/set-transparency (n)
"Set transparency."
(set-frame-parameter (selected-frame) 'alpha (list n n))
(add-to-list 'default-frame-alist (list 'alpha n n)))
;; change transparency interactively
(defun set-transparency ()
"Set transparency interactively."
(interactive)
(let ((n (read-string "Transparency (50-100): " "90")))
(my/set-transparency (string-to-number n))))
2022-08-04 22:19:52 -04:00
2022-05-03 18:30:29 -04:00
;; UI settings when not in a terminal
(when (display-graphic-p)
(setq mac-option-key-is-meta nil
mac-command-key-is-meta t
mac-command-modifier 'meta
mac-option-modifier nil
x-super-keysym 'meta
2022-05-03 18:30:29 -04:00
x-select-request-type '(UTF8_STRING COMPOUND_TEXT TEXT STRING))
(my/load-first-font my/fonts)
(my/set-transparency 90)
2022-05-03 18:30:29 -04:00
(set-foreground-color "#c7c7c7")
(set-background-color "#000000"))
;; set up font ligatures
(use-package pragmatapro-lig
:if (and window-system (my/has-font "PragmataPro"))
2022-05-03 18:30:29 -04:00
:straight (pragmatapro-lig :type git
:host github
:repo "lumiknit/emacs-pragmatapro-ligatures")
:config (add-hook 'prog-mode-hook 'pragmatapro-lig-mode))
;; interactive font size
(defun set-font-size ()
"Set font size interactively."
(interactive)
(let* ((family (face-attribute 'default :family))
(curHeight (face-attribute 'default :height))
(curSize (/ curHeight 10))
(newSize (string-to-number (read-string "Font-size: " (number-to-string curSize))))
(newHeight (* newSize 10)))
(set-face-attribute 'default nil :height newHeight)))
2022-05-05 12:28:09 -04:00
;; try using a fancier mode line
(use-package doom-modeline
:ensure t
:init (doom-modeline-mode 1)
:config
(setq doom-modeline-height 1
2022-05-12 16:05:12 -04:00
doom-modeline-buffer-file-name-style 'truncate-all
;doom-modeline-buffer-file-name-style 'truncate-with-project
2022-05-05 12:28:09 -04:00
;doom-modeline-buffer-file-name-style 'relative-to-project
doom-modeline-buffer-encoding nil)
(display-battery-mode 1))
2022-05-03 18:30:29 -04:00
;; line numbers
2022-05-04 14:29:15 -04:00
(add-hook 'prog-mode-hook 'display-line-numbers-mode)
2022-05-03 18:30:29 -04:00
(setq display-line-numbers "%4d ")
;; allow y or n instead of yes or no
(fset 'yes-or-no-p 'y-or-n-p)
;; C-x p to get back to mark
(bind-key "C-x p" 'pop-to-mark-command)
(setq set-mark-command-repeat-pop t)
2022-05-05 12:28:09 -04:00
;; install icons
(use-package all-the-icons
:if (display-graphic-p)
:config (let ((icon '(all-the-icons-faicon "recycle" :face all-the-icons-dcyan)))
(setq all-the-icons-mode-icon-alist
(cons (cons 'uxntal-mode icon) all-the-icons-mode-icon-alist))
(setq all-the-icons-extension-icon-alist
(cons (cons "tal" icon) all-the-icons-extension-icon-alist))))
;; show function names in modeline
(which-function-mode t)
2022-05-03 18:30:29 -04:00
;; work with multiple files not in same directory
(require 'find-dired)
(setq find-ls-option '("-print0 | xargs -0 ls -ld" . "-ld"))
;; comment regions using C-c # (uncomment with C-u C-c #)
(global-set-key "\C-c#" 'comment-region)
(setq comment-empty-lines nil)
;; indent regions using C-c > and C-c <
(global-set-key "\C-c>" 'indent-region)
(global-set-key "\C-c<" 'unindent-region)
;; use M-g to go to a certain line
(global-set-key "\M-g" 'goto-line)
;; use M-$ to do query-replace-regexp
(global-set-key "\M-$" 'query-replace-regexp)
;; modes
(electric-indent-mode 0)
;; global keybindings
(global-unset-key (kbd "C-z"))
; synchronize emacs exec-path and $PATH
(use-package exec-path-from-shell
:config (when (memq window-system '(mac ns x))
(exec-path-from-shell-initialize)))
;; rainbow delimiters
(use-package rainbow-delimiters)
;; distraction free writing
(use-package writeroom-mode)
;; C-c <left> restore old buffer view after popups
(use-package winner
:config (winner-mode 1))
;; compact mode line
(use-package smart-mode-line)
;; various modes that might come in handy
(use-package markdown-mode)
(use-package racket-mode)
(use-package tuareg)
2022-08-03 00:37:37 -04:00
;(use-package forth-mode)
2022-07-18 11:53:05 -04:00
(use-package rust-mode)
(use-package which-key
:ensure t
:init (which-key-mode))
(defun my/ansi-colorize-buffer ()
(let ((buffer-read-only nil))
(ansi-color-apply-on-region (point-min) (point-max))))
(use-package ansi-color
:ensure t
:config (add-hook 'compilation-filter-hook 'my/ansi-colorize-buffer))
2022-05-03 18:30:29 -04:00
;; scala-mode
(use-package scala-mode
:mode "\\.s\\(cala\\|bt\\)$"
:interpreter ("scala" . scala-mode)
2022-07-18 11:53:05 -04:00
:config (setq scala-indent:indent-value-expression nil
scala-indent:align-parameters nil
scala-indent:align-forms nil
scala-indent:use-javadoc-style t))
(use-package company
:hook (scala-mode . company-mode)
2022-08-03 00:37:37 -04:00
(java-mode . company-mode)
(emacs-lisp-mode . company-mode)
(rust-mode . company-mode)
(python-mode . company-mode)
2022-07-18 11:53:05 -04:00
:bind (("M-/" . company-complete))
:config (add-hook 'after-init-hook 'global-company-mode))
2022-08-03 00:37:37 -04:00
(defvar use-lsp)
2022-07-26 18:01:17 -04:00
(setq use-lsp (equal (system-name) "cult"))
;; when not using lsp use hippie expand
(when (not use-lsp)
;; hippie expand stuff: M-/ to expand things
(bind-key "M-/" 'hippie-expand)
(defun sanityinc/dabbrev-friend-buffer (other-buffer)
(< (buffer-size other-buffer) (* 1 1024 1024)))
(setq dabbrev-friend-buffer-function 'sanityinc/dabbrev-friend-buffer)
(setq hippie-expand-try-functions-list
'(try-expand-all-abbrevs
try-complete-file-name-partially
try-complete-file-name
try-expand-dabbrev
try-expand-dabbrev-from-kill
try-expand-dabbrev-all-buffers
try-expand-list
try-expand-line
try-complete-lisp-symbol-partially
try-complete-lisp-symbol)))
;; Posframe is a pop-up tool that must be manually installed for dap-mode
(use-package posframe
:if use-lsp)
;; Use the Debug Adapter Protocol for running tests and debugging
(use-package dap-mode
:if use-lsp
:hook (lsp-mode . dap-mode)
(lsp-mode . dap-ui-mode))
(use-package flycheck
:if use-lsp
:init (global-flycheck-mode))
(use-package lsp-mode
:if use-lsp
:ensure t
:config (setq lsp-headerline-breadcrumb-enable nil
lsp-keymap-prefix "C-c l"
lsp-enable-symbol-highlighting nil
;lsp-lens-enable nil
;lsp-signature-render-documentation nil
lsp-eldoc-enable-hover nil
;lsp-signature-auto-activate nil
;lsp-enable-file-watchers nil
read-process-output-max (* 1024 1024) ; 1M
lsp-modeline-diagnostics-enable nil
lsp-prefer-capf t
lsp-completion-provider :capf
lsp-completion-enable t
lsp-prefer-flymake nil)
;(setf (lsp--client-multi-root (gethash 'iph lsp-clients)) nil)
(define-key lsp-mode-map (kbd "C-c l") lsp-command-map)
:hook (lsp-mode . lsp-lens-mode)
(lsp-mode . lsp-enable-which-key-integration)
(scala-mode . lsp)
(rust-mode . lsp)
(java-mode . lsp))
(use-package lsp-metals
:if use-lsp
:ensure t
:config (setq lsp-metals-server-args '("-J-Dmetals.allow-multiline-string-formatting=off")
lsp-metals-show-inferred-type nil
lsp-metals-super-method-lenses-enabled nil
lsp-metals-show-implicit-arguments nil
lsp-meatals-show-implicit-conversions-and-classes nil))
(use-package lsp-ui
:if use-lsp
:ensure t
:hook (lsp-mode . lsp-ui-mode)
:config (setq lsp-ui-doc-enable nil
lsp-ui-sideline-enable t
;lsp-ui-sideline-show-code-actions nil
lsp-ui-sideline-diagnostic-max-line-length 60
lsp-ui-sideline-diagnostic-max-lines 6))
(use-package lsp-java
:if use-lsp
:ensure t
:config (add-hook 'java-mode-hook 'lsp))
2022-05-03 18:30:29 -04:00
;; projectile
(use-package projectile
:demand
:init (setq projectile-use-git-grep t)
;;;:config (projectile-global-mode t)
:bind (("C-c C-f" . projectile-find-file)
("C-c C-g" . projectile-ripgrep)))
;; ripgrep
(use-package rg)
;; ido
(use-package flx-ido
:demand
:init (setq ido-show-dot-for-dired nil
ido-enable-dot-prefix nil
ido-use-faces t)
:config (ido-mode 1)
(ido-everywhere 1)
(flx-ido-mode 1))
;; highlight-symbol
(use-package highlight-symbol
:diminish highlight-symbol-mode
:commands highlight-symbol
:bind ("s-h" . highlight-symbol))
;; popup-imenu
(use-package popup-imenu
:commands popup-imenu
:bind ("M-i" . popup-imenu))
2022-05-12 16:05:12 -04:00
;; eyebrowse
(use-package eyebrowse
:config (eyebrowse-mode t)
:bind (("M-0" . eyebrowse-switch-to-window-config-0)
("M-1" . eyebrowse-switch-to-window-config-1)
("M-2" . eyebrowse-switch-to-window-config-2)
("M-3" . eyebrowse-switch-to-window-config-3)
("M-4" . eyebrowse-switch-to-window-config-4)
("M-5" . eyebrowse-switch-to-window-config-5)
("M-6" . eyebrowse-switch-to-window-config-6)
("M-7" . eyebrowse-switch-to-window-config-7)
("M-8" . eyebrowse-switch-to-window-config-8)
("M-9" . eyebrowse-switch-to-window-config-9)))
2022-05-03 18:30:29 -04:00
;; magit
(use-package magit
:commands magit-status magit-blame
:bind (("C-x g" . magit-status)
2022-08-02 19:52:50 -04:00
("s-b" . magit-blame))
:init
;; Have magit-status go full screen and quit to previous
;; configuration. Taken from
;; http://whattheemacsd.com/setup-magit.el-01.html#comment-748135498
;; and http://irreal.org/blog/?p=2253
(defadvice magit-status (around magit-fullscreen activate)
(window-configuration-to-register :magit-fullscreen)
ad-do-it
(delete-other-windows))
(defadvice magit-quit-window (after magit-restore-screen activate)
(jump-to-register :magit-fullscreen))
:config (remove-hook 'magit-status-sections-hook 'magit-insert-tags-header)
(remove-hook 'magit-status-sections-hook 'magit-insert-status-headers)
(remove-hook 'magit-status-sections-hook 'magit-insert-unpushed-to-pushremote)
(remove-hook 'magit-status-sections-hook 'magit-insert-unpulled-from-pushremote)
(remove-hook 'magit-status-sections-hook 'magit-insert-unpulled-from-upstream)
(remove-hook 'magit-status-sections-hook 'magit-insert-unpushed-to-upstream-or-recent)
(setq magit-refresh-verbose t ; xyz
magit-revert-buffers nil))
2022-05-03 18:30:29 -04:00
(use-package org-roam
2022-07-26 18:01:17 -04:00
:if (equal (system-name) "cult")
2022-07-18 11:53:05 -04:00
:config (setq org-roam-directory "~/org/")
(org-roam-db-autosync-mode))
2022-05-03 18:30:29 -04:00
;; git-gutter
(use-package git-gutter
:config (global-git-gutter-mode t)
(set-face-foreground 'git-gutter:modified "orange")
(set-face-foreground 'git-gutter:added "green")
(set-face-foreground 'git-gutter:deleted "red")
(setq git-gutter:handled-backends '(git hg svn))
(global-set-key (kbd "C-x n") 'git-gutter:next-hunk))
;; ;; git-timemachine
;; (use-package git-timemachine)
2022-05-03 18:30:29 -04:00
;; json
(use-package json-mode)
2022-07-18 11:53:05 -04:00
;; custom load path for ad-hoc lisp
(add-to-list 'load-path (file-truename (concat user-emacs-directory "lisp")))
2022-05-03 18:30:29 -04:00
;; glauce
(require 'glauce-mode)
;; uxntal
(use-package uxntal-mode
:straight (uxntal-mode :type git
:host github
:repo "non/uxntal-mode")
:bind ("C-c d" . uxntal-explain-word)
:config (setq uxntal-mode-strict-comments nil))
2022-07-18 11:53:05 -04:00
;; lua
(use-package lua-mode)
;; pico-8
(use-package pico8-mode
:straight (pico8-mode :type git
:host github
:repo "Kaali/pico8-mode"))
2022-05-03 18:30:29 -04:00
;; C-c C-c for M-x compile
(global-set-key "\C-c\C-c" 'compile)
;; bazel
(use-package bazel
:straight (bazel :type git
:host github
:repo "bazelbuild/emacs-bazel-mode")
:bind ("C-c C-b" . bazel-build)
:config (setq bazel-command '("/usr/local/bin/bazel")))
;; thrift
(use-package thrift-mode
:straight (thrift-mode :type git
:host github
:repo "davidmiller/thrift-mode")
:config (add-to-list 'auto-mode-alist '("\\.thrift\\'" . thrift-mode)))
2022-05-17 13:09:54 -04:00
;; yaml
(use-package yaml-mode)
2022-05-24 16:02:45 -04:00
;; hcl / terraform
(use-package hcl-mode)
2022-08-03 00:37:37 -04:00
;; dired
(setq dired-auto-revert-buffer t)
(defun my/toggle-dotfiles ()
"Toggle visibility of files starting with dot."
(interactive)
(if (equal dired-listing-switches "-al")
(setq dired-listing-switches "-l")
(setq dired-listing-switches "-al")))
2022-05-03 18:30:29 -04:00
;;; turn off branch in mode line for now
;(setq vc-handled-backends nil)
;; force vc to update branches, etc. (unused for now)
(defun force-update-vcs ()
2022-08-03 00:37:37 -04:00
"Update vc in all verson-controlled buffers."
2022-05-03 18:30:29 -04:00
(interactive)
(dolist (buf (buffer-list))
(with-current-buffer buf
(vc-refresh-state))))
;; playing music in emacs
(use-package emms
:config
(setq emms-source-file-default-directory "~/bandcamp/"
emms-browser-covers 'emms-browser-cache-thumbnail-async
2022-05-17 13:09:54 -04:00
emms-repeat-playlist t
2022-05-03 18:30:29 -04:00
scroll-up-aggressively 0.0
scroll-down-aggressively 0.0
emms-playlist-buffer-name "*Music*")
(emms-all)
(emms-default-players))
;; browsing gemini/gopher sites in emacs
(use-package elpher
:config
(setq elpher-default-url-type "gemini://"))
2022-07-18 11:53:05 -04:00
;; ;; pdf/latex
;; (use-package doc-view
;; :custom doc-view-resolution 1600
;; doc-view-scale-internally nil)
2022-05-03 18:30:29 -04:00
;; local copy in .emacs.d/lisp
(require 'etags-select)
;; don't case fold for ctags
(setq tags-case-fold-search nil)
;; whitespace stuff
(require 'whitespace)
(global-whitespace-mode t)
(setq whitespace-style '(newline tab-mark))
(setq-default indent-tabs-mode nil
tab-width 4
c-basic-offset 4
show-trailing-whitespace t)
;; handy function to toggle tabs
(defun toggle-indent-tabs ()
2022-10-26 23:09:27 -04:00
"Toggle tabs on/off."
2022-05-03 18:30:29 -04:00
(interactive)
2022-07-18 11:53:05 -04:00
(setq indent-tabs-mode (not indent-tabs-mode)))
2022-05-03 18:30:29 -04:00
2022-10-26 23:09:27 -04:00
;;
(defun toggle-trailing-whitespace ()
"Toggle trailing whitespace visualization."
(interactive)
(setq show-trailing-whitespace (not show-trailing-whitespace)))
2022-05-03 18:30:29 -04:00
;; handy function to regenerate tags
2022-08-03 00:37:37 -04:00
(defun my/regenerate-tags ()
"Regenerate tags using ets."
2022-05-03 18:30:29 -04:00
(interactive)
2022-08-03 00:37:37 -04:00
(defun my/runloop (dir)
2022-05-03 18:30:29 -04:00
(let ((tagfile (concat dir "TAGS")))
(if (file-exists-p tagfile)
(let ((default-directory dir))
(progn
(shell-command "echo generating tags...")
(async-shell-command "ets")))
(progn
(let ((next (file-name-directory (directory-file-name dir))))
2022-08-03 00:37:37 -04:00
(if (equal dir next) (shell-command "uptime") (my/runloop next)))))))
(my/runloop default-directory))
(global-set-key (kbd "C-t") 'my/regenerate-tags)
2022-05-03 18:30:29 -04:00
;; spell checking as you type in text-mode
2022-05-17 13:12:05 -04:00
;(autoload 'flyspell-mode-on "flyspell" "On-the-fly ispell." t)
2022-05-03 18:30:29 -04:00
(add-hook 'text-mode-hook 'flyspell-mode-on)
;; use nicer diff colors
2022-08-03 00:37:37 -04:00
(defun my/update-diff-colors ()
"Update the colors for diff faces."
2022-05-03 18:30:29 -04:00
(set-face-foreground 'diff-added "green")
(set-face-foreground 'diff-removed "red")
(set-face-foreground 'diff-changed "purple"))
(eval-after-load "diff-mode"
2022-08-03 00:37:37 -04:00
'(my/update-diff-colors))
2022-07-18 11:53:05 -04:00
;; (custom-set-variables
;; ;; custom-set-variables was added by Custom.
;; ;; If you edit it by hand, you could mess it up, so be careful.
;; ;; Your init file should contain only one such instance.
;; ;; If there is more than one, they won't work right.
;; '(ansi-color-names-vector
;; ["#171717" "#E2434C" "#86B187" "#E0D063" "#8AC6F2" "#E18Cbb" "cyan" "#F6F3E8"]
;; (custom-set-faces
;; ;; custom-set-faces was added by Custom.
;; ;; If you edit it by hand, you could mess it up, so be careful.
;; ;; Your init file should contain only one such instance.
;; ;; If there is more than one, they won't work right.
;; )
2022-08-03 00:37:37 -04:00
(provide 'init)
;;; init.el ends here