Add macro for walking buffer content (for example to search)
This commit is contained in:
parent
b7dea0f333
commit
63a9b50fb4
1 changed files with 23 additions and 0 deletions
|
@ -498,6 +498,29 @@ Additionally ensures correct line numbers on the way, as a bonus."
|
|||
(cursor-line (cursor buffer)))))
|
||||
(move-cursor line-number (cursor-column (cursor buffer)))))
|
||||
|
||||
(defmacro do-buffer ((line column character &key start-line (start-column 0)
|
||||
(direction :forward))
|
||||
buffer &body body)
|
||||
(declare (type (member :forward :backward) direction))
|
||||
`(loop :with ,line := ,(or start-line (if (eql direction :forward)
|
||||
`(first-line ,buffer)
|
||||
`(last-line ,buffer)))
|
||||
:with ,column := ,start-column
|
||||
:for ,character := (ignore-errors
|
||||
(char (line-content ,line) ,column))
|
||||
:unless (null ,character)
|
||||
:do (progn ,@body)
|
||||
:do (incf ,column ,(if (eql direction :forward) 1 -1))
|
||||
:when ,(if (eql direction :forward)
|
||||
`(>= ,column (line-length ,line))
|
||||
`(< ,column 0))
|
||||
:do ,(if (eql direction :forward)
|
||||
`(setf ,line (next-line ,line)
|
||||
,column 0)
|
||||
`(setf ,line (prev-line ,line)
|
||||
,column (ignore-errors (line-length ,line))))
|
||||
:until (null ,line)))
|
||||
|
||||
|
||||
|
||||
(defun status-line-string ()
|
||||
|
|
Loading…
Add table
Reference in a new issue