-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Stop marching indentation for try-catch blocks
This patch not only fixes the issue but also includes a test case which has a lot of commentary explaining how CC Mode tries to indent try-case blocks and the potential problems therein. Our specific fix in this patch is to add the keyword `catch' to the constant list `php-block-stmt-2-kwds'. The result is that it adds the keyword to the CC Mode list `c-block-stmt-2-key' and that automatically takes care of indenting try-catch blocks in situations where we put the keywords and braces on the same lines together. GitHub-Issue: 68
- Loading branch information
Eric James Michael Ritz
committed
Aug 26, 2013
1 parent
babd790
commit 6db85bd
Showing
2 changed files
with
59 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
|
||
/** | ||
* GitHub Issue: https://github.com/ejmr/php-mode/issues/68 | ||
* | ||
* The 'catch' keywords should align with 'try' and not march | ||
* off to the right side of the screen like they do in the bug | ||
* report at the URL above. | ||
* | ||
*/ | ||
|
||
/* CC Mode uses the indentation for 'block-close' for these 'catch' | ||
* statements. However, that is assuming that the closing braces for | ||
* 'try' and each 'catch' align with the keywords themselves. If they | ||
* do not then CC Mode gets confused and starts trying to indent | ||
* 'catch' blocks as if they were function definitions and other | ||
* strange things. | ||
* | ||
* The easiest way to deal with this is to make sure that the | ||
* `c-block-stmt-2-key' list contains the string "catch", which we | ||
* take care of in the definition of `php-block-stmt-2-key'. | ||
*/ | ||
|
||
try { | ||
$mongo = new \Mongo($dsn, array("replicaSet" => 'mat_replica')); | ||
} catch (\MongoConnectionException $e) { | ||
throw $e; | ||
} catch (\Exception $e) { | ||
throw $e; | ||
} | ||
|
||
/* CC Mode uses the indentation syntax for 'topmost-intro' for the | ||
* 'catch' keywords in the remaining tests. | ||
*/ | ||
|
||
try { | ||
$mongo = new \Mongo($dsn, array("replicaSet" => 'mat_replica')); | ||
} | ||
catch (\MongoConnectionException $e) { | ||
throw $e; | ||
} | ||
catch (\Exception $e) { | ||
throw $e; | ||
} | ||
|
||
try | ||
{ | ||
$mongo = new \Mongo($dsn, array("replicaSet" => 'mat_replica')); | ||
} | ||
catch (\MongoConnectionException $e) | ||
{ | ||
throw $e; | ||
} | ||
catch (\Exception $e) | ||
{ | ||
throw $e; | ||
} |