Skip to main content

A tool for converting code snippets from Ultisnips to YASnippet format

Project description

Ultyas - UltiSnips to YASnippet Conversion Tool

License

Ultyas is a command-line tool that simplifies the process of converting code snippets from UltiSnips (Vim/Neovim) to YASnippet format (Emacs).

Transitioning from Vim/Neovim to Emacs can be difficult. Ultyas addresses this issue by offering a straightforward solution for converting your existing UltiSnips snippets into the YASnippet format.

Ultyas can be used for the following purposes:

  • Migrating your snippets from UltiSnips to YASnippet format.
  • Maintaining consistent snippets across both Vim/Neovim and Emacs. (For instance, the author of Ultyas effortlessly switches between Vim and Emacs depending on the machine and environment, ensuring that the same snippets are accessible in both editors.)

NOTE: Emacs users are recommended to install the ultisnips-mode package, which provides a major mode for editing Ultisnips snippet files (*.snippets). This mode includes syntax highlighting to simplify and improve the editing of Ultisnips snippets.

Installation

Here is how to install Ultyas locally to ~/.local/bin/ultyas using pip:

pip install --user ultyas

The command above will install Ultyas in the local directory: ~/.local/bin/ultyas.

Command usage example

To use Ultyas, simply run the command with the appropriate input and output files. Here is a basic example:

~/.local/bin/ultyas ~/.vim/UltiSnips/python.snippets -o ~/.emacs.d/snippets/python-mode/

This command takes an UltiSnips file python.snippets and converts it to a directory that contains YASnippet snippets at ~/.emacs.d/snippets/python-mode/.

Options and flags

usage: ultyas <file.snippets> -o <yasnippet-major-mode-dir>

A command-line tool for converting code snippets from UltiSnips to YASnippet format.

positional arguments:
  ultisnips_file        The UltiSnips .snippets file
                        (e.g. '~/.vim/UltiSnips/python.snippets')

options:
  -h, --help            show this help message and exit
  -o YASNIPPET_DIR, --yasnippet-dir YASNIPPET_DIR
                        The YASnippet snippets major mode directory
                        (e.g. '~/.emacs.d/snippets/python-mode/')
  -i {auto,fixed,nothing}, --yas-indent-line {auto,fixed,nothing}
                        Add one of the following comments to the YASnippet
                        snippets that will be generated:
                        "# expand-env: ((yas-indent-line 'fixed))" or
                        "# expand-env: ((yas-indent-line 'auto))".
  -t CONVERT_TABS_TO, --convert-tabs-to CONVERT_TABS_TO
                        Convert the tabs that are in the generated
                        snippets to the string passed to this
                        option (Default: The indentation marker '$>')
  -v, --verbose         Verbose mode
  -q, --quiet           Quiet mode

Example of an UltiSnips snippet that could be converted to Yasnippet

Here is an example of an UltiSnips snippet that can be converted by Ultyas from the UltiSnips format to the Yasnippet format:

priority 50

snippet if
if ${1:True}:
  ${2:pass}
endsnippet

snippet for
for ${1:_} in ${2:[]}:
  ${3:pass}
endsnippet

snippet while
while ${1:True}:
  ${2:pass}
endsnippet

Frequently Asked Questions

How does the author use Ultyas?

The author maintains all snippets in their original UltiSnips format for Vim and developed a shell script that automatically scans the UltiSnips directory, generating the corresponding Yasnippet files using Ultyas.

He uses the ultisnips-mode Emacs package to edit snippets, which provides syntax highlighting and code folding via hs-minor-mode.

This workflow allows editing and storing a single set of snippets while making them available in Vim and Emacs.

License

The ultyas Emacs package has been written by James Cherti and is distributed under terms of the GNU General Public License version 3, or, at your choice, any later version.

Copyright (C) 2023-2026 James Cherti

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program.

Links

