emacs多种配置共存的思路

emacs多种配置共存的思路

将配置放在early-init.el文件中,可以不需要init.el文件,将其他用户或其他独立的配置的init.el文件改成对应用户或独立的的配置后在early-init.el中加载即可

如果你希望增加通用性,可以让配置更加灵活,以便将来可以轻松切换或添加其他配置文件。以下是一个示例代码:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
  (defun load-emacs-config (config-name)
	"Load a specific Emacs configuration based on CONFIG-NAME."
	(let ((config-path (expand-file-name (concat config-name ".el") "~/.emacs.d/")))
	  (if (file-exists-p config-path)
		  (load config-path)
		(message "Config file not found: %s" config-path))))

  ;; 加载 remacs 配置
  (load-emacs-config "remacs")

  ;; 以后可以通过更改参数来加载不同的配置
  ;; (load-emacs-config "spacemacs")
  ;; (load-emacs-config "prelude")

这样,你可以通过调用 `load-emacs-config` 函数并传入配置文件名来加载不同的配置。

Licensed under CC BY-NC-SA 4.0