This commit is contained in:
Zelong Kuang
2026-03-30 16:37:02 +11:00
parent a3468b833e
commit 3e88318f79
8 changed files with 120 additions and 83 deletions

View File

@@ -1,10 +1,10 @@
;; -*- lexical-binding: t -*- ;; -*- lexical-binding: t -*-
(if noninteractive ; in CLI sessions (if noninteractive ; in CLI sessions
(setq gc-cons-threshold #x8000000 ; 128MB (setq-default gc-cons-threshold 100000000 ; 128MB
;; Backport from 29 (see emacs-mirror/emacs@73a384a98698) ;; Backport from 29 (see emacs-mirror/emacs@73a384a98698)
gc-cons-percentage 1.0) gc-cons-percentage 1.0)
(setq gc-cons-threshold most-positive-fixnum)) (setq-default gc-cons-threshold most-positive-fixnum))
(setq read-process-output-max (* 1024 1024)) (setq read-process-output-max (* 1024 1024))

View File

@@ -4,7 +4,7 @@
:demand t :demand t
:config :config
;; To disable collection of benchmark data after init is done. ;; To disable collection of benchmark data after init is done.
;; (add-hook 'emacs-startup-hook 'benchmark-init/deactivate) (add-hook 'emacs-startup-hook 'benchmark-init/deactivate)
) )
;; Load some component of large package (org, magit etc.) before complete mount ;; Load some component of large package (org, magit etc.) before complete mount

View File

@@ -32,6 +32,7 @@
(bind-keys ("s-r" . revert-buffer-quick) (bind-keys ("s-r" . revert-buffer-quick)
("C-x K" . delete-this-file) ("C-x K" . delete-this-file)
("C-c C-l" . reload-init-file)) ("C-c C-l" . reload-init-file)
("C-c C-w 0" . desktop-clear))
(provide 'init-bindings) (provide 'init-bindings)

View File

@@ -219,7 +219,7 @@ the element after the #+HEADER: tag."
:hook (org-latex-preview-mode . org-latex-preview-center-mode) :hook (org-latex-preview-mode . org-latex-preview-center-mode)
:config :config
;; Higher resolution when using dvipng ;; Higher resolution when using dvipng
(plist-put org-latex-preview-appearance-options :page-width 1.0) (plist-put org-latex-preview-appearance-options :page-width 0.6)
;; (plist-put org-latex-preview-appearance-options :margin 1) ;; (plist-put org-latex-preview-appearance-options :margin 1)
(plist-put org-latex-preview-appearance-options :scale 2.0) (plist-put org-latex-preview-appearance-options :scale 2.0)

View File

