Add optional flattening to creation of imenu index (again).