Skip to content

Repository files navigation

Demacs - Desmond’s Emacs Configuration

Introduction

Demacs is a personal Emacs configuration built with a modular architecture, managed via Nix flakes, and optimized for performance. It features the latest Emacs with IGC (Improved Garbage Collection) support, custom patches for macOS, and a curated selection of packages for programming, writing, and daily workflows.

Key Features

  • 🚀 Nix-managed - Reproducible builds with Nix flakes
  • IGC Support - Latest Emacs with Improved Garbage Collection
  • 🍎 macOS Optimized - Custom patches for rounded frames, system appearance, smooth cursor
  • 📦 Modular Design - Clean separation of concerns with modules/, lib/, and site-lisp/
  • 🎨 Rosé Pine Theme - Beautiful day/night themes with system appearance sync

Quick Start

# Enter development shell
nix develop

# Run Emacs (default: IGC build)
nix run .#demacs

# Alternative builds
nix run .#demacs-igc           # IGC without patches
nix run .#demacs-igc-patched   # IGC with macOS patches
nix run .#demacs-git           # Git master without patches
nix run .#demacs-git-patched   # Git master with patches

Directory Structure

~/.emacs.d/
├── init.el              # Main entry point
├── early-init.el        # Pre-initialization (GC, UI)
├── flake.nix            # Nix flake configuration
├── modules/             # Feature modules (init-*.el)
├── lib/                 # Shared helper libraries (lib-*.el)
├── site-lisp/           # Standalone packages
├── themes/              # Custom themes (Rosé Pine)
├── patches/             # Emacs patches for macOS
├── snippets/            # YASnippet templates
└── templates/           # Tempel templates

Core Configuration

Early Initialization

The early-init.el handles pre-initialization settings for optimal startup performance.

Garbage Collection Optimization

;; Maximize GC threshold during startup, restore after
(setq gc-cons-threshold most-positive-fixnum
      gc-cons-percentage 0.5)

(add-hook 'emacs-startup-hook
          (lambda ()
            (setq gc-cons-threshold (* 20 1024 1024))))

Performance Settings

;; Prefer newer compiled files
(setq load-prefer-newer t)

;; Increase process read chunk size
(setq read-process-output-max (* 1024 1024))  ; 1mb

;; Reduce rendering work
(setq-default cursor-in-non-selected-windows nil)
(setq highlight-nonselected-windows nil)

