Fragmenten

De Calibre editor ondersteunt snippets. Een snippet is een stukje tekst dat vaak wordt hergebruikt of veel overbodige tekst bevat. De editor helpt je om met een paar toetsen een snippet toe te voegen. Bijvoorbeeld: stel dat je vaak link labels toevoegt bij het bewerken van HTML files. Dan kan je simpel “<a” in de editor typen en LCTRL toetsen. De editor zal het uitbreiden naar:

<a href="filename"></a>

Niet alleen dat, het woord bestandsnaam zal worden geselecteerd, met de cursor eroverheen, zodat je eenvoudig de echte bestandsnaam kunt typen, met behulp van de handige functie van de editor: ref: editor_auto_complete. En als u klaar bent met het typen van de bestandsnaam, drukt u op Control+J opnieuw en de cursor springt naar de positie tussen de <a> -labels, zodat je eenvoudig de tekst voor de link kunt typen.

Het snippetsysteem in de editor is zeer geavanceerd, er zijn een paar ingebouwde fragmenten en u kunt uw fragmenten aanpassen aan uw bewerkingsstijl.

De volgende bespreking van de ingebouwde snippets zou de kracht van het snippetsysteem moeten illustreren.

Notitie

U kunt ook snippets gebruiken in de tekstinvoervelden in de :guilabel: Zoeken & vervangen-paneel, echter, plaatshouders (gebruikmakend van Control+J om rond te springen) zullen niet werken.

Ingebouwde fragmenten

The built-in snippets are described below. Note that you can override them by creating your own snippets with the same trigger text.

Opvultekst [Lorem] invoegen

The first built-in snippet, and the simplest is used to insert filler text into a document. The filler text is taken from De finibus bonorum et malorum a philosophical work by Cicero (translated to English). To use it simply type Lorem in an HTML file and press Control+J. It will be replaced by a couple of paragraphs of filler.

The definition of this snippet is very simple, the trigger text is defined as Lorem and the template is defined simply as the literal text to be inserted. You can easily customize it to use your favorite form of filler text.

Een zelf-sluitende HTML tag [<>] invoegen

Now let’s look at a simple example of the powerful concept of placeholders. Say you want to insert the self-closing tag <hr/>. Just type <>, and press Control+J, the editor will expand the snippet to:

<|/>

Here, the | symbol represents the current cursor position. You can then type hr and press Control+J to move the cursor to after the end of the tag. This snippet is defined as:

Trigger: <>
Template: <$1/>$2

Placeholders are simply the dollar ($) sign followed by a number. When the snippet is expanded by pressing Control+J the cursor is positioned at the first placeholder (the placeholder with the lowest number). When you press Control+J again the cursor jumps to the next placeholder (the placeholder with the next higher number).

Een HTML afbeelding tag [<i] invoegen

This is very similar to inserting an HTML link, as we saw above. It allows you to quickly input an <img src="filename" alt="description" /> tag and jump between the src and alt attributes:

Trigger: <i
Template: <img src="${1:filename}" alt="${2*:description}" />$3

Een willekeurige HTML tag [<<] invoegen

This allows you to insert an arbitrary full HTML tag (or wrap previously selected text in the tag). To use it, simply type << and press Control+J. The editor will expand it to:

<|></>

Typen van de tag naam, bijvoorbeeld: span en drukken op Control+J, zal resulteren in:

<span>|</span>

You will note that the closing tag has been automatically filled with span. This is achieved with yet another feature of placeholders, mirroring. Mirroring simply means that if you specify the sample placeholder more than once in a template, the second and all later positions will be automatically filled in with whatever you type in the first position, when you press Control+J. The definition for this snippet is:

Trigger: <<
Template: <$1>${2*}</$1>$3

As you can see, the first placeholder ($1) has been specified twice, the second time in the closing tag, which will simply copy whatever you type in the opening tag.

Inserting an arbitrary HTML tag with a class attribute [<c]

This is very similar to the insert arbitrary tag example above, except that it assumes that you want to specify a class for the tag:

Trigger: <c
Template: <$1 class="${2:classname}">${3*}</$1>$4

This will allow you to first type the tag name, press Control+J, type the class name, press Control+J type the contents of the tag and press Control+J one last time to jump out of the tag. The closing tag will be auto-filled.

Uw eigen fragmenten maken

Snippets really shine because you can create your own to suit your editing style. To create your own snippets go to Edit → Preferences → Editor settings → Manage snippets in the editor. This will pop-up an easy to use dialog to help you create your own snippets. Simply click the Add snippet button and you will see a dialog that looks like:

The create your own snippets tool

First give your snippet a name, something descriptive, to help identify the snippet in the future. Then specify the trigger. A trigger is simply the text that you have to type in the editor before pressing Control+J in order to expand the snippet.

Then specify the snippet template. You should start with one of the example above and modify it to suit your needs. Finally, specify which file types you want the snippet to be active for. This way you can have multiple snippets with the same trigger text that work differently in different file types.

The next step is to test your newly created snippet. Use the Test box at the bottom. Type in the trigger text and press Control+J to expand the snippet and jump between placeholders.