> For the complete documentation index, see [llms.txt](https://emacs-lisp.ivory.cafe/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://emacs-lisp.ivory.cafe/wen-ben/untitled/32.1-wei-zhi-dian-fu-jin-near-point.md).

# 32.1 位置点附近 (Near Point)

Emcas 提供了不少函数来处理 位置点附近 的字符. 下面就是一些简单的函数. (另外, 你可以在 正则搜寻章节 查看 looking-at 的定义.)

接下来的四个函数里, 起始位置 (beginning) 和 结束位置 (end) 是指缓冲区的编辑范围的起始位置和结束位置.

Function: char-after \&optional position\
&#x20; 这个函数返回当前缓冲区中, 紧挨着 位置 position 后的字符. 如果这个位置不在缓冲区的编辑范围内, 那么这个函数会返回 nil. 默认的位置是 当前位置点(point),

&#x20; 比如这个例子, 我们假设缓冲区的第一个字符是 '@', 那么会有:

```
(string (char-after 1))
    => "@"
```

Function: char-before \&optional position\
&#x20; 这个函数返回当前缓冲区中, 紧挨着 位置 position 前的字符. 同样的, 如果这个位置不在编辑范围内, 那么这个函数会返回 nil. 默认的位置是 当前位置点 (point).

Function: following-char\
&#x20; 这个函数返回当前缓冲区中紧挨着位置点的字符. 看起来和 (char-after (point)) 很相似. 不同的是, 如果位置点在缓冲区的末尾, following-char 会返回 0.

&#x20; 牢记在心: 位置点总是处于两个字符之间, 也就是光标覆盖的字符的前面一点点. 因此, 函数 following-char 返回的总是光标覆盖的那个字符.

这下面这个例子里, 位置点 位于 'a' 和 'c' 之间.

```
---------- Buffer: foo ----------
Gentlemen may cry ``Pea∗ce! Peace!,''
but there is no peace.
---------- Buffer: foo ----------

(string (preceding-char))
    => "a"
(string (following-char))
    => "c"
```

Function: preceding-char\
&#x20; 这个函数返回当前缓冲区紧挨着位置点的前一个字符. 和上面的 following-char 很类似. 此外, 如果位置点位于缓冲区的起始位置, 那这个函数会返回 0.

Function: bobp\
&#x20; 这是一个谓语, 如果位置点在缓冲区起始位置(**b**eginning **o**f the **b**uffer), 则返回 t. 如果启用了变窄 (narrowing), 那么此时 bob 就是文本的起始位置. (详情查阅 位置点章 的 point-min)

Function: eobp\
&#x20; 这是一个谓语, 如果位置点在缓冲区结束位置(end of the buffer), 则返回 t. 如果启用了变窄 (narrowing), 那么此时的 eob 就是文本的结束位置. (查阅 位置点章 的 point-max)

Function: bolp\
&#x20; 这是一个谓语, 如果位置点在行的起始位置(beginning of a line), 则返回 t. 此外, 缓冲区的起始位置始终算是行的起始位置.

Function: eolp\
&#x20; 这是一个谓语, 如果位置点在行的结束位置(end of a line). 则返回 t. 此外, 缓冲区的结束位置始终算是行的结束位置.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://emacs-lisp.ivory.cafe/wen-ben/untitled/32.1-wei-zhi-dian-fu-jin-near-point.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
