The following function determines the amount of indentation of a string. It returns two values. The first is an effective indentation where tabs are expanded such that their end aligns with 4 spaces steps. The second is just the amount of spaces and tabs before the first non-tab/space character.
roundup is a method that rounds the first argument to next higher multiple of the second argument. The rest is standard CL.
(defun indentation (line) (let ((spaces 0)) (dotimes (index (length line) (values spaces index)) (case (aref line index) (#\Space (incf spaces)) (#\Tab (setf spaces (roundup (1+ spaces) 4))) (otherwise (return (values spaces index)))))))
I don't like having to state the return value twice.