summaryrefslogtreecommitdiff
path: root/devdocs/elisp/interactive-examples.html
blob: 5aaa03cc6af887adf726364c45c3ffba41c60bfd (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
 <h4 class="subsection">Examples of Using interactive</h4>   <p>Here are some examples of <code>interactive</code>: </p> <div class="example"> <pre class="example">(defun foo1 ()              ; <span class="roman"><code>foo1</code> takes no arguments,</span>
    (interactive)           ;   <span class="roman">just moves forward two words.</span>
    (forward-word 2))
     ⇒ foo1
</pre>

<pre class="example">(defun foo2 (n)             ; <span class="roman"><code>foo2</code> takes one argument,</span>
    (interactive "^p")      ;   <span class="roman">which is the numeric prefix.</span>
                            ; <span class="roman">under <code>shift-select-mode</code>,</span>
                            ;   <span class="roman">will activate or extend region.</span>
    (forward-word (* 2 n)))
     ⇒ foo2
</pre>

<pre class="example">(defun foo3 (n)             ; <span class="roman"><code>foo3</code> takes one argument,</span>
    (interactive "nCount:") ;   <span class="roman">which is read with the Minibuffer.</span>
    (forward-word (* 2 n)))
     ⇒ foo3
</pre>

<pre class="example">(defun three-b (b1 b2 b3)
  "Select three existing buffers.
Put them into three windows, selecting the last one."
</pre>
<pre class="example">    (interactive "bBuffer1:\nbBuffer2:\nbBuffer3:")
    (delete-other-windows)
    (split-window (selected-window) 8)
    (switch-to-buffer b1)
    (other-window 1)
    (split-window (selected-window) 8)
    (switch-to-buffer b2)
    (other-window 1)
    (switch-to-buffer b3))
     ⇒ three-b
</pre>
<pre class="example">(three-b "*scratch*" "declarations.texi" "*mail*")
     ⇒ nil
</pre>
</div><div class="_attribution">
  <p class="_attribution-p">
    Copyright &copy; 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/Interactive-Examples.html" class="_attribution-link">https://www.gnu.org/software/emacs/manual/html_node/elisp/Interactive-Examples.html</a>
  </p>
</div>