Other Emacs packages by the same author:

  • minimal-emacs.d: This repository hosts a minimal Emacs configuration designed to serve as a foundation for your vanilla Emacs setup and provide a solid base for an enhanced Emacs experience.
  • compile-angel.el: Speed up Emacs! This package guarantees that all .el files are both byte-compiled and native-compiled, which significantly speeds up Emacs.
  • outline-indent.el: An Emacs package that provides a minor mode that enables code folding and outlining based on indentation levels for various indentation-based text files, such as YAML, Python, and other indented text files.
  • easysession.el: Easysession is lightweight Emacs session manager that can persist and restore file editing buffers, indirect buffers/clones, Dired buffers, the tab-bar, and the Emacs frames (with or without the Emacs frames size, width, and height).
  • vim-tab-bar.el: Make the Emacs tab-bar Look Like Vim’s Tab Bar.
  • elispcomp: A command line tool that allows compiling Elisp code directly from the terminal or from a shell script. It facilitates the generation of optimized .elc (byte-compiled) and .eln (native-compiled) files.
  • tomorrow-night-deepblue-theme.el: The Tomorrow Night Deepblue Emacs theme is a beautiful deep blue variant of the Tomorrow Night theme, which is renowned for its elegant color palette that is pleasing to the eyes. It features a deep blue background color that creates a calming atmosphere. The theme is also a great choice for those who miss the blue themes that were trendy a few years ago.
  • dir-config.el: Automatically find and evaluate .dir-config.el Elisp files to configure directory-specific settings.
  • flymake-bashate.el: A package that provides a Flymake backend for the bashate Bash script style checker.
  • flymake-ansible-lint.el: An Emacs package that offers a Flymake backend for ansible-lint.
  • inhibit-mouse.el: A package that disables mouse input in Emacs, offering a simpler and faster alternative to the disable-mouse package.
  • quick-sdcv.el: This package enables Emacs to function as an offline dictionary by using the sdcv command-line tool directly within Emacs.
  • enhanced-evil-paredit.el: An Emacs package that prevents parenthesis imbalance when using evil-mode with paredit. It intercepts evil-mode commands such as delete, change, and paste, blocking their execution if they would break the parenthetical structure.
  • stripspace.el: Ensure Emacs Automatically removes trailing whitespace before saving a buffer, with an option to preserve the cursor column.
  • persist-text-scale.el: Ensure that all adjustments made with text-scale-increase and text-scale-decrease are persisted and restored across sessions.
  • pathaction.el: Execute the pathaction command-line tool from Emacs. The pathaction command-line tool enables the execution of specific commands on targeted files or directories. Its key advantage lies in its flexibility, allowing users to handle various types of files simply by passing the file or directory as an argument to the pathaction tool. The tool uses a .pathaction.yaml rule-set file to determine which command to execute. Additionally, Jinja2 templating can be employed in the rule-set file to further customize the commands.
  • kirigami.el: The kirigami Emacs package offers a unified interface for opening and closing folds across a diverse set of major and minor modes in Emacs, including outline-mode, outline-minor-mode, outline-indent-minor-mode, org-mode, markdown-mode, vdiff-mode, vdiff-3way-mode, hs-minor-mode, hide-ifdef-mode, origami-mode, yafolding-mode, folding-mode, and treesit-fold-mode. With Kirigami, folding key bindings only need to be configured once. After that, the same keys work consistently across all supported major and minor modes, providing a unified and predictable folding experience.
  • buffer-guardian.el: Automatically saves Emacs buffers without requiring manual intervention. By default, it triggers a save when the user switches to another buffer, switches to another window or frame, Emacs loses focus, or the minibuffer is opened. Beyond standard file buffers, buffer-guardian also manages specialized editing buffers such as org-src and edit-indirect. Additional features, disabled by default, include periodic or idle-time saving of all buffers, automatic exclusion of remote, nonexistent, or large files, and support for custom exclusion rules via regular expressions or predicate functions.

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

ultyas-1.1.1.tar.gz (24.1 kB view details)

Uploaded Source

Built Distribution

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

ultyas-1.1.1-py3-none-any.whl (22.4 kB view details)

Uploaded Python 3

File details

Details for the file ultyas-1.1.1.tar.gz.

File metadata

  • Download URL: ultyas-1.1.1.tar.gz
  • Upload date:
  • Size: 24.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for ultyas-1.1.1.tar.gz
Algorithm Hash digest
SHA256 eedf2f9cdf35b11b6453329ac2e34c9d6fc549b031cee2b053fe7a9fa5861d97
MD5 68b94c23ec94d588695ef644f790cade
BLAKE2b-256 a2b39ed4632304f6f969bc40ff4e409c10a2191ae06dbae79c05c192782a4de9

See more details on using hashes here.

File details

Details for the file ultyas-1.1.1-py3-none-any.whl.

File metadata

  • Download URL: ultyas-1.1.1-py3-none-any.whl
  • Upload date:
  • Size: 22.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for ultyas-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 893e8f0499a88ffef7ddb1d56ce9df5e9b48712df88041b5df4839da322b15e7
MD5 008e4e5175ea769210c785b5f0a58c2a
BLAKE2b-256 25db828afb4c0c03c2d11c00ebdd20edf62336b65c2a2525eadb870aba78c63c

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