Eduardo Costa reported the error when indenting a form like
(defvar test
'( asdf ; note space after left paren
;ltk error on this line
Basic idea is to make the tokenizer skip leading whitespace.
Probably only slightly more robust than the previous code.
&optional (text-to-cursor (ltk::get-text-to-cursor txt)))
"Indents code as you type using the extensible rules of GET-INDENT-LEVEL."
(let ((str (ltk:text txt))
- (pos 0) (next) (start) (end) (indent) (token))
+ (pos 0) (indent))
(setf pos (- (length text-to-cursor) 1))
(when (and (> pos -1) (<= pos (length str)))
(multiple-value-bind (token start end) (find-current-function str pos)
+ (declare (ignore end))
(when token
(setf indent (get-indent-level token))
(setf start (+ start indent))
start end token)
(when next-open
(setf start (get-col-integer (strpos-to-textidx code-string next-open)))
- (setf end (position #\Space code-string :start next-open :test #'equal))
+ (loop :for i :from (1+ next-open) :below (length code-string)
+ :do (if (member (char code-string i) '(#\Space #\Tab #\Newline) :test #'char=)
+ (setf next-open i)
+ (return)))
+ (setf end (position #\Space code-string :start (1+ next-open) :test #'equal))
(setf token (subseq code-string (+ next-open 1) end)))
(values token start end)))