diff --git a/custom.el b/custom.el index 0f14e01..6500897 100644 --- a/custom.el +++ b/custom.el @@ -4,11 +4,6 @@ ;; 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. - '(custom-safe-themes - '("c98e359e2ec6d95e29f006202641f7bafc9e6e204f937d4d518c3ef154ed479b" - "7fea145741b3ca719ae45e6533ad1f49b2a43bf199d9afaee5b6135fd9e6f9b8" - "2b0fcc7cc9be4c09ec5c75405260a85e41691abb1ee28d29fcd5521e4fca575b" - default)) '(org-agenda-files '("d:/emacs/org/learning-org-mode.org" "d:/emacs/hugo/this-is-my-blog/all-blog.org")) @@ -16,7 +11,8 @@ '(ace-window benchmark-init cape cnfonts corfu crux drag-stuff eglot embark-consult everything exec-path-form-shell gcmh hungry-delete marginalia multiple-cursors orderless - restart-emacs smart-mode-line solarized-theme vertico))) + restart-emacs smart-mode-line solarized-theme vertico)) + '(warning-suppress-log-types '((initialization)))) (custom-set-faces ;; custom-set-faces was added by Custom. ;; If you edit it by hand, you could mess it up, so be careful. diff --git a/lisp/fix-theme-colors.el b/lisp/fix-theme-colors.el new file mode 100644 index 0000000..d70da0c --- /dev/null +++ b/lisp/fix-theme-colors.el @@ -0,0 +1,194 @@ +#!/usr/bin/env emacs --script +;;; fix-theme-colors.el --- Fix invalid color names and properties in Emacs themes + +;; This script fixes common issues in color-theme files: +;; 1. Space-separated color names (e.g., "deep sky blue" -> "DeepSkyBlue") +;; 2. Invalid color names (e.g., "PaleYellow" -> "LightYellow") +;; 3. Negative line-width values in :box properties +;; 4. Removes compiled .elc files to force reload of fixed sources + +(require 'cl-lib) + +(defvar theme-fixes-space + '(("deep sky blue" . "DeepSkyBlue") + ("spring green" . "SpringGreen") + ("light blue" . "LightBlue") + ("lime green" . "LimeGreen") + ("dark green" . "DarkGreen") + ("dim gray" . "DimGray") + ("forest green" . "ForestGreen") + ("light gray" . "LightGray") + ("light pink" . "LightPink") + ("medium purple" . "MediumPurple") + ("pale green" . "PaleGreen") + ("medium aquamarine" . "MediumAquamarine") + ("powder blue" . "PowderBlue") + ("dark olive green" . "DarkOliveGreen") + ("dark slate blue" . "DarkSlateBlue") + ("dark slate grey" . "DarkSlateGrey") + ("dark turquoise" . "DarkTurquoise") + ("dark violet" . "DarkViolet") + ("deep pink" . "DeepPink") + ("dodger blue" . "DodgerBlue") + ("floral white" . "FloralWhite") + ("ghost white" . "GhostWhite") + ("green yellow" . "GreenYellow") + ("hot pink" . "HotPink") + ("indian red" . "IndianRed") + ("lavender blush" . "LavenderBlush") + ("lawn green" . "LawnGreen") + ("lemon chiffon" . "LemonChiffon") + ("light coral" . "LightCoral") + ("light cyan" . "LightCyan") + ("light goldenrod" . "LightGoldenrod") + ("light goldenrod yellow" . "LightGoldenrodYellow") + ("light salmon" . "LightSalmon") + ("light sea green" . "LightSeaGreen") + ("light sky blue" . "LightSkyBlue") + ("light slate blue" . "LightSlateBlue") + ("light slate gray" . "LightSlateGray") + ("light steel blue" . "LightSteelBlue") + ("light yellow" . "LightYellow") + ("medium blue" . "MediumBlue") + ("medium orchid" . "MediumOrchid") + ("medium sea green" . "MediumSeaGreen") + ("medium slate blue" . "MediumSlateBlue") + ("medium spring green" . "MediumSpringGreen") + ("medium turquoise" . "MediumTurquoise") + ("medium violet red" . "MediumVioletRed") + ("midnight blue" . "MidnightBlue") + ("mint cream" . "MintCream") + ("misty rose" . "MistyRose") + ("navajo white" . "NavajoWhite") + ("navy blue" . "NavyBlue") + ("old lace" . "OldLace") + ("olive drab" . "OliveDrab") + ("orange red" . "OrangeRed") + ("pale goldenrod" . "PaleGoldenrod") + ("pale turquoise" . "PaleTurquoise") + ("pale violet red" . "PaleVioletRed") + ("papaya whip" . "PapayaWhip") + ("peach puff" . "PeachPuff") + ("rosy brown" . "RosyBrown") + ("royal blue" . "RoyalBlue") + ("saddle brown" . "SaddleBrown") + ("sandy brown" . "SandyBrown") + ("sea green" . "SeaGreen") + ("sky blue" . "SkyBlue") + ("slate blue" . "SlateBlue") + ("slate gray" . "SlateGray") + ("spring green" . "SpringGreen") + ("steel blue" . "SteelBlue") + ("white smoke" . "WhiteSmoke") + ("yellow green" . "YellowGreen") + ("antique white" . "AntiqueWhite") + ("blanched almond" . "BlanchedAlmond") + ("blue violet" . "BlueViolet") + ("burlywood" . "Burlywood") + ("cadet blue" . "CadetBlue") + ("chartreuse" . "Chartreuse") + ("chocolate" . "Chocolate") + ("cornflower blue" . "CornflowerBlue") + ("cornsilk" . "Cornsilk") + ("dark blue" . "DarkBlue") + ("dark cyan" . "DarkCyan") + ("dark goldenrod" . "DarkGoldenrod") + ("dark gray" . "DarkGray") + ("dark grey" . "DarkGrey") + ("dark khaki" . "DarkKhaki") + ("dark magenta" . "DarkMagenta") + ("dark orange" . "DarkOrange") + ("dark orchid" . "DarkOrchid") + ("dark red" . "DarkRed") + ("dark salmon" . "DarkSalmon") + ("dark sea green" . "DarkSeaGreen")) + "Mapping of space-separated color names to CamelCase.") + +(defvar theme-fixes-invalid + '(("PaleYellow" . "LightYellow") + ("Blue-Eshell" . "DeepSkyBlue")) + "Mapping of invalid color names to valid alternatives.") + +(defvar theme-fixes-box + '((":style none" . ":style nil") + (":line-width -1" . ":line-width 1")) + "Fixes for invalid :box properties.") + +(defun fix-theme-file (filepath) + "Fix all issues in a single theme file." + (message "Processing: %s" filepath) + (let ((content (with-temp-buffer + (insert-file-contents filepath) + (buffer-string))) + (changes 0)) + + ;; Fix space-separated colors + (dolist (fix theme-fixes-space) + (let ((old-color (car fix)) + (new-color (cdr fix)) + (case-fold-search nil)) + (when (string-match (regexp-quote (format "\"%s\"" old-color)) content) + (setq content (replace-regexp-in-string + (regexp-quote (format "\"%s\"" old-color)) + (format "\"%s\"" new-color) + content)) + (setq changes (1+ changes))))) + + ;; Fix invalid colors + (dolist (fix theme-fixes-invalid) + (let ((old-color (car fix)) + (new-color (cdr fix)) + (case-fold-search nil)) + (when (string-match (regexp-quote (format "\"%s\"" old-color)) content) + (setq content (replace-regexp-in-string + (regexp-quote (format "\"%s\"" old-color)) + (format "\"%s\"" new-color) + content)) + (setq changes (1+ changes))))) + + ;; Fix :box properties + (dolist (fix theme-fixes-box) + (let ((old-prop (car fix)) + (new-prop (cdr fix))) + (when (string-match (regexp-quote old-prop) content) + (setq content (replace-regexp-in-string + (regexp-quote old-prop) + new-prop + content)) + (setq changes (1+ changes))))) + + (with-temp-file filepath + (insert content)) + (message " Fixed %d issue(s)" changes) + changes)) + +(defun fix-all-themes (themes-dir) + "Fix all theme files in THEMES-DIR." + (let ((theme-files (directory-files themes-dir t "\\-theme\\.el$")) + (total-changes 0)) + (dolist (file theme-files) + (setq total-changes (+ total-changes (fix-theme-file file)))) + (message "\nTotal issues fixed across all themes: %d" total-changes))) + +(defun remove-compiled-themes (build-dir) + "Remove all compiled .elc theme files to force reload of sources." + (let ((elc-files (directory-files build-dir t "\\-theme\\.elc$")) + (count 0)) + (dolist (file elc-files) + (delete-file file) + (setq count (1+ count))) + (message "Removed %d compiled theme files (.elc)" count))) + +;; Main execution +(let* ((themes-dir (expand-file-name "~/.emacs.d/straight/repos/replace-colorthemes/")) + (build-dir (expand-file-name "~/.emacs.d/straight/build/color-theme-modern/"))) + + (if (file-directory-p themes-dir) + (progn + (fix-all-themes themes-dir) + (when (file-directory-p build-dir) + (remove-compiled-themes build-dir)) + (message "\nDone! Restart Emacs to load fixed themes.")) + (error "Themes directory not found: %s" themes-dir))) + +;;; fix-theme-colors.el ends here diff --git a/lisp/init-kbd.el b/lisp/init-kbd.el index e438bcc..d04cb7b 100644 --- a/lisp/init-kbd.el +++ b/lisp/init-kbd.el @@ -136,6 +136,13 @@ Disable jinx-mode if it's enable and global-jinx-mode is disable , otherwise tog (global-set-key (kbd "") 'next-buffer) (global-set-key (kbd "M-]") 'next-buffer) +;; 打开tab-line-mode +(global-set-key (kbd "C-c u l") 'global-tab-line-mode) +(global-set-key (kbd "") 'global-tab-line-mode) + +;; 关闭主题 +(global-set-key (kbd "C-c u d") 'disable-theme) + ;; 打开ibuffer (global-set-key (kbd "C-x C-b") 'ibuffer-other-window) (setq ibuffer-default-sorting-mode 'filename) @@ -144,10 +151,6 @@ Disable jinx-mode if it's enable and global-jinx-mode is disable , otherwise tog (global-set-key (kbd "M-p") 'backward-paragraph) (global-set-key (kbd "M-n") 'forward-paragraph) -;; 打开tab-line-mode -(global-set-key (kbd "C-c u t") 'global-tab-line-mode) -(global-set-key (kbd "") 'global-tab-line-mode) - ;; 中键使用embark打开定义 (global-set-key (kbd "") 'xref-find-definitions) @@ -200,6 +203,8 @@ Disable jinx-mode if it's enable and global-jinx-mode is disable , otherwise tog (global-set-key (kbd "C-x r b") 'consult-bookmark) ;; 书签菜单,embark中有更多操作 (define-key minibuffer-local-map (kbd "C-c C-e") 'embark-export) ;; 把minibuffer结果在一个菜单中显示 (global-set-key (kbd "C-c f e") 'consult-flycheck) ;; flycheck菜单 +(global-set-key (kbd "C-c u t") 'consult-theme) ;; 主题预览 + (if *is-mac* (progn (global-set-key (kbd "C-c f l") 'consult-fd-global) diff --git a/lisp/init-ui.el b/lisp/init-ui.el index f8aa73e..c930ae5 100644 --- a/lisp/init-ui.el +++ b/lisp/init-ui.el @@ -20,12 +20,19 @@ (use-package solarized-theme) (load-theme 'solarized-dark t) +;; 很多主题 +(use-package doom-themes) +(use-package color-theme-modern) + +;; 信任所有主题 +(setq custom-safe-themes t) + ;; 安装smart-mode-line (use-package smart-mode-line :defer 0.5 :config - (setq sml/no-confirm-load-theme t - sml/theme 'respectful) + (setq sml/no-confirm-load-theme t) + ;; sml/theme 'respectful) (sml/setup)) ;; eshell高亮 @@ -122,6 +129,12 @@ (cnfonts-mode 1) (cnfonts--select-profile "profile1")) +;; 主题修复脚本 +(defun fix-theme-colors () + "Fix invalid color name in theme files." + (interactive) + (load-file (expand-file-name "~/.emacs.d/lisp/fix-theme-colors.el"))) + (provide 'init-ui) ;;; init-ui.el ends here