Menu: Difference between revisions
Content added Content deleted
Langurmonkey (talk | contribs) m (→{{header|langur}}: replace deprecated ZLS token with "") |
(Add emacs lisp) |
||
Line 917: | Line 917: | ||
you chose: "tick tock" |
you chose: "tick tock" |
||
</pre> |
</pre> |
||
=={{header|Emacs Lisp}}== |
|||
<syntaxhighlight lang="lisp"> |
|||
(let ((prompt-buffer-name "***** prompt *****") |
|||
(option-list '("fee fie" |
|||
"huff and puff" |
|||
"mirror mirror" |
|||
"tick tock")) |
|||
(extra-prompt-message "") |
|||
(is-selected nil) |
|||
(user-input-value nil)) |
|||
;; Switch to an empty buffer |
|||
(switch-to-buffer-other-window prompt-buffer-name) |
|||
(read-only-mode -1) |
|||
(erase-buffer) |
|||
;; Display the options |
|||
(cl-loop for opt-idx from 1 to (length option-list) do |
|||
(insert (format "%d\) %s \n" opt-idx (nth (1- opt-idx) option-list)))) |
|||
(while (not is-selected) |
|||
;; Read user input |
|||
(setq user-input-value (read-string (concat "select an option" extra-prompt-message " : "))) |
|||
(setq user-input-value (read user-input-value)) |
|||
;; Validate user input |
|||
(if (and (fixnump user-input-value) |
|||
(<= user-input-value (length option-list)) |
|||
(> user-input-value 0)) |
|||
;; Display result |
|||
(progn |
|||
(end-of-buffer) |
|||
(insert (concat "\nYou selected: " (nth (1- user-input-value) option-list))) |
|||
(setq is-selected 't) |
|||
) |
|||
(progn |
|||
(setq extra-prompt-message " (please input a valid number)") |
|||
) |
|||
) |
|||
) |
|||
) |
|||
</syntaxhighlight> |
|||
=={{header|ERRE}}== |
=={{header|ERRE}}== |