The customization system is a built-in feature of Emacs designed to solve precisely the problem you describe—programming may not be the ideal way for the average user to configure their editor.
The primary entry point to the customization functionality is
M-x customize RET (or
Options > Customize Emacs > Top-level Customization Group from the menu). From there you'll see an interactive menu system for adjusting settings. This interface enforces that all settings are of the correct type (number, string, color, etc.), avoiding a major source of error encountered when users configure Emacs programmatically. If the user chooses to persist any changes they make through the UI, the settings are stored to a special section in the user's initialization file (read:
defcustom is wrapper around lower-level Emacs Lisp functionality like
defvar that both declares the variable and makes it visible within the customization interface. It also allows the developer to provide extra metadata needed to display an appropriate interactive control—i.e. what type of value is stored in this variable? An arbitrary string? A number? A choice from a fixed set of options? etc.
defgroup is a grouping construct for these customizable options so that they can be arranged into a nice hierarchy.
This functionality should be used any time a piece of data should be considered a configurable option for the user rather than an internal detail of the library.
Here's a simple example cribbed from a small library of mine:
(defgroup checkbox nil
"Quick manipulation of textual checkboxes."
(defcustom checkbox-states '("[ ]" "[x]")
"Checkbox states to cycle between.
First item will be the state for new checkboxes."
:type '(repeat string))
defgroup creates a new group within the Customization interface under the top-level
convenience item. I then needed a variable to store the possible checkbox states. I could have used
defvar, but since I want this to be easily customizable, I chose to use
:group portion indicates that it belongs to the previously-defined group, and the
:type indicates that it is a sequence of strings. There's also a default value and a description. There are also additional facilities (not shown here) for transforming values entered by the user.
If I now run
M-x customize RET and navigate to
Convenience > Checkbox, I see the following:
It's not the most beautiful interface in the world, but notice that it has interactive tools for customizing the value of "Checkbox States" (
checkbox-states internally). It shows the current string values along with
INS (insert) and
DEL (delete) buttons, and allows us to edit the string values in edit boxes. When we're done we can decide whether to apply our changes, revert them, or apply and save them for future sessions.