5

I have an Emacs mode. It has a defgroup and a number of defcustoms. Let's say:

(defgroup some-group nil
  "Some group"
  :prefix "prefix-"
  :group 'languages)

(defcustom some-option-1 t
  "Option 1"
  :tag "Option 1?"
  :type 'boolean
  :group 'some-group)

(defcustom some-option-2 t
  "Option 2"
  :tag "Option 2?"
  :type 'boolean
  :group 'some-group)

(defcustom some-option-3 t
  "Option 3"
  :tag "Option 3?"
  :type 'boolean
  :group 'some-group)

All works fine, except the order in which these appear in the Customize buffer shown by M-x customize is not the order the defcustoms appear in the source, or alphabetically by their identifier, or alphabetically by their :tag -- or any other pattern I've been able to figure out so far. For example the options above might end up in the UI as 3, 1, 2. But I'd like them to appear as 1, 2, 3.

The same seems true for the order of sub-groups.

Is there a way I can make them appear in an order that I specify, and if so, how?

(This with Emacs 24.3, in case that's relevant.)

  • They should be sorted alphabetically by name if you have it configured so (Customization group "Help/Customize/Custom Buffer"). Doesn't that work for you? – angus Jan 5 '15 at 10:03
  • I wasn't aware of that option. Thank you for letting me know about it. I just checked and it is on (the default). But I'm not seeing mine appear in alphabetical order. So I'm puzzled. At least now I know it's supposed to work this way, and I'll investigate more.... – Greg Hendershott Jan 5 '15 at 19:00
  • It turns out they were sorted alphabetically by the identifier name. I got confused by the use of :tags that sorted differently. @angus would you like to submit that as an answer I can accept? Or would you like me to self-answer? – Greg Hendershott Jan 7 '15 at 21:14
  • p.s. It seems unfortunate it doesn't sort by :tag if present, else by identifier. I'd like to pick a good identifier name for code, independent of thinking about UI sort order. The existence of :tags seems to recognize this separation of concerns... just not completely. Anyway, at least now I understand clearly what's happening. – Greg Hendershott Jan 7 '15 at 21:22
0

In short, when defcustoms are sorted alphabetically[^1], it is by their identifier name -- never by their :tag (if any).

You might use :tag because your identifier name is ideal for code, but less so in the customization UI. A related motivation is that :prefix no longer has any effect[^2]. But if the tag sorts differently than the identifier name, you might get confused, as I did.


[^1]: As @angus pointed out, the customization order is ultimately under control of the user, in a customization for custom buffers: Help / Customize / Custom Buffer / Custom Buffer Sort Automatically: "Whether to sort customization groups alphabetically in Custom buffer.".

[^2]: Commentary not in the GNU docs I originally read, but that I found here:

The prefix-discarding feature is currently turned off, which means that :prefix currently has no effect. We did this because we found that discarding the specified prefixes often led to confusing names for options. This happened because the people who wrote the defgroup definitions for various groups added :prefix keywords whenever they make logical sense--that is, whenever the variables in the library have a common prefix.

In order to obtain good results with :prefix, it would be necessary to check the specific effects of discarding a particular prefix, given the specific items in a group and their names and documentation. If the resulting text is not clear, then :prefix should not be used in that case.

It should be possible to recheck all the customization groups, delete the :prefix specifications which give unclear results, and then turn this feature back on, if someone would like to do the work.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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