@@ -2,37 +2,78 @@
(use-package shell (use-package shell
:straight nil :straight nil
:hook ((shell-mode . my/shell-mode-hook) :hook ((comint-output-filter-functions . comint-strip-ctrl-m))
(comint-output-filter-functions . comint-strip-ctrl-m))
:init :init
(setq system-uses-terminfo nil) (setq system-uses-terminfo nil))
;; Emacs command shell
(use-package eshell
:ensure nil
:defines eshell-prompt-function
:bind (:map eshell-mode-map
([remap recenter-top-bottom] . eshell/clear))
:config
(with-no-warnings (with-no-warnings
(defun my/shell-simple-send (proc command) (defun eshell/clear ()
"Various PROC COMMANDs pre-processing before sending to shell." "Clear the eshell buffer."
(cond (let ((inhibit-read-only t))
;; Checking for clear command and execute it. (erase-buffer)
((string-match "^[ \t]*clear[ \t]*$" command) (eshell-send-input)))
(comint-send-string proc "\n") (defun eshell/emacs (&rest args)
(erase-buffer)) "Open a file (ARGS) in Emacs. Some habits die hard."
;; Checking for man command and execute it. (if (null args)
((string-match "^[ \t]*man[ \t]*" command) ;; If I just ran "emacs", I probably expect to be launching
(comint-send-string proc "\n") ;; Emacs, which is rather silly since I'm already in Emacs.
(setq command (replace-regexp-in-string "^[ \t]*man[ \t]*" "" command)) ;; So just pretend to do what I ask.
(setq command (replace-regexp-in-string "[ \t]+$" "" command)) (bury-buffer)
;;(message (format "command %s command" command)) ;; We have to expand the file names or else naming a directory in an
(funcall 'man command)) ;; argument causes later arguments to be looked for in that directory,
;; Send other commands to the default handler. ;; not the starting directory
(t (comint-simple-send proc command)))) (mapc #'find-file (mapcar #'expand-file-name (flatten-tree (reverse args))))))
(defalias 'eshell/e #'eshell/emacs)
(defalias 'eshell/ec #'eshell/emacs)
(defun eshell/ebc (&rest args)
"Compile a file (ARGS) in Emacs. Use `compile' to do background make."
(if (eshell-interactive-output-p)
(let ((compilation-process-setup-function
(list 'lambda nil
(list 'setq 'process-environment
(list 'quote (eshell-copy-environment))))))
(compile (eshell-flatten-and-stringify args))
(pop-to-buffer compilation-last-buffer))
(throw 'eshell-replace-command
(let ((l (eshell-stringify-list (flatten-tree args))))
(eshell-parse-command (car l) (cdr l))))))
(put 'eshell/ebc 'eshell-no-numeric-conversions t)
(defun eshell-view-file (file)
"View FILE. A version of `view-file' which properly rets the eshell prompt."
(interactive "fView file: ")
(unless (file-exists-p file) (error "%s does not exist" file))
(let ((buffer (find-file-noselect file)))
(if (eq (get (buffer-local-value 'major-mode buffer) 'mode-class)
'special)
(progn
(switch-to-buffer buffer)
(message "Not using View mode because the major mode is special"))
(let ((undo-window (list (window-buffer) (window-start)
(+ (window-point)
(length (funcall eshell-prompt-function))))))
(switch-to-buffer buffer)
(view-mode-enter (cons (selected-window) (cons nil undo-window))
'kill-buffer)))))
(defun my/shell-mode-hook () (defun eshell/less (&rest args)
"Shell mode customization." "Invoke `view-file' on a file (ARGS).
(local-set-key '[up] 'comint-previous-input)
(local-set-key '[down] 'comint-next-input)
(local-set-key '[(shift tab)] 'comint-next-matching-input-from-input)
(ansi-color-for-comint-mode-on) \"less +42 foo\" will go to line 42 in the buffer for foo."
(setq comint-input-sender 'my/shell-simple-send)))) (while args
(if (string-match "\\`\\+\\([0-9]+\\)\\'" (car args))
(let* ((line (string-to-number (match-string 1 (pop args))))
(file (pop args)))
(eshell-view-file file)
(forward-line line))
(eshell-view-file (pop args)))))
(defalias 'eshell/more #'eshell/less)))
(use-package xterm-color (use-package xterm-color
:defines (compilation-environment :defines (compilation-environment
@@ -42,6 +83,18 @@
;; For shell and interpreters ;; For shell and interpreters
(setenv "TERM" "xterm-256color") (setenv "TERM" "xterm-256color")
(setq comint-output-filter-functions
(remove 'ansi-color-process-output comint-output-filter-functions))
(add-hook 'comint-preoutput-filter-functions 'xterm-color-filter)
(add-hook 'shell-mode-hook
(lambda ()
;; Disable font-locking to improve performance
(font-lock-mode -1)
;; Prevent font-locking from being re-enabled
(make-local-variable 'font-lock-function)
(setq font-lock-function #'ignore)))
;; For eshell
(with-eval-after-load 'esh-mode (with-eval-after-load 'esh-mode
(add-hook 'eshell-before-prompt-hook (add-hook 'eshell-before-prompt-hook
(lambda () (lambda ()
@@ -49,14 +102,22 @@
(add-to-list 'eshell-preoutput-filter-functions 'xterm-color-filter) (add-to-list 'eshell-preoutput-filter-functions 'xterm-color-filter)
(setq eshell-output-filter-functions (setq eshell-output-filter-functions
(remove 'eshell-handle-ansi-color eshell-output-filter-functions))) (remove 'eshell-handle-ansi-color eshell-output-filter-functions)))
(setq compilation-environment '("TERM=xterm-256color")) (setq compilation-environment '("TERM=xterm-256color"))
(defun my/advice-compilation-filter (fn proc string)
(funcall fn proc
(if (eq major-mode 'rg-mode) ; compatible with `rg'
string
(xterm-color-filter string))))
(advice-add 'compilation-filter :around #'my/advice-compilation-filter)
(advice-add 'gud-filter :around #'my/advice-compilation-filter)
) )
(setq eshell-banner-message "") (setq eshell-banner-message "")
(use-package eat (use-package eat
:bind ("C-`" . eshell-toggle) :bind ("C-`" . eat-toggle)
:bind ("C-<escape>" . eat-toggle) :bind ("C-<escape>" . eshell-toggle)
:hook ((eshell-load . eat-eshell-mode) :hook ((eshell-load . eat-eshell-mode)
(eshell-load . eat-eshell-visual-command-mode)) (eshell-load . eat-eshell-visual-command-mode))
:straight `(eat :repo "https://codeberg.org/akib/emacs-eat" :straight `(eat :repo "https://codeberg.org/akib/emacs-eat"
@@ -92,8 +153,8 @@
:defines eshell-highlight-prompt :defines eshell-highlight-prompt
:autoload (epe-theme-lambda epe-theme-dakrone epe-theme-pipeline) :autoload (epe-theme-lambda epe-theme-dakrone epe-theme-pipeline)
:init :init
(setq eshell-highlight-prompt t (setq eshell-highlight-prompt t)
eshell-prompt-function #'epe-theme-lambda)) (setq eshell-prompt-function #'epe-theme-lambda))
;; (use-package eshell-z ;; (use-package eshell-z
;; :hook (eshell-mode . (lambda () (require 'eshell-z)))) ;; :hook (eshell-mode . (lambda () (require 'eshell-z))))

View File

@@ -6,10 +6,11 @@
;; ("make"))) ;; ("make")))
:straight (auctex :type git :host nil :repo "https://git.savannah.gnu.org/git/auctex.git") :straight (auctex :type git :host nil :repo "https://git.savannah.gnu.org/git/auctex.git")
:mode (("\\.tex\\'" . LaTeX-mode)) :mode (("\\.tex\\'" . LaTeX-mode))
:hook (LaTeX-mode . prettify-symbols-mode) :hook ((LaTeX-mode . prettify-symbols-mode)
:hook (LaTeX-mode . visual-line-mode) (LaTeX-mode . visual-line-mode)
:hook (LaTeX-mode . turn-on-reftex) (LaTeX-mode . turn-on-reftex)
:hook (LaTeX-mode . lsp-deferred) (LaTeX-mode . lsp-deferred)
(LaTeX-mode . (lambda () (lsp-ui-mode -1))))
:bind (:map LaTeX-mode-map :bind (:map LaTeX-mode-map
("C-S-e" . latex-math-from-calc) ("C-S-e" . latex-math-from-calc)
("C-c x" . TeX-clean) ("C-c x" . TeX-clean)

View File

@@ -40,52 +40,23 @@
;; :config ;; :config
;; (modus-themes-load-theme 'standard-light-tinted)) ;; (modus-themes-load-theme 'standard-light-tinted))
;; fix this
(use-package doric-themes (use-package doric-themes
:bind ("<f5>" . doric-themes-load-random) :bind ("<f5>" . doric-themes-load-random)
:bind ("C-<f5>" . doric-load-random-light) :bind ("C-<f5>" . (lambda () (interactive) (doric-themes-load-random 'light)))
:bind ("M-<f5>" . doric-load-random-dark) :bind ("M-<f5>" . (lambda () (interactive) (doric-themes-load-random 'dark)))
:commands doric-themes-load-random
:init :init
(defvar my/doric-dark-themes
'(doric-fire
doric-valley
doric-walnut
doric-mermaid
doric-pine
doric-plum
doric-water))
(defvar my/doric-light-themes
'(doric-oak
doric-jade
doric-wind
doric-beach
doric-coral
doric-earth
doric-almond))
(defun synchronise-theme () (defun synchronise-theme ()
(let* ((hour (string-to-number (let* ((hour (string-to-number
(substring (current-time-string) 11 13))) (substring (current-time-string) 11 13))))
(theme-list (if (member hour (number-sequence 6 18)) (if (member hour (number-sequence 6 18))
my/doric-light-themes (doric-themes-load-random 'light)
my/doric-dark-themes)) (doric-themes-load-random 'dark))))
(loaded (seq-random-elt theme-list))) :init
(mapc #'disable-theme custom-enabled-themes)
(load-theme loaded :no-confirm)))
(synchronise-theme) (synchronise-theme)
(run-with-timer 3600 3600 'synchronise-theme) (run-with-timer 3600 3600 'synchronise-theme)
)
(defun doric-load-random-light ()
(interactive)
(mapc #'disable-theme custom-enabled-themes)
(let ((loaded (seq-random-elt my/doric-light-themes)))
(load-theme loaded :no-confirm)))
(defun doric-load-random-dark ()
(interactive)
(mapc #'disable-theme custom-enabled-themes)
(let ((loaded (seq-random-elt my/doric-dark-themes)))
(load-theme loaded :no-confirm))))
(use-package rainbow-delimiters (use-package rainbow-delimiters
:hook ((prog-mode . rainbow-delimiters-mode) :hook ((prog-mode . rainbow-delimiters-mode)
@@ -138,7 +109,7 @@
(pcase system-type (pcase system-type
('darwin ; macOS ('darwin ; macOS
(set-face-attribute 'default nil :font "Sarasa Mono TC Nerd Font-22") ; 20 * 1.5 (set-face-attribute 'default nil :font "Sarasa Term SC-22") ; 20 * 1.5
(set-face-attribute 'variable-pitch nil :font "Bookerly-22" :weight 'light) (set-face-attribute 'variable-pitch nil :font "Bookerly-22" :weight 'light)
(set-face-attribute 'fixed-pitch nil :font "Sarasa Term SC-22") (set-face-attribute 'fixed-pitch nil :font "Sarasa Term SC-22")

View File

@@ -49,13 +49,16 @@
;; Fast search tool `ripgrep' ;; Fast search tool `ripgrep'
(use-package rg (use-package rg
:hook (after-init . rg-enable-default-bindings) ;; :hook (after-init . rg-enable-default-bindings)
:bind (:map rg-global-map :bind (:map rg-global-map
("c" . rg-dwim-current-dir) ("c" . rg-dwim-current-dir)
("f" . rg-dwim-current-file) ("f" . rg-dwim-current-file)
("m" . rg-menu)) ("m" . rg-menu))
:init (setq rg-show-columns t) :init (setq rg-show-columns t)
:config (add-to-list 'rg-custom-type-aliases '("tmpl" . "*.tmpl"))) :config
(add-to-list 'rg-custom-type-aliases '("tmpl" . "*.tmpl"))
(rg-enable-default-bindings)
)
;; (use-package pdf-tools ;; (use-package pdf-tools
;; :config ;; :config