yasnippet-snippets icon indicating copy to clipboard operation
yasnippet-snippets copied to clipboard

Working with electric-pair-mode

Open Hamzehn opened this issue 4 years ago • 0 comments
trafficstars

I have electric-pair-mode turned on by default, and I noticed that when I'm using the python function docstring snippets, every time I define a default string value for a parameter the snippet expansion duplicates the entire argument list.

For example:

def foo(param1, param2=None, param3="bar"):

Produces the following output:

def foo(param1, param2=None, param3="bar"):
 """
 Keyword Arguments:
 param1 -- 
 param2 -- (default None)
 param3 -- (default "bar")Keyword Arguments:
 param1 -- 
 param2 -- (default None)
 param3 -- (default ")
 """

Notice how the extra text ends at the double quote.

The extra text gets inserted the moment I type the opening double quote and electric pair mode automatically adds the closing one. The cursor at the time will be on the opening quote. If I copy/paste a double quote pair in one shot, this doesn't happen.

This behavior continues by adding extra text above the old extra one if I continue adding parameters that have electric pairs like that. For example if I add a 4th parameter:

def foo(param1, param2=None, param3="bar", param4="baz"):
 """
 Keyword Arguments:
 param1 -- 
 param2 -- (default None)
 param3 -- (default "bar")
 param4 -- (default "baz")Keyword Arguments:
 param1 -- 
 param2 -- (default None)
 param3 -- (default "bar")
 param4 -- (default ")Keyword Arguments:
 param1 -- 
 param2 -- (default None)
 param3 -- (default ")
 """

Notice how it updates the arguments list correctly at the top, but it keeps adding extra text below while not removing the old one.

The same thing happens if I enter any of the other pair symbols (like '(', '[', '{' etc.). For example, if I add a 5th parameter that has a default list value (I know, not best practice in Python but just for illustration purposes):

def foo(param1, param2=None, param3="bar", param4="baz", param5=[1, 2]):
 """
 Keyword Arguments:
 param1 -- 
 param2 -- (default None)
 param3 -- (default "bar")
 param4 -- (default "baz")
 param5 -- (default [1)
 2]     -- Keyword Arguments:
 param1 -- 
 param2 -- (default None)
 param3 -- (default "bar")
 param4 -- (default "baz")
 param5 -- (default [)Keyword Arguments:
 param1 -- 
 param2 -- (default None)
 param3 -- (default "bar")
 param4 -- (default ")Keyword Arguments:
 param1 -- 
 param2 -- (default None)
 param3 -- (default ")
 """

Any idea how I can resolve this?

Hamzehn avatar Nov 06 '21 16:11 Hamzehn