reddit / emacs

set custom theme

RepublicWorried · 2022-11-01 12:12
I modifies the manoj-dark.el file to my liking. Its located in my .emacs.d dir and I want to set it as my default theme. I cannot, for the life of me, figure out how to do that. I have not set any other theme in the "customize-theme" menu and dont want to. Just load/set whatever the .el file as my standard theme. Can somebody please tell me how to achieve that?
andyjda · 2022-11-01 12:34
If you have your theme file open and you just do M-x load-file RET, it should ask for confirmation twice (first whether to treat it as safe, then whether it should be set as safe for future sessions). Once that is done, the way you set a theme as your default is simply by loading it at startup. So add: (load-theme ‘manoj-dark) to your init file. Note: for the last part to work, it might be better to give your modification a unique name, like my-manoj-theme. If you don’t it might confuse it with the original theme (not sure though). Feel free to ask questions if you run into other issues
RepublicWorried · 2022-11-01 12:42
thanks, tried it. loading seems to work, i.e. message buffer confirms Loading /home/ubuntu/.emacs.d/my-manoj-dark.el (source)...done &#x200B; I put (load-theme ‘my-manoj-dark) at the end of my init.el file but upon restarting, I get &#x200B; Symbol's value as variable is void: ‘my-manoj-darkSymbol's value as variable is void: ‘my-manoj-dark and debug says &#x200B; Debugger entered--Lisp error: (void-variable ‘my-manoj-dark) (load-theme ‘my-manoj-dark) eval-buffer(#<buffer \*load\*> nil "/home/ubuntu/.emacs.d/init.el" nil t) ; Reading at buffer position 14807 load-with-code-conversion("/home/ubuntu/.emacs.d/init.el" "/home/ubuntu/.emacs.d/init.el" t t) load("/home/ubuntu/.emacs.d/init" noerror nomessage) startup--load-user-init-file(#f(compiled-function () #<bytecode -0x15b3104f6135d7db>) #f(compiled-function () #<bytecode -0x1f3c6feddc0b9b75>) t) command-line() normal-top-level()
andyjda · 2022-11-01 12:59
my bad, I got the first step wrong: it's not `load-file`. It's `(load-theme 'your-theme-name)` That should prompt for the two confirmations. Once you run that and confirm both times, you should have something like this in your custom variables: `'(custom-safe-themes` `'("a000d0fedd5e1c3b58e3a1c645c316ec2faa66300fc014c9ad0af1a4c1de839b" default))` (The hash string is referring to your custom theme)
RepublicWorried · 2022-11-01 13:08
with my theme file open, if I call load-theme I am only presented with the built in themes (located under \~/emacs/etc/themes since I built Eamcs from source) &#x200B; fyi: I dont use require package or use-package or anything for that matter, does that matter?
andyjda · 2022-11-01 13:08
Also, for emacs to find your theme file, it should have `-theme` at the end of the name (eg `my-manoj-dark-theme.el`
andyjda · 2022-11-01 13:12
for emacs to find your theme file, it should have -theme at the end of the name (eg `my-manoj-dark-theme.el`) &#x200B; As long as you have the file within `.emacs.d` and put `-theme` at the end of the name, Emacs should be able to recognize it
RepublicWorried · 2022-11-01 13:26
thanks that worked, didnt not about the required -theme appendix
RepublicWorried · 2022-11-01 13:28
do I always manually have to load and and permit the file first once? How can I do this automatically?
andyjda · 2022-11-01 13:34
If you've added the theme to your `custom-safe-themes`, you should be good. The thing is, the custom variables are at the end of the init file, so if you load the theme before that, Emacs won't recognize it as safe. The simplest solution is to tell Emacs to load the full file *and then* load the theme: `(add-hook 'after-init-hook (lambda () (load-theme 'my-manoj-dark)))`