1

I recently switched to Atom text editor for programming from Geany text editor. I have lots of python snippets in geany. In geany writing snippets is super easy.

For example:

# for geany text editor (snippets.conf file)  
h=# Author : Bhishan Poudel\n# Date   : {date}\n  

If I type h and then hit enter, i will get the above snippet with current time.

How can we do so in ATOM?

My attempt so far is this:
I edited the snippets.cson file like this:

'.source.python':
  'example1':
    'prefix': 'h'
    'body': '
      #!/usr/bin/env python\n
      # -*- coding: utf-8\n
      #\nDate: {date}\n
      #Imports\n
      import numpy as np
      '

But, this did not work well.

Related links are:
Atom editor: snippet for inserting a timestamp
http://flight-manual.atom.io/using-atom/sections/snippets/
Atom Editor: multiple snippets

2 Answers 2

3

I have a solution for the multiline part of your question and a suggestion for the naming. What i did was this:

'.source.python':
  'header and imports for python':
    'prefix': 'pyhead'
    'body':"""
  #!/usr/bin/env python
  # -*- coding: utf-8
  #Date: $1
  #Imports
  import numpy as np
  $2
  """

the $1 indicates, that you jump to this is after the snipped is inserted. So that way you could file in the date yourself (not optimal I know). The $2 will be the place for the next TAB key. The other part is, that you use a prefix which is easy to identify. The multiline part is done with the """ at the beginning and end of the body so everything should be inserted smoothly

Sign up to request clarification or add additional context in comments.

Comments

0

You can easily solve multiline problem with using """ in body explanation of your snippet.

For instance:

'.source.python':
  'DATA SCIENCE':
    'prefix':'data_import'
    'body':"""import numpy as np
    import pandas as pd
    import seaborn as sns"""

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.