# Working with Plugins

&kate; offers several types of plugin. There are plugins for the &kate; editor component, which are available to any application using the editor component, such as KDevelop, Quanta, Kile, &kwrite; and many others. There are also plugins only available in the &kate; editor itself. There are two types of these plugins: some are written in native C++, while others are written in the Python programming language. There are subtle differences in these, described below.

You can enable any type of plugin in the configuration dialog, which also provides access to additional configuration options for plugins that require it.

There are many plugins for various purposes available and you can search the web for more. A few plugins are shipped with the editor component, for inserting automatic braces, inserting files, and exporting text as &HTML;.

## Editor Component Extensions

For information about available plugins, see the Editor Component Extensions section of the &katepart; Handbook.

## &kate; Application Plugins

&kate; plugins are additional functions for the &kate; editor. They can add extra menus and shortcuts, and extend &kate;'s features. You can install as many or as few as you like, from within &kate;. Open &kate;'s configuration dialog with Settings Configure &kate;... Select Application Plugins to choose the wanted plugins.

The available application plugins are:

- Backtrace Browser - Backtrace navigation tool view

- Build Plugin - Compile or Make and parse error messages

- Close Except/Like - Close group of documents based on a common path or file extension

- CTags - Look up definitions/declarations with CTags

- Document switcher - Quick document switching with &Alt; behavior

- File system browser - File system browser tool view

- &gdb; - Provides a simple &gdb; frontend

- Icon picker - Invokes Cuttlefish icon picker

- Lumen - Lumen is a Autocompletion Plugin for D, using the DCD autocompletion server

- Open Header - Opens the corresponding .h/[.cpp|.c] file

- Project Plugin - Project plugin for kate

- Replicode

- Rust code completion - Code completion for Rust source code

- Search & Replace - Search or replace patterns in opened documents or in files on disk

- Snippets tool view - Tool view embedding the snippets management

- SQL Plugin - Execute query on SQL databases

- Symbol Viewer - Extract and show reference symbols from source

- Terminal tool view - Tool view embedding a terminal widget

- Text Filter - Easy text filtering

- &XML;Completetion - Lists &XML; elements, attributes, attribute values and entities allowed by DTD

## &XML; Completion

This plugin gives hints about what is allowed at a certain position in an &XML; file, according to the file's DTD. It will list possible elements, attributes, attribute values or entities, depending on the cursor position (⪚ all entities are listed if the character on the left of the cursor is &). It's also possible to close the nearest open tag on the left.

The DTD must exist in &XML; format, as produced by the Perl program `dtdparse`. We will call a DTD in this format meta DTD. Some meta DTDs are supplied. They are installed in `$KDEDIR/share/apps/katexmltools/`, which is also the default folder when you choose Assign Meta DTD.... To produce your own meta DTDs, get `dtdparse` from http://dtdparse.sourceforge.net.

### How to Use

Start &kate; and open the configuration dialog under Settings Configure &kate;.... Then select &XML; Completion which will appear in the Application/Plugins section and close the dialog. After that, select &XML;Assign Meta DTD.... If your document contains no DOCTYPE or the doctype is unknown, you will have to select a meta DTD from the file system. Otherwise the meta DTD that matches the current document's DOCTYPE will be loaded automatically.

You can now use the plugin while typing your text:

< (less than key)

- This will trigger a list of possible elements unless the cursor is inside a tag already. Note that you currently cannot use this to insert the top level element (⪚ <html>).

</(less than key + slash)

- Entering these characters will offer to close the current element (nearest open one to the left of the cursor). Press &Enter; to accept the suggestion. Unlike the Close Element menu item, this works only with a DTD assigned.

" (quote key)

- The quote key will trigger a list of possible attribute values (if there are any) if you are inside a tag.

(space key)

- This key will trigger a list of possible attributes for the current element if you are inside a tag.

& (ampersand key)

- This key will trigger a list of named entities.

### Features and Limitations

