commit 0f2d954e25da10fd4a31a0bf6e1cef3fef334f47
parent 313d4ae2a31bfa91ceb4de52a6afe38a4dc75507
Author: Ethan Long <ethandavidlong@gmail.com>
Date: Thu, 17 Aug 2023 22:10:49 +1000
Emacs config cleaned up a little
Diffstat:
| M | config.org | | | 136 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------- |
| M | early-init.el | | | 10 | ++++++++++ |
| M | init.el | | | 50 | +++++++------------------------------------------- |
3 files changed, 111 insertions(+), 85 deletions(-)
diff --git a/config.org b/config.org
@@ -1,11 +1,11 @@
-#+STARTUP: show2levels
-* My emacs config
-This is my emacs configuration, it is designed to be portable across Unix-like operating systems, working on both Linux and Mac (maybe Windows in the future, but for now it's a no-go). I prefer to have a manual configuration like this rather than Doom Emacs, because then I know every package that goes into this bloated mess of an editor. The aim of this configuration is to make emacs as sufferable as possible. It turns out to be quite an okay & customisable editor after you give it vi bindings.
-** Elpaca
+#+Startup: overview
+#+Title:My emacs config
+#+Author:Ethan Long
+* Elpaca
The elpaca package manager is an alternative to ~use-package~ that works asynchronously in the background. Beyond the initial set-up, it is faster and more reliable than using ~package.el~. The main downside is also that it is asynchronous, as this means you need to put thought into the configuration of the rest of emacs, everything needs to be set up with ~use-package~ and a special ~elpaca-after-init-hook~ unless you want the blocking ~elpaca-wait~ function that completely defeats the purpose of elpaca.
Elpaca is installed in =init.el=, as we need to install the latest version of org before we enter here.
-** Catppuccin Theme
+* Theme
Catppuccin is best (dark) theme.
#+begin_src emacs-lisp
;; Catppuccin Mocha theme
@@ -16,7 +16,19 @@ Catppuccin is best (dark) theme.
(setq catppuccin-flavor 'mocha)
(catppuccin-reload)
#+end_src
-** General Emacs/editor settings
+When using emacs-plus, you can have a light and a dark theme :)
+#+begin_src emacs-lisp
+ (defun ethandl/apply-theme (appearance)
+ ;;"Load theme, taking current system APPEARANCE into consideration."
+ (mapc #'disable-theme custom-enabled-themes)
+ (pcase appearance
+ ('light (setq catppuccin-flavor 'latte))
+ ('dark (setq catppuccin-flavor 'mocha)))
+ (catppuccin-reload))
+
+ (add-hook 'ns-system-appearance-change-functions #'ethandl/apply-theme)
+#+end_src
+* General Emacs/Editor settings
We can use ~use-package~ to configure emacs at startup. On MacOS we leave things mostly default because emacs-mac doesn't look fugly, but on Linux we might as well get rid of all the clutter. Also we use spaces not tabs, begone tabs.
#+begin_src emacs-lisp
;; Emacs init config
@@ -27,10 +39,12 @@ We can use ~use-package~ to configure emacs at startup. On MacOS we leave things
(setq completion-cycle-threshold 3)
;; Get rid of default crud
(setq inhibit-startup-screen t)
- (unless (eq system-type 'darwin)
- (menu-bar-mode 0)
- (tool-bar-mode 0)
- (scroll-bar-mode 0))
+ (menu-bar-mode 0)
+ (tool-bar-mode 0)
+ (scroll-bar-mode 0)
+ (when (eq system-type 'darwin)
+ (setq mac-option-modifier nil
+ mac-command-modifier 'meta))
;; Modeline line and col number
(line-number-mode 1)
(column-number-mode 1)
@@ -49,7 +63,7 @@ Let's get rid of the autosave and backup crap that emacs puts into the active wo
;; create the autosave dir if necessary, since emacs won't.
(make-directory "~/.config/emacs/autosaves/" t)
#+end_src
-*** Fonts & Ligatures
+** Fonts & Ligature definitions
#+begin_src emacs-lisp
;; Set the fonts
(defun custom-set-fonts (&optional frame)
@@ -85,8 +99,8 @@ Let's get rid of the autosave and backup crap that emacs puts into the active wo
"/==" "/\\" "\\/" "__" "&&" "++" "+++"))
#+end_src
-** Packages
-*** Ivy and Counsel (Better Text Navigation)
+* 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.
#+begin_src emacs-lisp
;; ivy mode instead of ido mode:
@@ -96,7 +110,7 @@ Let's get rid of the autosave and backup crap that emacs puts into the active wo
(use-package counsel)
(add-hook 'elpaca-after-init-hook (lambda () (counsel-mode t)))
#+end_src
-*** Ligature.el / Ligature set up
+** Ligature.el / Ligature set up
Ligatures are native on =emacs-mac=, so we just call the built in helper function if we are on MacOS. If not, we will use [[https://github.com/mickeynp/ligature.el][ligature.el]] to give ligatures with Harfbuzz.
#+begin_src emacs-lisp
;; Font ligatures:
@@ -106,17 +120,18 @@ Ligatures are native on =emacs-mac=, so we just call the built in helper functio
(ligature-set-ligatures 'prog-mode victor-mono-ligs)
(global-ligature-mode t))
;; Else, on mac we have ligatures already
- (mac-auto-operator-composition-mode))
-
+ ;;(mac-auto-operator-composition-mode))
+ )
+
#+end_src
-*** Rainbow Delimiters
+** Rainbow Delimiters
Rainbow delimiters are essential for working with LISP, and are just nice to have elsewhere. This package has apparently got a very small footprint, and I can't be arsed actually benchmarking anything in this emacs config so I trust them.
#+begin_src emacs-lisp
;; Rainbow delimiters:
(use-package rainbow-delimiters
:hook (prog-mode . rainbow-delimiters-mode))
#+end_src
-*** Doom Modeline
+** Doom Modeline
This modeline is supposedly sexier than the original, honestly I don't mind the original either, it's also very nice. If there's ever a reason to ditch this because of some bug or performance issue, etc. then don't be afraid to.
#+begin_src emacs-lisp
;; Doom modeline:
@@ -124,7 +139,7 @@ This modeline is supposedly sexier than the original, honestly I don't mind the
(add-hook 'elpaca-after-init-hook (lambda () (doom-modeline-mode t)))
#+end_src
-*** Which Key?
+** Which Key?
Fix my ineptitude in this keyboard chord hell.
#+begin_src emacs-lisp
;; Which key (this is the thing responsible for coming up with the minibuffer of keys that you can pick):
@@ -134,7 +149,7 @@ Fix my ineptitude in this keyboard chord hell.
:config
(setq which-key-idle-delay 0.3))
#+end_src
-*** Evil mode
+** Evil mode
Fix my ineptitude in this chord hell that is emacs. I mean seriously, chords just to navigate? I don't want even more RSI & carpel tunnel.
#+begin_src emacs-lisp
;; Evil mode :D
@@ -160,7 +175,7 @@ Fix my ineptitude in this chord hell that is emacs. I mean seriously, chords jus
(evil-set-initial-state 'messages-buffer-mode 'normal)
(evil-set-initial-state 'dashboard-mode 'normal))
#+end_src
-**** Evil Collection
+*** Evil Collection
#+begin_src emacs-lisp
;; Extra modes for evil, if evil is playing up this would be the first thing to check
(use-package evil-collection
@@ -168,7 +183,7 @@ Fix my ineptitude in this chord hell that is emacs. I mean seriously, chords jus
:config
(evil-collection-init))
#+end_src
-*** Corfu & Cape (Completion)
+** Corfu & Cape (Completion)
Based completion. This is an overhaul of the autocomplete. Company mode sucks because when you resize a buffer with C-x-+ everything breaks.
#+begin_src emacs-lisp
;; Cape
@@ -186,7 +201,7 @@ Based completion. This is an overhaul of the autocomplete. Company mode sucks be
;; Shouldn't have to do this, but lsp is a little bugged:
(advice-add #'lsp-completion-at-point :around #'cape-wrap-noninterruptible))
#+end_src
-*** Scrolling Patches
+** Scrolling Patches
Scrolling via cursor movement is too slow in default emacs, this fixes that.
#+begin_src emacs-lisp
;; Faster scrolling:
@@ -202,29 +217,33 @@ Here are a few more nice things for scrolling.
(pixel-scroll-precision-mode t))
;; Scrolling down a file only goes down a single line when reaching the bottom
(setq scroll-step 1)
+ (setq hscroll-step 1)
;; The region that the curser needs to enter to trigger scrolling
- (setq scroll-margin 5)
+ ;;(setq scroll-margin 5)
;; Necessary to stop random jumps
(setq scroll-conservatively 10000)
#+end_src
-** Org Mode
+* Org Mode
My org mode is based on [[https://orgmode.org/guide/Hyperlinks.html][a post by Diego Zamboni]]. The general idea is that we want headings to be bigger and more noticable than text, all regular text should be non-monospace, and all code should be in the regular monospace font.
Starting out, let's configure the basics, we want indentation and variable pitch fonts, as well as lines that fill the whole screen well with variable font. We also want all code blocks to be fontified properly. We will wrap this all up in a function called ~org-mode-base~.
#+begin_src emacs-lisp
(defun ethandl/org-mode-base ()
(require 'org)
- (org-indent-mode 1)
- (variable-pitch-mode 1)
- (visual-line-mode 1)
+ (org-indent-mode t)
+ (variable-pitch-mode t)
+ (visual-line-mode t)
(setq org-src-fontify-natively t
org-src-tab-acts-natively t))
#+end_src
Now let's make org prettier, we want all non-textual markers gone, our fonts to be correct, and bullet points for our headings as well as bullet lists. This is all wrapped up in the ~org-mode-prettify~ function.
#+begin_src emacs-lisp
- (use-package org-bullets
+ (use-package org-superstar
+ :hook (org-mode . org-superstar-mode)
:config
- (add-hook 'org-mode-hook (lambda () (org-bullets-mode 1))))
+ (setq org-hide-leading-stars nil)
+ (setq org-superstar-leading-bullet ?\s)
+ (setq org-indent-mode-turns-on-hiding-stars nil))
(use-package org-autolist
:hook (org-mode . org-autolist-mode))
@@ -286,17 +305,34 @@ Unfortunately, there are some source mode highlighting issues with the Catppucci
(add-hook 'org-mode-hook 'ctp/text-org-blocks)
#+end_src
-Finally, we need to configure the ~org~ package. Technically we could install the git version here with elpaca, but that version is just broken. We therefore will just use the built-in package that comes with emacs. This initial setup will hook into the ~org-mode-base~ and ~org-mode-prettify~ functions that we made before to give us the final result 😌.
+We need to configure the ~org~ package. Technically we could install the git version here with elpaca, but that version is just broken. We therefore will just use the built-in package that comes with emacs. This initial setup will hook into the ~org-mode-base~ and ~org-mode-prettify~ functions that we made before to give us the final result 😌.
#+begin_src emacs-lisp
;; We already installed the latest version of org in our init.el
(use-package org
:elpaca nil
- :hook (org-mode . ethandl/org-mode-base)
+ :hook ((org-mode . ethandl/org-mode-base)
+ (org-mode . turn-on-org-cdlatex)
+ (org-mode . ethandl/org-mode-prettify)))
+#+end_src
+Adding in the ability to seamlessly paste in images from the clipboard:
+#+begin_src emacs-lisp
+ (use-package org-download
+ :after org
+ :defer nil
+ :custom
+ (org-download-method 'directory)
+ (org-download-image-dir "pasted-images")
+ (org-download-heading-lvl nil)
+ (org-download-timestamp "%Y%m%d-%H%M%S_")
+ (org-image-actual-width 300)
+ (org-download-screenshot-method "/opt/homebrew/bin/pngpaste %s")
+ :bind
+ ("M-p" . org-download-screenshot)
:config
- (ethandl/org-mode-prettify))
+ (require 'org-download))
#+end_src
-** Languages
-*** LSP Setup
+* Languages
+** LSP Setup
LSP, the Language Server Protocol. Very nice for debugging code live as you write it. It depends on the language as to how useful this really is.
*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.
@@ -309,11 +345,11 @@ LSP, the Language Server Protocol. Very nice for debugging code live as you writ
(setq read-process-output-max (* 1024 1024))
(setq lsp-completion-provider :none))
#+end_src
-*** C
+** C
There is nothing to report here, yet...
#+begin_src emacs-lisp
#+end_src
-*** Haskell
+** Haskell
This setup is just a combination of =haskell-mode= and the Haskell Language Server.
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
@@ -324,7 +360,7 @@ Haskell mode is really good for the indenting and overall behaviour of the edito
(add-hook 'haskell-mode-hook #'lsp)
(add-hook 'haskell-literate-mode-hook #'lsp))
#+end_src
-*** Rust
+** 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.
#+begin_src emacs-lisp
;; Rust setup
@@ -332,11 +368,11 @@ Rust mode alongside LSP again. The rust LSP is very good as far as LSPs go, very
:config
(add-hook 'rust-mode-hook #'lsp))
#+end_src
-*** Go
+** Go
Nothing to see here, yet...
#+begin_src emacs-lisp
#+end_src
-*** Java
+** 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.
#+begin_src emacs-lisp
@@ -345,7 +381,7 @@ A.K.A. OO hell.
:config
(add-hook 'java-mode-hook #'lsp))
#+end_src
-*** Python
+** 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
;; Python setup
@@ -354,7 +390,15 @@ A.K.A. the most overused and overhyped language. This language is incredibly slo
(require 'lsp-pyright)
(lsp))))
#+end_src
-*** OCaml
+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))
+#+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
@@ -371,3 +415,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 "~/.config/emacs/opam-user-setup.el")
#+end_src
+
+** LaTeX
+LaTeX isn't really a language, but we should set up stuff for it.
+Firstly, we should get CDLaTeX:
+#+begin_src emacs-lisp
+ (use-package cdlatex
+ :hook ((latex-mode LaTeX-mode) . turn-on-cdlatex))
+#+end_src
diff --git a/early-init.el b/early-init.el
@@ -1 +1,11 @@
+;; HACK Work around native compilation on macOS failing with 'ld: library not
+;; found for -lemutls_w'.
+;; https://github.com/d12frosted/homebrew-emacs-plus/issues/554
+(setenv "LIBRARY_PATH"
+ (string-join
+ '("/opt/homebrew/opt/gcc/lib/gcc/13"
+ "/opt/homebrew/opt/libgccjit/lib/gcc/13"
+ "/opt/homebrew/opt/gcc/lib/gcc/13/gcc/aarch64-apple-darwin22/13")
+ ":"))
(setq package-enable-at-startup nil)
+(add-to-list 'default-frame-alist '(undecorated-round . t))
diff --git a/init.el b/init.el
@@ -43,51 +43,15 @@
;; Assume :elpaca t unless otherwise specified.
(setq elpaca-use-package-by-default t))
-(unless (fboundp 'use-package)
- (elpaca-wait))
-
-;; Unfortunately have to install git org before going into config.org
-(use-package org
- :load-path "~/.config/emacs/elpaca/builds/org/")
-;; Unfortunately we need to wait for org to install to proceed, otherwise it will use the built-in and destroy everything
(elpaca-wait)
+;; If we want to use the git version of org mode, we need to download it now
+;; There are many reasons you might want to do this, but the git version is quite unstable as well
+;;(use-package org
+;; :load-path "~/.config/emacs/elpaca/builds/org/")
+;; We then need to wait for the download of org to complete before we can use org.
+;;(elpaca-wait)
+
(org-babel-load-file "~/.config/emacs/config.org")
;; Emacs crap that it does automatically:
-(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.
- '(auto-save-file-name-transforms '((".*" "~/.config/emacs/autosaves/\\1" t)))
- '(backup-directory-alist '((".*" . "~/.config/emacs/backups/")))
- '(warning-suppress-types '((comp) (comp) (org-element-cache) (org-element-cache))))
-(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.
- '(fixed-pitch ((t (:family "Victor Mono" :height 160 :weight regular))))
- '(org-block ((t (:inherit fixed-pitch))))
- '(org-code ((t (:inherit (shadow fixed-pitch)))))
- '(org-document-info ((t (:foreground "dark orange"))))
- '(org-document-info-keyword ((t (:inherit (shadow fixed-pitch)))))
- '(org-document-title ((t (:inherit default :weight bold :foreground "#cdd6f4" :font "ETBookOT" :height 2.0 :underline nil))))
- '(org-indent ((t (:inherit (org-hide fixed-pitch)))))
- '(org-level-1 ((t (:inherit default :weight bold :foreground "#cdd6f4" :font "ETBookOT" :height 1.75))))
- '(org-level-2 ((t (:inherit default :weight bold :foreground "#cdd6f4" :font "ETBookOT" :height 1.5))))
- '(org-level-3 ((t (:inherit default :weight bold :foreground "#cdd6f4" :font "ETBookOT" :height 1.25))))
- '(org-level-4 ((t (:inherit default :weight bold :foreground "#cdd6f4" :font "ETBookOT" :height 1.1))))
- '(org-level-5 ((t (:inherit default :weight bold :foreground "#cdd6f4" :font "ETBookOT" :height 1.1))))
- '(org-level-6 ((t (:inherit default :weight bold :foreground "#cdd6f4" :font "ETBookOT" :height 1.1))))
- '(org-level-7 ((t (:inherit default :weight bold :foreground "#cdd6f4" :font "ETBookOT" :height 1.1))))
- '(org-level-8 ((t (:inherit default :weight bold :foreground "#cdd6f4" :font "ETBookOT" :height 1.1))))
- '(org-link ((t (:foreground "royal blue" :underline t))))
- '(org-meta-line ((t (:inherit (font-lock-comment-face fixed-pitch)))))
- '(org-property-value ((t (:inherit fixed-pitch))) t)
- '(org-special-keyword ((t (:inherit (font-lock-comment-face fixed-pitch)))))
- '(org-table ((t (:inherit fixed-pitch :foreground "#83a598"))))
- '(org-tag ((t (:inherit (shadow fixed-pitch) :weight bold :height 0.8))))
- '(org-verbatim ((t (:inherit (shadow fixed-pitch)))))
- '(variable-pitch ((t (:family "ETBookOT" :height 200 :weight thin)))))