Use custom-file to save last used theme

This commit is contained in:
Joseph Ferano 2022-08-28 22:17:46 +07:00
parent fa37091109
commit c65ea59920

View File

@ -140,8 +140,7 @@ Don't let emacs add customised settings to init.el, which in our case is worse s
literate file. literate file.
#+begin_src emacs-lisp #+begin_src emacs-lisp
(setq custom-file (expand-file-name "custom.el" user-emacs-directory))
(load custom-file t)
#+end_src #+end_src
This avoids those annoying *#backup#* files that get added and eventually slow down loading the file again. This avoids those annoying *#backup#* files that get added and eventually slow down loading the file again.
@ -195,37 +194,33 @@ Use Dashboard.el. First load `all-the-icons` for nicer rendering
#+begin_src emacs-lisp #+begin_src emacs-lisp
(straight-use-package 'olivetti) (straight-use-package 'olivetti)
(require 'olivetti)
(setq olivetti-minimum-body-width 100) (setq olivetti-minimum-body-width 100)
(global-set-key (kbd "C-x x o") 'olivetti-mode) (global-set-key (kbd "C-x x o") 'olivetti-mode)
#+end_src #+end_src
*** Themes *** Themes
Simple functions to remember the last chosen theme. sanityinc-tomorrow-light is really good
#+begin_src emacs-lisp #+begin_src emacs-lisp
(straight-use-package 'doom-themes) (straight-use-package 'doom-themes)
(straight-use-package 'color-theme-sanityinc-tomorrow) (straight-use-package 'color-theme-sanityinc-tomorrow)
(setq custom-safe-themes t) (setq custom-safe-themes t)
#+end_src
Save the last used theme when exiting emacs and then reload it.
#+begin_src emacs-lisp
(setq custom-file (expand-file-name "custom.el" user-emacs-directory))
(load custom-file)
(defun joe/save-current-theme () (defun joe/save-current-theme ()
(let ((filename (expand-file-name "data" user-emacs-directory))) (customize-save-variable 'custom-enabled-themes custom-enabled-themes))
(with-temp-buffer
(print `((last-used-theme . ,custom-enabled-themes)) (current-buffer))
(if (file-writable-p filename)
(write-file filename)
(message (format "Cannot save themes because %s is not writable" filename))))))
(add-hook 'kill-emacs-hook #'joe/save-current-theme) (add-hook 'kill-emacs-hook #'joe/save-current-theme)
(let ((filename (expand-file-name "data" user-emacs-directory)))
(if (file-readable-p filename)
(let ((theme-data (with-temp-buffer
(insert-file-contents filename)
(buffer-string))))
(mapc 'load-theme (cdr (car (read theme-data)))))))
#+end_src #+end_src
*** Other *** Other
Setup other stuff Setup other stuff