Remillard / VHDL-Mode

A package for Sublime Text that aids coding in the VHDL language.
MIT License
40 stars 10 forks source link
emacs language sublime-text vhdl

VHDL Mode

Overview

This package attempts to recreate the functionality found in the well-loved language mode in Emacs. The extensibility of Sublime Text makes it an excellent platform upon which to attempt this.

This package may stand alone, however it was created to co-exist peacefully along with the Emacs Pro Essential package. In that same vein, the keyboard shortcuts were designed around the vhdl-mode shortcuts in Emacs. Additionally, there is now a Preferences setting that activates the Emacs vhdl-mode keybinds if desired.

Initially, the package relied upon the TextMate syntax file by Brian Padalino (after conversion to the ST3 YAML format). However after working with this syntax definition, it became apparent that this syntax definition did not conform well to current scoping best practices (noticable with color schemes) and had some issues with certain syntactical structures. An effort was undertaken to rewrite the syntax file from the language reference and incorporate meaningful and fine grained lexical scopes.

If any bugs are found or feature requests are desired, please visit either:

I will state up front that I cannot duplicate Emacs vhdl-mode perfectly (e.g. see the discussion on stutter typing). However if there is a particular omission or a feature that is desireable, please feel free to open an issue. I'm happy to investigate and attempt implementation.

Feature Set

Related Packages

Dependencies

Future Design Goals

Usage

Configuration

The VHDL Mode sublime-settings file contains fields that are used to fill in certain fields in the header template upon insertion. A user override may be created by selecting Preferences >> Package Settings >> VHDL Mode >> Settings. This will bring up the default settings file and a User variation on the settings. To customize the fields, simply copy and paste the defaults over to the User override file, and edit to taste.

These fields can also be set in the sublime-project file under "settings" for project specific behavior. To facilitate this, a project helper snippet was created to inject these settings when editing the project file. Simply select Project >> Edit Project from the menu, move the cursor past the "folders" line and type project and hit Tab for the snippet completion. The project snippet also creates a couple of sample build methods that can be used for the project.

One particular setting meshes with both the header template and the on-save time field. The vhdl-modified-time-string setting is the string that the code looks for when catching the on-save event, and updating that field. This should only be altered if the header snippet has been modified. When the event triggers, the code searches for that string, and replaces that line with the string, plus the time information.

Code beautification should pay attention to the tab_size and translate_tabs_to_spaces settings that are part of the standard Sublime Text preferences. Please let me know if this causes any issues.

Key Mappings

As mentioned, the goal here was to be familiar with Emacs vhdl-mode users. However I am well aware that I'm also in a Windows environment, and the commonly used C-c prefix for code mode commands in Emacs will conflict with the standard Windows copy command. Sublime Text 3 frequently uses M-k as an extension keymap and this seemed a suitable replacement (in the Windows environment the Meta key is Alt). The key mappings are also context selected, so should not trigger on anything that is not a source.vhdl file.

Another note, these are sequence keystrokes. For example to copy a port interface from an entity, move the point into the structure (anywhere should be fine) and hit Alt-k then p then w. These should not be chorded.

For the long-time Emacs vhdl-mode user, there is now a preference for activating the original Emacs vhdl-mode keybinds. I am not going to document these here as it will likely confuse new users however if interested, simply look at the Default (Windows|OSX|Linux).sublime-keymap file for the keybinds.

Port Interface Copy/Paste Functions

It may help to remember p for port, then w for write (to buffer). The other mnemonics are fairly straightforward. These commands are also available with the right-click context menu under the VHDL Mode heading.

The following animated GIF demonstrates a portion of the port copying feature.

Port Copying Demonstration

Subprogram Interface Copy/Paste Functions

It may help to remember s for subprogram, then w for write (to buffer). Much like the port version of this feature, the mnemonics are straightforward. These commands are also available with the right-click context menu under the VHDL Mode heading.

Commenting

It may help to remember 'c' for code, then 'c' for comment, 'b' for beautify, etc. These commands are also available with the right-click context menu under the VHDL Mode heading.

Template

Largely templating is handled by the snippet system, however the header is a special feature as it inserts various fields automatically. Remember 't' for template and 'h' for header. These commands are also available with the right-click context menu under the VHDL Mode heading.

Miscellaneous

Stutter Typing

In Emacs vhdl-mode, double striking some keys will insert some syntactical punctuation elements. Unfortunately, I cannot duplicate the entire Emacs vhdl-mode stutter typing repetoire since I do not have access to the keystream directly. What I have been able to do is use keybindings and in one case a keybinding plus a macro to replicate the behavior. I'll list the implemented replacements and then a note on the ones I cannot and why I cannot replicate these. The symbols below will have a space on either side of them which is difficult to see in this HTML documentation.

The following are the stutter typing replacements I cannot do.

Snippets

Most snippets will execute from the keyword associated with them (i.e. 'entity' will fill out the beginning and ending structures and leave the cursor in the middle.) Each of these snippet words require hitting Tab afterwards to execute. This is just a list of the less obvious shortcuts. A full list of the snippets implemented may be found by selecting the Tools >> Snippets menu.

Miscellaneous Features

Known Issues and Design Commentary

Miscellaneous

The supported method for installing this package is through Package Control. It is possible to install this by cloning the repository directly. This method is not supported by me. However here are a few pointers:

Contributors

This is a new section and I wanted to acknowledge and thank folks who have helped out with fixes and testing. If anyone else has fixes or contributions, please feel free to open an issue at the Github repository and we can discuss it. If submitting a pull-request, please target the develop branch, as I keep the master branch for releases only.

Conclusion

I hope you find this Sublime Text package useful for coding in VHDL. The language is a passion of mine and it has been a great experience extending Sublime Text to work with it.

This package is offered with no warranty and no liability. It's free to use and distribute with any code, however I would appreciate attribution for my work if forking, modifying, or incorporating. Happy to work with other Sublime Text package authors as well.

MIT License

Copyright (c) 2017 Mark Norton

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.