-
Notifications
You must be signed in to change notification settings - Fork 46
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Indentation issue using #else block. #148
Comments
Quick summary/test-case: // working
#if DEBUG
Console.WriteLine("Yay!");
#else
Debug.WriteLine("Nay!");
#endif
// not working
#if DEBUG
if (!success || this.debugMode)
#else
if (!success) // <-- incorrectly indented
#endif |
@josteink @jcs090218 #if DEBUG
Console.WriteLine("Yay!");
#else
Debug.WriteLine("Nay!");
#endif
#if DEBUG
if (!success || this.debugMode)
Console.WriteLine("Yay!");
#else
if (!success)
Debug.WriteLine("Nay!");
#endif |
It's a pseudo "not" operator for preprocessor directives. #if ! THING
// only when not thing
#endif I'm not sure if that's allowed, but surely #if #else is. #if THING
#else
// only when not thing
#endif |
Thanks. #if THING
#else
if (!success)
// Nothing needed here?
#endif Just haven't seen that before, is all |
Oh reading the full thing, I think a wider context might be needed, and I've probably misrepresented it as well 😨 Consider the following C#, which is perfectly valid: #if DEBUG
if (true) // always run this branch in debug-builds!
#else
if (!success)
#endif
{
// do some logging, or whatever
} In previous csharp-mode implementation this would result in indentation like this: #if DEBUG
if (true) // always run this branch in debug-builds!
#else
if (!success) // <-- incorrectly indented as a substatement of the one above if-statement
#endif
{
// do some logging, or whatever
} This is really hard to get right, I think, and if I were you, I wouldn't really lose my mind over it. If this doesn't work properly, it's fair to consider this an edge-case as far as common C#-usage is concerned. |
Btw, is this valid in C or C++? I noticed CC Mode does not support this edge case there. |
@theothornhill Is valid C and C++.
They don't?.... I am surprised. |
Yeah... So this is definitively not a bug in |
On namespace F
{
public class Bar
{
#if DEBUG
Console.WriteLine("Yay!");
#else
Debug.WriteLine("Nay!");
#endif
#if DEBUG
if (!success || this.debugMode)
#else
if (!success)
#endif
{
}
}
}``` |
Wow!!!! This is awesome! Does this bug appears in the upstream? Maybe we should apply to Emacs itself? Just wondering! But this is definitely awesome! 👍 |
In due time it will, I’m sure. The indent part is not in Melpa yet, so I’m keeping it for the time being here. As for adding it to emacs, the blocker for that is tree-sitter itself. @jcs090218 could you try to use the tree sitter branch for a while? I’d like some more input on how it works :) |
Yeah, sure. I will report issue if I have encountered one! Thanks for your hard work! 😄 This is definitely big step to Emacs itself. |
csharp-mode is now developed as part of core emacs. If you still have any issues, file a bug-report with the GNU Emacs bug-tracker :) |
As mentioned in #147 conversation. You would get the error when trying to indent on line with
#else
withif (true)
statement the before due tocsharp-mode
's indentation engine and this might requires a complete rewrite for this package.The text was updated successfully, but these errors were encountered: