&Anders.Lund; &Anders.Lund.mail;&Dominik.Haumann; &Dominik.Haumann.mail;&tde-authors;Advanced Editing ToolsComment/UncommentThe Comment and Uncomment commands, available from the
Tools menu allow you to add or remove comment
markers to the selection, or to the current line if no text is selected,
if comments are supported by the format of the file you are
editing.The rules for how commenting is done are defined in the syntax
definitions, so if syntax highlighting is not used, commenting/uncommenting
is not possible.Some formats define single line comment markers, some multiline
markers and some both. If multiline markers are not available,
commenting out a selection that does not fully include its last line
is not possible.If a single line marker is available, commenting single lines is
preferred where applicable, as this helps to avoid problems with
nested comments.When removing comment markers, no uncommented text should be
selected. When removing multiline comment markers from a selection,
any whitespace outside the comment markers is ignored.comment
To place comment markers, use the
ToolsComment
menu item or the related keyboard shortcut sequence, default is
&Ctrl;D.uncomment
To remove comment markers, use the
ToolsUncomment
menu item or the related keyboard shortcut, default is &Ctrl;&Shift;D.The Editor Component Command LineKate's editor component has an internal command line, allowing you to
perform various actions from a minimal GUI. The command line is a text entry
in the bottom of the editor area, to show it select
ViewSwitch to Command Line
or use the keyboard shortcut (default is
F7). The editor provides
a set of commands as documented below, and additional commands can be provided
by plugins.To execute a command, type the command and then press the enter key. The
command line will indicate whether it succeeded and possibly display a message. If
you entered the command line by pressing F7 it will
automatically hide after a few seconds. To clear the message and enter a new
command, press F7 again.The command line has a built-in help system, you can type the command
help to get started. To see a list of all available commands
type help list, to view help for a specific command, do
help command.The command line has a built-in history too, so you can reuse commands already
typed. To navigate the history, use the Up and
Down keys. When showing historical commands, the argument part
of the command will be selected, allowing you to easily overwrite the
arguments.Standard Command Line CommandsArgument typesBOOLEANThis is used with commands that turn things on or off.
Legal values are on, off,
true, false,
1, 0INTEGERAn integer numberSTRINGA stringCommands for Configuring the EditorThese commands are provided by the editor component, and allows you to
configure the active document and view only. This is handy if you want to use
a setting different from the default settings, for example for indentation.
set-tab-widthINTEGER widthSets the tab width to the number widthset-indent-widthINTEGER widthSets the indentation width to the number
width. Used only if you are indenting with
spaces.set-word-wrap-columnINTEGER widthSets the line width for hard wrapping to
width. This is used if you are having your text wrapped
automatically.set-icon-borderBOOLEAN enableSets the visibility of the icon border.set-folding-markersBOOLEAN enableSets the visibility of the folding markers pane.set-line-numbersBOOLEAN enableSets the visibility of the line numbers pane.set-replace-tabsBOOLEAN enableIf enabled, tabs are replaced with spaces as you type.
set-remove-trailing-spaceBOOLEAN enableIf enabled, trailing whitespace are removed whenever the cursor
leaves a line.set-show-tabsBOOLEAN enableIf enabled, TAB characters and trailing whitespace will be
visualized by a small dot.set-indent-spacesBOOLEAN enableIf enabled, the editor will indent with
spaces for each indentation level, rather than
with one TAB character.set-mixed-indentBOOLEAN enableIf enabled, kate will use a mix of TAB and spaces for
indentation. Each indentation level will be wide,
and more indentation levels will be optimized to use as many TAB characters as
possible.When executed, this command will additionally set space indentation enabled,
and if the indent width is unspecified it will be set to half of the
for the document at the time of execution.set-word-wrapBOOLEAN
enableEnables dynamic word wrap according to
enableset-replace-tabs-saveBOOLEAN enable
When enabled, tabs will be replaced with whitespaces whenever
the document is saved.set-remove-trailing-space-saveBOOLEAN enableWhen enabled, trailing space will be removed from each line
whenever the document is saved.set-indent-modenameSets the autoindentation mode to name.
If name is not known, the mode is set to 'none'. Valid
modes are 'cstyle', 'csands', 'xml', 'python', 'varindent' and 'none'.set-highlighthighlightSets the syntax highlighting system for the document. The
argument must be a valid highlight name, as seen in the
ToolsHighlighting
menu. This command provides an autocompletion list for its
argument.Commands for editingThese commands modify the current document.indentIndents the selected lines or the current line.unindentUnindents the selected lines or current line.cleanindentCleans up the indentation of the selected lines or current line
according to the indentation settings in the document.
commentInserts comment markers to make the selection or selected lines
or current line a comment according to the text format as defined by the syntax
highlight definition for the document.uncommentRemoves comment markers from the selection or selected lines
or current line according to the text format as defined by the syntax highlight
definition for the document.kill-lineDeletes the current line.replacepatternreplacementReplaces text matching pattern with
replacement. If you want to include whitespace in the
pattern, you must quote both the pattern
and replacement with single or double quotes. If the
arguments are unquoted, the first word is used as pattern
and the rest for replacement. If
replacement is empty, each occurrence of
pattern is removed.You can set flags to configure the search by adding a colon, followed
by one or more letters each representing a configuration, giving the form
replace:options pattern replacement. Available options
are:
bSearch backwards.cSearch from cursor position.eSearch in the selection only.rDo regular expression search. If set, you may use
\N where N is a number to represent captures in the
replacement string.sDo case sensitive search.pPrompt for permission to replace the next occurence.wMatch whole words only.dateformatInserts a date/time string as defined by the specified
format, or the format yyyy-MM-dd hh:mm:ss
if none is specified. The following translations are done when interpreting
format:
dThe day as number without a leading zero (1-31).ddThe day as number with a leading zero (01-31).dddThe abbreviated localized day name (e.g. 'Mon'..'Sun').ddddThe long localized day name (e.g. 'Monday'..'Sunday').MThe month as number without a leading zero (1-12).MMThe month as number with a leading zero (01-12).MMMThe abbreviated localized month name (e.g. 'Jan'..'Dec').yyThe year as two digit number
(00-99).yyyyThe year as four digit number (1752-8000).hThe hour without a leading zero (0..23 or 1..12 if AM/PM display).hhThe hour with a leading zero (00..23 or 01..12 if AM/PM display).mThe minute without a leading zero (0..59).mmThe minute with a leading zero (00..59).sThe second without a leading zero (0..59).ssThe second with a leading zero (00..59).zThe milliseconds without leading zeroes (0..999).zzzThe milliseconds with leading zeroes (000..999).APUse AM/PM display. AP will be replaced by either "AM" or "PM".apUse am/pm display. ap will be replaced by either "am" or "pm".charidentifierThis command allows you to insert literal characters by their
numerical identifier, in decimal, octal or hexadecimal form.
To use it launch the Editing Command dialog and type char:
[number] in the entry box, then hit
OK.char examplesInput: char:234Output: êInput: char:0x1234Output: ሴreplace, sed stylesearch, sed styles///[ig] and %s///[ig]This command does a sed-like search/replace operation on the
current line, or on the whole file (%s///).In short, &kate; searches for text matching the
search pattern (the regular expression between
the first and the second slash), and when a match is found the
matching part of the text is replaced with the expression between the
middle and last slash. Parenthesis in the search pattern
create back references, that is the command
remembers which part of the text matched in the parenthesis. These
strings can be reused in the replace pattern, referred to as
\1 for the first set of parenthesis,
\2 for the second and so on.To search for a literal ( or
), you need to escape it using
a backslash character: \(, \)If you put an i at the end of the
expression, the matching will be case insensitive. If you put a
g at the end, all occurrences of the pattern will be
replaced, otherwise only the first occurrence is replaced.Replacing text in the current lineYour friendly compiler just stopped, telling you that the class
myClass mentioned in line 3902 in your source file
is not defined."Buckle!" you think, it is of course
MyClass. You go to line 3902, and instead of trying
to find the word in the text, you launch the Editing Command Dialog,
enter s/myclass/MyClass/i, hit the
OK button, save the file and compile
successfully without the error.Replacing text in the whole fileImagine that you have a file, in which you mention a Miss
Jensen several times, when someone comes in and tells you that
she just got married to Mr. Jones. You want, of course,
to replace each and every occurrence of Miss Jensen
with Ms Jones.Enter the command line and issue the command
%s/Miss Jensen/Ms. Jones/ and hit enter, you
are done.Commands for navigationgotoINT lineThis command navigates to the specified line.findpatternThis command navigates to the first occurrence of
pattern according to the configuration. Following
occurrences can be found using
EditFind Next
(the default shortcut is F3).The find command can be configured by appending a colon followed by one or
more options, the form is
find:options pattern. The
following options are supported:
bSearch backwards.cSearch from cursor position.eSearch in the selection only.rDo regular expression search.sDo case sensitive search.wMatch whole words only.ifindpatternThis command provides incremental (as-you-type) searching. You
can configure the behavior of the search by appending a colon
followed by one or more options, like this:
ifind:options pattern. Allowed options are:
bSearch backwards.rDo regular expression search.sDo case sensitive search.cSearch from cursor position.Using Code FoldingCode folding allows you to hide parts of a document in the editor, making
it easier to overview large documents. In &kate; the foldable regions are
calculated using rules defined in the syntax highlight definitions and
therefore it is only available in some file formats - typically program source code,
XML markup and similar. Most highlight definition files supporting code folding
also let you manually define foldable regions, typically using the
BEGIN and END keywords.To use the code folding feature, activate the folding markers using
ViewShow Folding
Markers menu item if they are not already visible.
The Folding Markers Pane in the left side of the screen displays a graphical
view of the foldable regions, with +/- signs to indicate the possible operation
on a given region. A - means that the region is expanded; clicking on the - will
collapse the region and a + will be displayed instead.Four commands are provided to manipulate the state of folding regions,
see the menu documentation for details.
If you do not want to use the code folding feature, you can disable it
completely using the Show folding markers (if available) option in the
Editor Appearance configuration pageScripting the editor with JSIntroductionStarting with version 2.5, the &kate; editor component supports
scripting with ECMA script, also known as JavaScript.Scripts can be used through the built-in command line
only. The requirements are that the scripts are placed in a folder where &kate;
can find them, along with an optional .desktop file that defines the related
properties. The valid folders are named katepart/scripts
in the &tde; data folders. You can find the data folders by running the command
tde-config data.
You will usually have at least a system and a personal data folder. Of course
scripts in the system data folder are available to all users on the system,
while those in the personal folder are available to you only.The Kate JavaScript APIHere is the complete set of functions and properties available
in the document and view objects.
In addition, you can use all the standard objects such as
Math, StringRegex and so forth.When a script is run, the document object is the
current document, and the view object is the current
view.Types are not used in JavaScript. In this list, they are
there solely to indicate what sort of arguments the functions expect.Global Functionsdebug(string s)
functionparameterss the string to output.Outputs the string to STDERR using
kdDebug(). A dedicated output area is used for the output,
which will be prefixed by "Kate (KJS Scripts):"
The document APIdocument.attribute(uint line,
uint column)
functionParametersline the line of the position for which
to find the attribute.column the column of the position for
which to find the attribute.Returns the numeric ID of the attribute for the document position
[line, column]. The attribute
represents the visual appearance or style of the text, and is also used to
calculate the syntax highlight for a specific part of the text in mixed formats
like HTML or PHP.document.canBreakAt(char c,
attribute attrib) functionParametersc the character to test.attrib the attribute at the position
of c.Returns whether it is allowed to break the line at the character
c with attribute attribute.document.canComment(attribute start_attrib,
attribute end_attrib) functionParametersstart_attrib the attribute at the
start of the range to turn into a comment.end_attrib the attribute at end of
the range to turn into a comment.Returns whether start_attribute and
end_attribute belongs to the same
syntax highlight system. If they do, it is possible to comment the block.
document.clear() functionClears the document.document.commentStart(attribute attrib)
functionParametersattrib the attribute of the text for
which to get the commentStart string.Returns the string required to start a multiline comment for a text with
attribute attrib, or an empty string if multiline comments are not supported for that
text.document.commentMarker(attribute attrib)
functionParametersattrib the attribute of the text for
which to get the commentMarker string.Returns the string used to mark the rest of the line as a comment for a
text with attribute attrib or an empty string if single
line comments are not supported for that text.document.commentEnd(attribute attrib)
functionParametersattrib the attribute of the text for
which to get the commentEnd string.Returns the string required to end a multiline comment for a text with
attribute attrib, or an empty string if multiline
comments are not supported for that text.document.editBegin() functionStarts an editing group. All actions done until the call to editEnd() will
be grouped as a single undo action.document.editEnd() functionEnds an editing group.document.highlightMode property, read onlyThe name of the document's highlight mode, such as JavaScript or C++.
If no syntax highlight mode is set for the document, the value is none.
Notice that you need to use the English name in cases where it differs from the
translated one.document.indentMode property, read onlyThe name of the document indent mode, such as
normal or cstyle.
If no indent mode is set, the value is none.
document.indentWidth property, read onlyThe indentation width set for the document. This is used if space
indenting is enabled.document.insertLine(uint line,
string text) functionParametersline the document line number.text the text to insert.Inserts a new line with the text text at the
line line.document.insertText(uint line,
uint column, string text)
functionParametersline the line number.column the column number.text the text to insert.Inserts the text text in line
line at column column.document.length() functionReturns the document's size in bytes.document.lines() functionReturns the number of lines in the document.document.mixedIndent property, read onlyA boolean telling whether the mixed-indent setting is enabled for the
document. If so, indentation is optimized to contain a mix of tab characters and
spaces like in the Emacs editor.document.removeLine(uint line) functionParametersline the line number.Removes the document line line.document.removeText(uint startLine,
uint startColumn, uint endLine,
uint endColumn) functionParametersstartLine specifies the beginning line.startColumn specifies the beginning column.endLine specifies the ending line.endColumn specifies the ending column.Removes the text range from line startLine and
column startColumn to line
endLine and column endColumn.
document.setText(string text)
functionParameterstext the new document text.Sets the entire document content to text.document.spaceIndent property, read onlyA boolean telling whether space-indent is enabled for the document.
If so, the document is indented with indentWidth spaces per level, otherwise
indentation is one tab character per level.document.textFull() functionReturns the full document text. If the text spans over multiple lines the
linefeed character is \n.document.textLine(uint line) functionParametersline the line number.Returns the text at line line.document.textRange(uint startLine,
uint startColumn, uint endLine,
uint endColumn) functionParametersstartLine specifies the beginning line.startColumn specifies the beginning column.endLine specifies the ending line.endColumn specifies the ending column.Returns the specified text range. If the range spans over multiple lines
the linefeed character is \n.The view APIview.clearSelection() functionDeselects all text.view.cursorColumn() functionReturns the current cursor column (TAB characters are expanded).view.cursorColumnReal() functionReturns the current real cursor column (a TAB character counts as one).view.cursorLine() functionReturns the current cursor line.view.hasSelection() functionReturns true if some text in the view has been selected,
otherwise false.view.removeSelectedText() functionRemoves the selected text, if the view has a selection.view.selectAll() functionSelects all text.view.selection() functionReturns the selected text. If the selection spans over multiple lines the
linefeed character is \n.view.selectionEndColumn property, read onlyReturns the ending column of the selection.view.selectionEndLine property, read onlyReturns the ending line of the selection.view.selectionStartColumn property, read onlyReturns the starting column of the selection.view.selectionStartLine property, read onlyReturns the starting line of the selection.view.setCursorPosition(uint line,
uint column) functionParametersline specifies the new line for the cursor.column specifies the new column for the cursor.Sets the input cursor position in the view to (line,
column). TAB characters are expanded and
the cursor position is made visible. Both line
and column are zero-based.view.setCursorPositionReal(uint line,
uint column) functionParametersline specifies the new line for the cursor.column specifies the new column for the cursor.Sets the input cursor position to (line,
column). This sets the string position, that is a TAB
character counts for 1, and the cursor position is made visible. Both line
and column are zero-based.view.setSelection(uint startLine,
uint startColumn, uint endLine,
uint endColumn) functionParametersstartLine specifies the beginning line.startColumn specifies the beginning column.endLine specifies the ending line.endColumn specifies the ending column.Sets a selection from line startLine and column
startColumn to line endLine
and column endColumn.A sample scriptAs an example we will create a small script that transforms the selected
text to upper case. We first need to check whether a selection exists: if so we
get the text, change the case and then replace the original text with the new one.
An implementation would look something like this:
if (view.hasSelection())
{
// uppercase selection
column = view.selectionStartColumn;
line = view.selectionStartLine;
selection = view.selection().toUpperCase();
document.editBegin();
view.removeSelectedText();
document.insertText(line, column, selection);
document.editEnd();
}
To group this actions together so that they will be reverted by a single
activation of Undo, we encapsulate the lines
view.removeSelectedText()
document.insertText()
in a document.editBegin() -
document.editEnd() block.A sample .desktop fileHere is a sample .desktop file that accompanies the above script.
# Example of a .desktop file
[Desktop Entry]
Encoding=UTF-8
Name=Kate Part JavaScript Uppercase Script
Comment=Script to transform the selected text to upper case
X-Kate-Command=uppercase-selection
X-Kate-Help=<p>Usage: <code>uppercase-selection</code></p>
As you can see you can define the Encoding, set a Name, a Comment, a help
text using X-Kate-Help and the command line name via X-Kate-Command.Putting it all together&kate; will search the script folders (see above) for
.js files. For every such file found, &kate; will check
whether there is a corresponding .desktop file with
the same basename (for example script.js and script.desktop).If a corresponding .desktop file exists, the script
will be registered using the name from the .desktop entry X-Kate-Command.If a corresponding .desktop file can not be found, the script will
be registered with the file basename (i.e. without the ending .js).
If you only need the command name and none of the extra features
that a .desktop file would provide, you do not need a
.desktop file at all.