Skip to content

Commit d5d6de7

Browse files
authored
account for indentation (#84)
1 parent dc733b3 commit d5d6de7

File tree

2 files changed

+157
-143
lines changed

2 files changed

+157
-143
lines changed

src/printing.jl

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,9 +211,23 @@ function print_sourcecode(io::IO, code::String, line::Integer, defline::Integer)
211211
pop!(code)
212212
end
213213

214+
# Count indentation level (only count spaces for now)
215+
min_indentation = typemax(Int)
216+
for textline in code
217+
indent_line = 0
218+
for char in textline
219+
char != ' ' && break
220+
indent_line += 1
221+
end
222+
min_indentation = min(min_indentation, indent_line)
223+
end
224+
for i in 1:length(code)
225+
code[i] = code[i][min_indentation+1:end]
226+
end
227+
214228
for textline in code
215229
printstyled(io,
216-
string(rpad(lineno, stoplinelength), " ");
230+
string(rpad(lineno, stoplinelength), " ");
217231
color = lineno == current_line ? :yellow : :bold)
218232
println(io, textline)
219233
lineno += 1

0 commit comments

Comments
 (0)