1

I'm writing an emacs wrapper to a set of scripts that require a lot of config settings to run.

These can be variously environment variables, command line parameters and so forth. They should be user visible and tweakable. They will store things like a bunch of directory locations for data files and config switches to be passed into the underlying tool.

If these were fairly static options I'd make each option customizable and create a specific group to hold them, just like other emacs config.

The difference I have is that I may want to have several different configurations that I switch between regularly - perhaps several times a day.

It doesn't feel like making these customizable options is perhaps the right way to store them. To me customizable variables have a single copy stored and change infrequently (in my custom.el file)?

I could instead store all these values in a non-emacs solution such as an ini or yaml file and load the yaml as part of wrapper prior to executing the script.

But I was wondering if there is a more emacs-standard way of maintaining multiple custom configs that can easily be switched between?

The only thing I can think of is to use defvar with a * in the doc-string to make variables change-able using set-variable. This doesn't presume they are set in a specific place like the normal use of customize. However this is perhaps now deprecated in favour of customize?

I guess in this case each config file would be an e-lisp file setting each of these options. This doesn't feel much different from having the options as standard lisp global variables however.

Any advice or ideas how to achieve this? Perhaps custom is the right tool and I have misunderstood its purpose or there is something else?

Drew
  • 75,699
  • 9
  • 109
  • 225
Phil
  • 533
  • 4
  • 17
  • I use a countdown timer (e.g., 3 sec.) whenever I start Emacs that asks me if I want to start with zero user configuration or the full monty. You could have a countdown timer that asks you whether to load config #1, #2, #3, #4, #5, #6 or a default of config #0. Then, just restart Emacs and select your preferred config with a number, or a letter, or just let the timer countdown regularly and load your default, or interrupt with a number/letter not specifically defined. https://www.reddit.com/r/emacs/comments/aw63ja/is_there_a_good_way_to_have_two_instances_of/ehk97w0/?st=jwprhvr0&sh=cf3966d9 – lawlist Jun 10 '19 at 02:35
  • (This is kind of an opinion-based question, BTW.) – Drew Jun 10 '19 at 02:39
  • FWIW, there is nothing wrt `defcustom` that implies that it is for things that change seldom. Customize is often a good way to change values on the fly, in fact, as you can see more info, especially if the variable type is complex or has multiple possibilities. `defcustom` gives you this *or* `M-x set-variable`, and it does type-control. – Drew Jun 10 '19 at 02:39
  • 1
    Is it possible that [directory-local variables](https://www.emacswiki.org/emacs/DirectoryVariables) could solve your problem? – phils Jun 10 '19 at 03:33
  • Thanks for ideas - FWIW I am looking for more idiomatic answers than opinion. The directory local variables are definitely a possible solution (and it's a useful trick to know!). I accept `defcustom` could work - my issue is that I have my `custom.el` in git (which is not unusual) so changing several times a day, back and forth, would not work well with git. This is why I consider it relatively static, although I accept this is my use-case rather than a restriction with customize itself. – Phil Jun 11 '19 at 09:41
  • 1
    If you want to be able to *edit* the option sets, then you might create a complex customize type comprising an alist where each value is a list of option sets, such that you could add or delete an entire option set at any time, or edit the individual values of an existing one. You could then write a command which prompted the user for an option set key, and applied all of its associated settings. – phils Jun 13 '19 at 12:39

0 Answers0