AndreaCrotti / yasnippet-snippets

a collection of yasnippet snippets for many languages
GNU General Public License v3.0
1.17k stars 465 forks source link

python-mode snippets are expanded with wrong indentation if there is more than one level of indentation possible in the snippet #34

Closed lgp171188 closed 10 years ago

lgp171188 commented 10 years ago

Please refer to https://github.com/capitaomorte/yasnippet/issues/485 for more background information and the discussion that happened there. The issue happens because of python snippets having more than 1 level of indentation not having # expand-env: ((yas-indent-line 'fixed)) as per the yasnippet maintainer. This causes the snippet to be expanded with wrong indentation and hence wrong code. He pointed me to this repository and told that the fix has to be made in this repository. I have tested the changes by manually editing the snippet to add the # expand-env: ((yas-indent-line 'fixed)) line and I can see that the expansion works fine after that.

This issue happens only with snippets with more than one possible level of indentation.

AndreaCrotti commented 10 years ago

Hi and thanks for the report.. I still would rather solve the problem more globally though so we avoid having to write it in every snippet.

Maybe adding it to .yas-setup.el or just use the hook as discussed in https://github.com/capitaomorte/yasnippet/issues/485 would be enough?

lgp171188 commented 10 years ago

Any solution that would make sure the indentation for the affected python snippets is correct out of the box is fine. While asking the user to add something here and there might still solve the problem, a lot of users expect things to work fine out of the box :)

AndreaCrotti commented 10 years ago

If it's done in .yas-setup.el the user won't have to do anything..

I would like to try that however I can't even reproduce the problem you reported. I remember some time ago I noticed this bad behaviour for example in the "dec" snippet, but now it works perfectly fine.

So I suspect my python-mode got updated or something else that fixed it as consequence. Can you maybe try on your machine to set it in yas-setup.el?

I mean otherwise the other solution is just to make sure that every snippet with multiple levels always the declare that env variable and we're also happy.

npostavs commented 10 years ago

I remember some time ago I noticed this bad behaviour for example in the "dec" snippet, but now it works perfectly fine.

Emacs-24.4's python.el unindents after a return, but 24.3 doesn't.

AndreaCrotti commented 10 years ago

Ok well I use 24.3 but I use python-mode not python.el..

AndreaCrotti commented 10 years ago

Anyway I think I'll just close it then, if all we need is to fix it per snippet we can open different issues in case there are broken snippets.

bronger commented 3 years ago

FIWI, I observe the wrong indentation with try/except, using current Git Emacs (and thus, Python mode). Haven’t tried older Emacsen, though. My snippets directory is called elpa/yasnippet-snippets-20210408.1234/snippets/python-mode. My .emacs does not contain yasnippet-related thing, apart from those inserted by the package manager.

bronger commented 3 years ago

If I insert # expand-env: ((yas-indent-line 'fixed)) in the file try, it works fine.