Snippets plugin: Difference between revisions

From Bluefish Wiki
Jump to navigation Jump to search
Fal7i (talk | contribs)
mNo edit summary
Fal7i (talk | contribs)
mNo edit summary
Line 46: Line 46:
Snippets are organized in branches (chapters) and possibly sub-branches. In mediawiki branch there is a sub-branche called ''man bf'' where are usefull snippets to edit Bluefish manual. The title of the snippet gives an idea of what it does. By moving the mouse over the title of the snippet appears a tooltip giving details.
Snippets are organized in branches (chapters) and possibly sub-branches. In mediawiki branch there is a sub-branche called ''man bf'' where are usefull snippets to edit Bluefish manual. The title of the snippet gives an idea of what it does. By moving the mouse over the title of the snippet appears a tooltip giving details.
[[File:Man2_snippet_tooltip.png|none|frame|snippet tooltip]]
[[File:Man2_snippet_tooltip.png|none|frame|snippet tooltip]]
By double-clicking a snippet is inserted the code at the cursor position in the edit area.
By double-clicking a snippet the code is inserted at the cursor position in the edit area.


Snippet can use parameters, double-clicking opens a dialog box.
Snippet can use parameters, double-clicking opens a dialog box.
Line 67: Line 67:


=== Branch ===
=== Branch ===
 
All snippets should be placed in a branch. If your snippets file is empty, the first thing to create is the first branch.
=== Insert strings ===
=== Insert strings ===
 
To insert a snippet, choose a branch, right click on its name to open the snippets menu.
{|
{|
|valign="bottom" align="center"|[[File:Man2 create snippet.png|none|frame|lorem ipsum]]
|valign="bottom" align="center"|[[File:Man2 create snippet.png|none|frame|New snippet]]
|valign="bottom" align="center"|[[File:Man2 create snippet2.png|none|frame|lorem ipsum]]
|valign="bottom" align="center"|[[File:Man2 create snippet2.png|none|frame|Insert string]]
|valign="bottom" align="center"|[[File:Man2 create snippet3.png|none|frame|lorem ipsum]]
|valign="bottom" align="center"|[[File:Man2 create snippet3.png|none|frame|Name of the snippet and description for the tooltip]]
|}
|}


[[File:Man2 create snippet4.png|left|frame|lorem ipsum]]
[[File:Man2 create snippet4.png|left|frame|Before text, After text and variables]]
lorem ipsum
 
{{clear}}
{{clear}}



Revision as of 16:43, 9 January 2010


 

The snippets plugin allows you to record reusable pieces of code. There are two categories of snippets:

  • insert strings
  • search and replace patterns

Snippets are organized in branches. The first time you open Bluefish 2 you have no snippets. You have to create them, or import a set of snippets.

Bluefish 1.3 users
you can copy your old snippets to Bluefish 2
$ cp ~/.bluefish-unstable/snippets ~/.bluefish/
Bluefish 1.0 users
to import your Bluefish 1 Custom menu in snippets you can use Olivier's python script convert_custom_menu_to_snippets.py.
  • put convert_custom_menu_to_snippets.py in ~/.bluefish/ directory
  • make the script executable: $ chmod a+x convert_custom_menu_to_snippets.py
  • run the script: $ ./convert_custom_menu_to_snippets.py > mysnippets.xml
  • import mysnippets.xml in your snippets plugin.
You also can find useful snippets in Snippets repository



Import snippets

The first time you open Bluefish 2 you have no snippets. You have to create them, or import a set of snippets. Right click in the snippets area open the snippets menu.

import item in snippets menu
import a xml snippets file
mediawiki(en) snippets are imported
click on the arrow of the branch title to expand it.
see Snippets usage to learn how to use snippets.
You can find snippets to import in the Category:Snippets repository

Snippets usage

There are two kinds of snippets, insert snippets and replace snippets.

Insert snippets

Snippets are organized in branches (chapters) and possibly sub-branches. In mediawiki branch there is a sub-branche called man bf where are usefull snippets to edit Bluefish manual. The title of the snippet gives an idea of what it does. By moving the mouse over the title of the snippet appears a tooltip giving details.

snippet tooltip

By double-clicking a snippet the code is inserted at the cursor position in the edit area.

Snippet can use parameters, double-clicking opens a dialog box.

snippet insert dialog

Here is the result:

snippet insert result

Replace snippets

Some snippets make replace in a selected text. Select text before use them!

Export snippets

  • you can export:
    • a branch
    • a single snippet
  • to export your entire snippets file just copy ~/.bluefish/snippets to mysnippets.xml
  • to export a selection of branches, you have to create a new branch, move wanted branches into it and export the new branch.

Create snippets

Branch

All snippets should be placed in a branch. If your snippets file is empty, the first thing to create is the first branch.

Insert strings

To insert a snippet, choose a branch, right click on its name to open the snippets menu.

New snippet
Insert string
Name of the snippet and description for the tooltip
Before text, After text and variables


Search and replace patterns

lorem ipsum
lorem ipsum

lorem ipsum

Edit snippets

Reorder snippets

lorem ipsum

lorem ipsum

Set snippet accelerator

Delete branch/snippet

Show as menu