diff options
-rw-r--r-- | ccwl/ui.scm | 18 | ||||
-rw-r--r-- | tests/ui.scm | 8 |
2 files changed, 18 insertions, 8 deletions
diff --git a/ccwl/ui.scm b/ccwl/ui.scm index c499041..7f5c76a 100644 --- a/ccwl/ui.scm +++ b/ccwl/ui.scm @@ -124,14 +124,16 @@ with S-expression at LINE-NUMBER, COLUMN-NUMBER highlit in red. LINE-NUMBER and COLUMN-NUMBER are zero-based." (call-with-output-string (lambda (out) - ;; Get to line preceding syntax x. - (repeat (cut get-line port) - (max 0 (1- line-number))) - ;; Display line preceding syntax x unless blank. - (let ((line (get-line port))) - (unless (or (zero? line-number) - (string-blank? line)) - (put-line line out))) + ;; Unless the 0th line is requested, display line preceding + ;; syntax x. + (unless (zero? line-number) + ;; Get to line preceding syntax x. + (repeat (cut get-line port) + (1- line-number)) + ;; Display line preceding syntax x unless blank. + (let ((line (get-line port))) + (unless (string-blank? line) + (put-line line out)))) ;; Display part of line before syntax x. (display (get-string-n port column-number) out) diff --git a/tests/ui.scm b/tests/ui.scm index f7810d7..4189e6c 100644 --- a/tests/ui.scm +++ b/tests/ui.scm @@ -35,4 +35,12 @@ " (cut source-in-context <> 1 2))) +(test-equal "display source in context on 0th line" + (string-append "(foo " + (colorize-string "(bar)" 'BOLD 'RED) + ") +") + (call-with-input-string "(foo (bar))" + (cut source-in-context <> 0 5))) + (test-end "ui") |