1

So I have different customized themes. Different customized themes are written to a separate custom .el files and get called in the main init.el file. For example:

(setq custom-file "~/.emacs.d/myCustomSettings/customDarkLaptop.el") 

will call the customDarkLaptop.el, where all of my customized variables like font size, comment color..etc.

Suppose I want to switch to a different customized themes, I then go to init.el and change this

(setq custom-file "~/.emacs.d/myCustomSettings/customLight.el")

which will then load the customLight.el file.

I would like to write a script to automate this process, user just need to enter either the part after custom to the desire theme. For example:

  • enter Dark will automatically have customDark.el

Replacing text from a file can be easily be done with the sed command, i.e.

sed -i -e s/oldtext/newtext/g <enter file name here>

However, I am not sure how to incorporate this efficiently into my init.el file. What I want is something like this:

  • create a string variable in init.el: themeName = "Dark"
  • Append it to my set-q command file path like this:

    (setq custom-file "~/.emacs.d/myCustomSettings/custom<INSERT THE VARIABLE themeName HERE>.el")

My sed script will just replace one thing, the variable themeName in init.el.

How do you do this in elisp?

Drew
  • 75,699
  • 9
  • 109
  • 225
mle0312
  • 295
  • 1
  • 8

1 Answers1

2

It's not clear to me just what you need/want, or why you're using sed and bash (what you're using them for).

Maybe what you really want is to just have loading your init file prompt you for which theme you want. If so, you can do that by putting code in your init file similar to this:

(setq custom-file  (format "~/.emacs.d/myCustomSettings/custom%s"
                           (read-string "Theme/style: " nil nil "Light")))
(load-file custom-file))

If you want to be able to (re)load a given custom file anytime you can put such code in a command.

That code assumes you want to set custom-file to the given value, rather than just load the file. You would do that in order for Emacs to thereafter update the right custom-file if you use Customize etc. If you don't care about that then you can just use something like this:

(load-file (format "~/.emacs.d/myCustomSettings/custom%s"
                   (read-string "Theme/style: " nil nil "Light")))
Drew
  • 75,699
  • 9
  • 109
  • 225