branch: elpa/macrostep
commit 59972eb8efa5fdad0dc5103719423870a3f51728
Author: Luís Oliveira <[email protected]>
Commit: Luís Oliveira <[email protected]>
Fix handling of subforms contained within other subforms
---
swank-macrostep.lisp | 31 ++++++++++++++-----------------
1 file changed, 14 insertions(+), 17 deletions(-)
diff --git a/swank-macrostep.lisp b/swank-macrostep.lisp
index d822411..8cc7493 100644
--- a/swank-macrostep.lisp
+++ b/swank-macrostep.lisp
@@ -182,23 +182,20 @@
(incf p)))
(map 'list #'reverse positions)))
+(defun find-non-whitespace-position (string position)
+ (loop with non-whitespace-position = -1
+ for i from 0 and char across string
+ unless (whitespacep char)
+ do (incf non-whitespace-position)
+ until (eql non-whitespace-position position)
+ finally (return i)))
+
(defun collect-form-positions (expansion printed-expansion forms)
- (let* ((annotated-output
- (pprint-to-string expansion
- (make-tracking-pprint-dispatch forms)))
- (marker-positions
- (collect-marker-positions annotated-output (length forms))))
- (loop with i = -1 and non-whitespace-position = -1
- for (start end) in marker-positions
- collect (flet ((find-next (position)
- (loop until (or (eql non-whitespace-position
position)
- (= (1- (length printed-expansion))
- (1+ i)))
- unless (whitespacep (char printed-expansion
- (incf i)))
- do (incf non-whitespace-position))
- i))
- (list (find-next start)
- (find-next end))))))
+ (loop for (start end)
+ in (collect-marker-positions
+ (pprint-to-string expansion (make-tracking-pprint-dispatch
forms))
+ (length forms))
+ collect (list (find-non-whitespace-position printed-expansion start)
+ (find-non-whitespace-position printed-expansion end))))
(provide :swank-macrostep)