Skip to content

Commit

Permalink
Revert "indent, unindent: default tab width = 4."
Browse files Browse the repository at this point in the history
This reverts commit 6c71b13.
  • Loading branch information
JeffBezanson committed Jul 30, 2015
1 parent ced7165 commit 85bbc1f
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 32 deletions.
4 changes: 2 additions & 2 deletions base/LineEdit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions base/REPL.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 5 additions & 7 deletions base/strings/io.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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 == ' '
Expand All @@ -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)
Expand Down
30 changes: 9 additions & 21 deletions test/strings/io.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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"

0 comments on commit 85bbc1f

Please sign in to comment.