{"id":977,"date":"2012-08-04T08:40:00","date_gmt":"2012-08-04T12:40:00","guid":{"rendered":"http:\/\/irreal.org\/blog\/?p=977"},"modified":"2012-08-04T08:41:29","modified_gmt":"2012-08-04T12:41:29","slug":"prompting-for-user-input-with-elisp","status":"publish","type":"post","link":"https:\/\/irreal.org\/blog\/?p=977","title":{"rendered":"Prompting for User Input with Elisp"},"content":{"rendered":"<p>Xah Lee has a nice <a href=\"http:\/\/ergoemacs.org\/emacs\/elisp_idioms_prompting_input.html\">tutorial<\/a> on getting user input with Emacs Lisp. Most Elisp programmers are aware of the <code>interactive<\/code> control strings for this purpose and most of us probably use that for most occasions requiring user input:<\/p>\n<pre class=\"src src-emacs-lisp\">(<span style=\"color: #7f007f;\">defun<\/span> <span style=\"color: #0000ff;\">test-input-func<\/span> (msg)\r\n  (interactive <span style=\"color: #8b2252;\">\"sEnter Message: \"<\/span>)\r\n  (message <span style=\"color: #8b2252;\">\"Your message was: %s\"<\/span> msg))<\/pre>\n<p>The <code>interactive<\/code> form supports the input of many type of data as documented in the built-in info documentation and also the <a href=\"http:\/\/www.gnu.org\/software\/emacs\/manual\/html_node\/elisp\/Interactive-Codes.html#Interactive-Codes\">Emacs Lisp Reference Manual<\/a>.<\/p>\n<p>The nice thing about Lees tutorial is that he mentions the rarer but sometimes useful functions that also accept user input. These are handy when you need to get data from within a function that is not (necessarily) an input parameter. These functions are:<\/p>\n<table border=\"2\" frame=\"hsides\" rules=\"groups\" cellspacing=\"0\" cellpadding=\"6\">\n<caption>\u00a0<\/caption>\n<colgroup>\n<col class=\"left\" \/>\n<col class=\"left\" \/> <\/colgroup>\n<thead>\n<tr>\n<th class=\"left\" scope=\"col\">Function<\/th>\n<th class=\"left\" scope=\"col\">Use<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr class=\"tr-even\">\n<td class=\"left\"><code>read-string<\/code><\/td>\n<td class=\"left\">Read input as a string<\/td>\n<\/tr>\n<tr class=\"tr-odd\">\n<td class=\"left\"><code>read-file-name<\/code><\/td>\n<td class=\"left\">Read input as a file name<\/td>\n<\/tr>\n<tr class=\"tr-even\">\n<td class=\"left\"><code>read-regexp<\/code><\/td>\n<td class=\"left\">Read input as a regular expression<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>An additional benefit of these functions is that they support the history mechanism and that <code>read-regexp<\/code> doesn&#8217;t need the escaping that representing regular expressions as strings usually require.<\/p>\n<p>Head on over to Lee&#8217;s tutorial for all the details. If you do anything other than very simple Elisp, this is stuff you need to know.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Xah Lee has a nice tutorial on getting user input with Emacs Lisp. Most Elisp programmers are aware of the interactive control strings for this purpose and most of us probably use that for most occasions requiring user input: (defun &hellip; <a href=\"https:\/\/irreal.org\/blog\/?p=977\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[18,28],"class_list":["post-977","post","type-post","status-publish","format-standard","hentry","category-programming","tag-emacs","tag-emacs-lisp"],"_links":{"self":[{"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/977","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=977"}],"version-history":[{"count":6,"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/977\/revisions"}],"predecessor-version":[{"id":1001,"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/977\/revisions\/1001"}],"wp:attachment":[{"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=977"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=977"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/irreal.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=977"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}