Skip to content
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

Merge elpy snippets (again) #465

Merged
merged 35 commits into from Jan 5, 2024

Conversation

JulienPalard
Copy link
Contributor

A follow up of #278.

I tried to keep it simple, not much elisp, only simple additions.

I did not tested it yet, I'd like to test it a bit before merging.

It's my very first contribution to this repo so beware :D

jorgenschaefer and others added 30 commits June 16, 2013 11:32
Elpy now ships with a few YASnippet snippets for Python.

Fixes AndreaCrotti#43.
The enter and exit snippets now conform to the yasnippet-snippets
repository (mostly), while super now makes use of the .yas-setup.el
mechanism and is seriously improved. There's a new snippet for
__init__ methods, too, which automatically assigns arguments to
instance variables.
Previously when using the yasnippet "super", it will always return
"(class, arg).method" which was the Py2 way of doing it. In Py3, you
could simply do "().method" and Python will understand.
Thanks to galaunay for the idea to use this to "avoid unnecessary
keyspace pollution."
Please note that python-interpreter must be set to "python3" for this
to function correctly.

As a side-effect it also allows the use of Python 2 on systems that
install version 3 to /usr/bin/python and version 2 to
/usr/bin/python2.
Thanks to Andrea Crotti for the review and suggestion.
yas-snips-snippet-init-assignments should use values provided by
yas--apply-transform instead of grabbing them itself.

Thanks to npostavs for finding this issue.  See review discussion at
PR AndreaCrotti#278 for more info (search for "yas--apply-transform").
@JulienPalard
Copy link
Contributor Author

JulienPalard commented Mar 24, 2023

OK this looks almost OK to me.

Few things are not OK though:

The try / tryelse don't expand correctly, they "indent", is it due to my setup?

The files contains:

# -*- mode: snippet -*-
# name: try
# key: try
# --
try:
    $0
except ${1:Exception}:
    $2

and

# -*- mode: snippet -*-
# name: tryelse
# key: tryelse
# --
try:
    $0
except $1:
    $2
else:
    $3

It gives:

try:
    
    except Exception:

and:

try:
    
    except :
        
        else:
            

also for the "newlines at end of file" is that common to add them or not add them? I spotted that when there's a newline at end of file it also get inputed in the file, so the behavior is different, I hope there's an existing concensus on this?

@JulienPalard
Copy link
Contributor Author

@AndreaCrotti gentle ping

@JulienPalard
Copy link
Contributor Author

Oh my indentation issue has to do with the last lines of .yas-setup.yml:

(add-hook 'python-mode-hook #'yasnippet-snippets--fixed-indent)

and the way I test my snippets. I was testing them by just symlinking ~/.emacs.d/snippets/ to my clone, haha.

What is the proper way to run yasnippet-snippets from my clone instead of elpa?

@JulienPalard
Copy link
Contributor Author

I was able to test it properly using:

(use-package yasnippet-snippets
  :load-path "~/clones/yasnippet-snippets"
)

I checked ans yes, yasnippet-snippets--fixed-indent do runs. but in my Python buffer the yas-indent-line is still auto.

@JulienPalard
Copy link
Contributor Author

Using # expand-env: ((yas-indent-line 'fixed)) in the individual snippet that need it works though.

@JulienPalard
Copy link
Contributor Author

OK for me everything now works as expected.

@JulienPalard
Copy link
Contributor Author

Is there something I can do here?

@AndreaCrotti AndreaCrotti merged commit 9f67370 into AndreaCrotti:master Jan 5, 2024
1 check passed
@JulienPalard JulienPalard deleted the merge-elpy-snippets branch January 5, 2024 12:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants