Skip to content

Commit d73882b

Browse files
committed
point++ left-inserting
1 parent f4801a4 commit d73882b

File tree

1 file changed

+60
-16
lines changed

1 file changed

+60
-16
lines changed

content/en/development/internal-concepts.md

Lines changed: 60 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -95,32 +95,55 @@ They were initially added for the Claude Code integration.
9595
<img class="" src="/lem-attach-buffer.png" alt="Lem's attached buffers concept.">
9696

9797

98-
## Moving the point
98+
## The Point
9999

100100
The point is the cursor's location.
101101

102102
<!-- TODO: add internal/point.lisp package documentation about points and their :kind types -->
103103

104-
You may use these functions:
104+
`point` is an object that points to the position of some text in the buffer.
105105

106-
```
107-
(current-point)
108-
(copy-point)
109-
(point=) ;; and other comparison functions
110-
(point-max)
111-
(move-point point new-point)
112-
```
113-
114-
The macro `(save-excursion …)` will run its body and preserve the
115-
point position from before the macro was called.
106+
This is its definition:
116107

117108
```lisp
118-
(save-excursion
119-
(move-point (current-point) point)
120-
(prompt-for-string
121-
"Say hi: "))
109+
(defclass point ()
110+
((buffer
111+
:reader point-buffer
112+
:type buffer)
113+
(linum
114+
:accessor point-linum
115+
:type fixnum)
116+
(line
117+
:accessor point-line
118+
:type line)
119+
(charpos
120+
:accessor point-charpos
121+
:type fixnum)
122+
(kind
123+
:reader point-kind
124+
:type point-kind)))
122125
```
123126

127+
It has a `buffer` slot, a `line` number, and `charpos` is an offset from the beginning of the line, starting at zero.
128+
129+
`point` has a `kind` type. This is important as it defines how the
130+
text at point moves or not when you insert content before it.
131+
132+
If you insert content at the point position, with `:right-inserting` the original position is unchanged, and with `:left-inserting` the position is adjusted by the length of your edit.
133+
134+
When `kind` is `:left-inserting`, and if you insert content *before* the point, then the point position is adjusted by the length of your edit.
135+
136+
When `kind` is `:temporary`, the point is used for temporary reads. The
137+
overhead on creation and deletion is low, and there is no need to
138+
explicitly delete the point. If you edit the buffer before the
139+
position, the `point` cannot be used correctly any more.
140+
141+
When using `:left-inserting` or `:right-inserting`, you must explicitly delete the point after use with `delete-point`. For this reason, you should use the macro `with-point`, which automatically deletes it.
142+
143+
Use `with-points` to define points to use in the macro body, to ensure they are deleted.
144+
145+
Use `save-excursion` to move around the given point in the macro body, and come back to it once done.
146+
124147
See:
125148

126149
- [`src/buffer/internal/point.lisp`](https://github.com/lem-project/lem/blob/main/src/buffer/internal/point.lisp)
@@ -138,6 +161,27 @@ point should be discarded. You can use `make-point` and
138161
...)
139162
~~~
140163

164+
## Moving the point
165+
166+
You may use these functions on a point object:
167+
168+
```
169+
(current-point)
170+
(copy-point)
171+
(point=) ;; and other comparison functions
172+
(point-max)
173+
(move-point point new-point)
174+
```
175+
176+
The macro `(save-excursion …)` will run its body and preserve the
177+
point position from before the macro was called.
178+
179+
```lisp
180+
(save-excursion
181+
(move-point (current-point) point)
182+
(prompt-for-string
183+
"Say hi: "))
184+
```
141185

142186
## Prompts
143187

0 commit comments

Comments
 (0)