-
Notifications
You must be signed in to change notification settings - Fork 314
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Incorrect indentation after expanding python snippet #506
Comments
I just downloaded the latest Emacs for OSX which contains 24.3.1. Same problem. I am using the included python.el. |
You'll be wanting expand-env, don't forget to reload the snippet. Maybe we should have a warning about unrecognized headers. |
@npostavs, when and where would the warning be posted?
It could also be an error on snippet load... but that would probably do more harm than good |
By the way, this is related to #485. My conclusion there was that this is not an error, or at least it's Emacs behaviour by default. This is still arguable, but I'm not so sure right now. I did some tests after pasting the snippet's body in a
I don't remember my own rationale to have the autoindent behaviour in yasnippet not use |
I think Doing it on snippet expansion brings up the question of whether we want to warn every time the snippet is expanded or maybe just the first time. Plus, the snippet doesn't remember which file it's loaded from, right? Having a link to the line that causes the warning would be nice. And |
Thanks, yes Is there a way to enable this setting for all Python buffers? |
See #485 (comment) |
See my comment on #485. It looks like yasnippets combined with the new Python mode yields incorrect behavior for anything involving indentation choices. Even the simple try/except clause snippet is improperly indented. You might want to consider enabling this workaround whenever the new Python mode is detected. Or, at the very least making a prominent note in the documentation that Python users will want to add the hook documented in #485. |
If you can provide tests you would like me to run, I will gladly run them. I also dabble in Haskell and Idris which are also whitespace sensitive. I see similar misbehavior there if I do not apply the same expand-env trick. I have not had the chance to do an exhaustive emacs -Q test yet. More when I have. |
That seems sensible. It was discussed in AndreaCrotti/yasnippet-snippets#34, but things sort of died out there without anything concrete happening. |
@shaleh, the tests I'm asking for are simple. Everytime you discover yasnippet indenting behaviour that you find is surprising/irritanting/wrong, exit the snippet with some dummy values for the fields. Then, without ever re-entering yasnippet, call |
Thank you for the explanation @capitaomorte. I shall do so in the future. |
More testing. python-mode does not show the problem. This is a python.el bug for sure. I just started using python.el after updating my Emacs so I had not noticed the little differences yet. In a python-mode buffer:
The except lands back at the beginning of the line. No amount of pressing tab will cause it to move :-) In python.el:
Here you are not immediately indented out 4 spaces after pressing enter following the try. When you press tab after type 'except' the whole like is indented 4 spaces. Pressing tab again moves it back to column 0. You can repeat the indent cycle by repeatedly pressing tab. Sigh. This means debugging the python.el code and dealing with the GNU emacs maintainers to get it fixed in the long run. Short term I am switching back to python-mode which has always worked for me. I still need to look into the Haskell and Idris modes though. Based on what I have found so far it looks like setting certain modes to always be in 'fixed' mode is probably the right choice. Very few snippets will work correctly in python.el. |
Emacs version: "GNU Emacs 24.2.1 (x86_64-apple-darwin, NS apple-appkit-1038.36)
of 2012-08-27"
I have yasnippet-20140729.1240 installed using cask.
My snippet looks like this:
I added the yas-indent-line in expand-var to see if it helped. There is no difference with or without it.
When I expand the snippet this is what I get:
Notice that most of the code is now aligned under the first else. This occurs when I run via emacs -Q, run the following to setup yasnippets, and then attempt to expand "addlogging" in a Python buffer:
I cannot say if this is new behaviour or not because I just made the snippet. None of the other Python snippets I have contain multiple if/else blocks.
Let me know how I can help debug this.
Thanks.
The text was updated successfully, but these errors were encountered: