Skip to main content

Build code snippets for vscode

Project description

Sniptly

A Python command line tool for managing user defined code snippets in code for vscode.

Sniptly makes it possible to mantain code snippets in code and build the json representation vscode uses for code snippets when needed. Maintaining snippets in code is more convenient and allows one to benefit from code formatters or, for larger code snippet libraries, to have unit tests for the snippets.

Sniptly is at experimental stage for now. It is tested to some extent with Python. In principle, it should work with other languages as well.

Installation

To install the latest release on PYPI run

pip install sniptly

Usage

  • Create configuration file by running snitply create-config
  • Edit the newly created sniptly.toml configuration file by adding the languages you wish to create code snippets for. By default the configuration specifies to look for python and javascript files.
  • NOTE: Sniptly tries to figure out the folder where vscode keeps user snippets. Verify that the vscode_snippets_dir configuration has the correct value.
  • Optional steps with first time usage
    • Run sniptly create-sample to create a sample file named python_sniptly_snippets.py with sniptly comments. See the file contents to understand how comments are used to turn code fragments to user defined code snippets in vscode.
    • Run sniptly build --source python_sniptly_snippets.py to build the code snippet and to add the snippet to your existing vscode snippets.
    • Add sniptly code snippet template by running sniptly add-snippet-template --lang [language, for example: python]. Code from which to generate code snippets is commented with special comments. By adding the template as a code snippet it's easy to turn existing code fragments to vscode snippets.
  • Start adding sniptly comments for the code fragments you want to turn into vscode snippets
  • Run sniptly build --source [file or folder] to build code snippets from the specified file or folder for the languages you have enabled in sniptly.toml

Syntax for marking code fragments for snippet creation

The start sequence will specify where the snippet starts. The following lines specify name, prefix and description that will be used in the vscode's json representation for user defined code snippets. The end sequence ends the snippet.

Syntax can be modified via sniptly.toml. The {} in start_sequence and stop_sequence will be replaced by the value set in comment_character.

See the sample file contents below to see how code fragments can be marked for snippet creation.

Example of Python code fragment marked for snippet creation

# -->
# name: [my awesome snippet]
# prefix: [prefix for my awesome snippet]
# description: [snippet description]
import json
data = {"foo": "bar"}
data_as_json = json.dumps(data, indent=2)
with open("file.json", "w") as f:
    f.write(data_as_json)
# <--

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sniptly-0.1.25.tar.gz (12.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sniptly-0.1.25-py3-none-any.whl (14.3 kB view details)

Uploaded Python 3

File details

Details for the file sniptly-0.1.25.tar.gz.

File metadata

  • Download URL: sniptly-0.1.25.tar.gz
  • Upload date:
  • Size: 12.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.4 CPython/3.8.6 Darwin/19.6.0

File hashes

Hashes for sniptly-0.1.25.tar.gz
Algorithm Hash digest
SHA256 660af211ea9fbc7da1cda835d64d83ef1b8dc66c00cb17ab7a4b64e0331ef8b1
MD5 12340733b0db1c420c61b614a255fa92
BLAKE2b-256 2636f1210ea1c19a7baaa1adddeda72cd40f173f0167762fb8134a79afc81864

See more details on using hashes here.

File details

Details for the file sniptly-0.1.25-py3-none-any.whl.

File metadata

  • Download URL: sniptly-0.1.25-py3-none-any.whl
  • Upload date:
  • Size: 14.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.4 CPython/3.8.6 Darwin/19.6.0

File hashes

Hashes for sniptly-0.1.25-py3-none-any.whl
Algorithm Hash digest
SHA256 949276600a45d9231856bdbae58ba361fd2b21b0545a4bce6c9070f754c26771
MD5 c552ae0b6d27d28522aa973ea9756266
BLAKE2b-256 9b6b21d9122edf6fdf4af08df8db786e75762cf06551be183e306d42acc9dd9d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page