commit 229f446b2b35ee70ff48173353dc47f3cf3517b2
parent a97141645b081fc55949dc231697b1269da79480
Author: andsy10 <andsy1016@gmail.com>
Date: Sat, 10 Oct 2026 17:39:58 +0800
Centralize custom variables into init-custom.el
Diffstat:
11 files changed, 142 insertions(+), 89 deletions(-)
diff --git a/init.el b/init.el
@@ -22,13 +22,14 @@
(load custom-file t)
(defconst *is-mac* (eq system-type 'darwin))
+(defconst *is-emacs-mac-port* (featurep 'mac))
(defconst *is-linux* (eq system-type 'gnu/linux))
(defconst *is-windows* (or (eq system-type 'ms-dos) (eq system-type 'windows-nt)))
(defconst *is-android* (if (getenv "TERMUX_VERSION") t nil))
(if (or (display-graphic-p) *is-android*)
(progn
- (require 'init-proxy nil t)
+ (require 'init-custom)
(require 'init-startup)
(require 'init-elpa)
(require 'init-base)
diff --git a/lisp/init-custom.el b/lisp/init-custom.el
@@ -0,0 +1,60 @@
+;;; init-custom.el --- custom variables -*- lexical-binding: t -*-
+
+;;; Commentary:
+
+;;; Code:
+
+(defcustom my-enable-guix nil
+ "Enable `guix' or not."
+ :type 'boolean)
+
+(defcustom my-enable-exwm nil
+ "Enable `exwm' or not."
+ :type 'boolean)
+
+(defcustom my-enable-dashboard nil
+ "Enable `dashboard' or not."
+ :type 'boolean)
+
+(defcustom my-enable-unessentials nil
+ "Enable some unessential packages."
+ :type 'boolean)
+
+(defcustom my-blog-directory
+ (if *is-windows* "h:/emacs/blog/posts/" "~/org/blog/posts/")
+ "My blog directory"
+ :type 'string)
+
+(with-eval-after-load 'org
+ (defcustom my-org-capture-file
+ (concat org-directory "/20260509T232442==agenda--all-my-todos.org")
+ "File used to capture todos."
+ :type 'string)
+
+ (defcustom my-org-capture-game-file
+ (concat org-directory "/20260810T233455==agenda--all-about-game__game.org")
+ "File used to capture games"
+ :type 'string))
+
+(defcustom my-frame-parameter 'fullscreen
+ "Frame parameter on startup."
+ :type '(choice (const :tag "Fullscreen" fullscreen)
+ (const :tag "Maximized" maximized)))
+
+(defcustom my-cns-dir
+ (if *is-windows*
+ "h:/emacs/emacs-chinese-word-segmentation/"
+ "~/emacs-stuff/emacs-chinese-word-segmentation/")
+ "Directory for cns."
+ :type 'string)
+
+(defcustom my-proxy "127.0.0.1:7890"
+ "Proxy."
+ :type 'string)
+
+(defcustom my-load-proxy nil
+ "Load proxy config or not."
+ :type 'boolean)
+
+(provide 'init-custom)
+;;; init-custom.el ends here
diff --git a/lisp/init-dashboard.el b/lisp/init-dashboard.el
@@ -1,24 +0,0 @@
-;;; init-dashboard.el --- dashboard -*- lexical-binding: t -*-
-
-;;; Commentary:
-
-;;; Code:
-
-(my-use-package dashboard
- :autoload dashboard-setup-startup-hook
- :hook after-init
- :config
- (setq dashboard-banner-logo-title (format "%s" emacs-version)
- dashboard-banner-ascii " ##### # # # # ####### # # # ##### ##### \n# # ## # # # # ## ## # # # # # # \n# # # # # # # # # # # # # # # \n# #### # # # # # ##### # # # # # # ##### \n# # # # # # # # # # ####### # # \n# # # ## # # # # # # # # # # # \n ##### # # ##### ####### # # # # ##### ##### "
- dashboard-startup-banner 'ascii
- dashboard-footer-messages '("hello")
- dashboard-center-content t
- dashboard-navigation-cycle t
- dashboard-items '((recents . 8)
- (bookmarks . 5)
- (projects . 5))
- dashboard-item-shortcuts '((recents . "r") (bookmarks . "b") (projects . "p") (agenda . "a") (registers . "e")))
- (dashboard-setup-startup-hook))
-
-(provide 'init-dashboard)
-;;; init-dashboard.el ends here
diff --git a/lisp/init-exwm.el b/lisp/init-exwm.el
@@ -37,7 +37,7 @@
(eshell-command "fcitx5 -d"))
(eshell-command "fcitx5 -d"))))
-(my-use-package exwm *is-linux*
+(my-use-package exwm my-enable-exwm
:hook
(exwm-init . restart-fcitx5)
(exwm-init . my-desktop-init)
@@ -141,7 +141,7 @@
(exwm-workspace-rename-buffer exwm-class-name))
(add-hook 'exwm-update-class-hook #'my-exwm-update-class))
-(my-use-package desktop-environment *is-linux*
+(my-use-package desktop-environment my-enable-exwm
:after exwm
:demand t
:init
@@ -157,7 +157,7 @@
(desktop-environment-screenshot-partial-command
"import ~/Pictures/screenshot-$(date +%Y%m%d-%H%M%S).png"))
-(my-use-package xdg-launcher *is-linux*
+(my-use-package xdg-launcher my-enable-exwm
:demand t
:after exwm
:straight
@@ -167,7 +167,7 @@
:bind
(("s-SPC" . xdg-launcher-run-app)))
-(my-use-package launcher *is-mac*
+(my-use-package launcher (and *is-mac* my-enable-unessentials)
:straight
(launcher
:type git
diff --git a/lisp/init-gptel.el b/lisp/init-gptel.el
@@ -5,7 +5,7 @@
;;; Code:
-(my-use-package gptel
+(my-use-package gptel my-enable-unessentials
:config
(setq gptel-log-level t
gptel-default-mode 'org-mode
@@ -112,11 +112,11 @@ explanations, no quotes, no punctuation, no file extension."
(message "WARNING: gptel-request did not register callback!")))))
(keymap-set gptel-mode-map "C-c C-s" #'my-gptel-save-session))
-(my-use-package gptel-agent
+(my-use-package gptel-agent my-enable-unessentials
:after gptel
:demand t)
-(my-use-package gptel-magit
+(my-use-package gptel-magit my-enable-unessentials
:straight
(gptel-magit :fork (:host github :repo "ArthurHeymans/gptel-magit"))
:hook
@@ -143,7 +143,7 @@ explanations, no quotes, no punctuation, no file extension."
gptel-magit-backend (gptel-get-backend "gptel-Kimi-Code-magit"))))
;; pi-coding-agent
-(my-use-package pilish
+(my-use-package pilish my-enable-unessentials
:commands my-pilish
:config
(defun my-pilish ()
diff --git a/lisp/init-kbd.el b/lisp/init-kbd.el
@@ -496,5 +496,9 @@
(general-def "C-c <f12>" #'my-persp-scratch-buffer)
(general-def "C-c <delete>" #'my-persp-scratch-buffer))
+;; fullscreen
+(if *is-emacs-mac-port*
+ (general-def "<f12>" #'mac-toggle-frame-fullscreen))
+
(provide 'init-kbd)
;;; init-kbd.el ends here
diff --git a/lisp/init-org.el b/lisp/init-org.el
@@ -18,14 +18,6 @@
(*is-linux* "~/org/my-org-note")
(*is-android* "~/storage/shared/my-org-note")))
- (defcustom my-blog-directory
- (cond
- (*is-windows* "h:/emacs/blog/posts/")
- (*is-mac* "~/org/blog/posts/")
- (*is-linux* "~/org/blog/posts/")
- (*is-android* "~/org/blog/posts/"))
- "My blog directory")
-
:config
(defun my-org-tab-complete ()
(let ((completion-at-point-functions
@@ -341,13 +333,6 @@
;; capture
(my-use-package org-capture
:straight nil
- :init
- (defcustom my-org-capture-file
- (concat org-directory "/20260509T232442==agenda--all-my-todos.org")
- "File used to capture todos.")
- (defcustom my-org-capture-game-file
- (concat org-directory "/20260810T233455==agenda--all-about-game__game.org")
- "File used to capture games")
:config
(setq org-capture-templates
`(("t" "TODO" entry
@@ -367,7 +352,7 @@
"* GAME %?\n%T" :empty-lines 1))))
;; presentation
-(my-use-package org-tree-slide
+(my-use-package org-tree-slide my-enable-unessentials
:commands my-org-tree-slide-start my-org-tree-slide-stop
:config
(defun my-org-tree-slide-start ()
@@ -397,7 +382,7 @@
(org-tree-slide-mode -1))))
;; Chinese calendar
-(my-use-package cal-china-x
+(my-use-package cal-china-x my-enable-unessentials
:after calendar
:autoload cal-china-x-setup
:init
diff --git a/lisp/init-package.el b/lisp/init-package.el
@@ -5,7 +5,7 @@
;;; Code:
;; keycast
-(my-use-package keycast)
+(my-use-package keycast my-enable-unessentials)
;; spell checker
(my-use-package jinx (not *is-windows*)
@@ -244,7 +244,7 @@ against its previous revision."
:repo "https://git.trogloxene.org/project-ibuffer.git"))
;; emms
-(my-use-package emms
+(my-use-package emms my-enable-unessentials
:commands
(emms-playlist-mode-switch-buffer)
:config
@@ -255,7 +255,7 @@ against its previous revision."
(emms-history-load))
;; tokei
-(my-use-package tokei)
+(my-use-package tokei my-enable-unessentials)
;; helpful
(my-use-package helpful
@@ -299,15 +299,15 @@ against its previous revision."
(helpful-update))))))))
;; typing game
-(my-use-package typit)
+(my-use-package typit my-enable-unessentials)
;; z-machine interpreter
-(my-use-package malyon
+(my-use-package malyon my-enable-unessentials
:straight
(malyon :fork (:host github :repo "cjennings/malyon")))
;; guix
-(my-use-package guix *is-linux*)
+(my-use-package guix my-enable-guix)
;; process manager
(my-use-package proced
@@ -335,17 +335,17 @@ Prefix ARG controls sort order, see `proced-sort-interactive'."
(general-def proced-mode-map "s r" #'proced-sort-rss))
;; syncthing
-(my-use-package syncthing
+(my-use-package syncthing my-enable-unessentials
:hook
(syncthing-mode . enable-truncate-lines))
;; pinentry
-(my-use-package pinentry *is-linux*
+(my-use-package pinentry (and *is-linux* my-enable-unessentials)
:hook
(after-init . pinentry-start))
;; pass
-(my-use-package pass
+(my-use-package pass my-enable-unessentials
:config
(defvar my-pass-meta-fields '("url" "username" "email")
"List of pass metadata fields for completion.")
@@ -405,7 +405,7 @@ Prefix ARG controls sort order, see `proced-sort-interactive'."
(hyperbole-mode 1))
;; elfeed
-(my-use-package elfeed
+(my-use-package elfeed my-enable-unessentials
:config
(defun my-elfeed-search-preview-other-window ()
"Preview currently selected elfeed entry in another window."
@@ -420,10 +420,10 @@ Prefix ARG controls sort order, see `proced-sort-interactive'."
(setq-default elfeed-search-filter ""))
;; posframe
-(my-use-package posframe)
+(my-use-package posframe my-enable-unessentials)
;; translator
-(my-use-package gt
+(my-use-package gt my-enable-unessentials
:bind
(([remap gt-buffer-render--keyboard-quit] . keyboard-quit))
:config
@@ -434,7 +434,7 @@ Prefix ARG controls sort order, see `proced-sort-interactive'."
:render (gt-posframe-pin-render))))
;; thesaurus
-(my-use-package synosaurus
+(my-use-package synosaurus my-enable-unessentials
:autoload my-synosaurus-lookup
:config
(defun my-synosaurus-lookup (arg)
@@ -448,5 +448,31 @@ With a prefix ARG replace the word under the cursor by a synonym."
(setq synosaurus-prefix nil
synosaurus-choose-method 'default))
+;; dashboard
+(my-use-package dashboard my-enable-dashboard
+ :autoload dashboard-setup-startup-hook
+ :hook after-init
+ :config
+ (setq dashboard-banner-logo-title (format "%s" emacs-version)
+ dashboard-banner-ascii
+ "
+ ##### # # # # ####### # # # ##### #####
+# # ## # # # # ## ## # # # # # #
+# # # # # # # # # # # # # # #
+# #### # # # # # ##### # # # # # # #####
+# # # # # # # # # # ####### # #
+# # # ## # # # # # # # # # # #
+ ##### # # ##### ####### # # # # ##### #####
+"
+ dashboard-startup-banner 'ascii
+ dashboard-footer-messages '("hello")
+ dashboard-center-content t
+ dashboard-navigation-cycle t
+ dashboard-items '((recents . 8)
+ (bookmarks . 5)
+ (projects . 5))
+ dashboard-item-shortcuts '((recents . "r") (bookmarks . "b") (projects . "p") (agenda . "a") (registers . "e")))
+ (dashboard-setup-startup-hook))
+
(provide 'init-package)
;;; init-package.el ends here
diff --git a/lisp/init-segmentation.el b/lisp/init-segmentation.el
@@ -4,21 +4,19 @@
;;; Code:
-;; emacs-chinese-word-segmentation
+;; github@kanglmf/emacs-chinese-word-segmentation
(my-use-package cns
- (or (file-exists-p "h:/emacs/emacs-chinese-word-segmentation/")
- (file-exists-p "~/emacs-stuff/emacs-chinese-word-segmentation/"))
+ (file-exists-p my-cns-dir)
:straight nil
:hook
(after-init . require-cns)
(after-init . global-cns-mode)
:init
- (cond
- (*is-windows*
- (add-to-list 'load-path "h:/emacs/emacs-chinese-word-segmentation/")
- (setq cns-process-type 'shell)
- (setq cns-prog "h:/emacs/emacs-chinese-word-segmentation/cnws.exe")
- (setq cns-dict-directory "h:/emacs/emacs-chinese-word-segmentation/cppjieba/dict")
+ (add-to-list 'load-path my-cns-dir)
+ (setq cns-prog (expand-file-name (if *is-windows* "cnws.exe" "cnws") my-cns-dir)
+ cns-dict-directory (expand-file-name "cppjieba/dict" my-cns-dir)
+ cns-process-type 'shell)
+ (when *is-windows*
(setq cns-process-shell-command
(format "%s %s %s %s %s %s"
cns-prog
@@ -28,12 +26,6 @@
(concat (file-name-as-directory cns-dict-directory) "idf.utf8")
(concat (file-name-as-directory cns-dict-directory) "stop_words.utf8"))))
- (t
- (add-to-list 'load-path "~/emacs-stuff/emacs-chinese-word-segmentation/")
- (setq cns-process-type 'shell)
- (setq cns-prog "~/emacs-stuff/emacs-chinese-word-segmentation/cnws")
- (setq cns-dict-directory "~/emacs-stuff/emacs-chinese-word-segmentation/cppjieba/dict/")))
-
:config
(defun require-cns ()
(require 'cns nil t))
diff --git a/lisp/init-startup.el b/lisp/init-startup.el
@@ -19,14 +19,7 @@
(setq system-time-locale "C")
;; fullscreen
-(cond
- (*is-mac*
- (set-frame-parameter nil 'fullscreen 'fullscreen)
- (global-unset-key (kbd "<f12>"))
- (global-set-key (kbd "<f12>") #'toggle-frame-fullscreen))
- (*is-windows*
- (toggle-frame-maximized))
- (t nil))
+(set-frame-parameter nil 'fullscreen my-frame-parameter)
;; set lisp files directory
(setq user-lisp-directory (concat user-emacs-directory "lisp/"))
@@ -88,11 +81,27 @@
(put 'scroll-left 'disabled nil)
;; modifier keys on mac
-(when *is-mac*
+(when *is-emacs-mac-port*
(setq mac-command-modifier 'meta)
(setq mac-option-modifier 'super)
(setq mac-pass-control-to-system t)
(setq mac-pass-command-to-system nil))
+;; proxy
+(defun load-proxy ()
+ "Load proxy."
+ (interactive)
+ (setq url-proxy-services
+ `(("http" . ,my-proxy)
+ ("https" . ,my-proxy)
+ ("no_proxy" . "\\(localhost\\|127\\.0\\.0\\.1\\|192\\.168\\.*\\)"))))
+(when my-load-proxy
+ (load-proxy))
+
+(defun clear-proxy ()
+ "Clear proxy."
+ (interactive)
+ (setq url-proxy-services nil))
+
(provide 'init-startup)
;;; init-startup.el ends here
diff --git a/lisp/init-ui.el b/lisp/init-ui.el
@@ -26,7 +26,7 @@
;; color picker
;; from zHaOdANiuu's ElegantEmacs
-(my-use-package color-picker
+(my-use-package color-picker my-enable-unessentials
:straight
(color-picker :type git :host github :repo "zHaOdANiuu/color-picker.el")
:commands color-picker my-pick-color
@@ -45,7 +45,7 @@
(delete-region (region-beginning) (region-end)))
(insert color)))))))
-(my-use-package colorful-mode
+(my-use-package colorful-mode my-enable-unessentials
:hook (prog-mode . colorful-mode)
:commands my-colorful-color-picker
:config