examples: Update emacs configuration.

This commit is contained in:
Hilton Chain committed 2026-06-15 22:40:00 +08:00
1 parent 9f9e2915bf
commit 40a0e474c7
10 files changed
+278 -402

No files matched your search

@@ -1,90 +0,0 @@
;;; -*- lexical-binding: t -*-
(use-package emacs
:custom
;; Disable tab indentation.
(indent-tabs-mode nil)
;; CJK support.
(word-wrap-by-category t)
:config
;; Avoid re-indenting current line after entering `RET'.
(setopt electric-indent-inhibit t)
:hook
(before-save . delete-trailing-whitespace)
;; Automatic parenthesis pairing.
(after-init . electric-pair-mode))
;; Check syntax on the fly.
(use-package flycheck
:hook
(after-init . global-flycheck-mode))
(use-package flycheck-guile
:after (flycheck geiser-guile))
(use-package geiser
:custom
(geiser-autodoc-identifier-format "%s → %s")
(geiser-mode-smart-tab-p t)
(geiser-mode-start-repl-p t)
(geiser-repl-query-on-kill-p nil)
:init
;; Context menu on right click.
;; Taken from guile-studio: https://elephly.net/guile-studio/
(defun context-menu ()
(let ((menu (make-sparse-keymap)))
(pcase major-mode
('scheme-mode
(define-key menu (vector 'switch-to-repl)
'("Switch to REPL" . geiser-repl-switch))
(define-key menu (vector 'eval-buffer)
'("Evaluate buffer" . geiser-eval-buffer))
(define-key menu (vector 'lookup-documentation)
'("Show documentation". geiser-doc-symbol-at-point))
menu)
(_
(mouse-menu-major-mode-map)))))
:bind
([mouse-3] . (lambda (event)
(interactive "e")
(mouse-set-point event)
(popup-menu (context-menu)))))
(use-package geiser-guile
:after (geiser)
:custom
(geiser-active-implementation '(guile))
(geiser-default-implementation 'guile)
:config
;; TODO: Make `flycheck-guile' support `guix repl'.
(dolist (path
(mapcar
#'expand-file-name
'("~/.config/guix/current/lib/guile/3.0/site-ccache"
"~/.config/guix/current/share/guile/site/3.0"
"~/.guix-profile/lib/guile/3.0/site-ccache"
"~/.guix-profile/share/guile/site/3.0"
"~/.guix-home/profile/lib/guile/3.0/site-ccache"
"~/.guix-home/profile/share/guile/site/3.0"
"/run/current-system/profile/lib/guile/3.0/site-ccache"
"/run/current-system/profile/share/guile/site/3.0")))
(add-to-list 'geiser-guile-load-path path t)))
(use-package macrostep
:bind
("C-c e" . macrostep-expand))
(use-package macrostep-geiser
:after (geiser-mode)
:hook
(geiser-mode . macrostep-geiser-setup))
(use-package macrostep-geiser
:after (geiser-repl)
:hook
(geiser-repl-mode . macrostep-geiser-setup))
(use-package puni
:hook
((eval-expression-minibuffer-setup nxml-mode prog-mode sgml-mode tex-mode)
. puni-mode))
@@ -1,65 +0,0 @@
;;; -*- lexical-binding: t -*-
;; https://github.com/nykma/nema/blob/develop/my-sample/font.el
(defvar nema--font-size 12 "Font size")
(defvar nema-fonts '((sans . "sans")
(serif . "serif")
(mono . "Victor Mono")
(cjk . "Sarasa Mono CL")
(symbol . "Noto Color Emoji")
(modeline . "Source Serif 4"))
"Fonts to use.")
(defun nema//get-font-family (key)
(alist-get key nema-fonts))
(defun nema//generate-font-spec (key)
(format "%s-%d"
(nema//get-font-family key)
nema--font-size))
(defun nema//load-base-font ()
"Load the default font for ascii characters."
(let* ((font-spec (nema//generate-font-spec 'mono)))
(set-frame-parameter nil 'font font-spec)
(add-to-list 'default-frame-alist (cons 'font font-spec))))
(defun nema//load-face-font ()
"Load fonts used in faces.
This function must be called after frame creation."
(let ((mono (nema//generate-font-spec 'mono))
(sans (nema//generate-font-spec 'sans))
(serif (nema//generate-font-spec 'sans-serif))
(modeline (nema//generate-font-spec 'modeline)))
(set-face-attribute 'variable-pitch nil :font sans)
(set-face-attribute 'variable-pitch-text nil :font serif)
(set-face-attribute 'fixed-pitch nil :font mono)
(set-face-attribute 'fixed-pitch-serif nil :font mono)
(set-face-attribute 'mode-line nil :font modeline)
(set-face-attribute 'mode-line-inactive nil :font modeline)))
(defun nema//load-ext-font ()
"Load fonts used for non-ascii characters.
This function must be called after frame creation."
(let ((font (frame-parameter nil 'font))
(font-spec-cjk (font-spec :family (nema//get-font-family 'cjk)))
(font-spec-symbol (font-spec :family (nema//get-font-family 'symbol))))
(dolist (charset '(kana han hangul cjk-misc bopomofo))
(set-fontset-font font charset font-spec-cjk))
(set-fontset-font font 'symbol font-spec-symbol)))
(defun nema/load-font ()
"Load all font configuration."
(interactive)
(when (display-graphic-p)
(nema//load-base-font)
(nema//load-ext-font)
(nema//load-face-font)))
(if (daemonp)
(add-hook 'server-after-make-frame-hook #'nema/load-font)
;; Else: not in daemon
(add-hook 'after-init-hook #'nema/load-font))
@@ -1,116 +0,0 @@
;;; -*- lexical-binding: t -*-
(use-package emacs
:custom
(blink-cursor-mode nil)
(enable-recursive-minibuffers t)
(inhibit-splash-screen t)
(uniquify-buffer-name-style 'forward)
;; Exclude unavailable completions.
(read-extended-command-predicate 'command-completion-default-include-p)
;; Case-insensitive completion.
(completion-ignore-case t)
(read-buffer-completion-ignore-case t)
(read-file-name-completion-ignore-case t)
:bind
([remap list-buffers] . switch-to-buffer)
:hook
(prog-mode . display-line-numbers-mode)
;; Scrolling enhancement.
(after-init . pixel-scroll-precision-mode)
;; Recursive minibuffers indicatior.
(after-init . minibuffer-depth-indicate-mode)
;; Save minibuffer history.
(after-init . savehist-mode)
;; `fill-column' indicator.
(prog-mode . display-fill-column-indicator-mode))
;; Theming
(use-package emacs
:custom
(fringe-mode 0)
(modus-themes-italic-constructs t)
:config
(load-theme 'modus-operandi-tinted :no-confirm))
(use-package corfu
:custom
;; Auto-completion.
(corfu-auto t)
(corfu-auto-delay 0.3)
:hook
(after-init . global-corfu-mode)
:bind
;; Free the `RET' key for less intrusive behavior.
(:map corfu-map
("RET" . nil)))
(use-package doom-modeline
:custom
(doom-modeline-icon nil)
(doom-modeline-height 18)
:hook
(after-init . doom-modeline-mode))
(use-package helpful
:bind
([remap describe-function] . helpful-callable)
([remap describe-variable] . helpful-variable)
([remap describe-key] . helpful-key)
([remap describe-command] . helpful-command)
([remap describe-symbol] . helpful-symbol)
("C-c C-d" . helpful-at-point))
(use-package hl-todo
:custom
(hl-todo-highlight-punctuation ":")
:hook
(prog-mode . hl-todo-mode))
(use-package isearch
:custom
(isearch-lazy-count t)
(isearch-wrap-pause 'no-ding)
(regexp-search-ring-max 200)
(search-ring-max 200))
(use-package mwim
:bind
([remap move-beginning-of-line] . mwim-beginning)
([remap move-end-of-line] . mwim-end))
(use-package orderless
:custom
(completion-styles '(orderless basic))
(completion-category-overrides '((file (styles basic partial-completion))))
(orderless-matching-styles '(orderless-literal orderless-flex orderless-regexp)))
(use-package paren
:custom
(show-paren-context-when-offscreen 'overlay)
:hook
(after-init . show-paren-mode))
(use-package rainbow-delimiters
:hook
(prog-mode . rainbow-delimiters-mode))
(use-package vertico
:hook
(after-init . vertico-mode))
(use-package vertico-directory
:after (vertico)
:bind
(:map vertico-map
("RET" . vertico-directory-enter)
("DEL" . vertico-directory-delete-char)
("M-DEL" . vertico-directory-delete-word))
:hook
(rfn-eshadow-update-overlay . vertico-directory-tidy))
(use-package which-key
:config
(which-key-setup-side-window-right-bottom)
:hook
(after-init . which-key-mode))
@@ -1,32 +0,0 @@
;;; -*- lexical-binding: t -*-
(use-package dired
:custom
(dired-listing-switches
"-lv --all --group-directories-first --human-readable")
:bind
([remap list-directory] . dired))
(use-package dired-aux
:custom
(dired-create-destination-dirs 'ask)
(dired-create-destination-dirs-on-trailing-dirsep t)
(dired-vc-rename-file t))
(use-package envrc
:hook
(after-init . envrc-global-mode))
(use-package magit
:custom
(git-commit-cd-to-toplevel t))
(use-package project
:config
(add-to-list 'project-switch-commands '(magit-project-status "Magit") t)
:bind
(:map project-prefix-map
("m" . magit-project-status)))
(use-package forge
:after (magit))
+228 -18
View File
@@ -5,29 +5,241 @@
(make-empty-file custom-file)
(load custom-file))
;; Tweak garbage collection strategy.
(use-package gcmh
:config
(gcmh-mode 1))
;; Set default storage locations for various packages.
(use-package no-littering
:config
(no-littering-theme-backups))
(use-package emacs
:custom
;; Workaround to use fish as login shell.
(shell-file-name "/bin/sh"))
(load-file (locate-user-emacs-file "init-fonts.el"))
(load-file (locate-user-emacs-file "init-interface.el"))
(load-file (locate-user-emacs-file "init-editing.el"))
(load-file (locate-user-emacs-file "init-miscellaneous.el"))
(fill-column 80)
(indent-tabs-mode nil) ;disable tab indentation
(shell-file-name "/bin/sh") ;use POSIX-compatible shell
(word-wrap-by-category t) ;improve CJK word-wrapping
:config
(setopt electric-indent-inhibit t) ;disable automatic re-indentation
:hook
(before-save . delete-trailing-whitespace)
(prog-mode . display-line-numbers-mode)
(prog-mode . display-fill-column-indicator-mode))
;;;
;;; Set up initial screen.
;;; Enhancements to the default interface.
;;;
(use-package helpful
:bind
([remap describe-function] . helpful-callable)
([remap describe-variable] . helpful-variable)
([remap describe-key] . helpful-key)
([remap describe-command] . helpful-command)
([remap describe-symbol] . helpful-symbol)
("C-c C-d" . helpful-at-point))
(use-package isearch
:custom
(isearch-wrap-pause 'no-ding))
(use-package mwim
:bind
([remap move-beginning-of-line] . mwim-beginning)
([remap move-end-of-line] . mwim-end))
(use-package which-key
:config
(which-key-setup-side-window-right-bottom)
:hook
(after-init . which-key-mode))
;;;
;;; Completion.
;;;
(use-package corfu
:custom
(corfu-auto t) ;auto-complete
(corfu-auto-delay 0.3)
:hook
(after-init . global-corfu-mode))
(use-package orderless
:custom
(completion-styles '(orderless basic))
(completion-category-overrides '((file (styles basic partial-completion))))
(orderless-matching-styles '(orderless-literal orderless-flex orderless-regexp)))
(use-package vertico
:custom
;; Case-insensitive completion.
(completion-ignore-case t)
(read-buffer-completion-ignore-case t)
(read-file-name-completion-ignore-case t)
:hook
(after-init . savehist-mode) ;save minibuffer history
(after-init . vertico-mode))
(use-package vertico-directory
:after (vertico)
:hook
;; Tidy shadowed file names.
(rfn-eshadow-update-overlay . vertico-directory-tidy)
:bind
((:map vertico-map)
("RET" . vertico-directory-enter)
("DEL" . vertico-directory-delete-char)
("M-DEL" . vertico-directory-delete-word)))
;;;
;;; Guile hacking.
;;;
(use-package flycheck
:hook
(after-init . global-flycheck-mode))
(use-package flycheck-guile
:after (flycheck geiser-guile))
(use-package geiser
:custom
(geiser-autodoc-identifier-format "%s → %s")
(geiser-mode-smart-tab-p t)
(geiser-mode-start-repl-p t)
(geiser-repl-query-on-kill-p nil))
(use-package geiser-guile
:after (geiser)
:custom
(geiser-active-implementation '(guile))
(geiser-default-implementation 'guile)
:config
;; TODO: Add guix repl support to `flycheck-guile'.
(dolist (path
(mapcar
#'expand-file-name
'("~/.config/guix/current/share/guile/site/3.0"
"~/.guix-profile/share/guile/site/3.0"
"~/.guix-home/profile/share/guile/site/3.0"
"/run/current-system/profile/share/guile/site/3.0")))
(add-to-list 'geiser-guile-load-path path t)))
(use-package info-look
:config
(info-lookup-add-help
:mode 'scheme-mode
:regexp "[^()`',\" \n]+"
:ignore-case nil
:doc-spec
(mapcar (lambda (node-name)
(list node-name nil "^[ ]+-+ [^:]+:[ ]*" "\\b"))
'("(guile)R5RS Index"
"(guix)Programming Index"
"(guile)Procedure Index"
"(guile)Variable Index"
"(r5rs)Index"
"(guile)Concept Index"
"(guix)Concept Index"))))
(use-package parinfer-rust-mode
:config
;; These customizations are managed by Guix but will be overridden if using
;; `no-littering'. Reset them to standard values.
(custom-reevaluate-setting 'parinfer-rust-library-directory)
(custom-reevaluate-setting 'parinfer-rust-library)
:hook
((emacs-lisp-mode lisp-mode scheme-mode) . parinfer-rust-mode))
;;;
;;; Theming.
;;;
(use-package emacs
:config
(load-theme 'modus-operandi-tinted :no-confirm))
(use-package doom-modeline
:custom
(doom-modeline-icon nil)
(doom-modeline-height 18)
:hook
(after-init . doom-modeline-mode))
;;;
;;; Font configuration with proper CJK support. Based on
;;; https://github.com/nykma/nema/blob/develop/my-sample/font.el
;;;
(use-package emacs
:config
(defvar nema--font-size 12 "Font size")
(defvar nema-fonts '((sans . "sans")
(serif . "serif")
(mono . "Victor Mono")
(cjk . "Sarasa Mono CL")
(symbol . "Noto Color Emoji")
(modeline . "Source Serif 4"))
"Fonts to use.")
(defun nema//get-font-family (key)
(alist-get key nema-fonts))
(defun nema//generate-font-spec (key)
(format "%s-%d"
(nema//get-font-family key)
nema--font-size))
(defun nema//load-base-font ()
"Load the default font for ascii characters."
(let* ((font-spec (nema//generate-font-spec 'mono)))
(set-frame-parameter nil 'font font-spec)
(add-to-list 'default-frame-alist (cons 'font font-spec))))
(defun nema//load-face-font ()
"Load fonts used in faces.
This function must be called after frame creation."
(let ((mono (nema//generate-font-spec 'mono))
(sans (nema//generate-font-spec 'sans))
(serif (nema//generate-font-spec 'sans-serif))
(modeline (nema//generate-font-spec 'modeline)))
(set-face-attribute 'variable-pitch nil :font sans)
(set-face-attribute 'variable-pitch-text nil :font serif)
(set-face-attribute 'fixed-pitch nil :font mono)
(set-face-attribute 'fixed-pitch-serif nil :font mono)
(set-face-attribute 'mode-line nil :font modeline)
(set-face-attribute 'mode-line-inactive nil :font modeline)))
(defun nema//load-ext-font ()
"Load fonts used for non-ascii characters.
This function must be called after frame creation."
(let ((font (frame-parameter nil 'font))
(font-spec-cjk (font-spec :family (nema//get-font-family 'cjk)))
(font-spec-symbol (font-spec :family (nema//get-font-family 'symbol))))
(dolist (charset '(kana han hangul cjk-misc bopomofo))
(set-fontset-font font charset font-spec-cjk))
(set-fontset-font font 'symbol font-spec-symbol)))
(defun nema/load-font ()
"Load all font configuration."
(interactive)
(when (display-graphic-p)
(nema//load-base-font)
(nema//load-ext-font)
(nema//load-face-font)))
(if (daemonp)
(add-hook 'server-after-make-frame-hook #'nema/load-font)
;; Else: not in daemon
(add-hook 'after-init-hook #'nema/load-font)))
;;;
;;; Scratch buffer.
;;;
(progn
@@ -39,7 +251,5 @@
\n")
(scheme-mode)
(geiser-repl-import-module "(gnu)")
(geiser-repl-import-module "(nonguix)")
(geiser-repl-import-module "(rosenthal)")
(delete-window)
(display-splash-screen))
(geiser-repl-import-module "(guix)")
(delete-window))
+15 -5
View File
@@ -1,8 +1,18 @@
#!/bin/sh
dir="$(dirname "$(realpath "$0")")"
if [[ ! -f ~/.config/emacs/init.el ]]
TOP_DIR="$(dirname "$(realpath "$0")")"
# Install packages.
echo '
(use-modules (guix packages)
(guix scripts install))
(apply guix-install
(map package-name
(load "packages")))' |
guix repl --type=machine
# Install configuration file.
if [ ! -f ~/.config/emacs/init.el ]
then
mkdir -p ~/.config/emacs
cp "$dir/init"* ~/.config/emacs
install -D -mode=0644 --target-directory="$HOME/.config/emacs" "$TOP_DIR/init.el"
fi
cat "$dir/packages.txt" | xargs guix package --install
@@ -1,36 +0,0 @@
;; What follows is a "manifest" equivalent to the command line you gave.
;; You can store it in a file that you may then pass to any 'guix' command
;; that accepts a '--manifest' (or '-m') option.
(specifications->manifest
(list "emacs-pgtk"
"emacs-corfu"
"emacs-doom-modeline"
"emacs-edit-indirect"
"emacs-envrc"
"emacs-evil"
"emacs-fish-mode"
"emacs-flycheck"
"emacs-flycheck-guile"
"emacs-forge"
"emacs-gcmh"
"emacs-geiser"
"emacs-geiser-guile"
"emacs-helpful"
"emacs-hl-todo"
"emacs-json-mode"
"emacs-macrostep"
"emacs-macrostep-geiser"
"emacs-magit"
"emacs-markdown-mode"
"emacs-mwim"
"emacs-no-littering"
"emacs-orderless"
"emacs-puni"
"emacs-rainbow-delimiters"
"emacs-vertico"
"fontconfig"
"font-adobe-source-serif"
"font-google-noto-emoji"
"font-sarasa-gothic"
"font-victor-mono"))
+35
View File
@@ -0,0 +1,35 @@
;; -*- mode: scheme -*-
(use-modules (gnu packages))
(map specification->package
(list (if (getenv "WAYLAND_DISPLAY")
"emacs-pgtk"
"emacs")
"emacs-no-littering"
;; Enhancements to the default interface.
"emacs-helpful"
"emacs-mwim"
;; Completion.
"emacs-corfu"
"emacs-orderless"
"emacs-vertico"
;; Guile hacking.
"emacs-flycheck"
"emacs-flycheck-guile"
"emacs-geiser"
"emacs-geiser-guile"
"emacs-parinfer-rust-mode"
;; Theming.
"emacs-doom-modeline"
;; Fonts.
"font-adobe-source-serif"
"font-google-noto-emoji"
"font-sarasa-gothic"
"font-victor-mono"
"fontconfig"
;; Other useful packages.
"emacs-edit-indirect"
"emacs-evil"
"emacs-guix"
"emacs-magit"
"emacs-markdown-mode"))
@@ -1,31 +0,0 @@
emacs-pgtk
emacs-corfu
emacs-doom-modeline
emacs-edit-indirect
emacs-envrc
emacs-evil
emacs-fish-mode
emacs-flycheck
emacs-flycheck-guile
emacs-forge
emacs-gcmh
emacs-geiser
emacs-geiser-guile
emacs-helpful
emacs-hl-todo
emacs-json-mode
emacs-macrostep
emacs-macrostep-geiser
emacs-magit
emacs-markdown-mode
emacs-mwim
emacs-no-littering
emacs-orderless
emacs-puni
emacs-rainbow-delimiters
emacs-vertico
fontconfig
font-adobe-source-serif
font-google-noto-emoji
font-sarasa-gothic
font-victor-mono