diff --git a/editor/editor.lisp b/editor/editor.lisp index 57b3552..3625166 100644 --- a/editor/editor.lisp +++ b/editor/editor.lisp @@ -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 ()