Skip to content

Commit 6727685

Browse files
committed
internal-concepts: add buffers, point
1 parent 0d4b866 commit 6727685

File tree

2 files changed

+145
-15
lines changed

2 files changed

+145
-15
lines changed

content/en/development/displaying.md

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
---
2-
title: Lem's displaying concepts
2+
title: Displaying concepts
33
weight: -2
44
---
5+
56
Lem has some concept for displaying.
67
This document is a result of [a survey about them](https://gist.github.com/t-sin/cc0d036e40669395fd41cfd48bb9c997).
78

9+
{{< toc >}}
10+
811
## Display(s)
912

1013
Logical concept for physical displaying areas dealt by frontends; like ncurses, electron and so on.
@@ -200,16 +203,3 @@ Built-in attributes are defined in `src/attributes.lisp`, such as:
200203

201204
and so on.
202205

203-
## Attached buffers
204-
205-
This feature attaches “attached-window” to the bottom of a specific
206-
window. An "attached-window" has an "attached-buffer". When you attach an
207-
attached-window to a specific window, that window becomes the parent
208-
window from the perspective of the attached-window. The attached
209-
window remains visible even when the parent window is scrolled.
210-
211-
It's like a comment input form on slack or discord.
212-
213-
They were initially added for the Claude Code integration.
214-
215-
<img class="" src="/lem-attach-buffer.png" alt="Lem's attached buffers concept.">

content/en/development/internal-concepts.md

Lines changed: 141 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,144 @@
11
---
2-
title: Lem's internal concepts
2+
title: Internal concepts
33
weight: 1
44
---
55

6+
{{< toc >}}
7+
8+
9+
## Buffers
10+
11+
A buffer contains text to display on screen, and might be associated
12+
to a file, but might not be.
13+
14+
Buffers are regular CLOS objects with many slots:
15+
16+
```
17+
name
18+
temporary (boolean)
19+
filename
20+
directory
21+
read-only-p
22+
major-mode
23+
minor-modes
24+
point
25+
last-write-date
26+
27+
```
28+
29+
A `text-buffer` is a class and type for text buffers.
30+
31+
The variable `*current-buffer*` holds the current buffer, the one we
32+
are visiting in Lem. There will always be at least one buffer, even if
33+
it is the primordial one named `*tmp*`.
34+
35+
We don't directly access a buffer's slots, but we use small wrapper functions, such as:
36+
37+
```lisp
38+
buffer-name
39+
buffer-filename
40+
buffer-directory
41+
42+
```
43+
44+
They are `setf`-able, and work by default on the current-buffer.
45+
46+
Other manipulation functions include:
47+
48+
```lisp
49+
(current-buffer)
50+
(ensure-buffer)
51+
(get-buffer)
52+
;; If 'buffer-or-name' is a buffer, it is returned. If it is a string, it returns the buffer with that name.
53+
```
54+
55+
See:
56+
57+
- [`src/buffer/internal/buffer.lisp`](https://github.com/lem-project/lem/blob/main/src/buffer/internal/buffer.lisp)
58+
59+
### Manipulating buffers
60+
61+
See:
62+
63+
```lisp
64+
(buffer-list)
65+
(delete-buffer)
66+
(get-next-buffer)
67+
(get-previous-buffer)
68+
(defun get-file-buffer (filename)
69+
;; "Return the buffer corresponding to 'filename' or NIL if not found."
70+
etc
71+
```
72+
73+
74+
### Buffer variables
75+
76+
A buffer object might hold any other data in its `variables` slot (to
77+
get with `buffer-variables`), a hash-table that associates a variable
78+
key to its values.
79+
80+
The function `buffer-value buffer name &optional default` is used to
81+
access these variables. It is `setf`-able.
82+
83+
### Attached buffers
84+
85+
This feature attaches “attached-window” to the bottom of a specific
86+
window. An "attached-window" has an "attached-buffer". When you attach an
87+
attached-window to a specific window, that window becomes the parent
88+
window from the perspective of the attached-window. The attached
89+
window remains visible even when the parent window is scrolled.
90+
91+
It's like a comment input form on slack or discord.
92+
93+
They were initially added for the Claude Code integration.
94+
95+
<img class="" src="/lem-attach-buffer.png" alt="Lem's attached buffers concept.">
96+
97+
98+
## Moving the point
99+
100+
The point is the cursor's location.
101+
102+
<!-- TODO: add internal/point.lisp package documentation about points and their :kind types -->
103+
104+
You may use these functions:
105+
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.
116+
117+
```lisp
118+
(save-excursion
119+
(move-point (current-point) point)
120+
(prompt-for-string
121+
"Say hi: "))
122+
```
123+
124+
See:
125+
126+
- [`src/buffer/internal/point.lisp`](https://github.com/lem-project/lem/blob/main/src/buffer/internal/point.lisp)
127+
128+
### Create (and delete) points
129+
130+
Each created point creates an object in memory. After being used, a
131+
point should be discarded. You can use `make-point` and
132+
`delete-point`, or use the macro `with-point`.
133+
134+
~~~lisp
135+
(with-point ((p3 expr1)
136+
(p1 expr2 :left-inserting)
137+
(p2 expr3 :right-inserting))
138+
...)
139+
~~~
140+
141+
6142
## Prompts
7143

8144
Prompts are these interactive pop-up windows that allow you to search
@@ -36,6 +172,10 @@ Their signature are usually:
36172
:test-function #'function)
37173
```
38174

175+
See:
176+
177+
- [`src/prompt.lisp`](https://github.com/lem-project/lem/blob/main/src/prompt.lisp)
178+
39179

40180
### Example: prompt for strings
41181

0 commit comments

Comments
 (0)