【发布时间】:2012-09-15 07:28:39
【问题描述】:
我正在编写一个演变成一个包的 elisp 文件,因此我将它的一些变量转换为 defcustom 语句并记录它们。其中一些defcustom 变量是相关的,我想验证通过自定义系统输入的值,以确保关系成立。
这是我所拥有的一个例子:
(defcustom widget-canonical-names '("my_widget" . "widget_assembly 8911_j4")
"Documentation"
:type '(alist :key-type (string :tag "Widget's short name")
:value-type (string :tag "Full widget name"))
:risky nil
:group 'widgets)
(defcustom widget-colors '("my_widget" . "brown")
"Documentation"
:type '(alist :key-type (string :tag "Widget's short name")
:value-type (color :tag "color of the widget"))
:risky nil
:group 'widgets)
(defcustom widget-paths '("my_widget" . "~/widgets")
"Documentation"
:type '(alist :key-type (string :tag "Widget's short name")
:value-type (directory :tag "support files for widget"))
:risky nil
:group 'widgets)
所以有小部件,它们有各种设置,我需要能够通过只知道小部件的短名称来访问小部件的任意设置。我想做某种验证功能(不幸的是,谷歌搜索“emacs defcustom validate”并没有帮助),这样如果用户在widget-paths 或widget-colors 中输入不在widget-canonical-names 列表,他们得到一个“你确定吗?”警告并注意输入不匹配的名称。我可以将这样的验证功能附加到我的defcustoms 吗?如果是这样,它的语法是什么?
当然,理想的做法是让用户输入一次短名称,但我无法从“复合类型”elisp 文档中弄清楚如何做到这一点。因此,对我的问题的更好回答将告诉我如何安排一个defcustom 来设置类似于此 Python dict 的数据结构:
customized_widgets = {
"my_widget": { "canonical_name": "widget_assembly 8911_j4",
"widget_color": "brown",
"widget_path": "~/widgets",
},
"another_widget": { "canonical_name" : "widget_obsolete 11.0",
"widget_color": "blue",
"widget_path": "~/blue_widgets",
},
}
那么:我怎样才能获得我想要的行为,根据用于访问它们的数据对设置进行分组,或者当用户输入不一致的数据时验证功能在哪里警告用户?
【问题讨论】: