-
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
python-mode snippets are expanded with wrong indentation if there is more than one level of indentation in the snippet #485
Comments
At first sight this appears to be an emacs bug. If you cycle through the lines and type |
Yes, running For example, just have a look at this source code that has to be indented.
It can be indented as either
or
The correct one has to be chosen by the developer who writes the code and Emacs doesn't have a clue on what is correct. It will just pick one of the indentation levels to start the cycling of tabs on pressing tab key each time. Similarly for functions, which is the case here,
can be indented either as
where these are 2 different functions or as
which means fun2() is a function nested inside fun1() and is valid in Python. It looks like for such cases, Emacs picks the 1-level of forward indentation as the first in the cycle of possible indents which can be changed by tab key. What is correct cannot be picked by Emacs or by yasnippet code, it has to be specified by the snippet file in case of yasnippet and in other cases by the developer. Sorry for the long comment explaining what is in my mind. Hope it is relevant to solving this issue. |
This could be an issue with all the snippets with more than one level of indentation. |
@lgp171188, |
@capitaomorte Yes, |
I don't think the behaviour of
I think |
@npostavs perhaps you're right, and maybe just (add-hook 'python-mode-hook
'(lambda () (set (make-local-variable 'yas-indent-line) 'fixed))) is sufficient. @lgp171188 can you try this? But I still think there is a difference between Admittedly I haven't written any python in some years, or followed python-mode :-) , but I find it suspicious that this problem arises only now, when python snippets have been a part of yasnippet since almost its beginning in 2008. |
I'm finding the same behaviour in 23.4.2 (which is the oldest emacs I have handy). |
@lgp171188, I'm well aware of python indentation semantics. But it's the heuristic that emacs uses that is bringing trouble in this snippet, i.e. it always assume you want to continue statements in the deepest possible indent level. So it's actually the missing So, I'm not sure I agree with you @npostavs that yasnippet should force or recommend I do realise that omitting @lgp171188 perhaps you can test this change and then tell the maintainer of these snippets, which live at https://github.com/AndreaCrotti/yasnippet-snippets, to add it to his repo. |
Note: it's only in 24.4 that Emacs became smart enough to look for a |
@capitaomorte Thanks for suggesting a solution. I added the |
@capitaomorte, as I demonstrated in my ticket #506 the I also have this snippet:
The |
Shall do. |
I have installed yasnippet-20140514.1649 from melpa on Emacs 24.3.1 (packaged in Debian unstable). In python-mode, when I try expanding snippets like prop, props, propsg, the indentation is wrong. I checked the snippet file and the indentation is correct there, but the expansion has the wrong indentation like listed below
instead of
which is the correct indentation. This issue reproducible on all the listed commands even when running emacs with -Q option and manually loading just the yasnippet package. Since I am a developer writing code mostly in python, this makes yasnippet totally unusable for me. So would love to see this issue fixed.
The text was updated successfully, but these errors were encountered: