How create new snippet in cudatext?

Post Reply
Roberto
Posts: 5
Joined: 14.08.2017 19:38

How create new snippet in cudatext?

Post by Roberto »

in synwrite I selected menu / Tools / new snippet! Thereafter, the synwrite displayed a screen for entering 3 parameters and the text where it created the encoding.

In cudatext I have no indication of how to do it. I already downloaded the snippets plugin, but thereafter I don't know how to do it.
Could you help me by creating a step by step. Thankful.
hycmos
Posts: 86
Joined: 06.11.2019 02:17

Post by hycmos »

https://wiki.freepascal.org/CudaText#Fo ... ppet_files
cudatext\data\snippets\??



Format of snippet files
Snippets tab-stops

Specify tab-stops in the snippet text like this:

${NN}
${NN:default text}

This places markers (AKA tab-stops) in the editor, marker index NN should be from 0 to 40. After snippet insertion, tab-key goes to next marker(s) and deletes it.

Markers can be listed in any order (e.g. marker 4 can be between 1 and 2).
Tab-key first goes to marker 1, 2, 3... and marker 0 is always the last.
Markers with the same indexes will place multi-carets.
Nested markers (with default text) are allowed, but only with one nesting level, e.g. ${2:text is {$3:here}}.
Marker with default text ${NN:...} can specify multi-line default text (character "}" is on another line of snippet).

Snippets macros

Special "macros" are handled by Snippets plugin in snippet text:

${sel} - Replaced with text selected before snippet insertion. (If snippet called with Tab key, it's empty string.)
${cp} - Replaced with clipboard text.
${fname} - Replaced with current file name (w/out path and extension).
${date:nnnnnn} - Replaced with current date/time formatted by string nnnnnn. See Python doc.
${cmt_start} - Replaced with current lexer's "block comment" start symbols (or empty string).
${cmt_end} - Replaced with current lexer's "block comment" end symbols (or empty string).
${cmt_line} - Replaced with current lexer's "line comment" symbols (or empty string).

Snippets file names

Snippets are stored in separate files with extensions:

.cuda-snippet or .synw-snippet: main format.
.cuda-snips: compact format for collections of tiny snippets.

Encoding is UTF-8, no BOM. Files can be placed in any subfolder of "data/snippets" folder, file/folder names have no meaning, but it's recommented to name subfolders like AuthorName.SyntaxName, so users can easily find newly installed snippets.
Format of .cuda-snippet

First lines have format "key=value" (no spaces around "="), where "key" is one of strings:

"name": snippet full name, shown in dialog.
"id": snippet short alias for Tab-key (latin letters, digits, "_.$"), line is optional.
"lex": lexers list, comma-separated, for which snippet is active, line is optional, empty means snippet always active.

Then follows the line "text=" without value, and all next lines - are snippet contents.

Trailing blank lines are discarded.
Use tab-chars in text indents, they are auto replaced to spaces if current editor configured so.

Format of .cuda-snips

File contains one or several lines, one snippet per line. Empty lines, lines starting with "#" or space, are ignored. Format of lines:

id text
/N=name text
id /N=name text
id /L=lexers text
id /L=lexers /N=name text
id /L="lexers" /N="name" text

Here "id" is short alias for Tab-key, "name" (if not set, it's the same as "id") is full name for dialog, "lexers" is comma-separated lexer list, "text" is snippet contents. Contents can have escaped special chars: "\n", "\r", "\t" (tab-char), "\\" (backslash).
Post Reply