0

The current question is related to a previous question which is still not fully solved.

I have been doing the following:

1 - After executing describe-variable over exec-path, I get:

("/opt/homebrew/bin" "/opt/homebrew/sbin" "/usr/local/bin" "/Users/pedro/.sdkman/candidates/java/current/bin" "/Users/pedro/.nvm/versions/node/v8.0.0/bin" "/usr/local/bin" "/usr/bin" "/bin" "/usr/sbin" "/sbin" "/opt/X11/bin" "/Applications/Emacs.app/Contents/MacOS/bin-arm64-11" "/Applications/Emacs.app/Contents/MacOS/libexec-arm64-11" "/Applications/Emacs.app/Contents/MacOS/libexec")

2 - Due to the previous discussion above mentioned, I want sdkman to work on eshell! Thus, I am changing the path to point to the binary folder with shell file. Which is means tweaking from "/Users/pedro/.sdkman/candidates/java/current/bin" to "/Users/pedro/.sdkman/bin/sdkman-init.sh".

("/opt/homebrew/bin" "/opt/homebrew/sbin" "/usr/local/bin" "/Users/pedro/.sdkman/bin/sdkman-init.sh" "/Users/pedro/.nvm/versions/node/v8.0.0/bin" "/usr/local/bin" "/usr/bin" "/bin" "/usr/sbin" "/sbin" "/opt/X11/bin" "/Applications/Emacs.app/Contents/MacOS/bin-arm64-11" "/Applications/Emacs.app/Contents/MacOS/libexec-arm64-11" "/Applications/Emacs.app/Contents/MacOS/libexec")

3 - Ok, if I execute again the describe-variable command over exec-path things work out well! I have the new value.

The problem is when I re-start Emacs, the value is back to the original one!

Thus, I would like to ask: How to make this change persistent over time?

4 Answers 4

3

Besides desktop.el, which is likely overkill for just persisting some variable values. Here are two other approaches.

  1. You can use library savehist.el (part of vanilla Emacs) to persist any variable values. Just customize option savehist-additional-variables.

  2. With Bookmark+ you can create bookmarks that restore sets of variable values. Just jump to a bookmark to set a bunch of variables in a particular way.

You may not want to use #2 if all you want to do is persist a few variables. But if you use Bookmark+ for other reasons then you already have this possibility. And if you want to be able to restore different sets of variable values on demand, then this can be useful.

1
  • Great! I like the savehist.el. (It saves things in the file savehist-file.)
    – shynur
    Nov 19, 2023 at 10:44
2

All you have to do is edit your init file to include a call to add-to-list:

(add-to-list 'exec-path "/Users/pedro/.sdkman/candidates/java/current/bin")

But note that this won’t magically make the sdkman software compatible with Eshell; that would involve rewriting sdkman. Also, exec-path is a list of directories, adding shell scripts to it won’t do anything useful.

1
1

If you use desktop.el, you can add exec-path to the customization option desktop-globals-to-save. This is a list of variables that desktop-mode will save and restore across sessions.

5
  • Interesting, thanks. I am surprise there is a need for a package to change this... Aug 23, 2022 at 21:23
  • If my understanding is correct, this is an old package, right? Is it possible to install it with use-package? github.com/emacs-mirror/emacs/blob/master/lisp/desktop.el. I tried it here and it seems to work... Aug 23, 2022 at 21:24
  • I am searching for desktop-globals-to-save as a command. But, I can't find it. Is it a command? Aug 23, 2022 at 21:26
  • 1
    No, a user option (a variable you can customize). Aug 23, 2022 at 21:47
  • 1
    desktop.el is built in. Aug 23, 2022 at 21:48
0

There is also the GNU elpa package persist.el, which is made for persisting variables specifically. The two relevant functions are persist-defvar and persist--save-all (which the package does call on the emacs quit hook, but in case of crashing, you might like to put it on a timer)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.