Skip to content

Commit

Permalink
buffer: add buffer-ref to obtain a single entry
Browse files Browse the repository at this point in the history
  • Loading branch information
nmeum committed Aug 13, 2024
1 parent 833adb6 commit db21875
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/buffer.sld
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

(edward util))

(export make-buffer buffer->list buffer-length buffer-empty?
(export make-buffer buffer->list buffer-length buffer-empty? buffer-ref
buffer-append! buffer-remove! buffer-with-undo buffer-has-undo?
buffer-undo! buffer-replace! buffer-join! buffer-move!)

Expand Down
5 changes: 5 additions & 0 deletions lib/buffer/buffer.scm
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
(define (make-buffer)
(%make-buffer (flexvector) #f (make-stack)))

;;> Returns the element at `index` in the `buffer`, starting at zero.

(define (buffer-ref buffer index)
(flexvector-ref (buffer-lines buffer) index))

;;> Convert the line buffer to a list of lines. Additionally, this
;;> procedure accepts an optional `start` and `end` parameter. If
;;> these parameters are given the list only contains the elements
Expand Down
3 changes: 3 additions & 0 deletions lib/buffer/srfi214-minimal.scm
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
(define (flexvector)
(%make-flexvector (make-vector 4) 0))

(define (flexvector-ref fv index)
(vector-ref (vec fv) index))

(define (flexvector-add-all! fv i xs)
(let* ((len (flexvector-length fv))
(xv (list->vector xs))
Expand Down

0 comments on commit db21875

Please sign in to comment.