summaryrefslogtreecommitdiff
path: root/devdocs/elisp/near-point.html
blob: 87941f11633e5947cce58a27381c502dc5f76372 (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
 <h3 class="section">Examining Text Near Point</h3>  <p>Many functions are provided to look at the characters around point. Several simple functions are described here. See also <code>looking-at</code> in <a href="regexp-search">Regexp Search</a>. </p> <p>In the following four functions, “beginning” or “end” of buffer refers to the beginning or end of the accessible portion. </p> <dl> <dt id="char-after">Function: <strong>char-after</strong> <em>&amp;optional position</em>
</dt> <dd>
<p>This function returns the character in the current buffer at (i.e., immediately after) position <var>position</var>. If <var>position</var> is out of range for this purpose, either before the beginning of the buffer, or at or beyond the end, then the value is <code>nil</code>. The default for <var>position</var> is point. </p> <p>In the following example, assume that the first character in the buffer is ‘<samp>@</samp>’: </p> <div class="example"> <pre class="example">(string (char-after 1))
     ⇒ "@"
</pre>
</div> </dd>
</dl> <dl> <dt id="char-before">Function: <strong>char-before</strong> <em>&amp;optional position</em>
</dt> <dd><p>This function returns the character in the current buffer immediately before position <var>position</var>. If <var>position</var> is out of range for this purpose, either at or before the beginning of the buffer, or beyond the end, then the value is <code>nil</code>. The default for <var>position</var> is point. </p></dd>
</dl> <dl> <dt id="following-char">Function: <strong>following-char</strong>
</dt> <dd>
<p>This function returns the character following point in the current buffer. This is similar to <code>(char-after (point))</code>. However, if point is at the end of the buffer, then <code>following-char</code> returns 0. </p> <p>Remember that point is always between characters, and the cursor normally appears over the character following point. Therefore, the character returned by <code>following-char</code> is the character the cursor is over. </p> <p>In this example, point is between the ‘<samp>a</samp>’ and the ‘<samp>c</samp>’. </p> <div class="example"> <pre class="example">---------- Buffer: foo ----------
Gentlemen may cry ``Pea∗ce! Peace!,''
but there is no peace.
---------- Buffer: foo ----------
</pre>

<pre class="example">(string (preceding-char))
     ⇒ "a"
(string (following-char))
     ⇒ "c"
</pre>
</div> </dd>
</dl> <dl> <dt id="preceding-char">Function: <strong>preceding-char</strong>
</dt> <dd><p>This function returns the character preceding point in the current buffer. See above, under <code>following-char</code>, for an example. If point is at the beginning of the buffer, <code>preceding-char</code> returns 0. </p></dd>
</dl> <dl> <dt id="bobp">Function: <strong>bobp</strong>
</dt> <dd><p>This function returns <code>t</code> if point is at the beginning of the buffer. If narrowing is in effect, this means the beginning of the accessible portion of the text. See also <code>point-min</code> in <a href="point">Point</a>. </p></dd>
</dl> <dl> <dt id="eobp">Function: <strong>eobp</strong>
</dt> <dd><p>This function returns <code>t</code> if point is at the end of the buffer. If narrowing is in effect, this means the end of accessible portion of the text. See also <code>point-max</code> in See <a href="point">Point</a>. </p></dd>
</dl> <dl> <dt id="bolp">Function: <strong>bolp</strong>
</dt> <dd><p>This function returns <code>t</code> if point is at the beginning of a line. See <a href="text-lines">Text Lines</a>. The beginning of the buffer (or of its accessible portion) always counts as the beginning of a line. </p></dd>
</dl> <dl> <dt id="eolp">Function: <strong>eolp</strong>
</dt> <dd><p>This function returns <code>t</code> if point is at the end of a line. The end of the buffer (or of its accessible portion) is always considered the end of a line. </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/Near-Point.html" class="_attribution-link">https://www.gnu.org/software/emacs/manual/html_node/elisp/Near-Point.html</a>
  </p>
</div>