This is sort of a snippet question and sort of a plugin question. I’m trying to figure out which features of a language mode that doesn’t yet exist might be supported by snippets and which might require full plugin support. In particular, the language I’m working to support is VHDL. There is a syntax mode in the package repository, but I’m attempting to emulate the more full featured language support that currently exists in Emacs vhdl-mode which is pretty extensive. But… baby steps first.
So, onto the question, snippets seem pretty powerful however I’m not sure they’ll completely do the trick.
Question 1) Can a snippet hide/erase portions of a declaration that are possible, but not always present?
For example, one of the most basic VHDL language blocks is the entity description. It looks like this:
entity <entity name> is
generic (
generic_object_1 : type := default value;
....
generic_object_n : type := default value
port (
port_1 : direction type;
....
port_2 : direction type
);
end entity <entity name>;
None of these items save for the first and last line are mandatory. Most frequently, the port block is filled out, and sometimes the generic block is filled out. Is there a way to have the snippet hop to a block object, but if the user types enter with no text entry, it’ll omit that portion of the block and skip to the next?
Question 2) Is it possible to overwrite the triggering text?
For example, another language construct is a process. There are a couple different forms for this, but here’s an example:
PROCESS_NAME : process (some, stuff, goes, here)
begin
Other code here;
end process PROCESS_NAME;
What I’d LIKE to have happen is that the user type something like ‘procseq’ and hit tab. Then it undoes that word, moves back to the start of the line, prompts for that name, and then carries on through the field. Another variation might be triggered by ‘proccomb’ and tab. I just don’t want the snippet evocation command to be in the file after the snippet is triggered.
Question 3) Is it possible to embed point control in a snippet?
This one is kind of basic, but say I have a large mandatory comment header that needs to go into the file. Seems perfect for a snippet however I want to make sure it always goes at row 1, col 1. Is there a way to do this inside the snippet? If not, presumably a workaround might be to create a plugin command that upon evocation, moves the point to 1,1 and then triggers the snippet. But if I can do it within the snippet itself that would be good.
I think that takes care of it. I managed to find my other answer while researching these other questions (the language is kind of verbose, so there’s a lot of those blocks that start with a name, and the same name is repeated at the end – mirroring text fields does that trick.) Thanks in advance and I’ll be checking back. This is actually kind of exciting – the first editor I think that could really encompass this very complex language mode.