我需要用大量参数进行交互方式调用一个函数(目前为7,但会增长)。连续阅读所有论点会带来不好的经历。例如,我要求用户输入类名。班级名称可以完全由它包含在内的软件包中。因此,如果用户认为必须完全合格,然后我稍后要求他们提供包装名称,则用户无法返回并修复错误。
输入的许多方面也很难一次照顾。例如,我需要确保某些字符不会在读取的字符串中出现以某个模式。如果输入在输入的最后一项上验证了验证,则用户可以重新启动整个过程感到沮丧,如果我有自定义缓冲区可供使用,我可以简单地阻止他们在不验证并保持已经提交的良好价值的情况下进行更改。
tl; dr
我正在寻找一种打开自定义缓冲区的方法,并将用户输入读取为交互式称为函数。有办法做到吗?
我建议使用emacs窗口库,而不是自定义缓冲区本身。Emacs Info在小部件库上有一个很好的部分。您可以使用C-h i m Widget RET
从EMAC访问它。或者,您可以在此处访问HTML版本。这是手册中的小部件示例的片段。
(require 'widget)
(eval-when-compile
(require 'wid-edit))
(defvar widget-example-repeat)
(defun widget-example ()
"Create the widgets from the Widget manual."
(interactive)
(switch-to-buffer "*Widget Example*")
(kill-all-local-variables)
(make-local-variable 'widget-example-repeat)
(let ((inhibit-read-only t))
(erase-buffer))
(remove-overlays)
(widget-insert "Here is some documentation.nn")
(widget-create 'editable-field
:size 13
:format "Name: %v " ; Text after the field!
"My Name")
(widget-create 'menu-choice
:tag "Choose"
:value "This"
:help-echo "Choose me, please!"
:notify (lambda (widget &rest ignore)
(message "%s is a good choice!"
(widget-value widget)))
'(item :tag "This option" :value "This")
'(choice-item "That option")
'(editable-field :menu-tag "No option" "Thus option"))
(widget-create 'editable-field
:format "Address: %v"
"Some PlacenIn some CitynSome country.")
(widget-insert "nSee also ")
(widget-create 'link
:notify (lambda (&rest ignore)
(widget-value-set widget-example-repeat
'("En" "To" "Tre"))
(widget-setup))
"other work")
(widget-insert
" for more information.nnNumbers: count to three belown")
(setq widget-example-repeat
(widget-create 'editable-list
:entry-format "%i %d %v"
:notify (lambda (widget &rest ignore)
(let ((old (widget-get widget
':example-length))
(new (length (widget-value widget))))
(unless (eq old new)
(widget-put widget ':example-length new)
(message "You can count to %d." new))))
:value '("One" "Eh, two?" "Five!")
'(editable-field :value "three")))
(widget-insert "nnSelect multiple:nn")
(widget-create 'checkbox t)
(widget-insert " Thisn")
(widget-create 'checkbox nil)
(widget-insert " Thatn")
(widget-create 'checkbox
:notify (lambda (&rest ignore) (message "Tickle"))
t)
(widget-insert " ThusnnSelect one:nn")
(widget-create 'radio-button-choice
:value "One"
:notify (lambda (widget &rest ignore)
(message "You selected %s"
(widget-value widget)))
'(item "One") '(item "Another One.") '(item "A Final One."))
(widget-insert "n")
(widget-create 'push-button
:notify (lambda (&rest ignore)
(if (= (length (widget-value widget-example-repeat))
3)
(message "Congratulation!")
(error "Three was the count!")))
"Apply Form")
(widget-insert " ")
(widget-create 'push-button
:notify (lambda (&rest ignore)
(widget-example))
"Reset Form")
(widget-insert "n")
(use-local-map widget-keymap)
(widget-setup))