First time here? Check out the FAQ!
1

Do not understand how to create snippets with variables

I do not understand how to enter code for snippets with variable names. I create a new snippet and I get aan empty window in the editor. From there I would like to enter the code for a new test: def test_file_variable(self): string =

res = dstring_parse(string)
display_PathPoints(res, variable)

shouldbe = [

]
self.assertEqual(res, shouldbe)

I need a variable name instead of variable How can I do this?

piscvau's avatar
486
piscvau
asked 2020-08-25 04:35:43 -0500
Wingware Support's avatar
4k
Wingware Support
updated 2020-08-25 08:32:44 -0500
edit flag offensive 0 remove flag close merge delete

Comments

add a comment see more comments

1 Answer

0

The syntax is %(name|type|default)s and the type and default are optional. Examples:

  %(name)s
  %(created|datetime)s
  %(email||nobody@nowhere.com)s

You can also use environment variable references for the defaults:

  %(user||${USER})s

The documentation for this is at https://wingware.com/doc/edit/snippets and there are examples in the default set of snippets in the Snippets tool.

Wingware Support's avatar
4k
Wingware Support
answered 2020-08-25 08:35:08 -0500, updated 2020-08-25 08:35:28 -0500
edit flag offensive 0 remove flag delete link

Comments

Hello Please excuse me but I still do not understand and I am afraid I need more details. I did look into the documentation and the examples but it did not help. For example if I look at the 'from' snippet I see: |m|from %(module)s import |!| I see there a variable named module but I have not idea about what |m| and |!| is about. Coming back to my need for a snippet about a test, is I put %(name)s in the name of the function after def, I get a syntax error

piscvau's avatar piscvau (2020-08-26 04:36:16 -0500) edit

|m| tells Wing to match the indent of the context when placing the snippet and |!| is the final resting place of the caret after data entry for the snippet is complete. These and the other syntax options are described in the documentation at https://wingware.com/doc/edit/snippet...

Wingware Support's avatar Wingware Support (2020-08-26 08:24:36 -0500) edit
add a comment see more comments

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss.

Add Answer