From 85bbc1f634f19bd244831f545a1c3f8f20a0acd9 Mon Sep 17 00:00:00 2001 From: Jeff Bezanson Date: Thu, 30 Jul 2015 12:42:27 -0400 Subject: [PATCH] Revert "indent, unindent: default tab width = 4." This reverts commit 6c71b13e607a4bce8b02154982dbb13dc7f29dce. --- base/LineEdit.jl | 4 ++-- base/REPL.jl | 4 ++-- base/strings/io.jl | 12 +++++------- test/strings/io.jl | 30 +++++++++--------------------- 4 files changed, 18 insertions(+), 32 deletions(-) diff --git a/base/LineEdit.jl b/base/LineEdit.jl index 61666c015ab72..6387b6ffb7634 100644 --- a/base/LineEdit.jl +++ b/base/LineEdit.jl @@ -1433,8 +1433,8 @@ AnyDict( input = readuntil(ps.terminal, "\e[201~")[1:(end-6)] input = replace(input, '\r', '\n') if position(buffer(s)) == 0 - indent = Base.indentation(input)[1] - input = Base.unindent(input[(indent+1):end], indent) + indent = Base.indentation(input; tabwidth=4)[1] + input = Base.unindent(input[(indent+1):end], indent; tabwidth=4) end edit_insert(s, input) end, diff --git a/base/REPL.jl b/base/REPL.jl index 5ffe0408e2108..fc3af9c07d565 100644 --- a/base/REPL.jl +++ b/base/REPL.jl @@ -788,8 +788,8 @@ function setup_interface(repl::LineEditREPL; hascolor = repl.hascolor, extra_rep input = readuntil(ps.terminal, "\e[201~")[1:(end-6)] input = replace(input, '\r', '\n') if position(LineEdit.buffer(s)) == 0 - indent = Base.indentation(input)[1] - input = Base.unindent(lstrip(input), indent) + indent = Base.indentation(input; tabwidth=4)[1] + input = Base.unindent(lstrip(input), indent; tabwidth=4) end buf = copy(LineEdit.buffer(s)) edit_insert(buf,input) diff --git a/base/strings/io.jl b/base/strings/io.jl index 1672a9773fb22..09e7ec411e695 100644 --- a/base/strings/io.jl +++ b/base/strings/io.jl @@ -196,13 +196,12 @@ macro b_str(s); :($(unescape_string(s)).data); end ## multiline strings ## """ -Calculate the width of leading blank space, and also return if string is blank. -Assumes a tab width of 4, which is standard for Julia code. +Calculate the width of leading blank space, and also return if string is blank ### Returns: * (width of leading whitespace, flag if string is totally blank) """ -function indentation(str::AbstractString; tabwidth=4) +function indentation(str::AbstractString; tabwidth=8) count = 0 for ch in str if ch == ' ' @@ -217,13 +216,12 @@ function indentation(str::AbstractString; tabwidth=4) end """ -Removes leading indentation from string. -Assumes a tab width of 4, which is standard for Julia code. +Removes leading indentation from string ### Returns: -* `ASCIIString` or `UTF8String` of multiline string, with leading indentation of `indent` removed. +* `ASCIIString` or `UTF8String` of multiline string, with leading indentation of `indent` removed """ -function unindent(str::AbstractString, indent::Int; tabwidth=4) +function unindent(str::AbstractString, indent::Int; tabwidth=8) indent == 0 && return str pos = start(str) endpos = endof(str) diff --git a/test/strings/io.jl b/test/strings/io.jl index 5fa0183e8c3ef..1677094d93f9e 100644 --- a/test/strings/io.jl +++ b/test/strings/io.jl @@ -237,28 +237,16 @@ print_joined(myio, "", "", 1) # 11659 # The indentation code was not correctly counting tab stops @test Base.indentation(" \t") == (8, true) -@test Base.indentation(" \tfoob") == (4, false) -@test Base.indentation(" \t \t") == (8, true) +@test Base.indentation(" \tfoob") == (8, false) +@test Base.indentation(" \t \t") == (16, true) @test Base.unindent("\tfoo",0) == "\tfoo" -@test Base.unindent("\tfoo",2) == " foo" -@test Base.unindent("\tfoo",4) == "foo" +@test Base.unindent("\tfoo",4) == " foo" @test Base.unindent(" \tfoo",4) == " foo" -@test Base.unindent("\t\n \tfoo",2) == " \n foo" -@test Base.unindent("\t\n \tfoo",4) == "\n foo" -@test Base.unindent("\t\n \tfoo",6) == "\n foo" -@test Base.unindent("\t\n \tfoo",8) == "\nfoo" -@test Base.unindent("\tfoo\tbar",2) == " foo bar" -@test Base.unindent("\tfoo\tbar",4) == "foo bar" -@test Base.unindent("\n\tfoo",2) == "\n foo" -@test Base.unindent("\n\tfoo",4) == "\nfoo" -@test Base.unindent("\n \tfoo",2) == "\n foo" +@test Base.unindent("\t\n \tfoo",4) == " \n foo" +@test Base.unindent("\tfoo\tbar",4) == " foo bar" +@test Base.unindent("\n\tfoo",4) == "\n foo" @test Base.unindent("\n \tfoo",4) == "\n foo" -@test Base.unindent("\n \tfoo",6) == "\n foo" -@test Base.unindent("\n \tfoo",8) == "\nfoo" -@test Base.unindent("\n\t\n \tfoo",2) == "\n \n foo" -@test Base.unindent("\n\t\n \tfoo",4) == "\n\n foo" -@test Base.unindent("\n\t\n \tfoo",6) == "\n\n foo" -@test Base.unindent("\n\t\n \tfoo",8) == "\n\nfoo" -@test Base.unindent("\n\tfoo\tbar",2) == "\n foo bar" -@test Base.unindent("\n\tfoo\tbar",4) == "\nfoo bar" +@test Base.unindent("\n\t\n \tfoo",4) == "\n \n foo" +@test Base.unindent("\n\tfoo\tbar",4) == "\n foo bar" +