dot-emacs

My emacs dotfiles/config
git clone git://git.ethandl.dev/dot-emacs
Log | Files | Refs

commit 87974c8c6f5befdc373bd318020068ee4338ae56
parent 20aef1a176a493481fd89749b5219e27821818ce
Author: Ethan Long <ethandavidlong@gmail.com>
Date:   Fri,  8 Dec 2023 03:49:31 +1100

Updated the config :)

Diffstat:
Mconfig.org | 260+++++++++++++++++++++++++++++++++++++++++++++++--------------------------------
1 file changed, 156 insertions(+), 104 deletions(-)

diff --git a/config.org b/config.org @@ -28,14 +28,65 @@ When using emacs-plus, you can have a light and a dark theme :) (add-hook 'ns-system-appearance-change-functions #'ethandl/apply-theme) #+end_src +* Font & Ligature Definitions +It's here that we pick the code font. +#+begin_src emacs-lisp + ;; Set the fonts + ;; (setq code-font "Comic Code Ligatures-16") + (setq code-font "Victor Mono-16") + ;; (setq code-font "JuliaMono-16") + (add-hook 'after-make-frame-functions (apply-partially #'ethandl/set-fonts code-font)) +#+end_src +We also set the ligatures for code +#+begin_src emacs-lisp + (setq + comic-code-ligs + '(("-" (rx (+ "-"))) ("-" (rx (* "-") ">")) + ("+" (rx (+ "+"))) ("<" (rx (+ "="))) + ("<" (rx (+ "=") ">")) ("<" (rx (+ "~"))) + ("<" (rx (+ "~") ">")) ("<" (rx "!" (+ "-"))) + ("<" (rx (+ "-"))) ("<" (rx (+ "-") ">")) ("<" (rx "|")) + (">" (rx (+ "="))) (">" (rx ">" (+ "="))) + (">" (rx ">" (+ "=") ">")) (">" (rx (+ "-"))) + (">" (rx (+ "-") "<")) ("~" (rx (+ "~"))) + ("~" (rx (+ "~") ">")) ("=" (rx (* "=") ">")) + ("=" (rx (+ (or ">" "<" "|" "/" "~" ":" "!" "=")))) + "!=" "!==" "[|" "|]" "{|" "|}" "|>" "||" "&&") + + victor-mono-ligs + '("</" "</>" "/>" "~-" "-~" "~@" "<~" "<~>" "<~~" "~>" "~~" "~~>" ">=" "<=" + "<!--" "##" "###" "####" "|-" "-|" "|->" "<-|" ">-|" "|-<" "|=" "|=>" + ">-" "<-" "<--" "-->" "->" "-<" ">->" ">>-" "<<-" "<->" "->>" "-<<" "<-<" + "==>" "=>" "=/=" "!==" "!=" "<==" ">>=" "=>>" ">=>" "<=>" "<=<" + "=<=" "=>=" "<<=" "=<<" ".-" ".=" "=:=" "=!=" "==" "===" "::" ":=" ":>" + ":<" ">:" ";;" "<|" "<|>" "|>" "<>" "<$" "<$>" "$>" "<+" + "<+>" "+>" "?=" "/=" "/==" "/\\" "\\/" "__" "&&" "++" "+++") + + julia-mono-ligs + '("->" "=>" "|>" "<|" "::" "<--" "-->" "<-->" + ("=" (rx (+ "="))))) + (setq ligs victor-mono-ligs) +#+end_src * My Custom Elisp Functions ** General Programming Configuration #+begin_src emacs-lisp - (defun ethandl/rel-line-nums () - (display-line-numbers-mode t) - ;; Set line numbers to relative - (setq display-line-numbers 'relative) - (setq display-line-numbers-current-absolute t)) + (defun ethandl/num-lines () + (max 1 (count-lines (point-min) (point-max)))) + (defun ethandl/base-10-len (num) + (+ 1 (floor (log num 10)))) +#+end_src +#+begin_src emacs-lisp + (defun ethandl/format-buffer () + (cond (lsp-mode (lsp-format-buffer)) + (eglot--managed-mode (eglot-format-buffer)))) +#+end_src +#+begin_src emacs-lisp + (defun ethandl/line-nums-cfg () + (when (derived-mode-p 'prog-mode) + ;; Set line numbers to relative + (setq display-line-numbers 'relative + display-line-numbers-current-absolute t + display-line-numbers-width (ethandl/base-10-len (ethandl/num-lines))))) #+end_src #+begin_src emacs-lisp (defun ethandl/set-fonts (fontname &optional frame) @@ -44,6 +95,11 @@ When using emacs-plus, you can have a light and a dark theme :) (set-face-attribute 'font-lock-comment-face nil :slant 'italic) (set-face-attribute 'font-lock-keyword-face nil :slant 'italic))) #+end_src +#+begin_src emacs-lisp + (defun ethandl/reload-config () + (interactive) + (load user-init-file)) +#+end_src ** Org Mode Configuration The following function is the base config for org-mode, it sets org to indent on section depth, sets the font to be variable pitch, turns on visual lines for wrapped lines. #+begin_src emacs-lisp @@ -70,8 +126,8 @@ The following function is the config for org to set all the fonts. It is still a ((variable-font (if (x-list-fonts "ETBookOT") '(:font "ETBookOT") '(:family "Serif"))) - (mono-font (if (x-list-fonts "Victor Mono") - '(:font "Victor Mono") + (mono-font (if (x-list-fonts code-font) + `(:font ,code-font) '(:family "Mono"))) (base-font-color (face-foreground 'default nil 'default)) (headline `(:inherit default :weight bold :foreground ,base-font-color)) @@ -122,8 +178,12 @@ We can use ~use-package~ to configure emacs at startup. On MacOS we leave things (use-package emacs :elpaca nil :hook - (prog-mode . ethandl/rel-line-nums) + (prog-mode . display-line-numbers-mode) + (display-line-numbers-mode . ethandl/line-nums-cfg) + (before-save . ethandl/format-buffer) + (after-save . ethandl/line-nums-cfg) :init + (ethandl/set-fonts code-font) ;; Set fonts ;; Get rid of default crud (setq inhibit-startup-screen t) (menu-bar-mode 0) @@ -149,38 +209,6 @@ We can use ~use-package~ to configure emacs at startup. On MacOS we leave things (setq mac-option-modifier nil mac-command-modifier 'meta))) #+end_src -* Fonts & Ligature definitions -#+begin_src emacs-lisp - ;; Set the fonts - ;; (ethandl/set-fonts "Comic Code Ligatures-16") - (setq code-font "Victor Mono-16") - (ethandl/set-fonts code-font) - (add-hook 'after-make-frame-functions (apply-partially #'ethandl/set-fonts code-font)) -#+end_src -#+begin_src emacs-lisp - (setq comic-code-ligs '(("-" (rx (+ "-"))) ("-" (rx (* "-") ">")) - ("+" (rx (+ "+"))) ("<" (rx (+ "="))) - ("<" (rx (+ "=") ">")) ("<" (rx (+ "~"))) - ("<" (rx (+ "~") ">")) ("<" (rx "!" (+ "-"))) - ("<" (rx (+ "-"))) ("<" (rx (+ "-") ">")) ("<" (rx "|")) - (">" (rx (+ "="))) (">" (rx ">" (+ "="))) - (">" (rx ">" (+ "=") ">")) (">" (rx (+ "-"))) - (">" (rx (+ "-") "<")) ("~" (rx (+ "~"))) - ("~" (rx (+ "~") ">")) ("=" (rx (* "=") ">")) - ("=" (rx (+ (or ">" "<" "|" "/" "~" ":" "!" "=")))) - "!=" "!==" "[|" "|]" "{|" "|}" "|>" "||" "&&")) - - (setq victor-mono-ligs '("</" "</>" "/>" "~-" "-~" "~@" "<~" "<~>" "<~~" "~>" - "~~" "~~>" ">=" "<=" "<!--" "##" "###" "####" "|-" "-|" - "|->" "<-|" ">-|" "|-<" "|=" "|=>" ">-" "<-" "<--" - "-->" "->" "-<" ">->" ">>-" "<<-" "<->" "->>" "-<<" - "<-<" "==>" "=>" "=/=" "!==" "!=" "<==" ">>=" "=>>" - ">=>" "<=>" "<=<" "<<=" "=<<" ".-" ".=" "=:=" "=!=" - "==" "===" "::" ":=" ":>" ":<" ">:" ";;" "<|" "<|>" - "|>" "<>" "<$" "<$>" "$>" "<+" "<+>" "+>" "?=" "/=" - "/==" "/\\" "\\/" "__" "&&" "++" "+++")) - (setq ligs victor-mono-ligs) -#+end_src * Packages ** Ivy and Counsel (Better Text Navigation) [[https://github.com/abo-abo/swiper][Ivy and Counsel]] are replacements for the default ~find-file~ and =M-x= menus. @@ -360,14 +388,15 @@ LSP, the Language Server Protocol. Very nice for debugging code live as you writ *Warning:* Some LSPs are godawful slow and can chew through CPU and memory. Be careful, tinker, and don't be afraid to disable the training wheels. #+begin_src emacs-lisp - ;; LSP mode - (use-package lsp - :elpaca lsp-mode - :init - (setq gc-cons-threshold 100000000) - (setq read-process-output-max (* 1024 1024)) - (setq lsp-completion-provider :none) - (setq lsp-eldoc-render-all t)) + ;; LSP mode + (use-package lsp + :elpaca lsp-mode + :init + (setq gc-cons-threshold 100000000) + (setq read-process-output-max (* 1024 1024)) + (setq lsp-completion-provider :none) + (setq lsp-eldoc-render-all t)) + (use-package eglot) #+end_src A longer term goal of mine is to remove the need for =lsp-mode= and instead use =eglot=, but =lsp-mode= just has such a painless setup that I would rather just use it sometimes. ** Tree Sitter Setup @@ -377,6 +406,7 @@ Since Emacs 29, we don't need to install tree sitter separately anymore, it come '((bash "https://github.com/tree-sitter/tree-sitter-bash") (css "https://github.com/tree-sitter/tree-sitter-css") (go "https://github.com/tree-sitter/tree-sitter-go") + (gomod "https://github.com/camdencheek/tree-sitter-go-mod") (html "https://github.com/tree-sitter/tree-sitter-html") (javascript "https://github.com/tree-sitter/tree-sitter-javascript" "master" "src") (json "https://github.com/tree-sitter/tree-sitter-json") @@ -399,8 +429,10 @@ Since Emacs 29, we don't need to install tree sitter separately anymore, it come I like to have eldoc appear as a box below where I'm typing, rather than having it appear in the minibuffer. This is done with =eldoc-box=: #+begin_src emacs-lisp (use-package eldoc-box - :hook (eldoc-managed-mode . eldoc-box-hover-at-point-mode) - :hook (lsp-after-open . eldoc-box-hover-at-point-mode)) + :hook + (eldoc-managed-mode . eldoc-box-hover-mode) + (lsp-after-open . eldoc-box-hover-mode) + (eglot-managed-mode . eldoc-box-hover-mode)) #+end_src ** C We want to use tree sitter to generate syntax highlighting, so we should change the default major mode to be the tree-sitter mode. @@ -412,80 +444,101 @@ This setup is just a combination of =haskell-mode= and the Haskell Language Serv Haskell mode is really good for the indenting and overall behaviour of the editor, and the Haskell language server is definitely there... (It can be slow, so can be turned off on larger projects) #+begin_src emacs-lisp ;; Haskell setup - ;; Dumb hack for emacs 30 (see https://github.com/haskell/haskell-mode/issues/1825): - ;;(setq flymake-allowed-file-name-masks nil) (use-package haskell-mode) - (use-package lsp-haskell + (use-package eglot + :elpaca nil + :hook (haskell-mode . eglot-ensure) :config - (add-hook 'haskell-mode-hook #'lsp) - (add-hook 'haskell-literate-mode-hook #'lsp)) + (setq-default eglot-workplace-configuration + '((haskell + (plugin + (stan + (globalOn . :json-false)))))) + :custom + (eglot-autoshutdown t) + (eglot-confirm-server-initiated-edits nil)) #+end_src NOTE: This is not using tree sitter, as there is no haskell-ts-mode yet or probably for a while into the future. ** Rust Rust mode alongside LSP again. The rust LSP is very good as far as LSPs go, very helpful. Though sometimes it's better to compile and see the rustc errors as they tend to be more verbose. -/Chad =rust-ts-mode= configuration/: +/Chad =rust-ts-mode= configuration with eglot:/ #+begin_src emacs-lisp - (push '("\\.rs\\'" . rust-ts-mode) auto-mode-alist) - (add-hook 'rust-ts-mode-hook #'lsp) -#+end_src - -/Legacy =rust-mode= configuration/: -#+begin_src emacs-lisp :tangle no - ;; Rust setup - (use-package rust-mode + (use-package eglot + :elpaca nil + :hook (rust-ts-mode . eglot-ensure) :config - (add-hook 'rust-mode-hook #'lsp)) + (add-to-list 'eglot-server-programs + `(rust-mode . ("rust-analyzer" :initializationOptions + (:procmacro (:enable t)) + :cargo (:buildScripts (:enable t) + :features "all")))) + (push '("\\.rs\\'" . rust-ts-mode) auto-mode-alist)) #+end_src ** Go -Nothing to see here, yet... -#+begin_src emacs-lisp +This basic LSP setup is based on the golang guide: https://cs.opensource.google/go/x/tools/+/refs/tags/gopls/v0.14.2:gopls/doc/emacs.md +#+begin_src emacs-lisp + (push '("\\.go\\'" . go-ts-mode) auto-mode-alist) + (push '("\\.mod\\'" . go-mod-ts-mode) auto-mode-alist) + (defun golang/project-find-go-module (dir) + (when-let ((root (locate-dominating-file dir "go.mod"))) + (cons 'go-module root))) + (cl-defmethod project-root ((project (head go-module))) + (cdr project)) + + (use-package project + :elpaca nil + :config + (add-hook 'project-find-functions #'golang/project-find-go-module)) + + (use-package eglot + :elpaca nil + :hook (go-ts-mode . eglot-ensure) + :config + (setq-default eglot-workspace-configuration + '((:gopls . + ((staticcheck . t) + (matcher . "CaseSensitive"))))) + (push '("\\.go\\'" . go-ts-mode) auto-mode-alist) + (push '("\\.mod\\'" . go-mod-ts-mode) auto-mode-alist)) #+end_src ** Java -A.K.A. OO hell. -=lsp-java= is actually pretty okay, and uses the Eclipse Language Server. So basically emacs becomes eclipse but better (not hard). In general IntelliJ is probably still your best bet when it comes to Java development. +OO hell 😌 +Using the Eclipse JDT Language Server: #+begin_src emacs-lisp ;; Java setup - (use-package lsp-java - :config - (add-hook 'java-mode-hook #'lsp)) -#+end_src -We want to use tree sitter in our major mode: -#+begin_src emacs-lisp - (push '(java-mode . java-ts-mode) major-mode-remap-alist) - (add-hook 'java-ts-mode #'lsp) + (use-package eglot-java + :hook (java-ts-mode . eglot-java-mode) + :config (push '(java-mode . java-ts-mode) major-mode-remap-alist)) #+end_src ** JavaScript/TypeScript JavaScript and TypeScript are easy thanks to tree sitter! #+begin_src emacs-lisp - (push '(js-mode . js-ts-mode) major-mode-remap-alist) - (add-hook 'js-ts-mode-hook #'lsp) - (add-hook 'typescript-ts-mode #'lsp) - (add-hook 'tsx-ts-mode #'lsp) + (use-package eglot + :elpaca nil + :hook + (js-ts-mode . eglot-ensure) + (typescript-ts-mode . eglot-ensure) + (tsx-ts-mode . eglot-ensure) + :config + (push '(js-mode . js-ts-mode) major-mode-remap-alist) + (push '(javascript-mode . js-ts-mode) major-mode-remap-alist) + (push '("\\.ts\\'" . typescript-ts-mode) auto-mode-alist) + (push '("\\.tsx\\'" . tsx-ts-mode) auto-mode-alist)) #+end_src ** Python A.K.A. the most overused and overhyped language. This language is incredibly slow, which is why its language server is not written in Python LMAO. Anywho the =pyright= LSP is made by Microshit so maybe this is proprietary software or telemetry, idk. #+begin_src emacs-lisp - (push '(python-mode . python-ts-mode) major-mode-remap-alist) - ;; Python setup - (use-package lsp-pyright - :hook (python-ts-mode . (lambda () - (require 'lsp-pyright) - (lsp)))) -#+end_src -Let's set it up to use pyright over TRAMP: -#+begin_src lisp - (lsp-register-client - (make-lsp-client :new-connection (lsp-tramp-connection "pyright") - :major-modes '(python-mode) - :remote? t - :server-id 'pyright-remote)) + (use-package eglot + :elpaca nil + :hook (python-ts-mode . eglot-ensure) + :config + (add-to-list 'eglot-server-programs + `(python-ts-mode . ("pyright-langserver" "--stdio"))) + (push '(python-mode . python-ts-mode) major-mode-remap-alist)) #+end_src ** OCaml This is the basic OCaml config provided by opam on installation. It may be actually better to just use the language server that OCaml installed... #+begin_src emacs-lisp - ;; OCaml configuration - ;; - better error and backtrace matching - (defun set-ocaml-error-regexp () (set 'compilation-error-regexp-alist @@ -497,6 +550,11 @@ This is the basic OCaml config provided by opam on installation. It may be actua ;; ## added by OPAM user-setup for emacs / base ## 56ab50dc8996d2bb95e7856a6eddb17b ## you can edit, but keep this line (require 'opam-user-setup (expand-file-name "opam-user-setup.el" user-emacs-directory)) #+end_src +** Clojure +Installing clojure mode. +#+begin_src emacs-lisp + (use-package clojure-mode) +#+end_src ** LaTeX LaTeX isn't really a language, but we should set up stuff for it. Firstly, we should get CDLaTeX: @@ -504,9 +562,3 @@ Firstly, we should get CDLaTeX: (use-package cdlatex :hook ((latex-mode LaTeX-mode) . turn-on-cdlatex)) #+end_src -** Clojure -Firstly, we want to use clojure-mode: -#+begin_src emacs-lisp - (use-package clojure-mode) -#+end_src -I've not used clojure much yet so this section is subject to change.