You can test all functions and limitations by loading `$KDEDIR/share/apps/katexmltools/testcases.xml` into &kate; and following the instructions.

### Menu Structure

&Ctrl;Return &XML; Insert Element...

- This will open a dialog that lets you insert an &XML; element. The <, > characters and the closing tag will be inserted automatically. If you have selected text when this menu item is selected, the selected text will be surrounded by the opening and the closing tag. The dialog also offers completion of all elements that may be inserted at the current cursor position if you have assigned a meta DTD by using Assign Meta DTD....

&Ctrl;< &XML; Close Element

- This will search your text for a tag that is not yet closed and will close it by inserting the corresponding closing tag. The search starts at the cursor position and goes left. If it cannot find an open tag nothing will happen.

&XML; Assign Meta DTD...

- This will tell the plugin which meta DTD to use for the current document. Note that this assignment will not be saved. You will have to repeat it when you start &kate; the next time.

### Thanks and Acknowledgments

&kate; Plugin &XML; Completion copyright 2001,2002 &Daniel.Naber; &Daniel.Naber.mail;.

KDE SC 4 version copyright 2010 Tomáš Trnka

Documentation copyright 2001,2002 &Daniel.Naber;

## Exporter

### Menu Structure

File Export as &HTML;...

- Export your file in &HTML; format so your document can be viewed as a web page.

Edit Copy as &HTML;...

- Copies selected text with the syntax highlight as &HTML; text.

## Search & Replace

### Introduction

&kappname;'s Search & Replace plugin allows you to search for text or regular expressions in many different files at once. You can search all open files, all the files in one directory and optionally its subdirectories, or all files in the current project. You can even filter by filename, for instance searching only files that end with a particular file extension.

### Interface

#### Search Query

The following options are always displayed at the top of the Search in Files tool view:

New Tab

- You can have as many searches as you want open at the same time. Simply click the New Tab button at the top-left corner of the Search tool view and a new results tab will open permitting you to perform another search.

Toggle Results

- The down arrow in the top right-corner of the Search in Files tool view will toggle the bottom half of the tool view between displaying additional options for the Search in Folder mode and the results of your search.

Find

- This is where you type in what you want to find. You may enter standard text, or a regular expression if enabled.

Replace (text box)

- Replacement text that will be added to file(s) in place of the text in the Find text box.

Search

- When you've finished configuring everything, just press the Search button to perform your search. You may also press &Enter; in the Find text box to do the same.

Replace

- When you've finished configuring everything, just press the Replace button to replace the text entered in the Find text box with that of the Replace text box. You may also press &Enter; in the Replace text box to do the same.

Next

- Go to the next match of your search query, switching files if necessary.

Replace checked

- The same as Replace, but will only perform replacements in files that are checked in the pane below.

#### Search in Folder Options

These options are displayed below the aforementioned query options. If search results are being displayed instead, press the Toggle Results button to display them.

Match case

- Restricts search results to only those that have the exact same combination of upper and lower case letters as your search query.

Regular expressions

- Permits you to use regular expressions instead of simple text as your search query.

Expand results

- Display all the results found in each file, instead of just a list of files that contain the search query.

Search

- This has three options. Select in Open files to search all files currently open in &kappname;. Select in Folder to search inside a folder and optionally its subfolders. Select in Project to search all the files listed in the currently open project.

Folder

- You may enter the path of the folder you wish to search. For instance, you might enter `~/development/kde/kate/` if you wished to search the &kate; source code. This option is only available when using in Folder mode.

Open file dialog

- Press this button to locate the folder in your desktop's folder browser. This button only works when using in Folder mode.

Up

- Press this button to change Folder to the parent of the currently selected folder. This button only works when using in Folder mode.

Restore Current Folder

- This button will set the Folder entry to the folder in which the currently open document is located. This button only works when using in Folder mode.

Filter

- This permits you to only search filenames that match a particular pattern. For instance, to only search files written in C++, change it to `*.cpp`. To search only files beginning with `kate`, change it to `kate*`. You can enter multiple filters separated with a comma (`,`). This option is not available when using in Open files mode.

Exclude

- The opposite of Filter, this prevents &kappname; from searching files that match the specified patterns. As with Filter, you can enter multiple patterns separated with a comma (`,`). This option is not available when using in Open files mode.

Recursive

- If this option is enabled, &kappname; will also search in all subfolders of the selected folder. This option is only available when using in Folder mode.

Include hidden

- If this option is enabled, &kappname; will also search in files or folders that are typically hidden by your &OS;. This option is only available when using in Folder mode.

Follow symbolic links

- The Search in Files plugin typically doesn't follow symbolic links. When this option is enabled, the plugin will follow them instead and search inside the files or folders they reference. This option is only available when using in Folder mode.

  It's possible for symbolic links to reference a folder that is the parent of the folder currently being searched, or other folders that contain symbolic links to their parent. If there is such a link in the folder being searched and this option is enabled, &kappname; will repeatedly follow the link and search the folder, and the search will never complete.

Include binary files

- If enabled, &kappname; will also search in files that do not appear to be text files.

#### Search Results

The results of your search are displayed below the query options. If options for Search in Folder mode are displayed, simply press the Toggle Results button to display them. They will also automatically be displayed as soon as a search is performed.

The search results display a list of files that contains text that matches your search query, followed by the number of matches found in that file.

To see a list of matches in that file, simply click the expansion arrow to the left of the file name. (If you selected the Expand results option, this will already be done for you.) The line number each match is found on will be displayed, followed by the contents of that line, with your search query indicated in bold text.

To open the file your result was found in, simply double-click it. &kappname; will open the file if needed. You can also move the cursor to the location of a particular match by double-clicking on its listing instead of the file name.

### Menu Structure

Edit Search in Files

- Launches the Search and Replace tool view.

Edit Go to Next Match

- Go to the next match in a search performed by the Search and Replace plugin.

Edit Go to Previous Match

- Go to the previous match in a search performed by the Search and Replace plugin.

View Tool Views Show Search and Replace

- Toggle the display of &kappname;'s Search and Replace tool.

## Filesystem Browser

The Filesystem Browser is a folder viewer, allowing you to open files from a displayed folder in the current frame.

### Menu Structure

View Tool Views Show Filesystem Browser

- Toggle the display of &kate;'s Filesystem Browser.

### Interface

From the top down, the Filesystem Browser consists of the following elements:

A Toolbar

- This contains standard navigations tool buttons:

  Back

- Causes the folder view to `cd` to the previously displayed folder in the history. This button is disabled, if there is no previous item.

Forward

- Causes the folder view to `cd` to the next folder in the history. This button is disabled, if there is no next folder.

Bookmarks

- Opens a submenu to edit or add bookmarks and to add a new bookmark folder.

Current Document Folder

- This button will cause the folder view to `cd` to the folder of the currently active document if possible. This button is disabled, if the active document is a new, unsaved file, or the folder in which it resides can not be decided.

Options

- Short View

- Displays only the filenames.

Detailed View

- Displays Name, Date, Size and Type of the files.

Tree View

- Like Short View, but folders can be expanded to view their contents.

Detailed Tree View

- This also allows folders to be expanded, but displays the additional columns available in Detailed View.

Show Hidden Files

- Displays files normally hidden by your &OS;.

Automatically synchronize with current document

- When this option is enabled the filesystem browser will automatically `cd` to the folder of the document currently open in the editing area every time it changes.

A Location Entry

- This displays a breadcrumb navigation to the currently open folder, similarly to &dolphin;. You can click on a any folder to browse to it, or click on one of the arrows to the left of a folder to select any folders beneath it. You may also select from your list of Places by clicking the leftmost icon in the breadcrumb navigation, which displays an icon that represents your current Place.

  You can also click to the right of the breadcrumbs to change them to a text box where you can type the path of a folder to browse. The &URL; entry maintains a list of previously typed paths. To choose one, use the arrow button to the right of the entry.

  The &URL; entry has folder auto-completion. The completion method can be set using the &RMB; menu of the text entry.

A Folder View

- This is a standard &kde; folder view.

A Filter Entry

- The Filter entry allows you to enter a filter for the files displayed in the folder view. The filter uses standard globs; patterns must be separated by white space. Example: `*.cpp *.h *.moc`

  To display all files, enter a single asterisk `*`.

  The filter entry saves the last 10 filters entered between sessions. To use one, press the arrow button on the right of the entry and select the desired filter string. You can disable the filter by pressing the Clear text button to the left of the autocompletion arrow button.

### Configuration

This plugin can be configured on the Filesystem Browser page of &kate;'s configuration.

Toolbar

- Configure the buttons on the Filesystem Browser toolbar by moving the ones you want enabled to the Selected Actions list, and order them using the arrow buttons at the side of the list.

## Build Plugin

### Introduction

The Build plugin allows you to run actions like build, clean and compile on a project.

### Using the Build Plugin

The Build plugin adds a Build Output tool view at the bottom and a Build menu on the menubar. The tool view can be used to configure build target settings, while the menu can be used to perform build, clean and compile actions.

The Build Output tool view has three tabs:

- Target Settings

- Output

- Errors & Warnings

#### Target Settings tab

The target settings tab can be used to configure various build targets.

Each target contains four configuration options:

Working Directory

- You can set the path to the project here. Leave this empty to use the directory the current document is located in.

Build

- This option lets you define the build command. It is set to `make` by default.

Clean

- The option lets you define the clean command. It is set to `make clean` by default.

Quick Compile

- This option lets you define the quick compile command. It is set to `gcc -Wall -g %f` by default.

One can create a new target by using the New button. The Copy button can be used to make a copy of an existing target. To delete a target, use the Delete button.

#### Output tab

The Output tab shows the console output generated by the last command.

#### Errors & Warnings

The Errors & Warnings tab lists the errors and warnings generated by the last command.

Each line contains a message and the file name and line number if available. Clicking on the error or warning takes you to the appropriate file and places the cursor on the corresponding line number.

There are Errors, Warnings, and Others buttons at the top that allow you to show or hide those categories of output.

To navigate to the previous error, press &Ctrl;&Alt;Left. To navigate to the next error, press &Ctrl;&Alt;Right.

### Menu Structure

Build Build

- Runs the Build command for the currently selected target.

Build Clean

- Runs the Clean command for the currently selected target.

Build Quick Compile

- Runs the Quick Compile command for the currently selected target.

&Ctrl;&Alt;Left Build Previous Error

- Moves the cursor to the location of the previous error in the document.

&Ctrl;&Alt;Right Build Next Error

- Moves the cursor to the location of the next error in the document.

Build Targets

- Select from a list of targets configured by the user.

Build Next Target

- Switch to the next target configured by the user.

### Thanks and Acknowledgments

The &kate; Build Plugin was written by Kåre Särs.

Special thanks to Google Code-In 2011 participant Salma Sultana for writing much of this section.

## SQL Plugin

### Introduction

The Structured Query Language (SQL) is a specialized language for updating, deleting, and requesting information from databases.

The &kate; SQL Plugin allows you to:

- Create a database

- Connect to existing databases

- Insert and delete data in the database

- Execute queries

- Display results in a table

### Connecting to a Database

Select Add Connection from the SQL menu or toolbar, and then select the Qt database driver you want to use (including QSQLITE, QMYSQL3, QMYSQL, QODBC3, QODBC, QPSQL7, and QPSQL). If you can't see the desired driver, you need to install it. Then, press Next.

If the database you selected uses a file, simply indicate the database's location and press the Next button. If it requires connecting to a server, you must enter the hostname of the server, your username and password, and any other information that particular driver may require. Then press Next.

