Skip to content

Commit

Permalink
Fix Python's IndentationError issue in most cases
Browse files Browse the repository at this point in the history
Insert a `#` character at the beginning of blank lines above indention
line, to meet the REPL’s limitation.

Now the below Python code will work in Codi:

```
class Test(object):

  def __init__(self):
    pass

  def an_empty_line_above_this(self):

    return ‘No worry about the blank lines’

if __name__ == ‘__main__’:

  print(‘blank lines are cool, now PEP8 lint stop warning about it\’s
absence.’)
```
  • Loading branch information
heshiyou authored and metakirby5 committed Feb 13, 2017
1 parent 140b5aa commit e2aa007
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 13 deletions.
4 changes: 2 additions & 2 deletions autoload/codi/load.vim
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ endfunction
" Python rephrasers
function! s:rp_py(buf)
let b = a:buf
" Insert # in the blank lines above Python's class methods definition to avoid
" Insert # in the blank lines above Python's indention line to avoid
" `IndentationError`.
let b = substitute(b, '\(\s*\n\)\+\(\n\s\+def\)\@=', '\=substitute(submatch(0), "\s*\n", "\r#", "g")', 'g')
let b = substitute(b, '\(\s*\n\)\+\(\n\s\+\w\+\)\@=', '\=substitute(submatch(0), "\s*\n", "\r#", "g")', 'g')
return b
endfunction

Expand Down
12 changes: 1 addition & 11 deletions doc/codi.txt
Original file line number Diff line number Diff line change
Expand Up @@ -394,8 +394,6 @@ notes:
python~
bin: python
maintainer: @metakirby5
notes:
- Cannot leave empty lines in defs

ruby~
maintainer: @metakirby5
Expand All @@ -406,15 +404,7 @@ program; it supports nothing more than what the underlying bin supports.
This is why Haskell language pragmas don't work, PureScript only works
inside a project folder, and OCaml statements must end with ;;. Also, in
most whitespace-sensitive languages, an empty line represents the end of a
definition, so the below Python class will not work in Codi:
>
class Test(object):
def __init__(self):
pass
def oops_theres_an_empty_line_above_this(self):
return 1
<
definition.

OUTPUT SPECIFICATION *codi-interpreters-output-spec*

Expand Down

0 comments on commit e2aa007

Please sign in to comment.