|
1 | 1 | ---
|
2 |
| -title: Lem's internal concepts |
| 2 | +title: Internal concepts |
3 | 3 | weight: 1
|
4 | 4 | ---
|
5 | 5 |
|
| 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 | + |
6 | 142 | ## Prompts
|
7 | 143 |
|
8 | 144 | Prompts are these interactive pop-up windows that allow you to search
|
@@ -36,6 +172,10 @@ Their signature are usually:
|
36 | 172 | :test-function #'function)
|
37 | 173 | ```
|
38 | 174 |
|
| 175 | +See: |
| 176 | + |
| 177 | +- [`src/prompt.lisp`](https://github.com/lem-project/lem/blob/main/src/prompt.lisp) |
| 178 | + |
39 | 179 |
|
40 | 180 | ### Example: prompt for strings
|
41 | 181 |
|
|
0 commit comments