Finally, give a name to your connection, and press Finish.

### Running Queries

#### INSERT/DELETE/UPDATE

You can insert, delete, and update data using the SQL plugin just as you would from the command line or from within a program. Simply enter a query and press the Run query.

##### Some Example Queries

`INSERT`

-     INSERT INTO table_name ("feature1", "feature2", "feature3", "feature4", "feature5")
      VALUES ("value1", "value2", "value3", "value4", "value5" )

`DELETE`

-     DELETE FROM table_name WHERE name = "text"

`UPDATE`

-     UPDATE table_name SET "feature1" = "text", "feature2" = "text", "feature3" = "text", "feature4" = "text", "feature5" = "text"

#### SELECT

After running a `SELECT` query, you can view the results as a table that will appear in the SQL Data Output tool view at the bottom of &kappname;, or as text in the SQL Text Output. If there is an error, you can see it in the text output.

##### Example `SELECT` Query

    SELECT * FROM table_name

In the SQL Data Output tool view, there are several buttons:

Resize columns to contents

- Changes the size of columns to fit their contents.

Resize rows to contents

- Changes the size of rows to fit their contents.

Copy

- Selects all of the table contents and copies it to the clipboard buffer.

Export

- Exports all of the table contents to a file, the clipboard, or the current document in the Comma Separated Values format.

Clear

- Removes everything from the table view

You can now change the colors displayed in the table in the SQL section of Settings Configure &kate; .

### Browsing

You can browse your database using the SQL Schema Browser tool view on the left. The information displayed varies depending on which database driver you are using.

To refresh this list, right-click anywhere in the tool view and select Refresh. To generate a query on any entry in the list, right-click on an entry, select Generate, and select the query type (SELECT, UPDATE, INSERT, or DELETE) from the submenu that appears.

### Menu Structure

SQL Add connection...

- Adds a new connection using any database driver.

SQL Remove connection

- Removes the selected connection.

SQL Edit connection...

- Edits the current connection's settings.

Connections

- All database connections you have created are listed between the Edit connection and Run query menu items. Select one to run queries or make modifications to it.

&Ctrl;E SQL Run query

- Runs your query.

### Thanks and Acknowledgments

The SQL Plugin was written by Marco Mentasti.

Special thanks to Google Code-In 2011 participant Ömer Faruk ORUÇ for writing much of this section.

## &gdb; Plugin

### Introduction

&kappname;'s &gdb; plugin provides a simple frontend to the popular &GNU; Project Debugger.

Previous experience with &gdb; is strongly recommended. For more information on using &gdb;, visit the &gdb; website.

You can enable the &gdb; plugin in the Plugins section of &kappname;'s configuration.

For the plugin to work properly, you must have a source file (of any type supported by &gdb;) and an executable.

If you compile using &gcc;/`g++` you might want to use the ``-ggdb`` command line argument.

After these preparations are made, open the source file in &kappname;, enter the path to the executable in the Settings tab of the Debug View tool view, and select Debug Start Debugging from the menu to get started.

### Menu and Toolbar Structure

All of these options are available in &kappname;'s menus, and many are available on the Debug toolbar as well.

View Tool View Show Debug View

- Shows a tool view containing &gdb; output, the &gdb; command line used, and other settings.

View Tool View Show Locals

- Shows a list of all currently loaded variables and their values.

View Tool View Show Call Stack

- Shows a &gdb; backtrace.

Debug Targets

- A submenu containing a list of targets (executables).

Debug Arg Lists

- A submenu containing all argument lists.

Debug Start Debugging

- Starts &gdb; with a target.

Debug Kill / Stop Debugging

- Stops &gdb;.

Debug Restart Debugging

- Restarts &gdb;.

Debug Toggle Breakpoint / Break

- Set a breakpoint at the current cursor position.

Debug Step In

- Execute the present statement (function call will be debugged).