;; Disable bidirectional text for performance
(setq-default bidi-display-reordering 'left-to-right
              bidi-paragraph-direction 'left-to-right)

UI Cleanup

;; Disable GUI elements via frame parameters (faster than mode functions)
(push '(menu-bar-lines . 0)   default-frame-alist)
(push '(tool-bar-lines . 0)   default-frame-alist)
(push '(vertical-scroll-bars) default-frame-alist)
(push '(undecorated-round . t) default-frame-alist)  ; macOS rounded corners
(push '(fullscreen . maximized) default-frame-alist)

Main Initialization

The init.el bootstraps the configuration and loads modules in order.

User Settings

;; Personal information
(setq user-full-name "Desmond Wang")
(setq user-mail-address "desmond.wang@netint.ca")

;; Font configuration
(defconst *default-font* "Maple Mono NF")
(defconst *zh-default-font* "Maple Mono NF CN")
(defconst *symbol-default-font* "Symbols Nerd Font Mono")

;; Paths
(defconst *org-path* "~/Documents/Org/")

Module Loading Order

;; Load paths
(dolist (dir '("modules" "lib" "site-lisp" "themes"))
  (add-to-list 'load-path (expand-file-name dir user-emacs-directory)))

;; Core setup
(require 'setup)
(require 'init-setup)

;; Platform-specific
(when *is-mac* (require 'init-mac))

;; UI and editing
(require 'init-ui)
(require 'init-editing)
(require 'init-vc)
(require 'init-minibuffer)
(require 'init-completion)

;; Programming
(require 'init-prog)
(require 'init-util)
(require 'init-transient)
(require 'init-bitstream)

;; Org and documents
(require 'init-org)
(require 'init-reader)
(require 'init-social)

;; Shell and AI
(require 'init-shell)
(require 'init-ai)

;; Local customizations
(require 'init-local)

Modules

UI & Appearance (init-ui.el)

Visual customization and window management.

Theme System

;; Rosé Pine theme with automatic light/dark switching
(:option custom-enabled-themes '(rose-pine-night)
         light-theme 'rose-pine-day
         dark-theme 'rose-pine-night)

;; Sync with macOS system appearance
(when *is-mac*
  (apply-theme-based-on-appearance)
  (:with-hook ns-system-appearance-change-functions
    (:hook apply-theme-based-on-appearance)))

Window Management

  • popper - Popup window management (shells, help, compilation)
  • tabspaces - Session/workspace management

Tab Bar & Tab Line

;; Custom tab bar configuration
(:option tab-bar-separator ""
         tab-bar-close-button-show nil
         tab-bar-new-button-show nil
         tab-bar-tab-hints t
         tab-bar-select-tab-modifiers '(super))

Panel Dashboard

Custom startup panel with weather, image, and quote display.

Editing (init-editing.el)

Enhanced editing experience with modal editing and smart features.

Meow Modal Editing

;; Meow as the modal editing system
(require 'meow)
(meow-global-mode 1)
(meow-setup)

;; Use system clipboard
(:option meow-use-clipboard t)

;; Undo system
(undo-fu-session-global-mode)
(:option undo-limit 67108864
         undo-strong-limit 100663296
         undo-outer-limit 1006632960)

Input Method Switching (SIS)

Automatic input source switching for CJK support.

;; Switch to English on mode exit
(:hooks meow-insert-exit-hook sis-set-english)

;; Context-aware input switching for org-mode, telega
(sis-global-cursor-color-mode t)
(sis-global-respect-mode t)
(sis-global-context-mode t)

Key Editing Features

PackagePurpose
move-dupMove/duplicate lines
rainbow-delimitersColorful parentheses
symbol-overlayHighlight symbols
vundoVisual undo tree
gogglesPulse modified regions
ultra-scrollSmooth scrolling

Version Control (init-vc.el)

Git integration with Magit and related tools.

Magit Configuration

;; Full-screen magit status
(:advice magit-status :around #'magit-fullscreen)

;; Key bindings
(keymap-global-set "C-x g" 'magit-status)
(keymap-global-set "C-x M-g" 'magit-dispatch)

;; Refined diff highlighting
(:option magit-diff-refine-hunk t)

Forge (GitHub/GitLab)

Support for GitHub and GitLab forges, including custom GitLab instance.

Diff Highlights

  • diff-hl - Fringe indicators for changes
  • blame-reveal - Interactive git blame

Minibuffer (init-minibuffer.el)

Modern completion framework with Vertico ecosystem.

Vertico + Consult

;; Vertico for vertical completion
(vertico-mode)
(:option vertico-cycle t)

;; Vertico-posframe for floating completion
(vertico-posframe-mode 1)

;; Consult commands
(keymap-global-set "C-c f l" 'consult-line)
(keymap-global-set "C-c f i" 'consult-imenu)
(keymap-global-set "C-c f f" 'consult-fd)
(keymap-global-set "C-c f r" 'consult-ripfd)
(keymap-global-set "C-c f b" 'consult-buffer)

Embark Actions

Context-aware actions on completion candidates.

(keymap-global-set "C-c ." 'embark-act)
(keymap-global-set "M-n"   'embark-next-symbol)
(keymap-global-set "M-p"   'embark-previous-symbol)

Marginalia

Rich annotations in the minibuffer.

Miniline

Custom overlay-based mode-line in the echo area.

Completion (init-completion.el)

In-buffer completion with Corfu ecosystem.

Corfu

(global-corfu-mode)
(:option corfu-cycle t
         corfu-auto t
         corfu-auto-prefix 2
         corfu-preselect 'prompt)

Cape

Completion-at-point extensions.

(add-to-list 'completion-at-point-functions #'cape-dabbrev)
(add-to-list 'completion-at-point-functions #'cape-file)

Orderless

Flexible matching styles with pinyin support.

YASnippet

Template expansion system.

Programming (init-prog.el)

Language support and development tools.

Tree-sitter Modes

Automatic file associations for tree-sitter major modes:

ExtensionMode
.pypython-ts-mode
.jsjs-ts-mode
.tstypescript-ts-mode
.tsxtsx-ts-mode
.jsonjson-ts-mode
.yamlyaml-ts-mode
.nixnix-ts-mode
.rsrust-ts-mode
.gogo-ts-mode
.javajava-ts-mode
.vuevue-mode
.lpybasilisp-ts-mode

Eglot LSP

;; Auto-start for specific modes
(:with-mode (python-ts-mode js-ts-mode tsx-ts-mode vue-mode latex-mode)
  (:hook eglot-ensure))

;; Custom server configurations
(add-to-list 'eglot-server-programs
             '((python-mode python-ts-mode) . ("rass" "basedruff")))
(add-to-list 'eglot-server-programs
             `((vue-mode vue-ts-mode typescript-ts-mode)
               . ("vue-language-server" "--stdio"
                  :initializationOptions ,(vue-eglot-init-options))))

Apheleia Formatting

Automatic code formatting on save.

;; Format on save in prog-mode
(:hook-into prog-mode)

;; Custom formatters
(setf (alist-get 'python-ts-mode apheleia-mode-alist) 'ruff)
(setf (alist-get 'typescript-ts-mode apheleia-mode-alist) 'prettier)

Flymake Diagnostics

;; Show diagnostics at end of line (Emacs 31+)
(when (version<= "31" emacs-version)
  (setopt flymake-show-diagnostics-at-end-of-line t))

Project Management

;; Extra project markers
(setopt project-vc-extra-root-markers
        '("package.json" "deps.edn" "project.clj"
          "Package.swift" ".envrc" ".tags" ".project"))

Envrc

Directory-local environment with direnv integration.

Org Mode (init-org.el)

Comprehensive org-mode configuration for GTD and writing.

Basic Settings

(:option org-directory *org-path*
         org-log-done t
         org-startup-indented t
         org-hide-emphasis-markers t
         org-image-actual-width nil)

GTD Workflow

;; TODO keywords
org-todo-keywords
'((sequence "TODO(t)" "NEXT(n)" "|" "DONE(d!/!)")
  (sequence "PROJECT(p)" "|" "DONE(d!/!)" "CANCELLED(c/!)")
  (sequence "WAITING(w/!)" "DELEGATED(e!)" "HOLD(h)" "|" "CANCELLED(c/!)"))

Org Agenda

Custom agenda views for GTD workflow:

  • g - Main GTD view (agenda, next actions, projects, waiting)
  • v - Orphaned tasks and inbox
  • N - Notes

Visual Enhancements

PackagePurpose
org-modernModern styling
org-modern-indentIndented blocks
org-appearReveal markup on cursor
org-tidyClean property display
valignTable alignment
visual-fill-columnCentered, wrapped text

Denote

Zettelkasten-style note-taking.

(keymap-global-set "C-c n n" 'denote-open-or-create)
(keymap-global-set "C-c n l" 'denote-link)
(keymap-global-set "C-c n b" 'denote-backlinks)

Babel

Code execution in org documents.

(org-babel-do-load-languages
 'org-babel-load-languages '((python . t)
                             (shell . t)
                             (verb . t)
                             (latex . t)))

Shell (init-shell.el)

Terminal emulation and shell integration.

Vterm

Full-featured terminal emulator.

Ghostel

Ghostty-powered terminal emulator with automatic native module download on first launch.

(:option ghostel-shell "zsh"
         ghostel-module-auto-install 'download)

Eshell

Emacs-native shell with custom prompt and eat integration.

(keymap-global-set "<f8>" 'eshell)

(:option eshell-prompt-function 'eshell-prompt-multiline
         eshell-highlight-prompt nil
         eshell-banner-message "")

;; Eat for better terminal emulation in eshell
(:with-hook eshell-load-hook
  (:hook eat-eshell-mode)
  (:hook eat-eshell-visual-command-mode))

AI Integration (init-ai.el)

LLM and AI-powered features.

GPTel

(:option gptel-default-mode 'org-mode
         gptel-model "openrouter/auto")

Agent Shell

Claude Code and other AI agent integration with sidebar support.

(keymap-global-set "C-c a s" 'agent-shell-sidebar-toggle)
(keymap-global-set "C-c a f" 'agent-shell-sidebar-toggle-focus)

AI Code

Code generation and review with Magit integration.

Library Modules (lib/)

Shared helper functions used across modules:

LibraryPurpose
lib-appearanceTheme switching, opacity adjustment
lib-consultConsult extensions
lib-eglotLSP server configurations
lib-envEnvironment variable loading
lib-eshellEshell prompt and aliases
lib-faceFont setup
lib-gptelGPTel backend configuration
lib-hsHideshow cycling
lib-lispElisp evaluation helpers
lib-magitMagit enhancements
lib-meowMeow keybinding setup
lib-orgOrg-mode utilities
lib-tabbarTab bar formatting
lib-telegaTelegram helpers
lib-transientTransient menu definitions
lib-treesitTree-sitter grammar sources
lib-vtermVterm keybindings
lib-windowWindow manipulation

Site-lisp Packages

Custom/local packages:

PackageDescription
minilineOverlay-based mode-line in echo area
miniline-segmentsSegments for miniline
gptel-quickQuick GPTel interactions
fpga-managerFPGA development tools

Themes

Rosé Pine

A soothing color theme with day and night variants.

  • rose-pine-night - Dark variant (default)
  • rose-pine-day - Light variant

Automatically switches based on macOS system appearance.

Nix Configuration

Available Packages

PackageDescription
demacs / demacs-igcDefault IGC build
demacs-igc-patchedIGC with macOS patches
demacs-gitGit master build
demacs-git-patchedGit master with macOS patches

Applied Patches (patched variants)

  • round-undecorated-frame - Rounded window corners
  • system-appearance - OS light/dark mode detection
  • ns-alpha-background - Transparent frame background
  • smooth-cursor - Smooth cursor animation

Custom Package Sources

Packages fetched from GitHub:

  • telega - Telegram client (custom fork)
  • setup-el - Setup.el macro library
  • eglot-x - Eglot extensions
  • org-modern-indent - Org indentation
  • agent-shell-sidebar - AI agent sidebar
  • And more…

Key Bindings Reference

Global

KeyCommand
C-c gMagit status
C-c f lConsult line
C-c f bConsult buffer
C-c f fConsult fd
C-c .Embark act
C-;Avy goto word
C-c n nDenote open/create
C-c e eEmacs access transient
C-c a sAgent shell sidebar
C-c tTelega prefix
<f8>Eshell

Org Mode

KeyCommand
C-c LStore link
C-c C-oOpen at point
C-M-upUp element

Programming

KeyCommand
C-c e pProg commands transient
C-c C-x C-fFormat buffer

Contributing

This is a personal configuration, but suggestions are welcome! Please open an issue or pull request on GitHub.

License

This configuration is released under the GPL-3.0 license. See LICENSE for details.

Generated for demacs - Desmond’s Emacs Configuration

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages