{"action":"created","comment":{"url":"https://api.github.com/repos/google/yapf/pulls/comments/60892037","id":60892037,"diff_hunk":"@@ -116,9 +121,21 @@ def FormatCode(unformatted_source,\n     desired formatting style. changed is True if the source changed.\n   \"\"\"\n   _CheckPythonVersion()\n-  style.SetGlobalStyle(style.CreateStyleFromConfig(style_config))\n   if not unformatted_source.endswith('\\n'):\n     unformatted_source += '\\n'\n+\n+  fst_newline = unformatted_source.find('\\n')\n+\n+  indent_match = re.match('^(\\s+)', unformatted_source[:fst_newline])\n+  st = style.CreateStyleFromConfig(style_config)\n+  if indent_match:\n+    unformatted_source = dedent(unformatted_source)\n+    original_indent = indent_match.group(0)\n+    original_len = len(original_indent)\n+    offset = original_len - original_len % 4","path":"yapf/yapflib/yapf_api.py","position":28,"original_position":28,"commit_id":"61ca3564199e5bc4846ea472c8b1203db91bb7cc","original_commit_id":"61ca3564199e5bc4846ea472c8b1203db91bb7cc","user":{"login":"gwelymernans","id":5993918,"avatar_url":"https://avatars.githubusercontent.com/u/5993918?v=3","gravatar_id":"","url":"https://api.github.com/users/gwelymernans","html_url":"https://github.com/gwelymernans","followers_url":"https://api.github.com/users/gwelymernans/followers","following_url":"https://api.github.com/users/gwelymernans/following{/other_user}","gists_url":"https://api.github.com/users/gwelymernans/gists{/gist_id}","starred_url":"https://api.github.com/users/gwelymernans/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gwelymernans/subscriptions","organizations_url":"https://api.github.com/users/gwelymernans/orgs","repos_url":"https://api.github.com/users/gwelymernans/repos","events_url":"https://api.github.com/users/gwelymernans/events{/privacy}","received_events_url":"https://api.github.com/users/gwelymernans/received_events","type":"User","site_admin":false},"body":"The number of spaces is adjustable. See the `INDENT_WIDTH` in `style.py`.","created_at":"2016-04-25T10:24:25Z","updated_at":"2016-04-25T10:24:25Z","html_url":"https://github.com/google/yapf/pull/243#discussion_r60892037","pull_request_url":"https://api.github.com/repos/google/yapf/pulls/243","_links":{"self":{"href":"https://api.github.com/repos/google/yapf/pulls/comments/60892037"},"html":{"href":"https://github.com/google/yapf/pull/243#discussion_r60892037"},"pull_request":{"href":"https://api.github.com/repos/google/yapf/pulls/243"}}},"pull_request":{"url":"https://api.github.com/repos/google/yapf/pulls/243","id":67568438,"html_url":"https://github.com/google/yapf/pull/243","diff_url":"https://github.com/google/yapf/pull/243.diff","patch_url":"https://github.com/google/yapf/pull/243.patch","issue_url":"https://api.github.com/repos/google/yapf/issues/243","number":243,"state":"open","locked":false,"title":"Support for formatting partial blocks of codes.","user":{"login":"purpleP","id":6205841,"avatar_url":"https://avatars.githubusercontent.com/u/6205841?v=3","gravatar_id":"","url":"https://api.github.com/users/purpleP","html_url":"https://github.com/purpleP","followers_url":"https://api.github.com/users/purpleP/followers","following_url":"https://api.github.com/users/purpleP/following{/other_user}","gists_url":"https://api.github.com/users/purpleP/gists{/gist_id}","starred_url":"https://api.github.com/users/purpleP/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/purpleP/subscriptions","organizations_url":"https://api.github.com/users/purpleP/orgs","repos_url":"https://api.github.com/users/purpleP/repos","events_url":"https://api.github.com/users/purpleP/events{/privacy}","received_events_url":"https://api.github.com/users/purpleP/received_events","type":"User","site_admin":false},"body":"This as far as I've tested closes [https://github.com/google/yapf/issues/224](#224)\r\nI've ran your tests (changing two of them which were checking formatting of bad input) they all green.\r\nAlso I've tested if manually on some inputs and it works fine.\r\nOne thing though. If the indentation was incorrect (not a multiple of four etc) yapf wouldn't fix it for partial inputs. Which is actually easy to fix. But me or someone else could add this later.","created_at":"2016-04-22T20:29:26Z","updated_at":"2016-04-25T10:24:25Z","closed_at":null,"merged_at":null,"merge_commit_sha":"727a24fcfe46919e2a8e533cc4401c0592b195c4","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/google/yapf/pulls/243/commits","review_comments_url":"https://api.github.com/repos/google/yapf/pulls/243/comments","review_comment_url":"https://api.github.com/repos/google/yapf/pulls/comments{/number}","comments_url":"https://api.github.com/repos/google/yapf/issues/243/comments","statuses_url":"https://api.github.com/repos/google/yapf/statuses/61ca3564199e5bc4846ea472c8b1203db91bb7cc","head":{"label":"purpleP:master","ref":"master","sha":"61ca3564199e5bc4846ea472c8b1203db91bb7cc","user":{"login":"purpleP","id":6205841,"avatar_url":"https://avatars.githubusercontent.com/u/6205841?v=3","gravatar_id":"","url":"https://api.github.com/users/purpleP","html_url":"https://github.com/purpleP","followers_url":"https://api.github.com/users/purpleP/followers","following_url":"https://api.github.com/users/purpleP/following{/other_user}","gists_url":"https://api.github.com/users/purpleP/gists{/gist_id}","starred_url":"https://api.github.com/users/purpleP/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/purpleP/subscriptions","organizations_url":"https://api.github.com/users/purpleP/orgs","repos_url":"https://api.github.com/users/purpleP/repos","events_url":"https://api.github.com/users/purpleP/events{/privacy}","received_events_url":"https://api.github.com/users/purpleP/received_events","type":"User","site_admin":false},"repo":{"id":56880359,"name":"yapf","full_name":"purpleP/yapf","owner":{"login":"purpleP","id":6205841,"avatar_url":"https://avatars.githubusercontent.com/u/6205841?v=3","gravatar_id":"","url":"https://api.github.com/users/purpleP","html_url":"https://github.com/purpleP","followers_url":"https://api.github.com/users/purpleP/followers","following_url":"https://api.github.com/users/purpleP/following{/other_user}","gists_url":"https://api.github.com/users/purpleP/gists{/gist_id}","starred_url":"https://api.github.com/users/purpleP/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/purpleP/subscriptions","organizations_url":"https://api.github.com/users/purpleP/orgs","repos_url":"https://api.github.com/users/purpleP/repos","events_url":"https://api.github.com/users/purpleP/events{/privacy}","received_events_url":"https://api.github.com/users/purpleP/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/purpleP/yapf","description":"A formatter for Python files","fork":true,"url":"https://api.github.com/repos/purpleP/yapf","forks_url":"https://api.github.com/repos/purpleP/yapf/forks","keys_url":"https://api.github.com/repos/purpleP/yapf/keys{/key_id}","collaborators_url":"https://api.github.com/repos/purpleP/yapf/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/purpleP/yapf/teams","hooks_url":"https://api.github.com/repos/purpleP/yapf/hooks","issue_events_url":"https://api.github.com/repos/purpleP/yapf/issues/events{/number}","events_url":"https://api.github.com/repos/purpleP/yapf/events","assignees_url":"https://api.github.com/repos/purpleP/yapf/assignees{/user}","branches_url":"https://api.github.com/repos/purpleP/yapf/branches{/branch}","tags_url":"https://api.github.com/repos/purpleP/yapf/tags","blobs_url":"https://api.github.com/repos/purpleP/yapf/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/purpleP/yapf/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/purpleP/yapf/git/refs{/sha}","trees_url":"https://api.github.com/repos/purpleP/yapf/git/trees{/sha}","statuses_url":"https://api.github.com/repos/purpleP/yapf/statuses/{sha}","languages_url":"https://api.github.com/repos/purpleP/yapf/languages","stargazers_url":"https://api.github.com/repos/purpleP/yapf/stargazers","contributors_url":"https://api.github.com/repos/purpleP/yapf/contributors","subscribers_url":"https://api.github.com/repos/purpleP/yapf/subscribers","subscription_url":"https://api.github.com/repos/purpleP/yapf/subscription","commits_url":"https://api.github.com/repos/purpleP/yapf/commits{/sha}","git_commits_url":"https://api.github.com/repos/purpleP/yapf/git/commits{/sha}","comments_url":"https://api.github.com/repos/purpleP/yapf/comments{/number}","issue_comment_url":"https://api.github.com/repos/purpleP/yapf/issues/comments{/number}","contents_url":"https://api.github.com/repos/purpleP/yapf/contents/{+path}","compare_url":"https://api.github.com/repos/purpleP/yapf/compare/{base}...{head}","merges_url":"https://api.github.com/repos/purpleP/yapf/merges","archive_url":"https://api.github.com/repos/purpleP/yapf/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/purpleP/yapf/downloads","issues_url":"https://api.github.com/repos/purpleP/yapf/issues{/number}","pulls_url":"https://api.github.com/repos/purpleP/yapf/pulls{/number}","milestones_url":"https://api.github.com/repos/purpleP/yapf/milestones{/number}","notifications_url":"https://api.github.com/repos/purpleP/yapf/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/purpleP/yapf/labels{/name}","releases_url":"https://api.github.com/repos/purpleP/yapf/releases{/id}","deployments_url":"https://api.github.com/repos/purpleP/yapf/deployments","created_at":"2016-04-22T19:32:03Z","updated_at":"2016-04-22T19:32:04Z","pushed_at":"2016-04-23T08:57:26Z","git_url":"git://github.com/purpleP/yapf.git","ssh_url":"git@github.com:purpleP/yapf.git","clone_url":"https://github.com/purpleP/yapf.git","svn_url":"https://github.com/purpleP/yapf","homepage":"","size":722,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"google:master","ref":"master","sha":"f015a3c0c8b1bbabd2ddcab678182d4be9207513","user":{"login":"google","id":1342004,"avatar_url":"https://avatars.githubusercontent.com/u/1342004?v=3","gravatar_id":"","url":"https://api.github.com/users/google","html_url":"https://github.com/google","followers_url":"https://api.github.com/users/google/followers","following_url":"https://api.github.com/users/google/following{/other_user}","gists_url":"https://api.github.com/users/google/gists{/gist_id}","starred_url":"https://api.github.com/users/google/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/google/subscriptions","organizations_url":"https://api.github.com/users/google/orgs","repos_url":"https://api.github.com/users/google/repos","events_url":"https://api.github.com/users/google/events{/privacy}","received_events_url":"https://api.github.com/users/google/received_events","type":"Organization","site_admin":false},"repo":{"id":32476524,"name":"yapf","full_name":"google/yapf","owner":{"login":"google","id":1342004,"avatar_url":"https://avatars.githubusercontent.com/u/1342004?v=3","gravatar_id":"","url":"https://api.github.com/users/google","html_url":"https://github.com/google","followers_url":"https://api.github.com/users/google/followers","following_url":"https://api.github.com/users/google/following{/other_user}","gists_url":"https://api.github.com/users/google/gists{/gist_id}","starred_url":"https://api.github.com/users/google/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/google/subscriptions","organizations_url":"https://api.github.com/users/google/orgs","repos_url":"https://api.github.com/users/google/repos","events_url":"https://api.github.com/users/google/events{/privacy}","received_events_url":"https://api.github.com/users/google/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/google/yapf","description":"A formatter for Python files","fork":false,"url":"https://api.github.com/repos/google/yapf","forks_url":"https://api.github.com/repos/google/yapf/forks","keys_url":"https://api.github.com/repos/google/yapf/keys{/key_id}","collaborators_url":"https://api.github.com/repos/google/yapf/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/google/yapf/teams","hooks_url":"https://api.github.com/repos/google/yapf/hooks","issue_events_url":"https://api.github.com/repos/google/yapf/issues/events{/number}","events_url":"https://api.github.com/repos/google/yapf/events","assignees_url":"https://api.github.com/repos/google/yapf/assignees{/user}","branches_url":"https://api.github.com/repos/google/yapf/branches{/branch}","tags_url":"https://api.github.com/repos/google/yapf/tags","blobs_url":"https://api.github.com/repos/google/yapf/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/google/yapf/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/google/yapf/git/refs{/sha}","trees_url":"https://api.github.com/repos/google/yapf/git/trees{/sha}","statuses_url":"https://api.github.com/repos/google/yapf/statuses/{sha}","languages_url":"https://api.github.com/repos/google/yapf/languages","stargazers_url":"https://api.github.com/repos/google/yapf/stargazers","contributors_url":"https://api.github.com/repos/google/yapf/contributors","subscribers_url":"https://api.github.com/repos/google/yapf/subscribers","subscription_url":"https://api.github.com/repos/google/yapf/subscription","commits_url":"https://api.github.com/repos/google/yapf/commits{/sha}","git_commits_url":"https://api.github.com/repos/google/yapf/git/commits{/sha}","comments_url":"https://api.github.com/repos/google/yapf/comments{/number}","issue_comment_url":"https://api.github.com/repos/google/yapf/issues/comments{/number}","contents_url":"https://api.github.com/repos/google/yapf/contents/{+path}","compare_url":"https://api.github.com/repos/google/yapf/compare/{base}...{head}","merges_url":"https://api.github.com/repos/google/yapf/merges","archive_url":"https://api.github.com/repos/google/yapf/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/google/yapf/downloads","issues_url":"https://api.github.com/repos/google/yapf/issues{/number}","pulls_url":"https://api.github.com/repos/google/yapf/pulls{/number}","milestones_url":"https://api.github.com/repos/google/yapf/milestones{/number}","notifications_url":"https://api.github.com/repos/google/yapf/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/google/yapf/labels{/name}","releases_url":"https://api.github.com/repos/google/yapf/releases{/id}","deployments_url":"https://api.github.com/repos/google/yapf/deployments","created_at":"2015-03-18T18:22:31Z","updated_at":"2016-04-25T07:29:29Z","pushed_at":"2016-04-23T08:57:27Z","git_url":"git://github.com/google/yapf.git","ssh_url":"git@github.com:google/yapf.git","clone_url":"https://github.com/google/yapf.git","svn_url":"https://github.com/google/yapf","homepage":"","size":947,"stargazers_count":3338,"watchers_count":3338,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":216,"mirror_url":null,"open_issues_count":49,"forks":216,"open_issues":49,"watchers":3338,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/google/yapf/pulls/243"},"html":{"href":"https://github.com/google/yapf/pull/243"},"issue":{"href":"https://api.github.com/repos/google/yapf/issues/243"},"comments":{"href":"https://api.github.com/repos/google/yapf/issues/243/comments"},"review_comments":{"href":"https://api.github.com/repos/google/yapf/pulls/243/comments"},"review_comment":{"href":"https://api.github.com/repos/google/yapf/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/google/yapf/pulls/243/commits"},"statuses":{"href":"https://api.github.com/repos/google/yapf/statuses/61ca3564199e5bc4846ea472c8b1203db91bb7cc"}}}}