Debug Step Over

- Execute the present statement (function call will not be debugged).

Debug Step Out

- Resumes execution until the program that is executing terminates.

Debug Move PC

- Move program counter (next execution).

Debug Run To Cursor

- Runs the program until it reaches current cursor position.

Debug Continue

- Ignores any breakpoints and executes program until it terminates (successfully or not).

Debug Print Value

- Prints the value of the variable that the cursor is currently pointing to.

Settings Toolbars Shown&gdb; Plugin

- Display the debugging toolbar.

### Debug View

The Debug View tool view consists of several tabs:

&gdb; Output

- Contains output from &gdb; and a &gdb; command line.

  The Output Tab The Output tab.

  The Output tab displaying the output from a debugging session.

Settings

- Target

- Path to the target (executable) for debugging.

Working Directory

- The current working directory provided to the target.

Arg List

- Arguments passed to the program.

Keep focus

- Keeps focus on the &gdb; command line.

Redirect IO

- Opens a new IO tab in the Debug View where you can view output and provide input to the running program.

The Settings Tab The Settings tab.

The Settings tab displaying the configuration of a debugging session.

IO

- Contains an area that displays output from the running program and a command line where you may provide input to it.

  The IO Tab The IO tab.

  The IO tab displaying output from a simple test program.

### Call Stack and Locals

The Call Stack tool view contains a list of the formatted backtrace returned from &gdb;.

The &gdb; Call Stack Tool View The Call Stack tool view.

The &gdb; Plugin's Call Stack tool view.

The Locals tool view contains a list of all currently loaded variables from the program and their corresponding values.

The &gdb; Locals Tool View The Locals tool view.

The &gdb; Plugin's Locals tool view.

### Thanks and Acknowledgments

Special thanks to Google Code-In 2011 participant Martin Gergov for writing much of this section.

## Terminal Tool View Plugin

The built in Terminal Emulator is a copy of the &kde; &konsole; terminal application, for your convenience. It is available from the View Tool Views Show Terminal menu item and will get the focus whenever displayed. Additionally, if the Automatically synchronize the terminal with the current document when possible option is enabled, it will change to the directory of the current document if possible when it is displayed, or when the current document changes.

The default location in the &kate; window is at the bottom, below the editing area.

You can configure the &konsole; using its &RMB; menu, for more information, see the &konsole; manual.

The built-in terminal emulator is provided by the Terminal Tool View plugin, which is enabled by default.

### Menu Structure

View Tool Views Show Terminal

- Toggles the display of the built-in terminal emulator.

  When activated for the first time, the terminal will be created.

  When the terminal emulator is displayed, it will get the focus, so that you can start typing in commands immediately. If the Automatically synchronize the terminal with the current document when possible option is enabled in the Terminal page of the Main configuration dialog the shell session will change to the directory of the active document, if it is a local file.

Tools Pipe to Terminal

- Feed the currently selected text into the built-in terminal emulator. No newline is added after the text.

Tools Synchronize Terminal with Current Document

- This will cause the built-in Terminal to `cd` into the directory of the active document.

  Alternatively, you can configure &kappname; to always keep the terminal in sync with the current document. See konsole-config for more information.

Tools Focus/Defocus Terminal

- Switch the focus from the current document to the terminal and vice versa.

### Configuration

You can configure the Terminal Tool View plugin on the Terminal page of the configuration dialog.

The following options are available:

Automatically synchronize the terminal with the current document when possible

- This will cause the built-in terminal to `cd` into the directory of the active document when launched and when a new document gets the focus. If not enabled, you have to do all your navigation in the terminal on your own.

Set EDITOR environment variable to 'kate -b'

- This sets the `EDITOR` environment variable so programs run in the built-in terminal that automatically open a file in an editor will open them in &kate; instead of the default editor configured in your shell. You will not be able to continue using the terminal until you have closed the file in &kate;, so the calling program is aware you have finished editing the file.