summaryrefslogtreecommitdiff
path: root/devdocs/elisp/user_002dlevel-deletion.html
blob: 0b9ed50bceb255e318374579e01e1581c7a5e925 (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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
 <h3 class="section">User-Level Deletion Commands</h3> <p>This section describes higher-level commands for deleting text, commands intended primarily for the user but useful also in Lisp programs. </p> <dl> <dt id="delete-horizontal-space">Command: <strong>delete-horizontal-space</strong> <em>&amp;optional backward-only</em>
</dt> <dd>
 <p>This function deletes all spaces and tabs around point. It returns <code>nil</code>. </p> <p>If <var>backward-only</var> is non-<code>nil</code>, the function deletes spaces and tabs before point, but not after point. </p> <p>In the following examples, we call <code>delete-horizontal-space</code> four times, once on each line, with point between the second and third characters on the line each time. </p> <div class="example"> <pre class="example">---------- Buffer: foo ----------
I ∗thought
I ∗     thought
We∗ thought
Yo∗u thought
---------- Buffer: foo ----------
</pre>

<pre class="example">(delete-horizontal-space)   ; <span class="roman">Four times.</span>
     ⇒ nil

---------- Buffer: foo ----------
Ithought
Ithought
Wethought
You thought
---------- Buffer: foo ----------
</pre>
</div> </dd>
</dl> <dl> <dt id="delete-indentation">Command: <strong>delete-indentation</strong> <em>&amp;optional join-following-p beg end</em>
</dt> <dd>
<p>This function joins the line point is on to the previous line, deleting any whitespace at the join and in some cases replacing it with one space. If <var>join-following-p</var> is non-<code>nil</code>, <code>delete-indentation</code> joins this line to the following line instead. Otherwise, if <var>beg</var> and <var>end</var> are non-<code>nil</code>, this function joins all lines in the region they define. </p> <p>In an interactive call, <var>join-following-p</var> is the prefix argument, and <var>beg</var> and <var>end</var> are, respectively, the start and end of the region if it is active, else <code>nil</code>. The function returns <code>nil</code>. </p> <p>If there is a fill prefix, and the second of the lines being joined starts with the prefix, then <code>delete-indentation</code> deletes the fill prefix before joining the lines. See <a href="margins">Margins</a>. </p> <p>In the example below, point is located on the line starting ‘<samp>events</samp>’, and it makes no difference if there are trailing spaces in the preceding line. </p> <div class="example"> <pre class="example">---------- Buffer: foo ----------
When in the course of human
∗    events, it becomes necessary
---------- Buffer: foo ----------
</pre>
<pre class="example">

(delete-indentation)
     ⇒ nil

</pre>
<pre class="example">---------- Buffer: foo ----------
When in the course of human∗ events, it becomes necessary
---------- Buffer: foo ----------
</pre>
</div> <p>After the lines are joined, the function <code>fixup-whitespace</code> is responsible for deciding whether to leave a space at the junction. </p>
</dd>
</dl> <dl> <dt id="fixup-whitespace">Command: <strong>fixup-whitespace</strong>
</dt> <dd>
<p>This function replaces all the horizontal whitespace surrounding point with either one space or no space, according to the context. It returns <code>nil</code>. </p> <p>At the beginning or end of a line, the appropriate amount of space is none. Before a character with close parenthesis syntax, or after a character with open parenthesis or expression-prefix syntax, no space is also appropriate. Otherwise, one space is appropriate. See <a href="syntax-class-table">Syntax Class Table</a>. </p> <p>In the example below, <code>fixup-whitespace</code> is called the first time with point before the word ‘<samp>spaces</samp>’ in the first line. For the second invocation, point is directly after the ‘<samp>(</samp>’. </p> <div class="example"> <pre class="example">---------- Buffer: foo ----------
This has too many     ∗spaces
This has too many spaces at the start of (∗   this list)
---------- Buffer: foo ----------
</pre>

<pre class="example">(fixup-whitespace)
     ⇒ nil
(fixup-whitespace)
     ⇒ nil
</pre>

<pre class="example">---------- Buffer: foo ----------
This has too many spaces
This has too many spaces at the start of (this list)
---------- Buffer: foo ----------
</pre>
</div> </dd>
</dl> <dl> <dt id="just-one-space">Command: <strong>just-one-space</strong> <em>&amp;optional n</em>
</dt> <dd><p>This command replaces any spaces and tabs around point with a single space, or <var>n</var> spaces if <var>n</var> is specified. It returns <code>nil</code>. </p></dd>
</dl> <dl> <dt id="delete-blank-lines">Command: <strong>delete-blank-lines</strong>
</dt> <dd>
<p>This function deletes blank lines surrounding point. If point is on a blank line with one or more blank lines before or after it, then all but one of them are deleted. If point is on an isolated blank line, then it is deleted. If point is on a nonblank line, the command deletes all blank lines immediately following it. </p> <p>A blank line is defined as a line containing only tabs and spaces. </p> <p><code>delete-blank-lines</code> returns <code>nil</code>. </p>
</dd>
</dl> <dl> <dt id="delete-trailing-whitespace">Command: <strong>delete-trailing-whitespace</strong> <em>&amp;optional start end</em>
</dt> <dd>
<p>Delete trailing whitespace in the region defined by <var>start</var> and <var>end</var>. </p> <p>This command deletes whitespace characters after the last non-whitespace character in each line in the region. </p> <p>If this command acts on the entire buffer (i.e., if called interactively with the mark inactive, or called from Lisp with <var>end</var> <code>nil</code>), it also deletes all trailing lines at the end of the buffer if the variable <code>delete-trailing-lines</code> is non-<code>nil</code>. </p>
</dd>
</dl><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/User_002dLevel-Deletion.html" class="_attribution-link">https://www.gnu.org/software/emacs/manual/html_node/elisp/User_002dLevel-Deletion.html</a>
  </p>
</div>