blob: 64877f98b0718784ff2a5f4b2f90808d2ae63305 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
<h3 class="section">Reading Lisp Objects with the Minibuffer</h3> <p>This section describes functions for reading Lisp objects with the minibuffer. </p> <dl> <dt id="read-minibuffer">Function: <strong>read-minibuffer</strong> <em>prompt &optional initial</em>
</dt> <dd>
<p>This function reads a Lisp object using the minibuffer, and returns it without evaluating it. The arguments <var>prompt</var> and <var>initial</var> are used as in <code>read-from-minibuffer</code>. </p> <p>This is a simplified interface to the <code>read-from-minibuffer</code> function: </p> <div class="example"> <pre class="example">(read-minibuffer <var>prompt</var> <var>initial</var>)
≡
(let (minibuffer-allow-text-properties)
(read-from-minibuffer <var>prompt</var> <var>initial</var> nil t))
</pre>
</div> <p>Here is an example in which we supply the string <code>"(testing)"</code> as initial input: </p> <div class="example"> <pre class="example">(read-minibuffer
"Enter an expression: " (format "%s" '(testing)))
;; <span class="roman">Here is how the minibuffer is displayed:</span>
</pre>
<pre class="example">---------- Buffer: Minibuffer ----------
Enter an expression: (testing)∗
---------- Buffer: Minibuffer ----------
</pre>
</div> <p>The user can type <tt class="key">RET</tt> immediately to use the initial input as a default, or can edit the input. </p>
</dd>
</dl> <dl> <dt id="eval-minibuffer">Function: <strong>eval-minibuffer</strong> <em>prompt &optional initial</em>
</dt> <dd>
<p>This function reads a Lisp expression using the minibuffer, evaluates it, then returns the result. The arguments <var>prompt</var> and <var>initial</var> are used as in <code>read-from-minibuffer</code>. </p> <p>This function simply evaluates the result of a call to <code>read-minibuffer</code>: </p> <div class="example"> <pre class="example">(eval-minibuffer <var>prompt</var> <var>initial</var>)
≡
(eval (read-minibuffer <var>prompt</var> <var>initial</var>))
</pre>
</div> </dd>
</dl> <dl> <dt id="edit-and-eval-command">Function: <strong>edit-and-eval-command</strong> <em>prompt form</em>
</dt> <dd>
<p>This function reads a Lisp expression in the minibuffer, evaluates it, then returns the result. The difference between this command and <code>eval-minibuffer</code> is that here the initial <var>form</var> is not optional and it is treated as a Lisp object to be converted to printed representation rather than as a string of text. It is printed with <code>prin1</code>, so if it is a string, double-quote characters (‘<samp>"</samp>’) appear in the initial text. See <a href="output-functions">Output Functions</a>. </p> <p>In the following example, we offer the user an expression with initial text that is already a valid form: </p> <div class="example"> <pre class="example">(edit-and-eval-command "Please edit: " '(forward-word 1))
;; <span class="roman">After evaluation of the preceding expression,</span>
;; <span class="roman">the following appears in the minibuffer:</span>
</pre>
<pre class="example">---------- Buffer: Minibuffer ----------
Please edit: (forward-word 1)∗
---------- Buffer: Minibuffer ----------
</pre>
</div> <p>Typing <tt class="key">RET</tt> right away would exit the minibuffer and evaluate the expression, thus moving point forward one word. </p>
</dd>
</dl><div class="_attribution">
<p class="_attribution-p">
Copyright © 1990-1996, 1998-2022 Free Software Foundation, Inc. <br>Licensed under the GNU GPL license.<br>
<a href="https://www.gnu.org/software/emacs/manual/html_node/elisp/Object-from-Minibuffer.html" class="_attribution-link">https://www.gnu.org/software/emacs/manual/html_node/elisp/Object-from-Minibuffer.html</a>
</p>
</div>
|