1

How to identify the parent group(s) of a symbol defined with a defcustom form with elisp code?

For instance I would like to use or write a function custom-group-of such that

(custom-group-of 'delete-trailing-lines) 

would return editing, the group symbol of the delete-trailing-list defcustom.

Does such a function exist?

At first I assumed that the symbol would have a group property I could use, but

(symbol-plist 'delete-trailing-lines) 

does not return a group property or something that identifies it.

1 Answer 1

3

Emacs does not have such a function built-in. But there is a function that returns the members of a group, custom-group-members. Since we know that emacs is the root of all groups, we can start there and recurse until we reach a group that contains the symbol.

(defun my/get-group (symbol &optional grp) "Find the group that SYMBOL belongs to. GRP is the group from which to ascend, which defaults to `emacs', since that is the root of all other groups." (let* ((grp (if grp grp 'emacs)) (mems (custom-group-members grp nil)) (group (if (assq symbol mems) grp))) (while (and mems (not group)) (let ((mem (pop mems))) (if (eq (cadr mem) 'custom-group) (setq group (my/get-group symbol (car mem)))))) group)) 
3
  • A minor nit: an option can belong to multiple groups (and a subgroup can also have multiple parents), so this requires some elaboration to deal with the most general case, particularly if the OP wants absolute paths from the root of the "tree". Commented Oct 25 at 6:35
  • 1
    The multiple ownership of a defcustom element is often used. What I wanted is be able to generate reports of customizable user options grouped by their parent group. In the end, since the defcustom elements of interest were created by my code, I added a property identifying the parent group to the defcustom symbol and then later used that property to identify the parent. Commented Oct 25 at 14:31
  • 1
    It's too bad that custom.el does not store the parent group(s) as property as they do for the type. But no Emacs code needed that I guess. I needed it for some introspection reports for my system so I added the property where it was required, but it's not as good as if it was native. Commented Oct 25 at 14:34

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.