Warning, /utilities/kate/doc/katepart/development.docbook is written in an unsupported language. File is not indexed.

0001 <!-- auto-generate scripting documentation (kwrite-devel@kde.org Re: [kate] doc/kate: document most of the new scripts in 4.10) -->
0002 <chapter id="dev">
0003 <chapterinfo>
0004 <authorgroup>
0005 <author>&TC.Hollingsworth; &TC.Hollingsworth.mail;</author>
0006 <!-- TRANS:ROLES_OF_TRANSLATORS -->
0007 </authorgroup>
0008 </chapterinfo>
0009 <title>Extending &katepart;</title>
0010 
0011 <sect1 id="dev-intro">
0012 <title>Introduction</title>
0013 
0014 <para>Like any advanced text editor component, &katepart; offers a variety of
0015 ways to extend its functionality.  You can <link linkend="dev-scripting">write
0016 simple scripts to add functionality with &javascript;</link>.
0017 Finally, once you have extended &katepart;, you are
0018 welcome to <ulink url="https://kate-editor.org/join-us/">join us</ulink>
0019 and share your enhancements with the world!</para>
0020 
0021 </sect1>
0022 
0023 <sect1 id="highlight">
0024 <title>Working with Syntax Highlighting</title>
0025 
0026 <sect2 id="highlight-overview">
0027 
0028 <title>Overview</title>
0029 
0030 <para>Syntax Highlighting is what makes the editor automatically
0031 display text in different styles/colors, depending on the function of
0032 the string in relation to the purpose of the file.  In program source
0033 code for example, control statements may be rendered bold, while data
0034 types and comments get different colors from the rest of the
0035 text. This greatly enhances the readability of the text, and thus
0036 helps the author to be more efficient and productive.</para>
0037 
0038 <mediaobject>
0039 <imageobject><imagedata format="PNG" fileref="highlighted.png"/></imageobject>
0040 <textobject><phrase>A C++ function, rendered with syntax
0041 highlighting.</phrase></textobject>
0042 <caption><para>A C++ function, rendered with syntax highlighting.</para>
0043 </caption>
0044 </mediaobject>
0045 
0046 <mediaobject>
0047 <imageobject><imagedata format="PNG" fileref="unhighlighted.png"/></imageobject>
0048 <textobject><phrase>The same C++ function, without
0049 highlighting.</phrase></textobject>
0050 <caption><para>The same C++ function, without highlighting.</para></caption>
0051 </mediaobject>
0052 
0053 <para>Of the two examples, which is easiest to read?</para>
0054 
0055 <para>&kappname; comes with a flexible, configurable and capable system
0056 for doing syntax highlighting, and the standard distribution provides
0057 definitions for a wide range of programming, scripting and markup
0058 languages and other text file formats. In addition you can
0059 provide your own definitions in simple &XML; files.</para>
0060 
0061 <para>&kappname; will automatically detect the right syntax rules when you
0062 open a file, based on the &MIME; Type of the file, determined by its
0063 extension, or, if it has none, the contents. Should you experience a
0064 bad choice, you can manually set the syntax to use from the
0065 <menuchoice><guimenu>Tools</guimenu><guisubmenu>Highlighting
0066 </guisubmenu></menuchoice> menu.</para>
0067 
0068 <para>The styles and colors used by each syntax highlight definition
0069 can be configured using the <link
0070 linkend="prefcolors-highlighting-text-styles">Highlighting Text Styles</link> tab of the
0071 <link linkend="config-dialog">Config Dialog</link>, while the &MIME; Types and
0072 file extensions it should be used for are handled by the <link
0073 linkend="pref-open-save-modes-filetypes">Modes &amp; Filetypes</link>
0074 tab.</para>
0075 
0076 <note>
0077 <para>Syntax highlighting is there to enhance the readability of
0078 correct text, but you cannot trust it to validate your text. Marking
0079 text for syntax is difficult depending on the format you are using,
0080 and in some cases the authors of the syntax rules will be proud if 98%
0081 of text gets correctly rendered, though most often you need a rare
0082 style to see the incorrect 2%.</para>
0083 </note>
0084 
0085 </sect2>
0086 
0087 <sect2 id="katehighlight-system">
0088 
0089 <title>The &kappname; Syntax Highlight System</title>
0090 
0091 <para>This section will discuss the &kappname; syntax highlighting
0092 mechanism in more detail. It is for you if you want to know about
0093 it, or if you want to change or create syntax definitions.</para>
0094 
0095 <sect3 id="katehighlight-howitworks">
0096 
0097 <title>How it Works</title>
0098 
0099 <para>Whenever you open a file, one of the first things the &kappname;
0100 editor does is detect which syntax definition to use for the
0101 file. While reading the text of the file, and while you type away in
0102 it, the syntax highlighting system will analyze the text using the
0103 rules defined by the syntax definition and mark in it where different
0104 contexts and styles begin and end.</para>
0105 
0106 <para>When you type in the document, the new text is analyzed and marked on the
0107 fly, so that if you delete a character that is marked as the beginning or end
0108 of a context, the style of surrounding text changes accordingly.</para>
0109 
0110 <para>The syntax definitions used by the &kappname; Syntax Highlighting System are
0111 &XML; files, containing
0112 <itemizedlist>
0113 <listitem><para>Rules for detecting the role of text, organized into context blocks</para></listitem>
0114 <listitem><para>Keyword lists</para></listitem>
0115 <listitem><para>Style Item definitions</para></listitem>
0116 </itemizedlist>
0117 </para>
0118 
0119 <para>When analyzing the text, the detection rules are evaluated in
0120 the order in which they are defined, and if the beginning of the
0121 current string matches a rule, the related context is used. The start
0122 point in the text is moved to the final point at which that rule
0123 matched and a new loop of the rules begins, starting in the context
0124 set by the matched rule.</para>
0125 
0126 </sect3>
0127 
0128 <sect3 id="highlight-system-rules">
0129 <title>Rules</title>
0130 
0131 <para>The detection rules are the heart of the highlighting detection
0132 system. A rule is a string, character or <link
0133 linkend="regular-expressions">regular expression</link> against which
0134 to match the text being analyzed. It contains information about which
0135 style to use for the matching part of the text. It may switch the
0136 working context of the system either to an explicitly mentioned
0137 context or to the previous context used by the text.</para>
0138 
0139 <para>Rules are organized in context groups. A context group is used
0140 for main text concepts within the format, for example quoted text
0141 strings or comment blocks in program source code. This ensures that
0142 the highlighting system does not need to loop through all rules when
0143 it is not necessary, and that some character sequences in the text can
0144 be treated differently depending on the current context.
0145 </para>
0146 
0147 <para>Contexts may be generated dynamically to allow the usage of instance
0148 specific data in rules.</para>
0149 
0150 </sect3>
0151 
0152 <sect3 id="highlight-context-styles-keywords">
0153 <title>Context Styles and Keywords</title>
0154 
0155 <para>In some programming languages, integer numbers are treated
0156 differently from floating point ones by the compiler (the program that
0157 converts the source code to a binary executable), and there may be
0158 characters having a special meaning within a quoted string. In such
0159 cases, it makes sense to render them differently from the surroundings
0160 so that they are easy to identify while reading the text. So even if
0161 they do not represent special contexts, they may be seen as such by
0162 the syntax highlighting system, so that they can be marked for
0163 different rendering.</para>
0164 
0165 <para>A syntax definition may contain as many styles as required to
0166 cover the concepts of the format it is used for.</para>
0167 
0168 <para>In many formats, there are lists of words that represent a
0169 specific concept. For example, in programming languages, control
0170 statements are one concept, data type names another, and built in
0171 functions of the language a third. The &kappname; Syntax Highlighting
0172 System can use such lists to detect and mark words in the text to
0173 emphasize concepts of the text formats.</para>
0174 
0175 </sect3>
0176 
0177 <sect3 id="kate-highlight-system-default-styles">
0178 <title>Default Styles</title>
0179 
0180 <para>If you open a C++ source file, a &Java; source file and an
0181 &HTML; document in &kappname;, you will see that even
0182 though the formats are different, and thus different words are chosen
0183 for special treatment, the colors used are the same. This is because
0184 &kappname; has a predefined list of Default Styles which are employed by
0185 the individual syntax definitions.</para>
0186 
0187 <para>This makes it easy to recognize similar concepts in different
0188 text formats. For example, comments are present in almost any
0189 programming, scripting or markup language, and when they are rendered
0190 using the same style in all languages, you do not have to stop and
0191 think to identify them within the text.</para>
0192 
0193 <tip>
0194 <para>All styles in a syntax definition use one of the default
0195 styles. A few syntax definitions use more styles than there are
0196 defaults, so if you use a format often, it may be worth launching the
0197 configuration dialog to see if some concepts use the same
0198 style. For example, there is only one default style for strings, but as
0199 the Perl programming language operates with two types of strings, you
0200 can enhance the highlighting by configuring those to be slightly
0201 different. All <link linkend="kate-highlight-default-styles">available default styles</link>
0202 will be explained later.</para>
0203 </tip>
0204 
0205 </sect3>
0206 
0207 </sect2>
0208 
0209 <sect2 id="katehighlight-xml-format">
0210 <title>The Highlight Definition &XML; Format</title>
0211 
0212 <sect3>
0213 <title>Overview</title>
0214 
0215 <para>&kappname; uses the Syntax-Highlighting framework from &kde-frameworks;.
0216 The default highlighting &XML; files shipped with &kappname; are compiled
0217 into the Syntax-Highlighting library by default.
0218 </para>
0219 
0220 <para>This section is an overview of the Highlight Definition &XML;
0221 format. Based on a small example it will describe the main components
0222 and their meaning and usage. The next section will go into detail with
0223 the highlight detection rules.</para>
0224 
0225 <para>The formal definition, also known as the <acronym>XSD</acronym> you
0226 find in <ulink url="https://commits.kde.org/syntax-highlighting?path=data/schema">Syntax
0227 Highlighting repository</ulink> in the file <filename>language.xsd</filename>
0228 </para>
0229 
0230 <para>Custom <filename class="extension">.xml</filename> highlight definition files are
0231 located in <filename class="directory">org.kde.syntax-highlighting/syntax/</filename> in
0232 your user folder found with <userinput><command>qtpaths</command><option> --paths
0233 GenericDataLocation</option></userinput> which usually are
0234 <filename class="directory"><envar>$HOME</envar>/.local/share/</filename>
0235 and <filename class="directory">/usr/share/</filename>.
0236 </para>
0237 
0238 <para>In Flatpak and Snap packages, the above directory will not work
0239 as the data location is different for each application.
0240 In a Flatpak application, the location of custom &XML; files is usually
0241 <filename class="directory"><envar>$HOME</envar>/.var/app/<replaceable>flatpak-package-name</replaceable>/data/org.kde.syntax-highlighting/syntax/</filename>
0242 and in a Snap application that location is
0243 <filename class="directory"><envar>$HOME</envar>/snap/<replaceable>snap-package-name</replaceable>/current/.local/share/org.kde.syntax-highlighting/syntax/</filename>.
0244 </para>
0245 
0246 <para>On &Windows; these files are located <filename>%USERPROFILE%&#92;AppData&#92;Local&#92;org.kde.syntax-highlighting&#92;syntax</filename>.
0247 <replaceable>%USERPROFILE%</replaceable> usually expands to <filename>C:&#92;Users&#92;<replaceable>user</replaceable></filename>.</para>
0248 
0249 <para>In summary, for most configurations the directory of custom &XML;
0250 files is as follows:</para>
0251 
0252 <informaltable>
0253 <tgroup cols="2">
0254 <tbody>
0255 <row>
0256 <entry>For local user</entry>
0257 <entry><filename class="directory"><envar>$HOME</envar>/.local/share/org.kde.syntax-highlighting/syntax/</filename></entry>
0258 </row>
0259 <row>
0260 <entry>For all users</entry>
0261 <entry><filename class="directory">/usr/share/org.kde.syntax-highlighting/syntax/</filename></entry>
0262 </row>
0263 <row>
0264 <entry>For Flatpak packages</entry>
0265 <entry><filename class="directory"><envar>$HOME</envar>/.var/app/<replaceable>flatpak-package-name</replaceable>/data/org.kde.syntax-highlighting/syntax/</filename></entry>
0266 </row>
0267 <row>
0268 <entry>For Snap packages</entry>
0269 <entry><filename class="directory"><envar>$HOME</envar>/snap/<replaceable>snap-package-name</replaceable>/current/.local/share/org.kde.syntax-highlighting/syntax/</filename></entry>
0270 </row>
0271 <row>
0272 <entry>On &Windows;</entry>
0273 <entry><filename>%USERPROFILE%&#92;AppData&#92;Local&#92;org.kde.syntax-highlighting&#92;syntax</filename></entry>
0274 </row>
0275 </tbody>
0276 </tgroup>
0277 </informaltable>
0278 
0279 <para>If multiple files exist for the same language, the file with the highest <userinput>version</userinput> attribute in the <userinput>language</userinput> element will be loaded.</para>
0280 
0281 <variablelist>
0282 <title>Main sections of &kappname; Highlight Definition files</title>
0283 
0284 <varlistentry>
0285 <term>A highlighting file contains a header that sets the &XML; version:</term>
0286 <listitem>
0287 <programlisting>
0288 &lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
0289 </programlisting>
0290 </listitem>
0291 </varlistentry>
0292 
0293 <varlistentry>
0294 <term>The root of the definition file is the element <userinput>language</userinput>.
0295 Available attributes are:</term>
0296 
0297 <listitem>
0298 <para>Required attributes:</para>
0299 <para><userinput>name</userinput> sets the name of the language. It appears in the menus and dialogs afterwards.</para>
0300 <para><userinput>section</userinput> specifies the category.</para>
0301 <para><userinput>extensions</userinput> defines file extensions, such as &quot;*.cpp;*.h&quot;</para>
0302 <para><userinput>version</userinput> specifies the current revision of the definition file in terms of an integer number. Whenever you change a highlighting definition file, make sure to increase this number.</para>
0303 <para><userinput>kateversion</userinput> specifies the latest supported &kappname; version.</para>
0304 
0305 <para>Optional attributes:</para>
0306 <para><userinput>mimetype</userinput> associates files &MIME; type.</para>
0307 <para><userinput>casesensitive</userinput> defines, whether the keywords are case sensitive or not.</para>
0308 <para><userinput>priority</userinput> is necessary if another highlight definition file uses the same extensions. The higher priority will win.</para>
0309 <para><userinput>author</userinput> contains the name of the author and his email-address.</para>
0310 <para><userinput>license</userinput> contains the license, usually the MIT license for new syntax-highlighting files.</para>
0311 <para><userinput>style</userinput> contains the provided language and is used by the indenters for the attribute <literal>required-syntax-style</literal>.</para>
0312 <para><userinput>indenter</userinput> defines which indenter will be used by default. Available indenters are: <emphasis>ada, normal, cstyle, cmake, haskell, latex, lilypond, lisp, lua, pascal, python, replicode, ruby</emphasis> and <emphasis>xml</emphasis>.</para>
0313 <para><userinput>hidden</userinput> defines whether the name should appear in &kappname;'s menus.</para>
0314 <para>So the next line may look like this:</para>
0315 <programlisting>
0316 &lt;language name=&quot;C++&quot; version=&quot;1&quot; kateversion=&quot;2.4&quot; section=&quot;Sources&quot; extensions=&quot;*.cpp;*.h&quot; /&gt;
0317 </programlisting>
0318 </listitem>
0319 </varlistentry>
0320 
0321 
0322 <varlistentry>
0323 <term>Next comes the <userinput>highlighting</userinput> element, which
0324 contains the optional element <userinput>list</userinput> and the required
0325 elements <userinput>contexts</userinput> and <userinput>itemDatas</userinput>.</term>
0326 <listitem>
0327 <para><userinput>list</userinput> elements contain a list of keywords. In
0328 this case the keywords are <emphasis>class</emphasis> and <emphasis>const</emphasis>.
0329 You can add as many lists as you need.</para>
0330 <para>Since &kde-frameworks; 5.53, a list can include keywords from another
0331 list or language/file, using the <userinput>include</userinput> element.
0332 <userinput>##</userinput> is used to separate the list name and the language
0333 definition name, in the same way as in the <userinput>IncludeRules</userinput> rule.
0334 This is useful to avoid duplicating keyword lists, if you need to include the keywords
0335 of another language/file. For example, the <emphasis>othername</emphasis> list
0336 contains the <emphasis>str</emphasis> keyword and all the keywords of the
0337 <emphasis>types</emphasis> list, which belongs to the <emphasis>ISO C++</emphasis>
0338 language.</para>
0339 <para>The <userinput>contexts</userinput> element contains all contexts.
0340 The first context is by default the start of the highlighting. There are
0341 two rules in the context <emphasis>Normal Text</emphasis>, which match
0342 the list of keywords with the name <emphasis>somename</emphasis> and a
0343 rule that detects a quote and switches the context to <emphasis>string</emphasis>.
0344 To learn more about rules read the next chapter.</para>
0345 <para>The third part is the <userinput>itemDatas</userinput> element. It
0346 contains all color and font styles needed by the contexts and rules.
0347 In this example, the <userinput>itemData</userinput> <emphasis>Normal Text</emphasis>,
0348 <emphasis>String</emphasis> and <emphasis>Keyword</emphasis> are used.
0349 </para>
0350 <programlisting>
0351   &lt;highlighting&gt;
0352     &lt;list name=&quot;somename&quot;&gt;
0353       &lt;item&gt;class&lt;/item&gt;
0354       &lt;item&gt;const&lt;/item&gt;
0355     &lt;/list&gt;
0356     &lt;list name=&quot;othername&quot;&gt;
0357       &lt;item&gt;str&lt;/item&gt;
0358       &lt;include&gt;types##ISO C++&lt;/include&gt;
0359     &lt;/list&gt;
0360     &lt;contexts&gt;
0361       &lt;context attribute=&quot;Normal Text&quot; lineEndContext=&quot;#pop&quot; name=&quot;Normal Text&quot; &gt;
0362         &lt;keyword attribute=&quot;Keyword&quot; context=&quot;#stay&quot; String=&quot;somename&quot; /&gt;
0363         &lt;keyword attribute=&quot;Keyword&quot; context=&quot;#stay&quot; String=&quot;othername&quot; /&gt;
0364         &lt;DetectChar attribute=&quot;String&quot; context=&quot;string&quot; char=&quot;&amp;quot;&quot; /&gt;
0365       &lt;/context&gt;
0366       &lt;context attribute=&quot;String&quot; lineEndContext=&quot;#stay&quot; name=&quot;string&quot; &gt;
0367         &lt;DetectChar attribute=&quot;String&quot; context=&quot;#pop&quot; char=&quot;&amp;quot;&quot; /&gt;
0368       &lt;/context&gt;
0369     &lt;/contexts&gt;
0370     &lt;itemDatas&gt;
0371       &lt;itemData name=&quot;Normal Text&quot; defStyleNum=&quot;dsNormal&quot; /&gt;
0372       &lt;itemData name=&quot;Keyword&quot; defStyleNum=&quot;dsKeyword&quot; /&gt;
0373       &lt;itemData name=&quot;String&quot; defStyleNum=&quot;dsString&quot; /&gt;
0374     &lt;/itemDatas&gt;
0375   &lt;/highlighting&gt;
0376 </programlisting>
0377 </listitem>
0378 </varlistentry>
0379 
0380 <varlistentry>
0381 <term>The last part of a highlight definition is the optional
0382 <userinput>general</userinput> section. It may contain information
0383 about keywords, code folding, comments, indentation, empty lines and
0384 spell checking.</term>
0385 
0386 <listitem>
0387 <para>The <userinput>comment</userinput> section defines with what
0388 string a single line comment is introduced. You also can define a
0389 multiline comment using <emphasis>multiLine</emphasis> with the
0390 additional attribute <emphasis>end</emphasis>. This is used if the
0391 user presses the corresponding shortcut for <emphasis>comment/uncomment</emphasis>.</para>
0392 <para>The <userinput>keywords</userinput> section defines whether
0393 keyword lists are case sensitive or not. Other attributes will be
0394 explained later.</para>
0395 <para>The other sections, <userinput>folding</userinput>,
0396 <userinput>emptyLines</userinput> and <userinput>spellchecking</userinput>,
0397 are usually not necessary and are explained later.</para>
0398 <programlisting>
0399   &lt;general&gt;
0400     &lt;comments&gt;
0401       &lt;comment name="singleLine" start="#"/&gt;
0402       &lt;comment name="multiLine" start="###" end="###" region="CommentFolding"/&gt;
0403     &lt;/comments&gt;
0404     &lt;keywords casesensitive="1"/&gt;
0405     &lt;folding indentationsensitive="0"/&gt;
0406     &lt;emptyLines&gt;
0407       &lt;emptyLine regexpr="\s+"/&gt;
0408       &lt;emptyLine regexpr="\s*#.*"/&gt;
0409     &lt;/emptyLines&gt;
0410     &lt;spellchecking&gt;
0411       &lt;encoding char="&#225;" string="\&#39;a"/&gt;
0412       &lt;encoding char="&#224;" string="\&#96;a"/&gt;
0413     &lt;/spellchecking&gt;
0414   &lt;/general&gt;
0415 &lt;/language&gt;
0416 </programlisting>
0417 </listitem>
0418 </varlistentry>
0419 
0420 </variablelist>
0421 
0422 
0423 </sect3>
0424 
0425 <sect3 id="kate-highlight-sections">
0426 <title>The Sections in Detail</title>
0427 <para>This part will describe all available attributes for contexts,
0428 itemDatas, keywords, comments, code folding and indentation.</para>
0429 
0430 <variablelist>
0431 <varlistentry>
0432 <term>The element <userinput>context</userinput> belongs in the group
0433 <userinput>contexts</userinput>. A context itself defines context specific
0434 rules such as what should happen if the highlight system reaches the end of a
0435 line. Available attributes are:</term>
0436 
0437 
0438 <listitem>
0439 <para><userinput>name</userinput> states the context name. Rules will use this name
0440 to specify the context to switch to if the rule matches.</para>
0441 
0442 <para><userinput>attribute</userinput> identifies the style to use for a
0443 character when no rule matches or when a rule does not specify attribute.
0444 In the latter case, <emphasis>attribute</emphasis> of the context specified
0445 in the rule's <emphasis>context</emphasis> will be used.</para>
0446 
0447 <para><userinput>lineEndContext</userinput> defines the context the highlight
0448 system switches to if it reaches the end of a line. This may either be a name
0449 of another context, <userinput>#stay</userinput> to not switch the context
0450 (&eg;. do nothing) or <userinput>#pop</userinput> which will cause it to leave this
0451 context. It is possible to use for example <userinput>#pop#pop#pop</userinput>
0452 to pop three times, or even <userinput>#pop#pop!OtherContext</userinput> to pop
0453 two times and switch to the context named <userinput>OtherContext</userinput>.
0454 It is also possible to switch to a context that belongs to another language definition,
0455 in the same way as in the <userinput>IncludeRules</userinput> rules, &eg;,
0456 <userinput>SomeContext##JavaScript</userinput>.
0457 Context switches are also described in <xref linkend="kate-highlight-rules-detailled"/>.
0458 Default: #stay.</para>
0459 <para><userinput>lineEmptyContext</userinput> defines the context if an empty
0460 line is encountered. The nomenclature of context switches is the same as
0461 previously described in <emphasis>lineEndContext</emphasis>. Default: #stay.</para>
0462 <para><userinput>fallthroughContext</userinput> specifies the next context to
0463 switch to if no rule matches. The nomenclature of context switches is
0464 the same as previously described in <emphasis>lineEndContext</emphasis>.
0465 Default: #stay.</para>
0466 <para><userinput>fallthrough</userinput> defines if the highlight system switches
0467 to the context specified in <userinput>fallthroughContext</userinput> if no rule
0468 matches. Note that since &kde; &frameworks; 5.62 this attribute is deprecated
0469 in favor of <userinput>fallthroughContext</userinput>, since if the
0470 <userinput>fallthroughContext</userinput> attribute is present it is implicitly
0471 understood that the value of <userinput>fallthrough</userinput> is
0472 <emphasis>true</emphasis>. Default: <emphasis>false</emphasis>.</para>
0473 <para><userinput>noIndentationBasedFolding</userinput> disables indentation-based folding
0474 in the context. If indentation-based folding is not activated, this attribute is useless.
0475 This is defined in the element <emphasis>folding</emphasis> of the group <emphasis>general</emphasis>.
0476 Default: <emphasis>false</emphasis>.</para>
0477 </listitem>
0478 </varlistentry>
0479 
0480 
0481 <varlistentry>
0482 <term>The element <userinput>itemData</userinput> is in the group
0483 <userinput>itemDatas</userinput>. It defines the font style and colors.
0484 So it is possible to define your own styles and colors. However, we
0485 recommend you stick to the default styles if possible so that the user
0486 will always see the same colors used in different languages. Though,
0487 sometimes there is no other way and it is necessary to change color
0488 and font attributes. The attributes name and defStyleNum are required,
0489 the others are optional. Available attributes are:</term>
0490 
0491 <listitem>
0492 <para><userinput>name</userinput> sets the name of the itemData.
0493 Contexts and rules will use this name in their attribute
0494 <emphasis>attribute</emphasis> to reference an itemData.</para>
0495 <para><userinput>defStyleNum</userinput> defines which default style to use.
0496 Available default styles are explained in detail later.</para>
0497 <para><userinput>color</userinput> defines a color. Valid formats are
0498 '#rrggbb' or '#rgb'.</para>
0499 <para><userinput>selColor</userinput> defines the selection color.</para>
0500 <para><userinput>italic</userinput> if <emphasis>true</emphasis>, the text will be italic.</para>
0501 <para><userinput>bold</userinput> if <emphasis>true</emphasis>, the text will be bold.</para>
0502 <para><userinput>underline</userinput> if <emphasis>true</emphasis>, the text will be underlined.</para>
0503 <para><userinput>strikeout</userinput> if <emphasis>true</emphasis>, the text will be struck out.</para>
0504 <para><userinput>spellChecking</userinput> if <emphasis>true</emphasis>, the text will be spellchecked.</para>
0505 </listitem>
0506 </varlistentry>
0507 
0508 
0509 <varlistentry>
0510 <term>The element <userinput>keywords</userinput> in the group
0511 <userinput>general</userinput> defines keyword properties. Available attributes are:</term>
0512 
0513 <listitem>
0514 <para><userinput>casesensitive</userinput> may be <emphasis>true</emphasis>
0515 or <emphasis>false</emphasis>. If <emphasis>true</emphasis>, all keywords
0516 are matched case sensitively.</para>
0517 <para><userinput>weakDeliminator</userinput> is a list of characters that
0518 do not act as word delimiters. For example, the dot <userinput>'.'</userinput>
0519 is a word delimiter. Assume a keyword in a <userinput>list</userinput> contains
0520 a dot, it will only match if you specify the dot as a weak delimiter.</para>
0521 <para><userinput>additionalDeliminator</userinput> defines additional delimiters.</para>
0522 <para><userinput>wordWrapDeliminator</userinput> defines characters after which a
0523 line wrap may occur.</para>
0524 <para>Default delimiters and word wrap delimiters are the characters
0525 <userinput>.():!+,-&lt;=&gt;%&amp;*/;?[]^{|}~\</userinput>, space (<userinput>' '</userinput>)
0526 and tabulator (<userinput>'\t'</userinput>).</para>
0527 </listitem>
0528 </varlistentry>
0529 
0530 
0531 <varlistentry>
0532 <term>The element <userinput>comment</userinput> in the group
0533 <userinput>comments</userinput> defines comment properties which are used
0534 for <menuchoice><guimenu>Tools</guimenu><guimenuitem>Comment</guimenuitem></menuchoice>,
0535 <menuchoice><guimenu>Tools</guimenu><guimenuitem>Uncomment</guimenuitem></menuchoice> and
0536 <menuchoice><guimenu>Tools</guimenu><guimenuitem>Toggle Comment</guimenuitem></menuchoice>.
0537 Available attributes are:</term>
0538 
0539 <listitem>
0540 <para><userinput>name</userinput> is either <emphasis>singleLine</emphasis>
0541 or <emphasis>multiLine</emphasis>. If you choose <emphasis>multiLine</emphasis>
0542 the attributes <emphasis>end</emphasis> and <emphasis>region</emphasis> are
0543 required. If you choose <emphasis>singleLine</emphasis> you can add the optional
0544 attribute <emphasis>position</emphasis>.</para>
0545 <para><userinput>start</userinput> defines the string used to start a comment.
0546 In C++ this would be &quot;/*&quot; in multiline comments. This attribute is required
0547 for types <emphasis>multiLine</emphasis> and <emphasis>singleLine</emphasis>.</para>
0548 <para><userinput>end</userinput> defines the string used to close a comment.
0549 In C++ this would be &quot;*/&quot;. This attribute is only available and is
0550 required for comments of type <emphasis>multiLine</emphasis>.</para>
0551 <para><userinput>region</userinput> should be the name of the foldable
0552 multiline comment. Assume you have <emphasis>beginRegion="Comment"</emphasis>
0553 ... <emphasis>endRegion="Comment"</emphasis> in your rules, you should use
0554 <emphasis>region="Comment"</emphasis>. This way uncomment works even if you
0555 do not select all the text of the multiline comment. The cursor only must be
0556 in the multiline comment. This attribute is only available for type
0557 <emphasis>multiLine</emphasis>.</para>
0558 <para><userinput>position</userinput> defines where the single line comment is inserted.
0559 By default, the single line comment is placed at the beginning of the line at column 0,
0560 but if you use <emphasis>position="afterwhitespace"</emphasis> the comment is
0561 inserted after leading whitespaces right, before the first non-whitespace character.
0562 This is useful for putting comments correctly in languages where indentation
0563 is important, such as Python or YAML. This attribute is optional and the only
0564 possible value is <emphasis>afterwhitespace</emphasis>.
0565 This is only available for type <emphasis>singleLine</emphasis>.</para>
0566 </listitem>
0567 </varlistentry>
0568 
0569 
0570 <varlistentry>
0571 <term>The element <userinput>folding</userinput> in the group
0572 <userinput>general</userinput> defines code folding properties.
0573 Available attributes are:</term>
0574 
0575 <listitem>
0576 <para><userinput>indentationsensitive</userinput> if <emphasis>true</emphasis>, the code folding markers
0577 will be added indentation based, as in the scripting language Python. Usually you
0578 do not need to set it, as it defaults to <emphasis>false</emphasis>.</para>
0579 </listitem>
0580 </varlistentry>
0581 
0582 
0583 <varlistentry>
0584 <term>The element <userinput>emptyLine</userinput> in the group <userinput>emptyLines</userinput>
0585 defines which lines should be treated as empty lines. This allows modifying the behavior of the
0586 <emphasis>lineEmptyContext</emphasis> attribute in the elements <userinput>context</userinput>.
0587 Available attributes are:</term>
0588 
0589 <listitem>
0590 <para><userinput>regexpr</userinput> defines a regular expression that will be treated as an empty line.
0591 By default, empty lines do not contain any characters, therefore, this adds additional empty lines,
0592 for example, if you want lines with spaces to also be considered empty lines.
0593 However, in most syntax definitions you do not need to set this attribute.</para>
0594 </listitem>
0595 </varlistentry>
0596 
0597 
0598 <varlistentry>
0599 <term>The element <userinput>encoding</userinput> in the group <userinput>spellchecking</userinput>
0600 defines a character encoding for spell checking. Available attributes:</term>
0601 
0602 <listitem>
0603 <para><userinput>char</userinput> is a encoded character.</para>
0604 <para><userinput>string</userinput> is a sequence of characters that will be encoded as
0605 the character <emphasis>char</emphasis> in the spell checking.
0606 For example, in the language LaTeX, the string <userinput>\&quot;{A}</userinput> represents
0607 the character <userinput>&#196;</userinput>.</para>
0608 </listitem>
0609 </varlistentry>
0610 
0611 
0612 </variablelist>
0613 
0614 
0615 </sect3>
0616 
0617 <sect3 id="kate-highlight-default-styles">
0618 <title>Available Default Styles</title>
0619 <para>Default Styles were <link linkend="kate-highlight-system-default-styles">already explained</link>,
0620 as a short summary: Default styles are predefined font and color styles.</para>
0621 <variablelist>
0622 <varlistentry>
0623 <term>General default styles:</term>
0624 <listitem>
0625 <para><userinput>dsNormal</userinput>, when no special highlighting is required.</para>
0626 <para><userinput>dsKeyword</userinput>, built-in language keywords.</para>
0627 <para><userinput>dsFunction</userinput>, function calls and definitions.</para>
0628 <para><userinput>dsVariable</userinput>, if applicable: variable names (&eg; $someVar in PHP/Perl).</para>
0629 <para><userinput>dsControlFlow</userinput>, control flow keywords like if, else, switch, break, return, yield, ...</para>
0630 <para><userinput>dsOperator</userinput>, operators like + - * / :: &lt; &gt;</para>
0631 <para><userinput>dsBuiltIn</userinput>, built-in functions, classes, and objects.</para>
0632 <para><userinput>dsExtension</userinput>, common extensions, such as &Qt; classes and functions/macros in C++ and Python.</para>
0633 <para><userinput>dsPreprocessor</userinput>, preprocessor statements or macro definitions.</para>
0634 <para><userinput>dsAttribute</userinput>, annotations such as @override and __declspec(...).</para>
0635 </listitem>
0636 </varlistentry>
0637 
0638 <varlistentry>
0639 <term>String-related default styles:</term>
0640 <listitem>
0641 <para><userinput>dsChar</userinput>, single characters, such as 'x'.</para>
0642 <para><userinput>dsSpecialChar</userinput>, chars with special meaning in strings such as escapes, substitutions, or regex operators.</para>
0643 <para><userinput>dsString</userinput>, strings like "hello world".</para>
0644 <para><userinput>dsVerbatimString</userinput>, verbatim or raw strings like 'raw \backlash' in Perl, CoffeeScript, and shells, as well as r'\raw' in Python.</para>
0645 <para><userinput>dsSpecialString</userinput>, SQL, regexes, HERE docs, &latex; math mode, ...</para>
0646 <para><userinput>dsImport</userinput>, import, include, require of modules.</para>
0647 </listitem>
0648 </varlistentry>
0649 
0650 <varlistentry>
0651 <term>Number-related default styles:</term>
0652 <listitem>
0653 <para><userinput>dsDataType</userinput>, built-in data types like int, void, u64.</para>
0654 <para><userinput>dsDecVal</userinput>, decimal values.</para>
0655 <para><userinput>dsBaseN</userinput>, values with a base other than 10.</para>
0656 <para><userinput>dsFloat</userinput>, floating point values.</para>
0657 <para><userinput>dsConstant</userinput>, built-in and user defined constants like PI.</para>
0658 </listitem>
0659 </varlistentry>
0660 
0661 <varlistentry>
0662 <term>Comment and documentation-related default styles:</term>
0663 <listitem>
0664 <para><userinput>dsComment</userinput>, comments.</para>
0665 <para><userinput>dsDocumentation</userinput>, /** Documentation comments */ or """docstrings""".</para>
0666 <para><userinput>dsAnnotation</userinput>, documentation commands like @param, @brief.</para>
0667 <para><userinput>dsCommentVar</userinput>, the variable names used in above commands, like "foobar" in @param foobar.</para>
0668 <para><userinput>dsRegionMarker</userinput>, region markers like //BEGIN, //END in comments.</para>
0669 </listitem>
0670 </varlistentry>
0671 
0672 <varlistentry>
0673 <term>Other default styles:</term>
0674 <listitem>
0675 <para><userinput>dsInformation</userinput>, notes and tips like @note in doxygen.</para>
0676 <para><userinput>dsWarning</userinput>, warnings like @warning in doxygen.</para>
0677 <para><userinput>dsAlert</userinput>, special words like TODO, FIXME, XXXX.</para>
0678 <para><userinput>dsError</userinput>, error highlighting and wrong syntax.</para>
0679 <para><userinput>dsOthers</userinput>, when nothing else fits.</para>
0680 </listitem>
0681 </varlistentry>
0682 </variablelist>
0683 
0684 </sect3>
0685 
0686 </sect2>
0687 
0688 <sect2 id="kate-highlight-rules-detailled">
0689 <title>Highlight Detection Rules</title>
0690 
0691 <para>This section describes the syntax detection rules.</para>
0692 
0693 <para>Each rule can match zero or more characters at the beginning of
0694 the string they are tested against. If the rule matches, the matching
0695 characters are assigned the style or <emphasis>attribute</emphasis>
0696 defined by the rule, and a rule may ask that the current context is
0697 switched.</para>
0698 
0699 <para>A rule looks like this:</para>
0700 
0701 <programlisting>&lt;RuleName attribute=&quot;(identifier)&quot; context=&quot;(identifier)&quot; [rule specific attributes] /&gt;</programlisting>
0702 
0703 <para>The <emphasis>attribute</emphasis> identifies the style to use
0704 for matched characters by name, and the <emphasis>context</emphasis>
0705 identifies the context to use from here.</para>
0706 
0707 <para>The <emphasis>context</emphasis> can be identified by:</para>
0708 
0709 <itemizedlist>
0710 <listitem>
0711 <para>An <emphasis>identifier</emphasis>, which is the name of the other
0712 context.</para>
0713 </listitem>
0714 <listitem>
0715 <para>An <emphasis>order</emphasis> telling the engine to stay in the
0716 current context (<userinput>#stay</userinput>), or to pop back to a
0717 previous context used in the string (<userinput>#pop</userinput>).
0718 An empty or absent context is equivalent to <userinput>#stay</userinput>.</para>
0719 <para>To go back more steps, the #pop keyword can be repeated:
0720 <userinput>#pop#pop#pop</userinput></para>
0721 </listitem>
0722 <listitem>
0723 <para>An <emphasis>order</emphasis> followed by an exclamation mark
0724 (<emphasis>!</emphasis>) and an <emphasis>identifier</emphasis>, which
0725 will make the engine first follow the order and then switch to the
0726 other context, &eg; <userinput>#pop#pop!OtherContext</userinput>.</para>
0727 </listitem>
0728 <listitem>
0729 <para>An <emphasis>identifier</emphasis>, which is a context name,
0730 followed by two hashes (<userinput>##</userinput>) and another
0731 <emphasis>identifier</emphasis>, which is the name of a language definition.
0732 This naming is similar to that used in <userinput>IncludeRules</userinput>
0733 rules and allows you to switch to a context belonging to another syntax
0734 highlighting definition, e.g. <userinput>SomeContext##JavaScript</userinput>.
0735 </para>
0736 </listitem>
0737 </itemizedlist>
0738 
0739 <para>Rule specific attributes varies and are described in the
0740 following sections.</para>
0741 
0742 <itemizedlist>
0743 <title>Common attributes</title>
0744 <para>All rules have the following attributes in common and are
0745 available whenever <userinput>(common attributes)</userinput> appears.
0746 All attributes are optional.
0747 </para>
0748 
0749 <listitem>
0750 <para><emphasis>attribute</emphasis>: An attribute maps to a defined <emphasis>itemData</emphasis>. Default: <emphasis>attribute</emphasis> from the context specified in <emphasis>context</emphasis> attribute.</para>
0751 </listitem>
0752 <listitem>
0753 <para><emphasis>context</emphasis>: Specify the context to which the highlighting system switches if the rule matches. Default: #stay.</para>
0754 </listitem>
0755 <listitem>
0756 <para><emphasis>beginRegion</emphasis>: Start a code folding block. Default: unset.</para>
0757 </listitem>
0758 <listitem>
0759 <para><emphasis>endRegion</emphasis>: Close a code folding block. Default: unset.</para>
0760 </listitem>
0761 <listitem>
0762 <para><emphasis>lookAhead</emphasis>: If <emphasis>true</emphasis>, the
0763 highlighting system will not process the matches length.
0764 Default: <emphasis>false</emphasis>.</para>
0765 </listitem>
0766 <listitem>
0767 <para><emphasis>firstNonSpace</emphasis>: Match only, if the string is
0768 the first non-whitespace in the line. Default: <emphasis>false</emphasis>.</para>
0769 </listitem>
0770 <listitem>
0771 <para><emphasis>column</emphasis>: Match only, if the column matches. Default: unset.</para>
0772 </listitem>
0773 </itemizedlist>
0774 
0775 <itemizedlist>
0776 <title>Dynamic rules</title>
0777 <para>Some rules allow the optional attribute <userinput>dynamic</userinput>
0778 of type boolean that defaults to <emphasis>false</emphasis>. If dynamic is
0779 <emphasis>true</emphasis>, a rule can use placeholders representing the text
0780 matched by a <emphasis>regular expression</emphasis> rule that switched to the
0781 current context in its <userinput>string</userinput> or
0782 <userinput>char</userinput> attributes. In a <userinput>string</userinput>,
0783 the placeholder <replaceable>%N</replaceable> (where N is a number) will be
0784 replaced with the corresponding capture <replaceable>N</replaceable>
0785 from the calling regular expression, starting from 1. In a
0786 <userinput>char</userinput> the placeholder must be a number
0787 <replaceable>N</replaceable> and it will be replaced with the first character of
0788 the corresponding capture <replaceable>N</replaceable> from the calling regular
0789 expression. Whenever a rule allows this attribute it will contain a
0790 <emphasis>(dynamic)</emphasis>.</para>
0791 
0792 <listitem>
0793 <para><emphasis>dynamic</emphasis>: may be <emphasis>(true|false)</emphasis>.</para>
0794 </listitem>
0795 </itemizedlist>
0796 
0797 <para><userinput>How does it work:</userinput></para>
0798 
0799 <para>In the <link linkend="regular-expressions">regular expressions</link> of the
0800 <userinput>RegExpr</userinput> rules, all text within simple curved brackets
0801 <userinput>(PATTERN)</userinput> is captured and remembered.
0802 These captures can be used in the context to which it is switched, in the rules with the
0803 attribute <userinput>dynamic</userinput> <emphasis>true</emphasis>, by
0804 <replaceable>%N</replaceable> (in <emphasis>String</emphasis>) or
0805 <replaceable>N</replaceable> (in <emphasis>char</emphasis>).</para>
0806 
0807 <para>It is important to mention that a text captured in a <userinput>RegExpr</userinput> rule is
0808 only stored for the switched context, specified in its <userinput>context</userinput> attribute.</para>
0809 
0810 <tip>
0811 <itemizedlist>
0812 
0813 <listitem>
0814 <para>If the captures will not be used, both by dynamic rules and in the same regular expression,
0815 <userinput>non-capturing groups</userinput> should be used: <userinput>(?:PATTERN)</userinput></para>
0816 <para>The <emphasis>lookahead</emphasis> or <emphasis>lookbehind</emphasis> groups such as
0817 <userinput>(?=PATTERN)</userinput>, <userinput>(?!PATTERN)</userinput> or
0818 <userinput>(?&lt;=PATTERN)</userinput> are not captured.
0819 See <link linkend="regular-expressions">Regular Expressions</link> for more information.</para>
0820 </listitem>
0821 
0822 <listitem>
0823 <para>The capture groups can be used within the same regular expression,
0824 using <replaceable>\N</replaceable> instead of <replaceable>%N</replaceable> respectively.
0825 For more information, see <link linkend="regex-capturing">Capturing matching text (back references)</link>
0826 in <link linkend="regular-expressions">Regular Expressions</link>.</para>
0827 </listitem>
0828 
0829 </itemizedlist>
0830 </tip>
0831 
0832 <para>Example 1:</para>
0833 <para>In this simple example, the text matched by the regular expression
0834 <userinput>=*</userinput> is captured and inserted into <replaceable>%1</replaceable>
0835 in the dynamic rule. This allows the comment to end with the same amount of
0836 <userinput>=</userinput> as at the beginning. This matches text like:
0837 <userinput>[[ comment ]]</userinput>, <userinput>[=[ comment ]=]</userinput> or
0838 <userinput>[=====[ comment ]=====]</userinput>.</para>
0839 <para>In addition, the captures are available only in the switched context
0840 <emphasis>Multi-line Comment</emphasis>.</para>
0841 
0842 <programlisting>
0843 &lt;context name="Normal" attribute="Normal Text" lineEndContext="#stay"&gt;
0844   &lt;RegExpr context="Multi-line Comment" attribute="Comment" String="\[(=*)\[" beginRegion="RegionComment"/&gt;
0845 &lt;/context&gt;
0846 &lt;context name="Multi-line Comment" attribute="Comment" lineEndContext="#stay"&gt;
0847   &lt;StringDetect context="#pop" attribute="Comment" String="]%1]" dynamic="true" endRegion="RegionComment"/&gt;
0848 &lt;/context&gt;
0849 </programlisting>
0850 
0851 <para>Example 2:</para>
0852 <para>In the dynamic rule, <replaceable>%1</replaceable> corresponds to the capture that matches
0853 <userinput>#+</userinput>, and <replaceable>%2</replaceable> to <userinput>&amp;quot;+</userinput>.
0854 This matches text as: <userinput>#label""""inside the context""""#</userinput>.</para>
0855 <para>These captures will not be available in other contexts, such as
0856 <emphasis>OtherContext</emphasis>, <emphasis>FindEscapes</emphasis> or
0857 <emphasis>SomeContext</emphasis>.</para>
0858 
0859 <programlisting>
0860 &lt;context name="SomeContext" attribute="Normal Text" lineEndContext="#stay"&gt;
0861   &lt;RegExpr context="#pop!NamedString" attribute="String" String="(#+)(?:[\w-]|[^[:ascii:]])(&amp;quot;+)"/&gt;
0862 &lt;/context&gt;
0863 &lt;context name="NamedString" attribute="String" lineEndContext="#stay"&gt;
0864   &lt;RegExpr context="#pop!OtherContext" attribute="String" String="%2(?:%1)?" dynamic="true"/&gt;
0865   &lt;DetectChar context="FindEscapes" attribute="Escape" char="\"/&gt;
0866 &lt;/context&gt;
0867 </programlisting>
0868 
0869 <para>Example 3:</para>
0870 <para>This matches text like:
0871 <userinput>Class::function&lt;T&gt;( ... )</userinput>.</para>
0872 
0873 <programlisting>
0874 &lt;context name="Normal" attribute="Normal Text" lineEndContext="#stay"&gt;
0875   &lt;RegExpr context="FunctionName" lookAhead="true"
0876               String="\b([a-zA-Z_][\w-]*)(::)([a-zA-Z_][\w-]*)(?:&amp;lt;[\w\-\s]*&amp;gt;)?(\()"/&gt;
0877 &lt;/context&gt;
0878 &lt;context name="FunctionName" attribute="Normal Text" lineEndContext="#pop"&gt;
0879   &lt;StringDetect context="#stay" attribute="Class" String="%1" dynamic="true"/&gt;
0880   &lt;StringDetect context="#stay" attribute="Operator" String="%2" dynamic="true"/&gt;
0881   &lt;StringDetect context="#stay" attribute="Function" String="%3" dynamic="true"/&gt;
0882   &lt;DetectChar context="#pop" attribute="Normal Text" char="4" dynamic="true"/&gt;
0883 &lt;/context&gt;
0884 </programlisting>
0885 
0886 <itemizedlist>
0887 <title>Local deliminators</title>
0888 <para>Some rules allow the optional attributes <userinput>weakDeliminator</userinput>
0889 and <userinput>additionalDeliminator</userinput> which are combined with attributes
0890 of the same name of <userinput>keywords</userinput> tag. For example, when
0891 <userinput>'%'</userinput> is a weak delimiter of <userinput>keywords</userinput>,
0892 it can become a word delimiter only for a rule by putting it in its
0893 <userinput>additionalDeliminator</userinput> attribute. Whenever a rule allows these
0894 attributes it will contain a <emphasis>(local deliminators)</emphasis>.</para>
0895 
0896 <listitem>
0897 <para><emphasis>weakDeliminator</emphasis>: list of characters that do not act as word
0898 delimiters.</para>
0899 </listitem>
0900 <listitem>
0901 <para><emphasis>additionalDeliminator</emphasis>: defines additional delimiters.</para>
0902 </listitem>
0903 </itemizedlist>
0904 
0905 <sect3 id="highlighting-rules-in-detail">
0906 <title>The Rules in Detail</title>
0907 
0908 <variablelist>
0909 <varlistentry>
0910 <term>DetectChar</term>
0911 <listitem>
0912 <para>Detect a single specific character. Commonly used for example to
0913 find the ends of quoted strings.</para>
0914 <programlisting>&lt;DetectChar char=&quot;(character)&quot; (common attributes) (dynamic) /&gt;</programlisting>
0915 <para>The <userinput>char</userinput> attribute defines the character
0916 to match.</para>
0917 </listitem>
0918 </varlistentry>
0919 
0920 <varlistentry>
0921 <term>Detect2Chars</term>
0922 <listitem>
0923 <para>Detect two specific characters in a defined order.</para>
0924 <programlisting>&lt;Detect2Chars char=&quot;(character)&quot; char1=&quot;(character)&quot; (common attributes) /&gt;</programlisting>
0925 <para>The <userinput>char</userinput> attribute defines the first character to match,
0926 <userinput>char1</userinput> the second.</para>
0927 <para>This rule is present for historical reasons and for readability it's
0928 preferable to use <userinput>StringDetect</userinput>.</para>
0929 </listitem>
0930 </varlistentry>
0931 
0932 <varlistentry>
0933 <term>AnyChar</term>
0934 <listitem>
0935 <para>Detect one character of a set of specified characters.</para>
0936 <programlisting>&lt;AnyChar String=&quot;(string)&quot; (common attributes) /&gt;</programlisting>
0937 <para>The <userinput>String</userinput> attribute defines the set of
0938 characters.</para>
0939 </listitem>
0940 </varlistentry>
0941 
0942 <varlistentry>
0943 <term>StringDetect</term>
0944 <listitem>
0945 <para>Detect an exact string.</para>
0946 <programlisting>&lt;StringDetect String=&quot;(string)&quot; [insensitive=&quot;true|false&quot;] (common attributes) (dynamic) /&gt;</programlisting>
0947 <para>The <userinput>String</userinput> attribute defines the string
0948 to match. The <userinput>insensitive</userinput> attribute defaults to
0949 <emphasis>false</emphasis> and is passed to the string comparison
0950 function. If the value is <emphasis>true</emphasis> insensitive
0951 comparing is used.</para>
0952 </listitem>
0953 </varlistentry>
0954 
0955 <varlistentry>
0956 <term>WordDetect</term>
0957 <listitem>
0958 <para>Detect an exact string but additionally require word boundaries
0959 such as a dot <userinput>'.'</userinput> or a whitespace on the beginning
0960 and the end of the word. Think of <userinput>\b&lt;string&gt;\b</userinput>
0961 in terms of a regular expression, but it is faster than the rule <userinput>RegExpr</userinput>.</para>
0962 <programlisting>&lt;WordDetect String=&quot;(string)&quot; [insensitive=&quot;true|false&quot;] (common attributes) (local deliminators) /&gt;</programlisting>
0963 <para>The <userinput>String</userinput> attribute defines the string
0964 to match. The <userinput>insensitive</userinput> attribute defaults to
0965 <emphasis>false</emphasis> and is passed to the string comparison
0966 function. If the value is <emphasis>true</emphasis> insensitive
0967 comparing is used.</para>
0968 <para>Since: &kate; 3.5 (&kde; 4.5)</para>
0969 </listitem>
0970 </varlistentry>
0971 
0972 <varlistentry>
0973 <term>RegExpr</term>
0974 <listitem>
0975 <para>Matches against a regular expression.</para>
0976 <programlisting>&lt;RegExpr String=&quot;(string)&quot; [insensitive=&quot;true|false&quot;] [minimal=&quot;true|false&quot;] (common attributes) (dynamic) /&gt;</programlisting>
0977 <para>The <userinput>String</userinput> attribute defines the regular
0978 expression.</para>
0979 <para><userinput>insensitive</userinput> defaults to
0980 <emphasis>false</emphasis> and is passed to the regular expression
0981 engine.</para>
0982 <para><userinput>minimal</userinput> defaults to
0983 <emphasis>false</emphasis> and is passed to the regular expression
0984 engine.</para>
0985 <para>Because the rules are always matched against the beginning of
0986 the current string, a regular expression starting with a caret
0987 (<literal>^</literal>) indicates that the rule should only be
0988 matched against the start of a line.</para>
0989 <para>See <link linkend="regular-expressions">Regular Expressions</link>
0990 for more information on those.</para>
0991 </listitem>
0992 </varlistentry>
0993 
0994 <varlistentry>
0995 <term>keyword</term>
0996 <listitem>
0997 <para>Detect a keyword from a specified list.</para>
0998 <programlisting>&lt;keyword String=&quot;(list name)&quot; (common attributes) (local deliminators) /&gt;</programlisting>
0999 <para>The <userinput>String</userinput> attribute identifies the
1000 keyword list by name. A list with that name must exist.</para>
1001 <para>The highlighting system processes keyword rules in a very optimized way.
1002 This makes it an absolute necessity that any keywords to be matched need to be
1003 surrounded by defined delimiters, either implied (the default delimiters),
1004 or explicitly specified within the <emphasis>additionalDeliminator</emphasis>
1005 property of the <emphasis>keywords</emphasis> tag.</para>
1006 <para>If a keyword to be matched shall contain a delimiter character, this
1007 respective character must be added to the <emphasis>weakDeliminator</emphasis>
1008 property of the <emphasis>keywords</emphasis> tag.  This character will then
1009 loose its delimiter property in all <emphasis>keyword</emphasis> rules. It is
1010 also possible to use the <emphasis>weakDeliminator</emphasis> attribute of
1011 <emphasis>keyword</emphasis> so that this modification only applies to this
1012 rule.</para>
1013 </listitem>
1014 </varlistentry>
1015 
1016 <varlistentry>
1017 <term>Int</term>
1018 <listitem>
1019 <para>Detect an integer number (as the regular expression: <userinput>\b[0-9]+</userinput>).</para>
1020 <para><programlisting>&lt;Int (common attributes) (local deliminators) /&gt;</programlisting></para>
1021 <para>This rule has no specific attributes.</para>
1022 </listitem>
1023 </varlistentry>
1024 
1025 <varlistentry>
1026 <term>Float</term>
1027 <listitem>
1028 <para>Detect a floating point number (as the regular expression:
1029 <userinput>(\b[0-9]+\.[0-9]*|\.[0-9]+)([eE][-+]?[0-9]+)?</userinput>).</para>
1030 <para><programlisting>&lt;Float (common attributes) (local deliminators) /&gt;</programlisting></para>
1031 <para>This rule has no specific attributes.</para>
1032 </listitem>
1033 </varlistentry>
1034 
1035 <varlistentry>
1036 <term>HlCOct</term>
1037 <listitem>
1038 <para>Detect an octal point number representation (as the regular
1039 expression: <userinput>\b0[0-7]+</userinput>).</para>
1040 <para><programlisting>&lt;HlCOct (common attributes) (local deliminators) /&gt;</programlisting></para>
1041 <para>This rule has no specific attributes.</para>
1042 </listitem>
1043 </varlistentry>
1044 
1045 <varlistentry>
1046 <term>HlCHex</term>
1047 <listitem>
1048 <para>Detect a hexadecimal number representation (as a regular expression:
1049 <userinput>\b0[xX][0-9a-fA-F]+</userinput>).</para>
1050 <para><programlisting>&lt;HlCHex (common attributes) (local deliminators) /&gt;</programlisting></para>
1051 <para>This rule has no specific attributes.</para>
1052 </listitem>
1053 </varlistentry>
1054 
1055 <varlistentry>
1056 <term>HlCStringChar</term>
1057 <listitem>
1058 <para>Detect an escaped character.</para>
1059 <para><programlisting>&lt;HlCStringChar (common attributes) /&gt;</programlisting></para>
1060 <para>This rule has no specific attributes.</para>
1061 
1062 <para>It matches literal representations of characters commonly used in
1063 program code, for example <userinput>\n</userinput>
1064 (newline) or <userinput>\t</userinput> (TAB).</para>
1065 
1066 <para>The following characters will match if they follow a backslash
1067 (<literal>\</literal>):
1068 <userinput>abefnrtv&quot;'?\</userinput>. Additionally, escaped
1069 hexadecimal numbers such as for example <userinput>\xff</userinput> and
1070 escaped octal numbers, for example <userinput>\033</userinput> will
1071 match.</para>
1072 
1073 </listitem>
1074 </varlistentry>
1075 
1076 <varlistentry>
1077 <term>HlCChar</term>
1078 <listitem>
1079 <para>Detect an C character.</para>
1080 <para><programlisting>&lt;HlCChar (common attributes) /&gt;</programlisting></para>
1081 <para>This rule has no specific attributes.</para>
1082 
1083 <para>It matches C characters enclosed in a tick (Example: <userinput>'c'</userinput>).
1084 The ticks may be a simple character or an escaped character.
1085 See HlCStringChar for matched escaped character sequences.</para>
1086 
1087 </listitem>
1088 </varlistentry>
1089 
1090 <varlistentry>
1091 <term>RangeDetect</term>
1092 <listitem>
1093 <para>Detect a string with defined start and end characters.</para>
1094 <programlisting>&lt;RangeDetect char=&quot;(character)&quot;  char1=&quot;(character)&quot; (common attributes) /&gt;</programlisting>
1095 <para><userinput>char</userinput> defines the character starting the range,
1096 <userinput>char1</userinput> the character ending the range.</para>
1097 <para>Useful to detect for example small quoted strings and the like, but
1098 note that since the highlighting engine works on one line at a time, this
1099 will not find strings spanning over a line break.</para>
1100 </listitem>
1101 </varlistentry>
1102 
1103 <varlistentry>
1104 <term>LineContinue</term>
1105 <listitem>
1106 <para>Matches a specified char at the end of a line.</para>
1107 <programlisting>&lt;LineContinue (common attributes) [char="\"] /&gt;</programlisting>
1108 <para><userinput>char</userinput> optional character to match, default is
1109 backslash (<userinput>'\'</userinput>). New since &kde; 4.13.</para>
1110 <para>This rule is useful for switching context at end of line. This is needed for
1111  example in C/C++ to continue macros or strings.</para>
1112 </listitem>
1113 </varlistentry>
1114 
1115 <varlistentry>
1116 <term>IncludeRules</term>
1117 <listitem>
1118 <para>Include rules from another context or language/file.</para>
1119 <programlisting>&lt;IncludeRules context=&quot;contextlink&quot; [includeAttrib=&quot;true|false&quot;] /&gt;</programlisting>
1120 
1121 <para>The <userinput>context</userinput> attribute defines which context to include.</para>
1122 <para>If it is a simple string it includes all defined rules into the current context, example:
1123 <programlisting>&lt;IncludeRules context=&quot;anotherContext&quot; /&gt;</programlisting></para>
1124 
1125 <para>
1126 If the string contains a <userinput>##</userinput> the highlight system
1127 will look for a context from another language definition with the given name,
1128 for example
1129 <programlisting>&lt;IncludeRules context=&quot;String##C++&quot; /&gt;</programlisting>
1130 would include the context <emphasis>String</emphasis> from the <emphasis>C++</emphasis>
1131 highlighting definition.</para>
1132 <para>If <userinput>includeAttrib</userinput> attribute is
1133 <emphasis>true</emphasis>, change the destination attribute to the one of
1134 the source. This is required to make, for example, commenting work, if text
1135 matched by the included context is a different highlight from the host
1136 context.
1137 </para>
1138 </listitem>
1139 </varlistentry>
1140 
1141 
1142 <varlistentry>
1143 <term>DetectSpaces</term>
1144 <listitem>
1145 <para>Detect whitespaces.</para>
1146 <programlisting>&lt;DetectSpaces (common attributes) /&gt;</programlisting>
1147 
1148 <para>This rule has no specific attributes.</para>
1149 <para>Use this rule if you know that there can be several whitespaces ahead,
1150 for example in the beginning of indented lines. This rule will skip all
1151 whitespace at once, instead of testing multiple rules and skipping one at a
1152 time due to no match.</para>
1153 </listitem>
1154 </varlistentry>
1155 
1156 
1157 <varlistentry>
1158 <term>DetectIdentifier</term>
1159 <listitem>
1160 <para>Detect identifier strings (as the regular expression:
1161 <userinput>[a-zA-Z_][a-zA-Z0-9_]*</userinput>).</para>
1162 <programlisting>&lt;DetectIdentifier (common attributes) /&gt;</programlisting>
1163 
1164 <para>This rule has no specific attributes.</para>
1165 <para>Use this rule to skip a string of word characters at once, rather than
1166 testing with multiple rules and skipping one at a time due to no match.</para>
1167 </listitem>
1168 </varlistentry>
1169 
1170 </variablelist>
1171 </sect3>
1172 
1173 <sect3>
1174 <title>Tips &amp; Tricks</title>
1175 
1176 <itemizedlist>
1177 <para>Once you have understood how the context switching works it will be
1178 easy to write highlight definitions. Though you should carefully check what
1179 rule you choose in what situation. Regular expressions are very mighty, but
1180 they are slow compared to the other rules. So you may consider the following
1181 tips.
1182 </para>
1183 
1184 <listitem>
1185 <para>Regular expressions are easy to use but often there is another much
1186 faster way to achieve the same result. Consider you only want to match
1187 the character <userinput>'#'</userinput> if it is the first character in the
1188 line. A regular expression based solution would look like this:
1189 <programlisting>&lt;RegExpr attribute=&quot;Macro&quot; context=&quot;macro&quot; String=&quot;^\s*#&quot; /&gt;</programlisting>
1190 You can achieve the same much faster in using:
1191 <programlisting>&lt;DetectChar attribute=&quot;Macro&quot; context=&quot;macro&quot; char=&quot;#&quot; firstNonSpace=&quot;true&quot; /&gt;</programlisting>
1192 If you want to match the regular expression <userinput>'^#'</userinput> you
1193 can still use <userinput>DetectChar</userinput> with the attribute <userinput>column=&quot;0&quot;</userinput>.
1194 The attribute <userinput>column</userinput> counts characters, so a tabulator is only one character.
1195 </para>
1196 </listitem>
1197 <listitem>
1198 <para>In <userinput>RegExpr</userinput> rules, use the attribute <userinput>column="0"</userinput> if the pattern
1199 <userinput>^PATTERN</userinput> will be used to match text at the beginning of a line.
1200 This improves performance, as it will avoid looking for matches in the rest of the columns.</para>
1201 </listitem>
1202 <listitem>
1203 <para>In regular expressions, use non-capturing groups <userinput>(?:PATTERN)</userinput> instead of
1204 capturing groups <userinput>(PATTERN)</userinput>, if the captures will not be used in the same regular
1205 expression or in dynamic rules. This avoids storing captures unnecessarily.</para>
1206 </listitem>
1207 <listitem>
1208 <para>You can switch contexts without processing characters. Assume that you
1209 want to switch context when you meet the string <userinput>*/</userinput>, but
1210 need to process that string in the next context. The below rule will match, and
1211 the <userinput>lookAhead</userinput> attribute will cause the highlighter to
1212 keep the matched string for the next context.
1213 <programlisting>&lt;StringDetect attribute=&quot;Comment&quot; context=&quot;#pop&quot; String=&quot;*/&quot; lookAhead=&quot;true&quot; /&gt;</programlisting>
1214 </para>
1215 </listitem>
1216 <listitem>
1217 <para>Use <userinput>DetectSpaces</userinput> if you know that many whitespaces occur.</para>
1218 </listitem>
1219 <listitem>
1220 <para>Use <userinput>DetectIdentifier</userinput> instead of the regular expression <userinput>'[a-zA-Z_]\w*'</userinput>.</para>
1221 </listitem>
1222 <listitem>
1223 <para>Use default styles whenever you can. This way the user will find a familiar environment.</para>
1224 </listitem>
1225 <listitem>
1226 <para>Look into other &XML; files to see how other people implement tricky rules.</para>
1227 </listitem>
1228 <listitem>
1229 <para>You can validate every &XML; file by using the command
1230 <command>validatehl.sh mySyntax.xml</command>.
1231 The file <filename>validatehl.sh</filename> uses <filename>language.xsd</filename> which are both available in <ulink url="https://commits.kde.org/syntax-highlighting?path=data/schema">Syntax
1232 Highlighting repository</ulink>.
1233 </para>
1234 </listitem>
1235 <listitem>
1236 <para>If you repeat complex regular expression very often you can use
1237 <emphasis>ENTITIES</emphasis>. Example:</para>
1238 <programlisting>
1239 &lt;?xml version="1.0" encoding="UTF-8"?&gt;
1240 &lt;!DOCTYPE language
1241 [
1242         &lt;!ENTITY myref    "[A-Za-z_:][\w.:_-]*"&gt;
1243 ]&gt;
1244 </programlisting>
1245 <para>Now you can use <emphasis>&amp;myref;</emphasis> instead of the regular
1246 expression.</para>
1247 </listitem>
1248 <listitem>
1249 <para>On Kate Editor, you can reload syntaxes using the built-in command line
1250 (<userinput>F7</userinput> shortcut by default) and the <command>reload-highlighting</command>
1251 command.</para>
1252 </listitem>
1253 <listitem>
1254 <para>You can use the command-line utility named <userinput>ksyntaxhighlighter6</userinput>
1255 (<userinput>kate-syntax-highlighter</userinput> on older versions) to test a
1256 syntax and display the style and regions associated with each part of a text.</para>
1257 
1258 <mediaobject>
1259 <imageobject><imagedata format="PNG" fileref="ksyntaxhighlighter6-trace-format.png"/></imageobject>
1260 <textobject><phrase>Result of <command>ksyntaxhighlighter6 --output-format=ansi --syntax-trace=format test.cpp</command>.</phrase></textobject>
1261 <caption><para>Result of <command>ksyntaxhighlighter6 --output-format=ansi --syntax-trace=format test.cpp</command>.</para>
1262 </caption>
1263 </mediaobject>
1264 
1265 <para>Use <command>ksyntaxhighlighter6 -h</command> for more options.</para>
1266 </listitem>
1267 </itemizedlist>
1268 </sect3>
1269 
1270 </sect2>
1271 
1272 </sect1>
1273 
1274 
1275 <sect1 id="color-themes">
1276 <title>Working with Color Themes</title>
1277 
1278 <sect2 id="color-themes-overview">
1279 
1280 <title>Overview</title>
1281 
1282 <para>Color themes define the colors of the
1283 <link linkend="kate-part">text editing area</link> and the
1284 <link linkend="highlight">syntax highlighting</link>. A color
1285 theme encompasses the following:
1286 <itemizedlist>
1287 <listitem><para>The text style, used for syntax highlighting through the
1288 <emphasis>default styles attributes</emphasis>. For example, the text
1289 color and the selected text color.</para></listitem>
1290 <listitem><para>The background of the text editing area, including the text
1291 selection and the current line.</para></listitem>
1292 <listitem><para>The icon border of the text area: their background, the separator line,
1293 the line numbers, the line word wrap markers, the modified line marks and
1294 the code folding.</para></listitem>
1295 <listitem><para>Text decorators such as the search markers, the indentation and tab/space
1296 line marks, the bracket matching and the spell checking.</para></listitem>
1297 <listitem><para>Bookmarks and snippets.</para></listitem>
1298 </itemizedlist>
1299 </para>
1300 
1301 <para>To avoid confusion, the following is out of scope:
1302 <itemizedlist>
1303 <listitem><para>The font type and the font size.</para></listitem>
1304 <listitem><para>The colors of the text editing application, such as the scroll bar map, the menus,
1305 the tab bar, the window color, etc. In &kde; applications, like &kate; or &kdevelop;, these colors
1306 are defined by the <userinput>&kde; &plasma; global color scheme</userinput>, which are set in
1307 the <ulink url="help:/kcontrol/colors/"><quote>Colors</quote> module in &systemsettings;</ulink>
1308 or from the application itself in the menu
1309 <menuchoice><guimenu>Settings</guimenu><guisubmenu>Color Scheme</guisubmenu></menuchoice>.
1310 </para></listitem>
1311 </itemizedlist>
1312 </para>
1313 
1314 <mediaobject>
1315 <imageobject><imagedata format="PNG" fileref="breeze-color-theme-preview.png"/></imageobject>
1316 <textobject><phrase><quote>Breeze Light</quote> and <quote>Breeze Dark</quote> color themes
1317 with the <quote>C++</quote> syntax highlighting.</phrase>
1318 </textobject>
1319 <caption><para><quote>Breeze Light</quote> and <quote>Breeze Dark</quote> color themes
1320 with the <quote>C++</quote> syntax highlighting.</para>
1321 </caption>
1322 </mediaobject>
1323 
1324 </sect2>
1325 
1326 <sect2 id="color-themes-ksyntaxhighlighting">
1327 
1328 <title>The KSyntaxHighlighting Color Themes</title>
1329 
1330 <para>The <ulink url="https://api.kde.org/frameworks/syntax-highlighting/html/">KSyntaxHighlighting</ulink>
1331 framework, which is the <link linkend="highlight">syntax highlighting</link> engine,
1332 is the library that <userinput>provides and manages the color themes</userinput>.
1333 This is part of &kde; &frameworks; and is used in &kde; text editors such as
1334 <ulink url="https://apps.kde.org/en/kate">&kate;</ulink>,
1335 <ulink url="https://apps.kde.org/en/kwrite">&kwrite;</ulink>,
1336 <ulink url="https://apps.kde.org/en/kile">&kile;</ulink> and
1337 <ulink url="https://apps.kde.org/en/kdevelop">&kdevelop;</ulink>.
1338 This dependency looks like the following:</para>
1339 
1340 <mediaobject>
1341 <imageobject><imagedata format="PNG" fileref="kf5-ksyntaxhighlighting.png"/></imageobject>
1342 <textobject><phrase>Dependence of &kde; &frameworks; 5 libraries on text editors.</phrase></textobject>
1343 <caption><para>Dependence of &kde; &frameworks; libraries on text editors.</para>
1344 </caption>
1345 </mediaobject>
1346 
1347 <para>KSyntaxHighlighting includes a variety of built-in themes which are displayed on
1348 the <ulink url="https://kate-editor.org/themes/"><quote>Color Themes</quote> page of
1349 the Kate editor website</ulink>.</para>
1350 
1351 <para>The <ulink url="https://api.kde.org/frameworks/ktexteditor/html/">KTextEditor</ulink>
1352 framework, which is the text editing engine, provides a user interface for creating and editing
1353 color themes, including a tool for importing and exporting themes. This is the simplest way to
1354 create and edit them, you can access it from the
1355 <link linkend="config-dialog"><quote>Configure</quote> dialog</link> of the text editor.
1356 More details in <xref linkend="color-themes-gui"/>.</para>
1357 
1358 <mediaobject>
1359 <imageobject><imagedata format="PNG" fileref="color-themes-gui-breeze-dark-default-text-styles.png"/></imageobject>
1360 <textobject><phrase>The &GUI; to manage color themes in &kate;'s settings.</phrase></textobject>
1361 <caption><para>The &GUI; to manage color themes in &kate;'s settings.</para>
1362 </caption>
1363 </mediaobject>
1364 
1365 <para>It is important to mention that, in the &kde; text editors like &kate; or &kdevelop;,
1366 the KSyntaxHighlighting color themes are used
1367 <ulink url="https://kate-editor.org/post/2020/2020-09-13-kate-color-themes-5.75/">since
1368 &kde; &frameworks; 5.75</ulink>, released on October 10, 2020. Previously, &kate;'s color
1369 schemes (KConfig based schema config) were used and are now deprecated. However, it is
1370 possible to convert the old &kate; schemes to the KSyntaxHighlighting color themes.
1371 The <ulink url="https://invent.kde.org/frameworks/syntax-highlighting">KSyntaxHighlighting
1372 repository</ulink> includes the <userinput>utils/kateschema_to_theme_converter.py</userinput>
1373 script and the <userinput>utils/schema-converter/</userinput> utility for that purpose.
1374 </para>
1375 
1376 </sect2>
1377 
1378 <sect2 id="color-themes-json">
1379 
1380 <title>The Color Themes &JSON; Format</title>
1381 
1382 <sect3 id="color-themes-json-overview">
1383 
1384 <title>Overview</title>
1385 
1386 <para>Color themes are stored in &JSON; format files, with the
1387 <userinput>.theme</userinput> extension.</para>
1388 
1389 <para>In the <ulink url="https://invent.kde.org/frameworks/syntax-highlighting">
1390 KSyntaxHighlighting source code</ulink>, the &JSON; files of built-in themes
1391 are located in the <userinput>data/themes/</userinput> directory.
1392 Note that in text editors, the built-in themes are compiled into the
1393 KSyntaxHighlighting library, therefore, the way to access them is through the
1394 source code or by <link linkend="color-themes-gui-import-export">exporting them
1395 from the &GUI; to manage themes of KTextEditor</link>.</para>
1396 
1397 <para>It is also possible to easily add additional or custom themes, which are
1398 loaded from the file system. User-customized theme files are located in the
1399 <filename class="directory">org.kde.syntax-highlighting/themes/</filename>
1400 directory in your user folder, which you can find with the command
1401 <userinput><command>qtpaths</command><option> --paths GenericDataLocation</option></userinput>
1402 and are commonly <filename class="directory"><envar>$HOME</envar>/.local/share/</filename>
1403 and <filename class="directory">/usr/share/</filename>.
1404 </para>
1405 
1406 <para>In Flatpak and Snap packages, the above directory will not work
1407 as the data location is different for each application.
1408 In a Flatpak application, the location of custom theme files is usually
1409 <filename class="directory"><envar>$HOME</envar>/.var/app/<replaceable>flatpak-package-name</replaceable>/data/org.kde.syntax-highlighting/themes/</filename>
1410 and in a Snap application that location is
1411 <filename class="directory"><envar>$HOME</envar>/snap/<replaceable>snap-package-name</replaceable>/current/.local/share/org.kde.syntax-highlighting/themes/</filename>.
1412 </para>
1413 
1414 <para>On &Windows; these files are located
1415 <filename>%USERPROFILE%&#92;AppData&#92;Local&#92;org.kde.syntax-highlighting&#92;themes</filename>.
1416 <replaceable>%USERPROFILE%</replaceable> usually expands to
1417 <filename>C:&#92;Users&#92;<replaceable>user-name</replaceable></filename>.</para>
1418 
1419 <para>In summary, for most configurations the custom themes directory is as follows:</para>
1420 
1421 <informaltable>
1422 <tgroup cols="2">
1423 <tbody>
1424 <row>
1425 <entry>For local user</entry>
1426 <entry><filename class="directory"><envar>$HOME</envar>/.local/share/org.kde.syntax-highlighting/themes/</filename></entry>
1427 </row>
1428 <row>
1429 <entry>For all users</entry>
1430 <entry><filename class="directory">/usr/share/org.kde.syntax-highlighting/themes/</filename></entry>
1431 </row>
1432 <row>
1433 <entry>For Flatpak packages</entry>
1434 <entry><filename class="directory"><envar>$HOME</envar>/.var/app/<replaceable>flatpak-package-name</replaceable>/data/org.kde.syntax-highlighting/themes/</filename></entry>
1435 </row>
1436 <row>
1437 <entry>For Snap packages</entry>
1438 <entry><filename class="directory"><envar>$HOME</envar>/snap/<replaceable>snap-package-name</replaceable>/current/.local/share/org.kde.syntax-highlighting/themes/</filename></entry>
1439 </row>
1440 <row>
1441 <entry>On &Windows;</entry>
1442 <entry><filename>%USERPROFILE%&#92;AppData&#92;Local&#92;org.kde.syntax-highlighting&#92;themes</filename></entry>
1443 </row>
1444 </tbody>
1445 </tgroup>
1446 </informaltable>
1447 
1448 <para>If multiple theme files exist with the same name, the file with the highest <userinput>revision</userinput> will be loaded.
1449 </para>
1450 
1451 </sect3>
1452 
1453 <sect3 id="color-themes-json-basic">
1454 
1455 <title>The &JSON; Structure</title>
1456 
1457 <para>The structure of a &JSON; file is explained on
1458 <ulink url="https://www.json.org">their website</ulink>.
1459 Basically, a &JSON; format file consists of:
1460 <itemizedlist>
1461 <listitem><para>Collections of key/value pairs, separated by commas and grouped in
1462 <userinput>{ }</userinput> which we will call <quote>objects</quote>.</para></listitem>
1463 <listitem><para>Ordered lists of values, separated by commas and grouped in
1464 <userinput>[ ]</userinput> which we will call <quote>array</quote>.</para></listitem></itemizedlist>
1465 </para>
1466 
1467 <para>The nomenclature <quote>key</quote>, <quote>value</quote>, <quote>object</quote>
1468 and <quote>array</quote> will be used in this article. If this is your first time working
1469 with &JSON; files, understanding them is as simple as looking at the examples below.
1470 </para>
1471 
1472 </sect3>
1473 
1474 <sect3 id="color-themes-json-root">
1475 
1476 <title>Main Sections of the &JSON; Color Theme Files</title>
1477 
1478 <para>The root object of the color theme &JSON; file contains the following
1479 schema keys:</para>
1480 
1481 <itemizedlist>
1482 <listitem><para><userinput>metadata</userinput>: It is mandatory. The value
1483 is an object with the theme's metadata, such as name, revision and license.</para>
1484 <para>This is detailed in <xref linkend="color-themes-json-metadata"/>.</para>
1485 </listitem>
1486 
1487 <listitem><para><userinput>editor-colors</userinput>: It is mandatory. The
1488 value is an object with the colors of the text editing area, such as the
1489 background, the icon border and the text decoration.</para>
1490 <para>This is detailed in <xref linkend="color-themes-editor-colors"/>.</para>
1491 </listitem>
1492 
1493 <listitem><para><userinput>text-styles</userinput>: It is mandatory. The value
1494 is an object with the <emphasis>default text style</emphasis> attributes of
1495 the syntax highlighting. Each attribute defines its <emphasis>text color</emphasis>,
1496 its <emphasis>selected text color</emphasis>, or whether it <emphasis>bold</emphasis>
1497 or <emphasis>italic</emphasis>, for example. The text styles can be referenced
1498 from <link linkend="kate-highlight-default-styles">the attributes of the syntax
1499 definition &XML; files</link>.</para>
1500 <para>This is detailed in <xref linkend="color-themes-text-styles"/>.</para>
1501 </listitem>
1502 
1503 <listitem><para><userinput>custom-styles</userinput>: It is optional. Defines
1504 text styles for the attributes of specific syntax highlighting definitions.
1505 For example, in a highlighting definition such as <userinput>Python</userinput>
1506 or <userinput>Markdown</userinput> you can specify a different text style that
1507 overrides the default defined in <userinput>text-styles</userinput>.</para>
1508 <para>This is detailed in <xref linkend="color-themes-custom-styles"/>.</para>
1509 </listitem>
1510 </itemizedlist>
1511 
1512 <para>The &JSON; language does not support comments. However, you can use the
1513 optional key <userinput>_comments</userinput> in the root object to write comments,
1514 for example, if you are adapting an existing theme you can put the URL of the
1515 original repository. The most practical way is to use an array of strings.
1516 </para>
1517 
1518 <para>Below is an example file for the <quote>Breeze Light</quote> theme.
1519 You can notice that, to avoid the example being too large, the
1520 <userinput>editor-colors</userinput> and <userinput>text-styles</userinput>
1521 objects do not contain all the required keys. You can see the full archive of
1522 <ulink url="https://invent.kde.org/frameworks/syntax-highlighting/-/blob/master/data/themes/breeze-light.theme">
1523 the <quote>Breeze Light</quote> theme in the KSyntaxHighlighting repository</ulink>.
1524 </para>
1525 
1526 <programlisting>
1527 {
1528     "_comments": [
1529         "This is a comment.",
1530         "If this theme is an adaptation of another, put the link to the original repository."
1531     ],
1532     "metadata": {
1533         "name" : "Breeze Light",
1534         "revision" : 5,
1535         "copyright": [
1536             "SPDX-FileCopyrightText: 2016 Volker Krause &lt;vkrause@kde.org&gt;",
1537             "SPDX-FileCopyrightText: 2016 Dominik Haumann &lt;dhaumann@kde.org&gt;"
1538         ],
1539         "license": "SPDX-License-Identifier: MIT"
1540     },
1541     "editor-colors": {
1542         "BackgroundColor" : "#ffffff",
1543         "CodeFolding" : "#94caef",
1544         "BracketMatching" : "#ffff00",
1545         "CurrentLine" : "#f8f7f6",
1546         "IconBorder" : "#f0f0f0",
1547         "IndentationLine" : "#d2d2d2",
1548         "LineNumbers" : "#a0a0a0",
1549         "CurrentLineNumber" : "#1e1e1e",
1550         <replaceable>The other editor color keys...</replaceable>
1551 
1552     },
1553     "text-styles": {
1554         "Normal" : {
1555             "text-color" : "#1f1c1b",
1556             "selected-text-color" : "#ffffff",
1557             "bold" : false,
1558             "italic" : false,
1559             "underline" : false,
1560             "strike-through" : false
1561         },
1562         "Keyword" : {
1563             "text-color" : "#1f1c1b",
1564             "selected-text-color" : "#ffffff",
1565             "bold" : true
1566         },
1567         "Function" : {
1568             "text-color" : "#644a9b",
1569             "selected-text-color" : "#452886"
1570         },
1571         "Variable" : {
1572             "text-color" : "#0057ae",
1573             "selected-text-color" : "#00316e"
1574         },
1575         <replaceable>The other text style keys...</replaceable>
1576 
1577     },
1578     "custom-styles": {
1579         "ISO C++": {
1580             "Data Type": {
1581                 "bold": true,
1582                 "selected-text-color": "#009183",
1583                 "text-color": "#00b5cf"
1584             },
1585             "Keyword": {
1586                 "text-color": "#6431b3"
1587             }
1588         },
1589         "YAML": {
1590             "Attribute": {
1591                 "selected-text-color": "#00b5cf",
1592                 "text-color": "#00b5cf"
1593             }
1594         }
1595     }
1596 }
1597 </programlisting>
1598 
1599 </sect3>
1600 
1601 <sect3 id="color-themes-json-metadata">
1602 
1603 <title>Metadata</title>
1604 
1605 <para>The &JSON; object of the <userinput>metadata</userinput> key contains
1606 relevant information on the theme. This object has the following keys:
1607 
1608 <itemizedlist>
1609 <listitem><para><userinput>name</userinput>: It is a <emphasis>string</emphasis>
1610 sets the name of the language. It appears in the menus and dialogs afterwards.
1611 It is mandatory.</para></listitem>
1612 
1613 <listitem><para><userinput>revision</userinput>: It is an
1614 <emphasis>integer</emphasis> number that specifies the current revision of the
1615 theme file. Whenever you update a color theme file, make sure to increase this
1616 number. It is mandatory.</para></listitem>
1617 
1618 <listitem><para><userinput>license</userinput>: It is a
1619 <emphasis>string</emphasis> that defines the license of the theme, using the
1620 identifier <userinput>SPDX-License-Identifier</userinput> from the standard
1621 <ulink url="https://spdx.dev/">SPDX license communication format</ulink>.
1622 It is optional.</para>
1623 <para>You can see the full list of SPDX license identifiers
1624 <ulink url="https://spdx.org/licenses/">here</ulink>.</para></listitem>
1625 
1626 <listitem><para><userinput>copyright</userinput>: It is an <emphasis>array</emphasis>
1627 of <emphasis>strings</emphasis> that specifies the authors of the theme, using
1628 the identifier <userinput>SPDX-FileCopyrightText</userinput> from the standard
1629 <ulink url="https://spdx.dev/">SPDX license communication format</ulink>.
1630 It is optional.</para></listitem>
1631 </itemizedlist>
1632 </para>
1633 
1634 <programlisting>
1635 "metadata": {
1636     "name" : "Breeze Light",
1637     "revision" : 5,
1638     "copyright": [
1639         "SPDX-FileCopyrightText: 2016 Volker Krause &lt;vkrause@kde.org&gt;",
1640         "SPDX-FileCopyrightText: 2016 Dominik Haumann &lt;dhaumann@kde.org&gt;"
1641     ],
1642     "license": "SPDX-License-Identifier: MIT"
1643 }
1644 </programlisting>
1645 
1646 </sect3>
1647 
1648 </sect2>
1649 
1650 <sect2 id="color-themes-editing">
1651 
1652 <title>Colors in Detail</title>
1653 
1654 <para>This section details all the available color attributes and available
1655 color settings.</para>
1656 
1657 <sect3 id="color-themes-editor-colors">
1658 
1659 <title>Editor Colors</title>
1660 
1661 <para>Corresponds to the colors of the <link linkend="kate-part">text editing area</link>.</para>
1662 
1663 <para>In the <link linkend="color-themes-json">&JSON; theme file</link>, the respective key
1664 <userinput>editor-colors</userinput> has as value an <emphasis>object</emphasis> where each
1665 key references an attribute color of the text editor. Here, <userinput>all available keys
1666 are mandatory</userinput>, their values are <userinput>strings</userinput> with hexadecimal
1667 color codes, like <quote>#00B5CF</quote>.
1668 </para>
1669 
1670 <para>In <link linkend="color-themes-gui">the &GUI; to manage themes of KTextEditor</link>,
1671 these attributes can be modified in the <userinput><guilabel>Colors</guilabel></userinput> tab.
1672 </para>
1673 
1674 <para>The available keys are the following; the keys used in the
1675 <link linkend="color-themes-json">&JSON; file</link> are listed in <emphasis>bold</emphasis>,
1676 the names used in the <link linkend="color-themes-gui">&GUI;</link> are shown in parentheses.
1677 </para>
1678 
1679 <variablelist>
1680 
1681 <varlistentry id="variable-prefcolors-colors-text-background">
1682 <term><guilabel>Editor Background Colors</guilabel></term>
1683 <listitem>
1684 
1685 <variablelist>
1686 
1687 <varlistentry id="variable-pref-colors-normal-text">
1688 <term><userinput>BackgroundColor</userinput> (<guilabel>Text Area</guilabel>)</term>
1689 <listitem><para>This is the default background for the editor area, it will be
1690 the dominant color on the editor area.</para>
1691 <mediaobject>
1692 <imageobject><imagedata format="PNG" fileref="editor-colors-BackgroundColor.png"/></imageobject>
1693 <caption><para></para></caption>
1694 </mediaobject>
1695 </listitem>
1696 </varlistentry>
1697 
1698 <varlistentry id="variable-pref-colors-selected-text">
1699 <term><userinput>TextSelection</userinput> (<guilabel>Selected Text</guilabel>)</term>
1700 <listitem><para>This is the background for selected text.
1701 </para>
1702 <mediaobject>
1703 <imageobject><imagedata format="PNG" fileref="editor-colors-TextSelection.png"/></imageobject>
1704 <caption><para></para></caption>
1705 </mediaobject>
1706 </listitem>
1707 </varlistentry>
1708 
1709 <varlistentry id="variable-pref-colors-current-line">
1710 <term><userinput>CurrentLine</userinput> (<guilabel>Current Line</guilabel>)</term>
1711 <listitem><para>Set the color for the current line. Setting this a bit different
1712 from the Normal text background helps to keep focus on the current line.
1713 </para>
1714 <mediaobject>
1715 <imageobject><imagedata format="PNG" fileref="editor-colors-CurrentLine.png"/></imageobject>
1716 <caption><para></para></caption>
1717 </mediaobject>
1718 </listitem>
1719 </varlistentry>
1720 
1721 <varlistentry id="variable-pref-colors-search-highlight">
1722 <term><userinput>SearchHighlight</userinput> (<guilabel>Search Highlight</guilabel>)</term>
1723 <listitem><para>Set the color for the text that matches your last search.
1724 </para>
1725 <mediaobject>
1726 <imageobject><imagedata format="PNG" fileref="editor-colors-SearchHighlight.png"/></imageobject>
1727 <caption><para></para></caption>
1728 </mediaobject>
1729 </listitem>
1730 </varlistentry>
1731 
1732 <varlistentry id="variable-pref-colors-replace-highlight">
1733 <term><userinput>ReplaceHighlight</userinput> (<guilabel>Replace Highlight</guilabel>)</term>
1734 <listitem><para>Set the color for the text that matches your last replace
1735 operation.</para>
1736 <mediaobject>
1737 <imageobject><imagedata format="PNG" fileref="editor-colors-ReplaceHighlight.png"/></imageobject>
1738 <caption><para></para></caption>
1739 </mediaobject>
1740 </listitem>
1741 </varlistentry>
1742 
1743 </variablelist>
1744 </listitem>
1745 </varlistentry>
1746 
1747 <varlistentry id="variable-prefcolors-colors-icon-border">
1748 <term><guilabel>Icon Border</guilabel></term>
1749 <listitem>
1750 <variablelist>
1751 
1752 <varlistentry>
1753 <term><userinput>IconBorder</userinput> (<guilabel>Background Area</guilabel>)</term>
1754 <listitem><para>This color is used for the marks, line numbers and folding
1755 marker borders in the left side of the editor view when they are displayed.
1756 </para></listitem>
1757 </varlistentry>
1758 
1759 <varlistentry>
1760 <term><userinput>LineNumbers</userinput> (<guilabel>Line Numbers</guilabel>)</term>
1761 <listitem><para>This color is used to draw the line numbers on the left side of
1762 the view when displayed.</para></listitem>
1763 </varlistentry>
1764 
1765 <varlistentry>
1766 <term><userinput>CurrentLineNumber</userinput> (<guilabel>Current Line Number</guilabel>)</term>
1767 <listitem><para>This color is used to draw the line number of the current line,
1768 on the left side of the view when displayed. Setting this a bit different from
1769 <quote>LineNumbers</quote> helps to keep focus on the current line.
1770 </para></listitem>
1771 </varlistentry>
1772 
1773 <varlistentry>
1774 <term><userinput>Separator</userinput> (<guilabel>Separator</guilabel>)</term>
1775 <listitem><para>This color is used to draw the vertical line that separates the
1776 icon border from the background of the text area.</para>
1777 <mediaobject>
1778 <imageobject><imagedata format="PNG" fileref="editor-colors-IconBorder.png"/></imageobject>
1779 <caption><para></para></caption>
1780 </mediaobject>
1781 </listitem>
1782 </varlistentry>
1783 
1784 <varlistentry>
1785 <term><userinput>WordWrapMarker</userinput> (<guilabel>Word Wrap Marker</guilabel>)</term>
1786 <listitem><para>This color is used to draw a pattern to the left of dynamically
1787 wrapped lines when those are aligned vertically, as well as for the static word
1788 wrap marker.</para>
1789 <mediaobject>
1790 <imageobject><imagedata format="PNG" fileref="editor-colors-WordWrapMarker.png"/></imageobject>
1791 <caption><para></para></caption>
1792 </mediaobject>
1793 </listitem>
1794 </varlistentry>
1795 
1796 <varlistentry>
1797 <term><userinput>CodeFolding</userinput> (<guilabel>Code Folding</guilabel>)</term>
1798 <listitem><para>This color is used to highlight the section of code that would
1799 be folded when you click on the code folding arrow to the left of a document.
1800 For more information, see
1801 <link linkend="advanced-editing-tools-code-folding">the code
1802 folding documentation</link>.</para>
1803 <mediaobject>
1804 <imageobject><imagedata format="PNG" fileref="editor-colors-CodeFolding.png"/></imageobject>
1805 <caption><para></para></caption>
1806 </mediaobject>
1807 </listitem>
1808 </varlistentry>
1809 
1810 <varlistentry>
1811 <term><userinput>ModifiedLines</userinput> (<guilabel>Modified Lines</guilabel>)</term>
1812 <listitem><para>This color is used to highlight to the left of a document lines
1813 that have been modified but not yet saved.  For more information, see
1814 <xref linkend="kate-part-line-modification"/>.</para></listitem>
1815 </varlistentry>
1816 
1817 <varlistentry>
1818 <term><userinput>SavedLines</userinput> (<guilabel>Saved Lines</guilabel>)</term>
1819 <listitem><para>This color is used to highlight to the left of a document lines
1820 that have been modified this session and saved.  For more information, see
1821 <xref linkend="kate-part-line-modification"/>.</para>
1822 <mediaobject>
1823 <imageobject><imagedata format="PNG" fileref="editor-colors-ModifiedLines.png"/></imageobject>
1824 <caption><para></para></caption>
1825 </mediaobject>
1826 </listitem>
1827 </varlistentry>
1828 
1829 </variablelist>
1830 </listitem>
1831 </varlistentry>
1832 
1833 <varlistentry id="variable-prefcolors-colors-text-decorations">
1834 <term><guilabel>Text Decorations</guilabel></term>
1835 <listitem>
1836 <variablelist>
1837 
1838 <varlistentry>
1839 <term><userinput>SpellChecking</userinput> (<guilabel>Spelling Mistake Line</guilabel>)</term>
1840 <listitem><para>This color is used to indicate spelling mistakes.</para>
1841 <mediaobject>
1842 <imageobject><imagedata format="PNG" fileref="editor-colors-SpellChecking.png"/></imageobject>
1843 <caption><para></para></caption>
1844 </mediaobject>
1845 </listitem>
1846 </varlistentry>
1847 
1848 <varlistentry>
1849 <term><userinput>TabMarker</userinput> (<guilabel>Tab and Space Markers</guilabel>)</term>
1850 <listitem><para>This color is used to draw white space indicators, when they are
1851 enabled.</para>
1852 <mediaobject>
1853 <imageobject><imagedata format="PNG" fileref="editor-colors-TabMarker.png"/></imageobject>
1854 <caption><para></para></caption>
1855 </mediaobject>
1856 </listitem>
1857 </varlistentry>
1858 
1859 <varlistentry>
1860 <term><userinput>IndentationLine</userinput> (<guilabel>Indentation Line</guilabel>)</term>
1861 <listitem><para>This color is used to draw a line to the left of indented blocks,
1862 if <link linkend="appearance-general">that feature is enabled</link>.</para>
1863 <mediaobject>
1864 <imageobject><imagedata format="PNG" fileref="editor-colors-IndentationLine.png"/></imageobject>
1865 <caption><para></para></caption>
1866 </mediaobject>
1867 </listitem>
1868 </varlistentry>
1869 
1870 <varlistentry>
1871 <term><userinput>BracketMatching</userinput> (<guilabel>Bracket Highlight</guilabel>)</term>
1872 <listitem><para>This color is used to draw the background of matching brackets.
1873 </para>
1874 <mediaobject>
1875 <imageobject><imagedata format="PNG" fileref="editor-colors-BracketMatching.png"/></imageobject>
1876 <caption><para></para></caption>
1877 </mediaobject>
1878 </listitem>
1879 </varlistentry>
1880 
1881 </variablelist>
1882 </listitem>
1883 </varlistentry>
1884 
1885 <varlistentry id="variable-prefcolors-colors-marker-colors">
1886 <term><guilabel>Marker Colors</guilabel></term>
1887 <listitem>
1888 <variablelist>
1889 
1890 <varlistentry>
1891 <term><userinput>MarkBookmark</userinput> (<guilabel>Bookmark</guilabel>)</term>
1892 <listitem><para>This color is used to indicate bookmarks. Note that this color
1893 has an opacity of 22% (and 33% for the current line) with respect to the background.
1894 For more information, see <xref linkend="kate-part-bookmarks"/>.</para>
1895 <mediaobject>
1896 <imageobject><imagedata format="PNG" fileref="editor-colors-MarkBookmark.png"/></imageobject>
1897 <caption><para></para></caption>
1898 </mediaobject>
1899 </listitem>
1900 </varlistentry>
1901 
1902 <varlistentry>
1903 <term><userinput>MarkBreakpointActive</userinput> (<guilabel>Active Breakpoint</guilabel>)</term>
1904 <listitem><para>This color is used by the GDB plugin to indicate an active
1905 breakpoint. Notice that this color has an opacity to the background.
1906 For more information, see <ulink url="help:/kate/kate-application-plugin-gdb.html">the
1907 GDB Plugin documentation</ulink>.</para></listitem>
1908 </varlistentry>
1909 
1910 <varlistentry>
1911 <term><userinput>MarkBreakpointReached</userinput> (<guilabel>Reached Breakpoint</guilabel>)</term>
1912 <listitem><para>This color is used by the GDB plugin to indicate a breakpoint
1913 you have reached while debugging. Notice that this color has an opacity
1914 to the background.
1915 For more information, see <ulink url="help:/kate/kate-application-plugin-gdb.html">the
1916 GDB Plugin documentation</ulink>.</para></listitem>
1917 </varlistentry>
1918 
1919 <varlistentry>
1920 <term><userinput>MarkBreakpointDisabled</userinput> (<guilabel>Disabled Breakpoint</guilabel>)</term>
1921 <listitem><para>This color is used by the GDB plugin to indicate an inactive
1922 breakpoint. Notice that this color has an opacity to the background.
1923 For more information, see <ulink url="help:/kate/kate-application-plugin-gdb.html">the
1924 GDB Plugin documentation</ulink>.</para></listitem>
1925 </varlistentry>
1926 
1927 <varlistentry>
1928 <term><userinput>MarkExecution</userinput> (<guilabel>Execution</guilabel>)</term>
1929 <listitem><para>This color is used by the GDB plugin the line presently being
1930 executed. Notice that this color has an opacity to the background.
1931 For more information, see <ulink url="help:/kate/kate-application-plugin-gdb.html">the
1932 GDB Plugin documentation</ulink>.</para></listitem>
1933 </varlistentry>
1934 
1935 <varlistentry>
1936 <term><userinput>MarkWarning</userinput> (<guilabel>Warning</guilabel>)</term>
1937 <listitem><para>This color is used by the build plugin to indicate a line that
1938 has caused a compiler warning. Notice that this color has an opacity to the background.
1939 For more information, see <ulink url="help:/kate/kate-application-plugin-build.html">the
1940 Build Plugin documentation</ulink>.</para></listitem>
1941 </varlistentry>
1942 
1943 <varlistentry>
1944 <term><userinput>MarkError</userinput> (<guilabel>Error</guilabel>)</term>
1945 <listitem><para>This color is used by the build plugin to indicate a line that
1946 has caused a compiler error. Notice that this color has an opacity to the background.
1947 For more information, see <ulink url="help:/kate/kate-application-plugin-build.html">the
1948 Build Plugin documentation</ulink>.</para></listitem>
1949 </varlistentry>
1950 
1951 </variablelist>
1952 </listitem>
1953 </varlistentry>
1954 
1955 <varlistentry id="variable-prefcolors-colors-text-templates-snippets">
1956 <term><guilabel>Text Templates &amp; Snippets</guilabel></term>
1957 <listitem>
1958 <variablelist>
1959 
1960 <varlistentry>
1961 <term><userinput>TemplateBackground</userinput> (<guilabel>Background</guilabel>)</term>
1962 <listitem><para>This color is used by the &kate; Snippets plugin to mark the
1963 background of a snippet.  For more information, see
1964 <ulink url="help:/kate/kate-application-plugin-snippets.html">the &kate; Snippets
1965 documentation</ulink>.</para></listitem>
1966 </varlistentry>
1967 
1968 <varlistentry>
1969 <term><userinput>TemplatePlaceholder</userinput> (<guilabel>Editable Placeholder</guilabel>)</term>
1970 <listitem><para>This color is used by the &kate; Snippets plugin to mark a
1971 placeholder that you can click in to edit manually.  For more information, see
1972 <ulink url="help:/kate/kate-application-plugin-snippets.html">the &kate; Snippets
1973 documentation</ulink>.</para></listitem>
1974 </varlistentry>
1975 
1976 <varlistentry>
1977 <term><userinput>TemplateFocusedPlaceholder</userinput> (<guilabel>Focused Editable Placeholder</guilabel>)</term>
1978 <listitem><para>This color is used by the &kate; Snippets plugin to mark the
1979 placeholder that you are presently editing.  For more information, see
1980 <ulink url="help:/kate/kate-application-plugin-snippets.html">the &kate; Snippets
1981 documentation</ulink>.</para>
1982 <mediaobject>
1983 <imageobject><imagedata format="PNG" fileref="editor-colors-Template.png"/></imageobject>
1984 <caption><para></para></caption>
1985 </mediaobject>
1986 </listitem>
1987 </varlistentry>
1988 
1989 <varlistentry>
1990 <term><userinput>TemplateReadOnlyPlaceholder</userinput> (<guilabel>Not Editable Placeholder</guilabel>)</term>
1991 <listitem><para>This color is used by the &kate; Snippets plugin to mark a
1992 placeholder that cannot be edited manually, such as one that is automatically
1993 populated.  For more information, see
1994 <ulink url="help:/kate/kate-application-plugin-snippets.html">the &kate; Snippets
1995 documentation</ulink>.</para>
1996 <mediaobject>
1997 <imageobject><imagedata format="PNG" fileref="editor-colors-TemplateReadOnlyPlaceholder.png"/></imageobject>
1998 <caption><para></para></caption>
1999 </mediaobject>
2000 </listitem>
2001 </varlistentry>
2002 
2003 </variablelist>
2004 </listitem>
2005 </varlistentry>
2006 
2007 </variablelist>
2008 
2009 </sect3>
2010 
2011 <sect3 id="color-themes-text-styles">
2012 
2013 <title>Default Text Styles</title>
2014 
2015 <para>The default text styles are inherited by the highlight text styles, allowing
2016 the editor to present text in a very consistent way, for example comment text is using
2017 the same style in almost all of the text formats that KSyntaxHighlighting can highlight.
2018 </para>
2019 
2020 <note>
2021 <para>
2022 These text styles can be referenced from the <userinput>default styles</userinput> used
2023 in <link linkend="highlight">syntax highlighting</link> definition &XML; files, for example,
2024 the <quote>Normal</quote> attribute is equivalent to <quote>dsNormal</quote> in the &XML; files,
2025 and <quote>DataType</quote> is equivalent to <quote>dsDataType</quote>.
2026 See <xref linkend="kate-highlight-default-styles"/> in the syntax highlighting documentation.
2027 </para>
2028 </note>
2029 
2030 <tip>
2031 <para>
2032 Make sure to choose readable colors with good contrast especially in combination with
2033 the <userinput><link linkend="color-themes-editor-colors">Editor Colors</link></userinput>.
2034 See <xref linkend="color-themes-contrast"/>.
2035 </para>
2036 </tip>
2037 
2038 <para>In the <link linkend="color-themes-json">&JSON; file</link>, the respective key
2039 <userinput>text-styles</userinput> has as value an <emphasis>object</emphasis> where
2040 each key corresponds to the name of a <emphasis>default text style</emphasis>, which are
2041 equivalent to those used in the syntax highlighting definitions. Here, <userinput>all available
2042 text style keys are mandatory</userinput>, these are listed below.
2043 </para>
2044 
2045 <programlisting>
2046 "text-styles": {
2047     "Normal" : {
2048         "text-color" : "#1f1c1b",
2049         "selected-text-color" : "#ffffff",
2050         "bold" : false,
2051         "italic" : false,
2052         "underline" : false,
2053         "strike-through" : false
2054     },
2055     "Keyword" : {
2056         "text-color" : "#1f1c1b",
2057         "selected-text-color" : "#ffffff",
2058         "bold" : true
2059     },
2060     "Function" : {
2061         "text-color" : "#644a9b",
2062         "selected-text-color" : "#452886"
2063     },
2064     <replaceable>The other text style keys...</replaceable>
2065 }
2066 </programlisting>
2067 
2068 <variablelist>
2069 <varlistentry>
2070 
2071 <term>Each key of <emphasis>default text style</emphasis> has a &JSON; object as
2072 its value, where values such as <emphasis>color</emphasis>, <emphasis>bold</emphasis>,
2073 <emphasis>italic</emphasis>, etc. are specified. These keys are as follows:
2074 </term>
2075 
2076 <listitem>
2077 
2078 <para><userinput>text-color</userinput>: It is a <emphasis>string</emphasis> with the
2079 text color in hexadecimal color code. This key/value is required.</para>
2080 
2081 <para><userinput>selected-text-color</userinput>: The text color when it is selected
2082 is generally the same value as <quote>text-color</quote>. When the text is selected,
2083 the background is defined by the value of
2084 <link linkend="variable-pref-colors-selected-text">TextSelection</link> in the
2085 <link linkend="color-themes-editor-colors">Editor Colors</link>, so you must ensure that
2086 the text has good contrast and is readable with this background. The value is a
2087 <emphasis>string</emphasis> with a hexadecimal color code. This key/value is required.</para>
2088 
2089 <para><userinput>bold</userinput>: It is a <emphasis>boolean</emphasis> that determines
2090 if the text is in bold. This key is optional, the default value is <userinput>false</userinput>.</para>
2091 
2092 <para><userinput>italic</userinput>: It is a <emphasis>boolean</emphasis> that determines
2093 if the text is curved. This key is optional, the default value is <userinput>false</userinput>.</para>
2094 
2095 <para><userinput>underline</userinput>: It is a <emphasis>boolean</emphasis> that determines
2096 if the text is underlined. This key is optional, the default value is <userinput>false</userinput>.</para>
2097 
2098 <para><userinput>strike-through</userinput>: It is a <emphasis>boolean</emphasis> that
2099 determines if the text is strike through. This key is optional, the default value is <userinput>false</userinput>.</para>
2100 
2101 <para><userinput>background-color</userinput>: Determines the background of the text,
2102 used for example in alerts in comments. The value is a <emphasis>string</emphasis> with
2103 a hexadecimal color code. This key is optional, by default there is no background.</para>
2104 
2105 <para><userinput>selected-background-color</userinput>: Determines the background of the
2106 text when it is selected. The value is a <emphasis>string</emphasis> with a hexadecimal
2107 color code. This key is optional, by default there is no background.</para>
2108 
2109 </listitem>
2110 </varlistentry>
2111 </variablelist>
2112 
2113 <para>In <link linkend="color-themes-gui">the &GUI; to manage color themes of KTextEditor</link>,
2114 these attributes can be modified in the <userinput><guilabel>Default Text Styles</guilabel></userinput>
2115 tab. The name in the list of styles is using the style configured for the item, providing you
2116 with an immediate preview when configuring a style. Each style lets you select common attributes
2117 as well as foreground and background colors. To unset a background color, right-click to
2118 use the context menu.</para>
2119 
2120 <para>The available text style keys are the following; the keys used in the
2121 <link linkend="color-themes-json">&JSON; file</link> are listed in <emphasis>bold</emphasis>,
2122 the names used in the <link linkend="color-themes-gui">&GUI;</link> are shown in parentheses
2123 if they are different.</para>
2124 
2125 <variablelist>
2126 <varlistentry>
2127 <term><guilabel>Normal Text &amp; Source Code</guilabel></term>
2128 <listitem>
2129 <para><userinput>Normal</userinput>:
2130 Default text style for normal text and source code without special highlighting.</para>
2131 
2132 <para><userinput>Keyword</userinput>:
2133 Text style for built-in language keywords.</para>
2134 
2135 <para><userinput>Function</userinput>:
2136 Text style for function definitions and function calls.</para>
2137 
2138 <para><userinput>Variable</userinput>:
2139 Text style for variables, if applicable. For instance, variables in PHP/Perl typically
2140 start with a <userinput>$</userinput>, so all identifiers following the pattern
2141 <userinput>$foo</userinput> are highlighted as variable.</para>
2142 
2143 <para><userinput>ControlFlow</userinput> (<guilabel>Control Flow</guilabel>):
2144 Text style for control flow keywords, such as <emphasis>if</emphasis>, <emphasis>then</emphasis>,
2145 <emphasis>else</emphasis>, <emphasis>return</emphasis>, <emphasis>switch</emphasis>,
2146 <emphasis>break</emphasis>, <emphasis>yield</emphasis>, <emphasis>continue</emphasis>, etc.</para>
2147 
2148 <para><userinput>Operator</userinput>:
2149 Text style for operators, such as <userinput>+</userinput>, <userinput>-</userinput>,
2150 <userinput>*</userinput>, <userinput>/</userinput>, <userinput>%</userinput>, etc.</para>
2151 
2152 <para><userinput>BuiltIn</userinput> (<guilabel>Built-in</guilabel>):
2153 Text style for built-in language classes, functions and objects.</para>
2154 
2155 <para><userinput>Extension</userinput>:
2156 Text style for well-known extensions, such as &Qt; classes, functions/macros in C++ and
2157 Python or boost.</para>
2158 
2159 <para><userinput>Preprocessor</userinput>:
2160 Text style for preprocessor statements or macro definitions.</para>
2161 
2162 <para><userinput>Attribute</userinput>:
2163 Text style for annotations or attributes of functions or objects, e.g.
2164 <userinput>@override</userinput> in Java, or <userinput>__declspec(...)</userinput> and
2165 <userinput>__attribute__((...))</userinput> in C++.</para>
2166 </listitem>
2167 </varlistentry>
2168 
2169 <varlistentry>
2170 <term><guilabel>Numbers, Types &amp; Constants</guilabel></term>
2171 <listitem>
2172 <para><userinput>DataType</userinput> (<guilabel>Data Type</guilabel>):
2173 Text style for built-in data types such as <emphasis>int</emphasis>, <emphasis>char</emphasis>,
2174 <emphasis>float</emphasis>, <emphasis>void</emphasis>, <emphasis>u64</emphasis>, etc.</para>
2175 
2176 <para><userinput>DecVal</userinput> (<guilabel>Decimal/Value</guilabel>):
2177 Text style for decimal values.</para>
2178 
2179 <para><userinput>BaseN</userinput> (<guilabel>Base-N Integer</guilabel>):
2180 Text style for numbers with base other than 10.</para>
2181 
2182 <para><userinput>Float</userinput> (<guilabel>Floating Point</guilabel>):
2183 Text style for floating point numbers.</para>
2184 
2185 <para><userinput>Constant</userinput>:
2186 Text style for language constants and user defined constants, e.g. <emphasis>True</emphasis>,
2187 <emphasis>False</emphasis>, <emphasis>None</emphasis> in Python or <emphasis>nullptr</emphasis>
2188 in C/C++; or math constants like <emphasis>PI</emphasis>.</para>
2189 </listitem>
2190 </varlistentry>
2191 
2192 <varlistentry>
2193 <term><guilabel>Strings &amp; Characters</guilabel></term>
2194 <listitem>
2195 <para><userinput>Char</userinput> (<guilabel>Character</guilabel>):
2196 Text style for single characters such as <userinput>'x'</userinput>.</para>
2197 
2198 <para><userinput>SpecialChar</userinput> (<guilabel>Special Character</guilabel>):
2199 Text style for escaped characters in strings, e.g. <quote><userinput>hello\n</userinput></quote>,
2200 and other characters with special meaning in strings, such as substitutions or regex operators.</para>
2201 
2202 <para><userinput>String</userinput>:
2203 Text style for strings like <quote><userinput>hello world</userinput></quote>.</para>
2204 
2205 <para><userinput>VerbatimString</userinput> (<guilabel>Verbatim String</guilabel>):
2206 Text style for verbatim or raw strings like <userinput>'raw \backlash'</userinput> in
2207 Perl, CoffeeScript, and shells, as well as <userinput>r'\raw'</userinput> in Python,
2208 or such as HERE docs.</para>
2209 
2210 <para><userinput>SpecialString</userinput> (<guilabel>Special String</guilabel>):
2211 Text style for special strings, such as regular expressions in ECMAScript, the &latex; math
2212 mode, SQL, etc.</para>
2213 
2214 <para><userinput>Import</userinput> (<guilabel>Imports, Modules, Includes</guilabel>):
2215 Text style for includes, imports, modules or &latex; packages.</para>
2216 </listitem>
2217 </varlistentry>
2218 
2219 <varlistentry>
2220 <term><guilabel>Comments &amp; Documentation</guilabel></term>
2221 <listitem>
2222 <para><userinput>Comment</userinput>:
2223 Text style for normal comments.</para>
2224 
2225 <para><userinput>Documentation</userinput>:
2226 Text style for comments that reflect API documentation, such as
2227 <userinput>/** doxygen comments */</userinput> or <userinput>"""docstrings"""</userinput>.</para>
2228 
2229 <para><userinput>Annotation</userinput>:
2230 Text style for annotations in comments or documentation commands, such as
2231 <userinput>@param</userinput> in Doxygen or JavaDoc.</para>
2232 
2233 <para><userinput>CommentVar</userinput> (<guilabel>Comment Variable</guilabel>):
2234 Text style that refers to variables names used in above commands in a comment, such as
2235 <userinput>foobar</userinput> in <quote><userinput>@param foobar</userinput></quote>,
2236 in Doxygen or JavaDoc.</para>
2237 
2238 <para><userinput>RegionMarker</userinput> (<guilabel>Region Marker</guilabel>):
2239 Text style for region markers, typically defined by <userinput>//BEGIN</userinput>
2240 and <userinput>//END</userinput> in comments.</para>
2241 
2242 <para><userinput>Information</userinput>:
2243 Text style for information, notes and tips, such as the keyword
2244 <userinput>@note</userinput> in Doxygen.</para>
2245 
2246 <para><userinput>Warning</userinput>:
2247 Text style for warnings, such as the keyword <userinput>@warning</userinput> in Doxygen.</para>
2248 
2249 <para><userinput>Alert</userinput>:
2250 Text style for special words in comments, such as <userinput>TODO</userinput>,
2251 <userinput>FIXME</userinput>, <userinput>XXXX</userinput> and <userinput>WARNING</userinput>.</para>
2252 </listitem>
2253 </varlistentry>
2254 
2255 <varlistentry>
2256 <term><guilabel>Miscellaneous</guilabel></term>
2257 <listitem>
2258 <para><userinput>Error</userinput>:
2259 Text style indicating error highlighting and wrong syntax.</para>
2260 
2261 <para><userinput>Others</userinput>:
2262 Text style for attributes that do not match any of the other default styles.</para>
2263 </listitem>
2264 </varlistentry>
2265 </variablelist>
2266 
2267 </sect3>
2268 
2269 <sect3 id="color-themes-custom-styles">
2270 
2271 <title>Custom Highlighting Text Styles</title>
2272 
2273 <para>Here you can establish text styles for a specific syntax highlighting definition,
2274 overriding the <userinput>default text style</userinput> described in
2275 <link linkend="color-themes-text-styles">the previous section</link>.
2276 </para>
2277 
2278 <para>In the <link linkend="color-themes-json">&JSON; theme file</link>, this corresponds
2279 to the <userinput>custom-styles</userinput> key, whose value is an <emphasis>object</emphasis>
2280 where each subschema key corresponds to the <userinput>name of a syntax highlighting definition</userinput>.
2281 Its value is an <emphasis>object</emphasis> where each key refers to the <userinput>style attributes
2282 name</userinput> defined in <link linkend="kate-highlight-sections">the <userinput>itemData</userinput>
2283 elements</link> of the syntax highlighting &XML; file, and the respective value is a sub-object with the keys
2284 <emphasis>text-color</emphasis>, <emphasis>selected-text-color</emphasis>, <emphasis>bold</emphasis>,
2285 <emphasis>italic</emphasis>, <emphasis>underline</emphasis>, <emphasis>strike-through</emphasis>,
2286 <emphasis>background-color</emphasis> and <emphasis>selected-background-color</emphasis>, defined in
2287 <link linkend="color-themes-text-styles">the previous section</link>. Each of these values are optional,
2288 since if they are not present, the style set in <userinput>text-styles</userinput> is considered.
2289 </para>
2290 
2291 <para>For example, in this piece of code, the <quote>ISO C++</quote> syntax highlighting definition
2292 has a special text style for the <quote>Type Modifiers</quote> and <quote>Standard Classes</quote>
2293 attributes. In the corresponding &XML; file <quote>isocpp.xml</quote>, the defined attribute
2294 <quote>Standard Classes</quote> uses the default style <userinput>BuiltIn</userinput> (or dsBuiltIn).
2295 In this attribute, only the value of <userinput>text-color</userinput> is overwritten by the new
2296 color <quote>#6431b3</quote>.
2297 </para>
2298 
2299 <programlisting>
2300 "custom-styles": {
2301     "ISO C++": {
2302         "Standard Classes": {
2303             "text-color": "#6431b3"
2304         },
2305         "Type Modifiers": {
2306             "bold": true,
2307             "selected-text-color": "#009183",
2308             "text-color": "#00b5cf"
2309         }
2310     }
2311 }
2312 </programlisting>
2313 
2314 <note>
2315 <itemizedlist>
2316 
2317 <listitem>
2318 <para>You should consider that these text styles are associated with the attribute names defined
2319 in the syntax highlighting &XML; files. If an XML file is updated and some attributes are renamed
2320 or removed, the custom style defined in the theme will no longer apply.</para>
2321 </listitem>
2322 
2323 <listitem>
2324 <para>Syntax highlighting definitions often include other definitions. For example, the
2325 <quote>QML</quote> highlighter includes the <quote>JavaScript</quote> highlighter,
2326 since they share functionality in highlighting.</para>
2327 </listitem>
2328 
2329 </itemizedlist>
2330 </note>
2331 
2332 <para>In <link linkend="color-themes-gui">the &GUI; to manage themes of KTextEditor</link>,
2333 these attributes can be modified in the
2334 <userinput><guilabel>Highlighting Text Styles</guilabel></userinput> tab.
2335 By default, the editor preselects the highlighting of the current document. You will notice that
2336 many highlights contain other highlights represented by groups in the style list. For example
2337 most highlights import the <quote>Alert</quote> highlight, and many source code formats import
2338 the <quote>Doxygen</quote> highlight.
2339 </para>
2340 
2341 </sect3>
2342 
2343 </sect2>
2344 
2345 <sect2 id="color-themes-gui">
2346 
2347 <title>The Color Themes &GUI;</title>
2348 
2349 <para>The simplest way to create and edit color themes is through the &GUI; within
2350 the <link linkend="config-dialog"><quote>Configure</quote> dialog</link> provided
2351 by <ulink url="https://api.kde.org/frameworks/ktexteditor/html/">KTextEditor</ulink>.
2352 To access it, select <menuchoice><guimenu>Settings</guimenu>
2353 <guimenuitem>Configure <replaceable>Application</replaceable>...</guimenuitem></menuchoice>
2354 from the menubar in your text editor. This brings up the <guilabel>Configure</guilabel>
2355 dialog box, there select <guilabel>Color Themes</guilabel> in the side panel.
2356 </para>
2357 
2358 <mediaobject>
2359 <imageobject><imagedata format="PNG" fileref="color-themes-gui-default-text-styles.png"/></imageobject>
2360 <textobject><phrase>&kate;'s settings dialog box with the color theme management.</phrase></textobject>
2361 <caption><para>&kate;'s settings dialog box with the color theme management.</para>
2362 </caption>
2363 </mediaobject>
2364 
2365 <para>In this <link linkend="config-dialog">dialog</link> you can configure all the colors
2366 in any theme you have, as well as create/copy new themes, delete them, export them to a
2367 <userinput>.theme</userinput> file with <link linkend="color-themes-json">&JSON; format</link>
2368 or import them from external <userinput>.theme</userinput> files. Each theme has settings
2369 for text colors and styles.
2370 </para>
2371 
2372 <para>The built-in themes cannot be modified by default. To do this, you need to copy
2373 them and give them a new name.</para>
2374 
2375 <para>To use a theme permanently in your text editor, you must select it in the combobox
2376 labeled <guilabel>Default theme for <replaceable>Application</replaceable></guilabel> at
2377 the bottom of the dialog and press <guibutton>Apply</guibutton> or <guibutton>OK</guibutton>.
2378 By default, the <userinput><guilabel>Automatic Selection</guilabel></userinput> option is
2379 active, which chooses a more appropriate color theme according to the
2380 <emphasis>&kde; &plasma; color scheme</emphasis> used in the text editing application;
2381 it usually chooses between <quote>Breeze Light</quote> and <quote>Breeze Dark</quote>
2382 if the scheme is light or dark, respectively.
2383 </para>
2384 
2385 <tip>
2386 <para>
2387 You can adjust the &kde; global color scheme in the
2388 <ulink url="help:/kcontrol/colors/"><quote>Colors</quote> module in &systemsettings;</ulink>.
2389 You can also change it in some applications individually such as &kate; or &kdevelop;, from the menu
2390 <menuchoice><guimenu>Settings</guimenu><guisubmenu>Color Scheme</guisubmenu></menuchoice>.
2391 </para>
2392 </tip>
2393 
2394 <sect3 id="color-themes-gui-new-theme">
2395 
2396 <title>Create a new theme</title>
2397 
2398 <para>To create a new theme, it is first necessary to copy an existing one. Select an existing
2399 theme which you want to use as a base, such as <quote>Breeze Light</quote> or <quote>Breeze Dark</quote>,
2400 and click <guibutton>Copy</guibutton>. Then write a name for the new theme.
2401 </para>
2402 
2403 <para>If you want to modify a built-in or read-only theme, you must first copy it under a different name.</para>
2404 
2405 </sect3>
2406 
2407 <sect3 id="color-themes-gui-import-export">
2408 
2409 <title>Import or export &JSON; theme files</title>
2410 
2411 <para>You can export a selected theme (including built-in ones) to a
2412 <link linkend="color-themes-json">&JSON; file</link> with <userinput>.theme</userinput>
2413 extension, with the <guibutton>Export</guibutton> button. This will open a dialog
2414 to save the file. To add a color theme from an external
2415 <link linkend="color-themes-json">&JSON; file</link>, just press the
2416 <guibutton>Import</guibutton> button and select the
2417 <userinput>.theme</userinput> file from the dialog.
2418 </para>
2419 
2420 <tip>
2421 <itemizedlist>
2422 
2423 <listitem>
2424 <para>As <link linkend="color-themes-json-overview">mentioned above</link>, user-customized theme
2425 files are stored in the <filename class="directory">org.kde.syntax-highlighting/themes/</filename>
2426 directory. When you copy or create a theme, it will automatically appear there. Also, importing
2427 or adding a theme is equivalent to copying an external <userinput>.theme</userinput> file into this
2428 directory. KSyntaxHighlighting automatically picks up color theme files from this directory.</para>
2429 </listitem>
2430 
2431 <listitem>
2432 <para>If you want to publish a theme created by you, it is essential to check the
2433 <link linkend="color-themes-json-metadata">metadata</link> object of the
2434 <link linkend="color-themes-json">&JSON; file</link>, adding the respective license and
2435 checking the revision number.</para>
2436 </listitem>
2437 
2438 </itemizedlist>
2439 </tip>
2440 
2441 </sect3>
2442 
2443 <sect3 id="color-themes-gui-editing">
2444 
2445 <title>Editing color themes</title>
2446 
2447 <sect4 id="prefcolors-colors">
2448 
2449 <title>Colors</title>
2450 
2451 <para>Here the colors of the text editing area are adjusted. These are detailed in
2452 <xref linkend="color-themes-editor-colors"/>.</para>
2453 
2454 </sect4>
2455 
2456 <sect4 id="prefcolors-normal-text-styles">
2457 
2458 <title>Default Text Styles</title>
2459 
2460 <para>The default text styles are inherited by the highlight text styles,
2461 allowing the editor to present text in a very consistent way, for example comment
2462 text is using the same style in almost all of the text formats that
2463 KSyntaxHighlighting can highlight.</para>
2464 <para>The name in the list of styles is using the style configured for
2465 the item, providing you with an immediate preview when configuring a style.
2466 </para>
2467 <para>Each style lets you select common attributes as well as foreground
2468 and background colors. To unset a background color, right-click to use the
2469 context menu.</para>
2470 <para>The attributes of this area are detailed in
2471 <xref linkend="color-themes-text-styles"/>.</para>
2472 
2473 </sect4>
2474 
2475 <sect4 id="prefcolors-highlighting-text-styles">
2476 
2477 <title>Highlighting Text Styles</title>
2478 
2479 <para>Here you can edit the text styles used by a specific highlight definition.
2480 The editor preselects the highlight used by your current document. To work on a
2481 different highlight, select one in the <guilabel>Highlight</guilabel> combobox
2482 above the style list.
2483 </para>
2484 <para>The name in the list of styles is using the style configured for
2485 the item, providing you with an immediate preview when configuring a style.
2486 </para>
2487 <para>Each style lets you select common attributes as well as foreground
2488 and background colors. To unset a background color, right-click to use the
2489 context menu. In addition you can see if a style is equal to the default style
2490 used for the item, and set it to that if not.</para>
2491 <para>You will notice that many highlights contain other highlights represented
2492 by groups in the style list. For example most highlights import the Alert
2493 highlight, and many source code formats imports the Doxygen highlight. Editing
2494 colors in those groups only affects the styles when used in the edited highlight
2495 format.
2496 </para>
2497 
2498 </sect4>
2499 
2500 </sect3>
2501 
2502 </sect2>
2503 
2504 <sect2 id="color-themes-tips-and-tricks">
2505 
2506 <title>Tips &amp; Tricks</title>
2507 
2508 <sect3 id="color-themes-contrast">
2509 
2510 <title>Contrast of Text Colors</title>
2511 
2512 <para>An important aspect when working with color themes is to choose a text contrast
2513 that makes it easier to read, especially in combination with the background.</para>
2514 
2515 <para>The <userinput>Kontrast</userinput> application is a color contrast checker. It tells
2516 you that the text color and background color combinations are readable and accessible, so
2517 this is an excellent tool to help you create color themes.</para>
2518 
2519 <para>You can download <userinput>Kontrast</userinput> from
2520 <ulink url="https://apps.kde.org/en/kontrast">the &kde; Applications website</ulink>
2521 or from <ulink url="https://flathub.org/apps/details/org.kde.kontrast">the Flatpak
2522 package on Flathub</ulink> (only in GNU/Linux).</para>
2523 
2524 <para>The GNOME <userinput>Contrast</userinput> application is similar. You can download
2525 <ulink url="https://flathub.org/apps/details/org.gnome.design.Contrast">the Flatpak
2526 package on Flathub</ulink> (only in GNU/Linux).</para>
2527 
2528 </sect3>
2529 
2530 <sect3 id="color-themes-tips-and-tricks-consistency">
2531 
2532 <title>Suggestions of Consistency with Syntax Highlighting</title>
2533 
2534 <para>KSyntaxHighlighting includes <ulink url="https://kate-editor.org/syntax/">more
2535 than 300 syntax highlighting definitions</ulink>, therefore it is ideal that you
2536 make sure your new theme looks good in all syntax highlighting definitions.
2537 The built-in color themes have the following similarities that it is
2538 recommended (but not required) to follow to achieve a correct display of all syntax
2539 highlighting definitions:</para>
2540 
2541 <itemizedlist>
2542 <listitem><para>Use bold for the <quote>Keyword</quote> and <quote>ControlFlow</quote>
2543 <link linkend="color-themes-text-styles">text styles</link>.</para></listitem>
2544 
2545 <listitem><para>Do not use background color in any
2546 <link linkend="color-themes-text-styles">text style</link>, except <quote>Alert</quote>
2547 and <quote>RegionMarker</quote>.</para></listitem>
2548 </itemizedlist>
2549 
2550 <para>Most of the syntax highlighters are intended to look good on the default themes
2551 <quote>Breeze Light</quote> and <quote>Breeze Dark</quote>, therefore, another way to
2552 maintain consistency is to use similar colors in the
2553 <link linkend="color-themes-text-styles">text styles</link>, like <emphasis>green</emphasis>
2554 for <quote>Preprocessor</quote> and <quote>Others</quote>, <emphasis>blue</emphasis> for
2555 <quote>DataType</quote> and <quote>Attribute</quote>, or <emphasis>purple</emphasis> for
2556 <quote>Function</quote>.</para>
2557 
2558 <para>Note that these recommendations are not mandatory when creating and publishing
2559 a theme.</para>
2560 
2561 </sect3>
2562 
2563 </sect2>
2564 
2565 </sect1>
2566 
2567 
2568 <sect1 id="dev-scripting">
2569 <title>Scripting with &javascript;</title>
2570 
2571 <para>
2572 The &kappname; editor component is easily extensible by writing scripts.
2573 The scripting language is ECMAScript (widely known as &javascript;).
2574 &kappname; supports two kinds of scripts: indentation and command line scripts.
2575 </para>
2576 
2577 <sect2 id="dev-scripting-indentation">
2578 <title>Indentation Scripts</title>
2579 
2580 <para>
2581 Indentation scripts - also referred as indenters - automatically indent the
2582 source code while typing text. As an example, after hitting the return key
2583 the indentation level often increases.
2584 </para>
2585 
2586 <para>
2587 The following sections describe step by step how to create the skeleton for a
2588 simple indenter. As a first step, create a new <filename>*.js</filename> file
2589 called &eg; <filename>javascript.js</filename> in the local home folder
2590 <filename>$<envar>XDG_DATA_HOME</envar>/katepart5/script/indentation</filename>.
2591 Therein, the environment variable <envar>XDG_DATA_HOME</envar> typically expands to
2592 either <filename>~/.local</filename> or <filename>~/.local/share</filename>.
2593 </para>
2594 <para>On &Windows; these files are located in <filename>%USERPROFILE%\AppData\Local\katepart5\script\indentation</filename>.
2595 <replaceable>%USERPROFILE%</replaceable> usually expands to <filename>C:\\Users\\<replaceable>user</replaceable></filename>.</para>
2596 
2597 <sect3 id="dev-scripting-indentation-header">
2598 <title>The Indentation Script Header</title>
2599 <para>
2600 The header of the file <filename>javascript.js</filename> is embedded as &JSON; at the beginning of the document as follows:
2601 
2602 <programlisting>
2603 var katescript = {
2604     "name": "JavaScript",
2605     "author": "Example Name &lt;example.name@some.address.org&gt;",
2606     "license": "BSD License",
2607     "revision": 1,
2608     "kate-version": "5.1",
2609     "required-syntax-style": "javascript",
2610     "indent-languages": ["javascript"],
2611     "priority": 0,
2612 }; // kate-script-header, must be at the start of the file without comments
2613 </programlisting>
2614 
2615 Each entry is explained in detail now:
2616 <itemizedlist>
2617 <listitem><para>
2618 <literal>name</literal> [required]: This is the indenter name that appears in the menu
2619 <menuchoice><guimenu>Tools</guimenu><guimenuitem>Indentation</guimenuitem></menuchoice>
2620 and in the configuration dialog.
2621 </para></listitem>
2622 <listitem><para>
2623 <literal>author</literal> [optional]: The author's name and contact information.
2624 </para></listitem>
2625 <listitem><para>
2626 <literal>license</literal> [optional]: Short form of the license, such as BSD License or LGPLv3.
2627 </para></listitem>
2628 <listitem><para>
2629 <literal>revision</literal> [required]: The revision of the script. This number should be increased whenever the script is modified.
2630 </para></listitem>
2631 <listitem><para>
2632 <literal>kate-version</literal> [required]: Minimum required &kappname; version.
2633 </para></listitem>
2634 <listitem><para>
2635 <literal>required-syntax-style</literal> [optional]: The required syntax style, which matches the specified <literal>style</literal> in syntax highlighting files. This is important for indenters that rely on specific highlight information in the document. If a required syntax style is specified, the indenter is available only when the appropriate highlighter is active. This prevents <quote>undefined behavior</quote> caused by using the indenter without the expected highlighting schema. For instance, the Ruby indenter makes use of this in the files <filename>ruby.js</filename> and <filename>ruby.xml</filename>.
2636 </para></listitem>
2637 <listitem><para>
2638 <literal>indent-languages</literal> [optional]: &JSON; array of syntax styles the indenter can indent correctly, &eg;: <literal>["c++", "java"]</literal>.
2639 </para></listitem>
2640 <listitem><para>
2641 <literal>priority</literal> [optional]: If several indenters are suited for a certain highlighted file, the priority decides which indenter is chosen as default indenter.
2642 </para></listitem>
2643 </itemizedlist>
2644 </para>
2645 
2646 </sect3>
2647 
2648 <sect3 id="dev-scripting-indentation-body">
2649 <title>The Indenter Source Code</title>
2650 <para>
2651 Having specified the header this section explains how the indentation scripting
2652 itself works. The basic skeleton of the body looks like this:
2653 
2654 <programlisting>
2655 // required katepart js libraries, &eg; range.js if you use Range
2656 require ("range.js");
2657 
2658 triggerCharacters = "{}/:;";
2659 function indent(line, indentWidth, ch)
2660 {
2661     // called for each newline (ch == '\n') and all characters specified in
2662     // the global variable triggerCharacters. When calling <menuchoice><guimenu>Tools</guimenu><guimenuitem>Format Indentation</guimenuitem></menuchoice>
2663     // the variable ch is empty, i.e. ch == ''.
2664     //
2665     // see also: Scripting API
2666     return -2;
2667 }
2668 </programlisting>
2669 
2670 The function <function>indent()</function> has three parameters:
2671 <itemizedlist>
2672 <listitem><para><literal>line</literal>: the line that has to be indented</para></listitem>
2673 <listitem><para><literal>indentWidth</literal>: the indentation width in number of spaces</para></listitem>
2674 <listitem><para><literal>ch</literal>: either a newline character (<literal>ch == '\n'</literal>), the trigger character specified in <literal>triggerCharacters</literal> or empty if the user invoked the action <menuchoice><guimenu>Tools</guimenu><guimenuitem>Format Indentation</guimenuitem></menuchoice>.</para></listitem>
2675 </itemizedlist>
2676 The return value of the <function>indent()</function> function specifies how
2677 the line will be indented. If the return value is a simple integer number, it
2678 is interpreted as follows:
2679 <itemizedlist>
2680 <listitem><para>return value <literal>-2</literal>: do nothing</para></listitem>
2681 <listitem><para>return value <literal>-1</literal>: keep indentation (searches for previous non-blank line)</para></listitem>
2682 <listitem><para>return value <literal> 0</literal>: numbers &gt;= 0 specify the indentation depth in spaces</para></listitem>
2683 </itemizedlist>
2684 Alternatively, an array of two elements can be returned:
2685 <itemizedlist>
2686 <listitem><para><literal>return [ indent, align ];</literal></para></listitem>
2687 </itemizedlist>
2688 In this case, the first element is the indentation depth as above with the
2689 same meaning of the special values. However, the second element is an absolute
2690 value representing a column for <quote>alignment</quote>. If this value is higher than the
2691 indent value, the difference represents a number of spaces to be added after
2692 the indentation of the first parameter. Otherwise, the second number is ignored.
2693 Using tabs and spaces for indentation is often referred to as <quote>mixed mode</quote>.
2694 </para>
2695 
2696 <para>
2697 Consider the following example: Assume using tabs to indent, and tab width is set
2698 to 4. Here, &lt;tab&gt; represents a tab and '.' a space:
2699 <programlisting>
2700 1: &lt;tab&gt;&lt;tab&gt;foobar("hello",
2701 2: &lt;tab&gt;&lt;tab&gt;......."world");
2702 </programlisting>
2703 When indenting line 2, the <function>indent()</function> function returns [8, 15]. As result, two
2704 tabs are inserted to indent to column 8, and 7 spaces are added to align the
2705 second parameter under the first, so that it stays aligned if the file is viewed
2706 with a different tab width.
2707 </para>
2708 
2709 <para>
2710 A default &kde; installation ships &kappname; with several indenters. The
2711 corresponding &javascript; source code can be found in <filename>$<envar>XDG_DATA_DIRS</envar>/katepart5/script/indentation</filename>.</para>
2712 <para>On &Windows; these files are located in <filename>%USERPROFILE%\AppData\Local\katepart5\script\indentation</filename>.
2713 <replaceable>%USERPROFILE%</replaceable> usually expands to <filename>C:\\Users\\<replaceable>user</replaceable></filename>.
2714 </para>
2715 
2716 <para>
2717 Developing an indenter requires reloading the scripts to see whether the changes
2718 behave appropriately. Instead of restarting the application, simply switch to
2719 the command line and invoke the command <command>reload-scripts</command>.
2720 </para>
2721 
2722 <para>
2723 If you develop useful scripts please consider contributing to the &kappname; Project
2724 by <ulink url="mailto:kwrite-devel@kde.org">contacting the mailing list</ulink>.
2725 </para>
2726 
2727 </sect3>
2728 </sect2>
2729 
2730 <sect2 id="dev-scripting-command-line">
2731 <title>Command Line Scripts</title>
2732 
2733 <para>
2734 As it is hard to satisfy everyone's needs, &kappname; supports little helper tools
2735 for quick text manipulation through the
2736 <link linkend="advanced-editing-tools-commandline">built-in command line</link>.
2737 For instance, the command
2738 <command>sort</command> is implemented as a script. This section explains how to create
2739 <filename>*.js</filename> files to extend &kappname; with arbitrary helper scripts.
2740 </para>
2741 
2742 <para>
2743 Command line scripts are located in the same folder as indentation scripts.
2744 So as a first step, create a new <filename>*.js</filename> file called
2745 <filename>myutils.js</filename> in the local home folder
2746 <filename>$<envar>XDG_DATA_HOME</envar>/katepart5/script/commands</filename>.
2747 Therein, the environment variable <envar>XDG_DATA_HOME</envar> typically expands to
2748 either <filename>~/.local</filename> or <filename>~/.local/share</filename>.</para>
2749 <para>On &Windows; these files are located in <filename>%USERPROFILE%\AppData\Local\katepart5\script\commands</filename>.
2750 <replaceable>%USERPROFILE%</replaceable> usually expands to <filename>C:\\Users\\<replaceable>user</replaceable></filename>.
2751 </para>
2752 
2753 <sect3 id="dev-scripting-command-line-header">
2754 <title>The Command Line Script Header</title>
2755 <para>
2756 The header of each command line script is embedded in &JSON; at the beginning of the script as follows:
2757 
2758 <programlisting>
2759 var katescript = {
2760     "author": "Example Name &lt;example.name@some.address.org&gt;",
2761     "license": "LGPLv2+",
2762     "revision": 1,
2763     "kate-version": "5.1",
2764     "functions": ["sort", "moveLinesDown"],
2765     "actions": [
2766         {   "function": "sort",
2767             "name": "Sort Selected Text",
2768             "category": "Editing",
2769             "interactive": "false"
2770         },
2771         {   "function": "moveLinesDown",
2772             "name": "Move Lines Down",
2773             "category": "Editing",
2774             "shortcut": "Ctrl+Shift+Down",
2775             "interactive": "false"
2776         }
2777     ]
2778 }; // kate-script-header, must be at the start of the file without comments
2779 </programlisting>
2780 
2781 Each entry is explained in detail now:
2782 <itemizedlist>
2783 <listitem><para><literal>author</literal> [optional]: The author's name and contact information.</para></listitem>
2784 <listitem><para><literal>license</literal> [optional]: Short form of the license, such as BSD License or LGPLv2.</para></listitem>
2785 <listitem><para><literal>revision</literal> [required]: The revision of the script. This number should be increased whenever the script is modified.</para></listitem>
2786 <listitem><para><literal>kate-version</literal> [required]: Minimum required &kappname; version.</para></listitem>
2787 <listitem><para><literal>functions</literal> [required]: &JSON; array of commands in the script.</para></listitem>
2788 <listitem><para><literal>actions</literal> [optional]: &JSON; Array of &JSON; objects that defines the actions that appear in the application menu. Detailed information is provided in the section <link linkend="advanced-editing-tools-commandline">Binding Shortcuts</link>.</para></listitem>
2789 </itemizedlist>
2790 </para>
2791 
2792 <para>
2793 Since the value of <literal>functions</literal> is a &JSON; array, a single script is able to contain an arbitrary number
2794 of command line commands. Each function is available through &kappname;'s
2795 <link linkend="advanced-editing-tools-commandline">built-in command line</link>.
2796 </para>
2797 </sect3>
2798 
2799 <sect3 id="dev-scripting-command-line-body">
2800 <title>The Script Source Code</title>
2801 
2802 <para>
2803 All functions specified in the header have to be implemented in the script.
2804 For instance, the script file from the example above needs to implement the two
2805 functions <command>sort</command> and <command>moveLinesDown</command>.
2806 All functions have the following syntax:
2807 
2808 <programlisting>
2809 // required katepart js libraries, &eg; range.js if you use Range
2810 require ("range.js");
2811 
2812 function &lt;name&gt;(arg1, arg2, ...)
2813 {
2814     // ... implementation, see also: Scripting API
2815 }
2816 </programlisting>
2817 </para>
2818 
2819 <para>
2820 Arguments in the command line are passed to the function as
2821 <parameter>arg1</parameter>, <parameter>arg2</parameter>, &etc;
2822 In order to provide documentation for each command, simply implement the
2823 '<function>help</function>' function as follows:
2824 
2825 <programlisting>
2826 function help(cmd)
2827 {
2828     if (cmd == "sort") {
2829         return i18n("Sort the selected text.");
2830     } else if (cmd == "...") {
2831         // ...
2832     }
2833 }
2834 </programlisting>
2835 
2836 Executing <command>help sort</command> in the command line then calls this help function with
2837 the argument <parameter>cmd</parameter> set to the given command, &ie;
2838 <parameter>cmd == "sort"</parameter>. &kappname; then presents the returned text as
2839 documentation to the user. Make sure to
2840 <link linkend="dev-scripting-api-i18n">translate the strings</link>.
2841 </para>
2842 
2843 <para>
2844 Developing a command line script requires reloading the scripts to see whether
2845 the changes behave appropriately. Instead of restarting the application, simply
2846 switch to the command line and invoke the command <command>reload-scripts</command>.
2847 </para>
2848 
2849 <sect4 id="dev-scripting-command-line-shortcuts">
2850 <title>Binding Shortcuts</title>
2851 <para>In order to make the scripts accessible in the application menu and assign shortcuts, the script needs to provide an appropriate
2852 script header. In the above example, both functions <literal>sort</literal> and <literal>moveLinesDown</literal> appear in the menu
2853 due to the following part in the script header:
2854 <programlisting>
2855 var katescript = {
2856     ...
2857     "actions": [
2858         {   "function": "sort",
2859             "name": "Sort Selected Text",
2860             "icon": "",
2861             "category": "Editing",
2862             "interactive": "false"
2863         },
2864         {   "function": "moveLinesDown",
2865             "name": "Move Lines Down",
2866             "icon": "",
2867             "category": "Editing",
2868             "shortcut": "Ctrl+Shift+Down",
2869             "interactive": "false"
2870         }
2871     ]
2872 };
2873 </programlisting>
2874 The fields for one action are as follows:
2875 <itemizedlist>
2876 <listitem><para><literal>function</literal> [required]: The function that should appear in the menu <menuchoice><guimenu>Tools</guimenu> <guisubmenu>Scripts</guisubmenu></menuchoice>.</para></listitem>
2877 <listitem><para><literal>name</literal> [required]: The text appears in the script menu.</para></listitem>
2878 <listitem><para><literal>icon</literal> [optional]: The icon appears next to the text in the menu. All &kde; icon names can be used here.</para></listitem>
2879 <listitem><para><literal>category</literal> [optional]: If a category is specified, the script appears in a submenu.</para></listitem>
2880 <listitem><para><literal>shortcut</literal> [optional]: The shortcut given here is the default shortcut. Example: <literal>Ctrl+Alt+t</literal>. See the <ulink url="https://doc.qt.io/qt-5/qt.html#Key-enum">&Qt; documentation</ulink> for further details.</para></listitem>
2881 <listitem><para><literal>interactive</literal> [optional]: If the script needs user input in the command line, set this to <literal>true</literal>.</para></listitem>
2882 </itemizedlist>
2883 </para>
2884 
2885 <para>
2886 If you develop useful scripts please consider contributing to the &kappname; Project
2887 by <ulink url="mailto:kwrite-devel@kde.org">contacting the mailing list</ulink>.
2888 </para>
2889 
2890 </sect4>
2891 </sect3>
2892 </sect2>
2893 
2894 <sect2 id="dev-scripting-api">
2895 <title>Scripting API</title>
2896 
2897 <para>
2898 The scripting API presented here is available to all scripts, &ie; indentation
2899 scripts and command line commands.
2900 The <classname>Cursor</classname> and <classname>Range</classname> classes are provided by library files in <filename>$<envar>XDG_DATA_DIRS</envar>/katepart5/libraries</filename>.
2901 If you want to use them in your script, which needs to use some of the <classname>Document</classname> or <classname>View</classname> functions, please include the necessary library by using:
2902 
2903 <programlisting>
2904 // required katepart js libraries, &eg; range.js if you use Range
2905 require ("range.js");
2906 </programlisting>
2907 </para>
2908 
2909 <para>
2910 To extend the standard scripting API with your own functions and prototypes simply
2911 create a new file in &kde;'s local configuration folder
2912 <filename>$<envar>XDG_DATA_HOME</envar>/katepart5/libraries</filename> and include it into your script using:
2913 
2914 <programlisting>
2915 require ("myscriptnamehere.js");
2916 </programlisting>
2917 
2918 </para>
2919 
2920 <para>On &Windows; these files are located in <filename>%USERPROFILE%\AppData\Local\katepart5\libraries</filename>.
2921 <replaceable>%USERPROFILE%</replaceable> usually expands to <filename>C:\\Users\\<replaceable>user</replaceable></filename>.</para>
2922 
2923 <para>
2924 To extend existing prototypes like <classname>Cursor</classname> or
2925 <classname>Range</classname>, the recommended way is to
2926 <emphasis>not</emphasis> modify the global <filename>*.js</filename> files.
2927 Instead, change the <classname>Cursor</classname> prototype in &javascript; after the <filename>cursor.js</filename> is included into your
2928 script via <literal>require</literal>.
2929 </para>
2930 
2931 <sect3 id="dev-scripting-api-prototypes">
2932 <title>Cursors and Ranges</title>
2933 
2934 <para>
2935 As &kappname; is a text editor, all the scripting API is based on cursors and
2936 ranges whenever possible. A Cursor is a simple <literal>(line, column)</literal>
2937 tuple representing a text position in the document. A Range spans text from a
2938 starting cursor position to an ending cursor position. The API is explained in
2939 detail in the next sections.
2940 </para>
2941 
2942 <sect4 id="dev-scripting-api-cursors">
2943 <title>The Cursor Prototype</title>
2944 
2945 <variablelist><varlistentry>
2946 <term><synopsis>
2947 Cursor();
2948 </synopsis></term>
2949 <listitem><para>
2950 Constructor. Returns a Cursor at position <literal>(0, 0)</literal>.</para>
2951 <para>Example: <function>var cursor = new Cursor();</function>
2952 </para></listitem>
2953 </varlistentry>
2954 
2955 
2956 <varlistentry>
2957 <term><synopsis>
2958 Cursor(<parameter>int <replaceable>line</replaceable></parameter>, <parameter>int <replaceable>column</replaceable></parameter>);
2959 </synopsis></term>
2960 <listitem><para>
2961 Constructor. Returns a Cursor at position (line, column).
2962 </para>
2963 <para>Example: <function>var cursor = new Cursor(3, 42);</function>
2964 </para></listitem>
2965 </varlistentry>
2966 
2967 
2968 <varlistentry>
2969 <term><synopsis>
2970 Cursor(<parameter>Cursor <replaceable>other</replaceable></parameter>);
2971 </synopsis></term>
2972 <listitem><para>
2973 Copy constructor. Returns a copy of the cursor <replaceable>other</replaceable>.
2974 </para>
2975 <para>Example: <function>var copy = new Cursor(other);</function>
2976 </para></listitem>
2977 </varlistentry>
2978 
2979 
2980 <varlistentry>
2981 <term><synopsis>
2982 Cursor Cursor.clone();
2983 </synopsis></term>
2984 <listitem><para>
2985 Returns a clone of the cursor.</para>
2986 <para>Example: <function>var clone = cursor.clone();</function>
2987 </para></listitem>
2988 </varlistentry>
2989 
2990 
2991 <varlistentry>
2992 <term><synopsis>
2993 Cursor.setPosition(<parameter>int <replaceable>line</replaceable></parameter>, <parameter>int <replaceable>column</replaceable></parameter>);
2994 </synopsis></term>
2995 <listitem><para>
2996 Sets the cursor position to <replaceable>line</replaceable> and <replaceable>column</replaceable>.</para>
2997 <para>
2998 Since: &kde; 4.11
2999 </para></listitem>
3000 </varlistentry>
3001 
3002 
3003 <varlistentry>
3004 <term><synopsis>
3005 bool Cursor.isValid();
3006 </synopsis></term>
3007 <listitem><para>
3008 Check whether the cursor is valid. The cursor is invalid, if line and/or
3009 column are set to <literal>-1</literal>.
3010 </para>
3011 <para>
3012 Example: <function>var valid = cursor.isValid();</function>
3013 </para></listitem>
3014 </varlistentry>
3015 
3016 
3017 <varlistentry>
3018 <term><synopsis>
3019 Cursor Cursor.invalid();
3020 </synopsis></term>
3021 <listitem><para>
3022 Returns a new invalid cursor located at <literal>(-1, -1)</literal>.
3023 </para>
3024 <para>Example: <function>var invalidCursor = cursor.invalid();</function>
3025 </para></listitem>
3026 </varlistentry>
3027 
3028 <varlistentry>
3029 <term><synopsis>
3030 int Cursor.compareTo(<parameter>Cursor <replaceable>other</replaceable></parameter>);
3031 </synopsis></term>
3032 <listitem><para>
3033 Compares this cursor to the cursor <replaceable>other</replaceable>. Returns
3034 <itemizedlist>
3035 <listitem><para><literal>-1</literal>, if this cursor is located before the cursor <replaceable>other</replaceable>,</para></listitem>
3036 <listitem><para><literal>0</literal>, if both cursors equal and</para></listitem>
3037 <listitem><para><literal>+1</literal>, if this cursor is located after the cursor <replaceable>other</replaceable>.</para></listitem>
3038 </itemizedlist>
3039 </para></listitem>
3040 </varlistentry>
3041 
3042 
3043 <varlistentry>
3044 <term><synopsis>
3045 bool Cursor.equals(<parameter>Cursor <replaceable>other</replaceable></parameter>);
3046 </synopsis></term>
3047 <listitem><para>
3048 Returns <literal>true</literal>, if this cursor and the cursor <replaceable>other</replaceable> are
3049 equal, otherwise <literal>false</literal>.
3050 </para></listitem>
3051 </varlistentry>
3052 
3053 
3054 <varlistentry>
3055 <term><synopsis>
3056 String Cursor.toString();
3057 </synopsis></term>
3058 <listitem><para>
3059 Returns the cursor as a string of the form <quote><literal>Cursor(line, column)</literal></quote>.
3060 </para></listitem>
3061 </varlistentry></variablelist>
3062 
3063 </sect4>
3064 
3065 
3066 <sect4 id="dev-scripting-api-ranges">
3067 <title>The Range Prototype</title>
3068 
3069 <variablelist><varlistentry>
3070 <term><synopsis>
3071 Range();
3072 </synopsis></term>
3073 <listitem><para>
3074 Constructor. Calling <literal>new Range()</literal> returns a Range at (0, 0) - (0, 0).
3075 </para></listitem>
3076 </varlistentry>
3077 
3078 
3079 <varlistentry>
3080 <term><synopsis>
3081 Range(<parameter>Cursor <replaceable>start</replaceable></parameter>, <parameter>Cursor <replaceable>end</replaceable></parameter>);
3082 </synopsis></term>
3083 <listitem><para>
3084 Constructor. Calling <literal>new Range(<replaceable>start</replaceable>, <replaceable>end</replaceable>)</literal> returns the Range (<replaceable>start</replaceable>, <replaceable>end</replaceable>).
3085 </para></listitem>
3086 </varlistentry>
3087 
3088 
3089 <varlistentry>
3090 <term><synopsis>
3091 Range(<parameter>int <replaceable>startLine</replaceable></parameter>, <parameter>int <replaceable>startColumn</replaceable></parameter>, <parameter>int <replaceable>endLine</replaceable></parameter>, <parameter>int <replaceable>endColumn</replaceable></parameter>);
3092 </synopsis></term>
3093 <listitem><para>
3094 Constructor. Calling <literal>new Range(<replaceable>startLine</replaceable>, <replaceable>startColumn</replaceable>, <replaceable>endLine</replaceable>, <replaceable>endColumn</replaceable>)</literal>
3095 returns the Range from (<replaceable>startLine</replaceable>, <replaceable>startColumn</replaceable>) to (<replaceable>endLine</replaceable>, <replaceable>endColumn</replaceable>).
3096 </para></listitem>
3097 </varlistentry>
3098 
3099 
3100 <varlistentry>
3101 <term><synopsis>
3102 Range(<parameter>Range <replaceable>other</replaceable></parameter>);
3103 </synopsis></term>
3104 <listitem><para>
3105 Copy constructor. Returns a copy of Range <replaceable>other</replaceable>.
3106 </para></listitem>
3107 </varlistentry>
3108 
3109 
3110 <varlistentry>
3111 <term><synopsis>
3112 Range Range.clone();
3113 </synopsis></term>
3114 <listitem><para>
3115 Returns a clone of the range.
3116 </para>
3117 <para>Example: <function>var clone = range.clone();</function>
3118 </para></listitem>
3119 </varlistentry>
3120 
3121 
3122 <varlistentry>
3123 <term><synopsis>
3124 bool Range.isEmpty();
3125 </synopsis></term>
3126 <listitem><para>
3127 Returns <literal>true</literal>, if the start and end cursors are equal.
3128 </para>
3129 <para>Example: <function>var empty = range.isEmpty();</function>
3130 </para>
3131 <para>
3132 Since: &kde; 4.11
3133 </para></listitem>
3134 </varlistentry>
3135 
3136 
3137 <varlistentry>
3138 <term><synopsis>
3139 bool Range.isValid();
3140 </synopsis></term>
3141 <listitem><para>
3142 Returns <literal>true</literal>, if both start and end cursor are valid, otherwise <literal>false</literal>.
3143 </para>
3144 <para>Example: <function>var valid = range.isValid();</function>
3145 </para></listitem>
3146 </varlistentry>
3147 
3148 
3149 <varlistentry>
3150 <term><synopsis>
3151 Range Range.invalid();
3152 </synopsis></term>
3153 <listitem><para>
3154 Returns the Range from (-1, -1) to (-1, -1).
3155 </para></listitem>
3156 </varlistentry>
3157 
3158 
3159 <varlistentry>
3160 <term><synopsis>
3161 bool Range.contains(<parameter>Cursor <replaceable>cursor</replaceable></parameter>);
3162 </synopsis></term>
3163 <listitem><para>
3164 Returns <literal>true</literal>, if this range contains the cursor position, otherwise <literal>false</literal>.
3165 </para></listitem>
3166 </varlistentry>
3167 
3168 
3169 <varlistentry>
3170 <term><synopsis>
3171 bool Range.contains(<parameter>Range <replaceable>other</replaceable></parameter>);
3172 </synopsis></term>
3173 <listitem><para>
3174 Returns <literal>true</literal>, if this range contains the Range <replaceable>other</replaceable>,
3175 otherwise <literal>false</literal>.
3176 </para></listitem>
3177 </varlistentry>
3178 
3179 
3180 <varlistentry>
3181 <term><synopsis>
3182 bool Range.containsColumn(<parameter>int <replaceable>column</replaceable></parameter>);
3183 </synopsis></term>
3184 <listitem><para>
3185 Returns <literal>true</literal>, if <replaceable>column</replaceable> is in the half open interval
3186 <literal>[start.column, end.column)</literal>, otherwise <literal>false</literal>.
3187 </para></listitem>
3188 </varlistentry>
3189 
3190 
3191 <varlistentry>
3192 <term><synopsis>
3193 bool Range.containsLine(<parameter>int <replaceable>line</replaceable></parameter>);
3194 </synopsis></term>
3195 <listitem><para>
3196 Returns <literal>true</literal>, if <replaceable>line</replaceable> is in the half open interval
3197 <literal>[start.line, end.line)</literal>, otherwise <literal>false</literal>.
3198 </para></listitem>
3199 </varlistentry>
3200 
3201 
3202 <varlistentry>
3203 <term><synopsis>
3204 bool Range.overlaps(<parameter>Range <replaceable>other</replaceable></parameter>);
3205 </synopsis></term>
3206 <listitem><para>
3207 Returns <literal>true</literal>, if this range and the range <replaceable>other</replaceable> share
3208 a common region, otherwise <literal>false</literal>.
3209 </para></listitem>
3210 </varlistentry>
3211 
3212 
3213 <varlistentry>
3214 <term><synopsis>
3215 bool Range.overlapsLine(<parameter>int <replaceable>line</replaceable></parameter>);
3216 </synopsis></term>
3217 <listitem><para>
3218 Returns <literal>true</literal>, if <replaceable>line</replaceable> is in the interval
3219 <literal>[start.line, end.line]</literal>, otherwise <literal>false</literal>.
3220 </para></listitem>
3221 </varlistentry>
3222 
3223 
3224 <varlistentry>
3225 <term><synopsis>
3226 bool Range.overlapsColumn(<parameter>int <replaceable>column</replaceable></parameter>);
3227 </synopsis></term>
3228 <listitem><para>
3229 Returns <literal>true</literal>, if <replaceable>column</replaceable> is in the interval
3230 <literal>[start.column, end.column]</literal>, otherwise <literal>false</literal>.
3231 </para></listitem>
3232 </varlistentry>
3233 
3234 
3235 <varlistentry>
3236 <term><synopsis>
3237 bool Range.onSingleLine();
3238 </synopsis></term>
3239 <listitem><para>
3240 Returns <literal>true</literal>, if the range starts and ends at the same line,
3241 &ie; if <replaceable>Range.start.line == Range.end.line</replaceable>.
3242 </para>
3243 <para>
3244 Since: &kde; 4.9
3245 </para></listitem>
3246 </varlistentry>
3247 
3248 
3249 <varlistentry>
3250 <term><synopsis>
3251 bool Range.equals(<parameter>Range <replaceable>other</replaceable></parameter>);
3252 </synopsis></term>
3253 <listitem><para>
3254 Returns <literal>true</literal>, if this range and the Range <replaceable>other</replaceable> are
3255 equal, otherwise <literal>false</literal>.
3256 </para></listitem>
3257 </varlistentry>
3258 
3259 
3260 <varlistentry>
3261 <term><synopsis>
3262 String Range.toString();
3263 </synopsis></term>
3264 <listitem><para>
3265 Returns the range as a string of the form <quote><literal>Range(Cursor(line, column), Cursor(line, column))</literal></quote>.
3266 </para></listitem>
3267 </varlistentry></variablelist>
3268 
3269 </sect4>
3270 </sect3>
3271 
3272 <sect3 id="dev-scripting-api-global">
3273 <title>Global Functions</title>
3274 <para>This section lists all global functions.</para>
3275 
3276 
3277 <sect4 id="dev-scripting-api-includes">
3278 <title>Reading &amp; Including Files</title>
3279 
3280 <variablelist><varlistentry>
3281 <term><synopsis>
3282 String read(<parameter>String <replaceable>file</replaceable></parameter>);
3283 </synopsis></term>
3284 <listitem><para>
3285 Will search the given <replaceable>file</replaceable> relative to the <literal>katepart5/script/files</literal> directory and return its content as a string.
3286 </para></listitem>
3287 </varlistentry></variablelist>
3288 
3289 <variablelist><varlistentry>
3290 <term><synopsis>
3291 void require(<parameter>String <replaceable>file</replaceable></parameter>);
3292 </synopsis></term>
3293 <listitem><para>
3294 Will search the given <replaceable>file</replaceable> relative to the <literal>katepart5/script/libraries</literal> directory and evaluate it.
3295 <literal>require</literal> is internally guarded against multiple inclusions of the same <replaceable>file</replaceable>.
3296 </para>
3297 <para>
3298   Since: &kde; 4.10
3299 </para>
3300 </listitem>
3301 </varlistentry></variablelist>
3302 
3303 </sect4>
3304 
3305 <sect4 id="dev-scripting-api-debug">
3306 <title>Debugging</title>
3307 
3308 <variablelist><varlistentry>
3309 <term><synopsis>
3310 void debug(<parameter>String <replaceable>text</replaceable></parameter>);
3311 </synopsis></term>
3312 <listitem><para>
3313 Prints <replaceable>text</replaceable> to <literal>stdout</literal> in the
3314 console launching the application.
3315 </para></listitem>
3316 </varlistentry></variablelist>
3317 
3318 </sect4>
3319 
3320 <sect4 id="dev-scripting-api-i18n">
3321 <title>Translation</title>
3322 
3323 <para>In order to support full localization, there are several functions to translate
3324 strings in scripts, namely <literal>i18n</literal>, <literal>i18nc</literal>,
3325 <literal>i18np</literal> and <literal>i18ncp</literal>. These functions behave
3326 exactly like <ulink url="https://techbase.kde.org/Development/Tutorials/Localization/i18n">
3327 &kde;'s translation functions</ulink>.
3328 </para>
3329 
3330 <para>The translation functions translate the wrapped strings through &kde;'s
3331 translation system to the language used in the application. Strings in scripts
3332 being developed in the official &kappname; sources are automatically extracted and
3333 translatable. In other words, as a &kappname; developer you do not have to bother with
3334 message extraction and translation. It should be noted though, that the translation
3335 only works inside the &kde; infrastructure, &ie;, new strings in 3rd-party
3336 scripts developed outside of &kde; are not translated.
3337 Therefore, please consider contributing your scripts to &kate; such that
3338 proper translation is possible.
3339 </para>
3340 
3341 <variablelist><varlistentry>
3342 <term><synopsis>
3343 void i18n(<parameter>String <replaceable>text</replaceable></parameter>, <replaceable>arg1</replaceable>, ...);
3344 </synopsis></term>
3345 <listitem><para>
3346 Translates <replaceable>text</replaceable> into the language used by the application.
3347 The arguments <replaceable>arg1</replaceable>, ..., are optional and used to
3348 replace the placeholders <literal>%1</literal>, <literal>%2</literal>, &etc;</para></listitem>
3349 </varlistentry>
3350 
3351 <varlistentry>
3352 <term><synopsis>
3353 void i18nc(<parameter>String <replaceable>context</replaceable></parameter>, <parameter>String <replaceable>text</replaceable></parameter>, <replaceable>arg1</replaceable>, ...);
3354 </synopsis></term>
3355 <listitem><para>
3356 Translates <replaceable>text</replaceable> into the language used by the
3357 application. Additionally, the string <replaceable>context</replaceable> is
3358 visible to translators so they can provide a better translation.
3359 The arguments <replaceable>arg1</replaceable>, ..., are optional and used to
3360 replace the placeholders <literal>%1</literal>, <literal>%2</literal>, &etc;</para></listitem>
3361 </varlistentry>
3362 
3363 <varlistentry>
3364 <term><synopsis>
3365 void i18np(<parameter>String <replaceable>singular</replaceable></parameter>, <parameter>String <replaceable>plural</replaceable></parameter>, <parameter>int <replaceable>number</replaceable></parameter>, <replaceable>arg1</replaceable>, ...);
3366 </synopsis></term>
3367 <listitem><para>
3368 Translates either <replaceable>singular</replaceable> or
3369 <replaceable>plural</replaceable> into the language used by the application,
3370 depending on the given <replaceable>number</replaceable>.
3371 The arguments <replaceable>arg1</replaceable>, ..., are optional and used to
3372 replace the placeholders <literal>%1</literal>, <literal>%2</literal>, &etc;</para></listitem>
3373 </varlistentry>
3374 
3375 <varlistentry>
3376 <term><synopsis>
3377 void i18ncp(<parameter>String <replaceable>context</replaceable></parameter>, <parameter>String <replaceable>singular</replaceable></parameter>, <parameter>String <replaceable>plural</replaceable></parameter>, <parameter>int <replaceable>number</replaceable></parameter>, <replaceable>arg1</replaceable>, ...);
3378 </synopsis></term>
3379 <listitem><para>
3380 Translates either <replaceable>singular</replaceable> or
3381 <replaceable>plural</replaceable> into the language used by the application,
3382 depending on the given <replaceable>number</replaceable>. Additionally, the
3383 string <replaceable>context</replaceable> is visible to translators so they
3384 can provide a better translation. The arguments <replaceable>arg1</replaceable>,
3385 ..., are optional and used to replace the placeholders <literal>%1</literal>,
3386 <literal>%2</literal>, &etc;</para></listitem>
3387 </varlistentry></variablelist>
3388 
3389 </sect4>
3390 </sect3>
3391 
3392 <sect3 id="dev-scripting-api-view">
3393 <title>The View API</title>
3394 <para>Whenever a script is being executed, there is a global variable
3395 <quote><literal>view</literal></quote> representing the current active editor
3396 view. The following is a list of all available View functions.
3397 
3398 <variablelist>
3399 
3400 <varlistentry>
3401 <term><synopsis>
3402 <function>void view.copy()</function>
3403 </synopsis></term>
3404 <listitem>
3405 <para>Copy the selection if there is one, otherwise the current line if the option <userinput>[ ] Copy/Cut the current line if no selection</userinput> is set.</para>
3406 <para>Since: &kde-frameworks; 5.79</para>
3407 </listitem>
3408 </varlistentry>
3409 
3410 
3411 <varlistentry>
3412 <term><synopsis>
3413 <function>void view.cut()</function>
3414 </synopsis></term>
3415 <listitem>
3416 <para>Cut the selection if there is one, otherwise the current line if the option <userinput>[ ] Copy/Cut the current line if no selection</userinput> is set.</para>
3417 <para>Since: &kde-frameworks; 5.79</para>
3418 </listitem>
3419 </varlistentry>
3420 
3421 
3422 <varlistentry>
3423 <term><synopsis>
3424 <function>void view.paste()</function>
3425 </synopsis></term>
3426 <listitem>
3427 <para>Paste the clipboard content.</para>
3428 <para>Since: &kde-frameworks; 5.79</para>
3429 </listitem>
3430 </varlistentry>
3431 
3432 
3433 <varlistentry>
3434 <term><synopsis>
3435 <function>Cursor view.cursorPosition()</function>
3436 </synopsis></term>
3437 <listitem><para>Returns the current cursor position in the view.</para></listitem>
3438 </varlistentry>
3439 
3440 
3441 <varlistentry>
3442 <term><synopsis>
3443 void view.setCursorPosition(<parameter>int <replaceable>line</replaceable></parameter>, <parameter>int <replaceable>column</replaceable></parameter>);
3444 void view.setCursorPosition(<parameter>Cursor <replaceable>cursor</replaceable></parameter>);
3445 </synopsis></term>
3446 <listitem><para>
3447 Set the current cursor position to either (line, column) or to the given cursor.
3448 </para></listitem>
3449 </varlistentry>
3450 
3451 
3452 <varlistentry>
3453 <term><synopsis>
3454 Cursor view.virtualCursorPosition();
3455 </synopsis></term>
3456 <listitem><para>
3457 Returns the virtual cursor position with each tab counting the corresponding amount of spaces depending on the current tab width.
3458 </para></listitem>
3459 </varlistentry>
3460 
3461 
3462 <varlistentry>
3463 <term><synopsis>
3464 void view.setVirtualCursorPosition(<parameter>int <replaceable>line</replaceable></parameter>, <parameter>int <replaceable>column</replaceable></parameter>);
3465 void view.setVirtualCursorPosition(<parameter>Cursor <replaceable>cursor</replaceable></parameter>);
3466 </synopsis></term>
3467 <listitem><para>
3468 Set the current virtual cursor position to (line, column) or to the given cursor.
3469 </para></listitem>
3470 </varlistentry>
3471 
3472 
3473 <varlistentry>
3474 <term><synopsis>
3475 String view.selectedText();
3476 </synopsis></term>
3477 <listitem><para>
3478 Returns the selected text. If no text is selected, the returned string is empty.
3479 </para></listitem>
3480 </varlistentry>
3481 
3482 
3483 <varlistentry>
3484 <term><synopsis>
3485 bool view.hasSelection();
3486 </synopsis></term>
3487 <listitem><para>
3488 Returns <literal>true</literal>, if the view has selected text, otherwise <literal>false</literal>.
3489 </para></listitem>
3490 </varlistentry>
3491 
3492 
3493 <varlistentry>
3494 <term><synopsis>
3495 Range view.selection();
3496 </synopsis></term>
3497 <listitem><para>
3498 Returns the selected text range. The returned range is invalid if there is no
3499 selected text.
3500 </para></listitem>
3501 </varlistentry>
3502 
3503 
3504 <varlistentry>
3505 <term><synopsis>
3506 void view.setSelection(<parameter>Range <replaceable>range</replaceable></parameter>);
3507 </synopsis></term>
3508 <listitem><para>
3509 Set the selected text to the given range.
3510 </para></listitem>
3511 </varlistentry>
3512 
3513 
3514 <varlistentry>
3515 <term><synopsis>
3516 void view.removeSelectedText();
3517 </synopsis></term>
3518 <listitem><para>
3519 Remove the selected text. If the view does not have any selected text, this
3520 does nothing.
3521 </para></listitem>
3522 </varlistentry>
3523 
3524 
3525 <varlistentry>
3526 <term><synopsis>
3527 void view.selectAll();
3528 </synopsis></term>
3529 <listitem><para>
3530 Selects the entire text in the document.
3531 </para></listitem>
3532 </varlistentry>
3533 
3534 
3535 <varlistentry>
3536 <term><synopsis>
3537 void view.clearSelection();
3538 </synopsis></term>
3539 <listitem><para>
3540 Clears the text selection without removing the text.
3541 </para></listitem>
3542 </varlistentry>
3543 
3544 
3545 <varlistentry>
3546 <term><synopsis>
3547 void view.setBlockSelection(bool on);
3548 </synopsis></term>
3549 <listitem><para>
3550 Set block selection mode on or off.
3551 </para></listitem>
3552 </varlistentry>
3553 
3554 <varlistentry>
3555 <term><synopsis>
3556 bool view.blockSelection();
3557 </synopsis></term>
3558 <listitem><para>
3559 Returns <literal>true</literal>, if block selection mode is on, otherwise <literal>false</literal>.
3560 </para></listitem>
3561 </varlistentry>
3562 
3563 
3564 <varlistentry>
3565 <term><synopsis>
3566 void view.align(<parameter>Range <replaceable>range</replaceable></parameter>);
3567 </synopsis></term>
3568 <listitem><para>
3569 Properly re-indent lines within <replaceable>range</replaceable> according to current indentation settings.
3570 </para>
3571 </listitem>
3572 </varlistentry>
3573 
3574 <varlistentry>
3575 <term><synopsis>
3576 void view.alignOn(<parameter>Range <replaceable>range</replaceable></parameter>, <parameter>String <replaceable>pattern</replaceable> = &quot;&quot;</parameter>);
3577 </synopsis></term>
3578 <listitem><para>
3579 Aligns lines in <replaceable>range</replaceable> on the column given by the regular expression <replaceable>pattern</replaceable>.
3580 With an empty <replaceable>pattern</replaceable> it will align on the first non-blank character by default.
3581 If the pattern has a capture it will indent on the captured match.
3582 </para>
3583 <para><emphasis>Examples:</emphasis></para>
3584 <para><literal>view.alignOn(document.documentRange(), '-');</literal> will insert spaces before the first <literal>-</literal> of each lines to align them all on the same column.</para>
3585 <para><literal>view.alignOn(document.documentRange(), ':\\s+(.)');</literal> will insert spaces before the first non-blank character that occurs after a colon to align them all on the same column.</para>
3586 </listitem>
3587 </varlistentry>
3588 
3589 <varlistentry>
3590 <term><synopsis>
3591 object view.executeCommand(<parameter>String <replaceable>command</replaceable></parameter>,
3592                            <parameter>String <replaceable>args</replaceable></parameter>,
3593                            <parameter>Range <replaceable>range</replaceable></parameter>);
3594 </synopsis></term>
3595 <listitem><para>
3596 Executes the <link linkend="advanced-editing-tools-commandline">command line command</link> <replaceable>command</replaceable>
3597 with the optional arguments <replaceable>args</replaceable> and the optional <replaceable>range</replaceable>.
3598 The returned <replaceable>object</replaceable> has a boolean property <replaceable>object.ok</replaceable>
3599 that indicates whether execution of the <replaceable>command</replaceable> was successful.
3600 In case of an error, the string <replaceable>object.status</replaceable> contains an error message.
3601 </para>
3602 <para>Since: &kde-frameworks; 5.50</para>
3603 </listitem>
3604 </varlistentry>
3605 
3606 <varlistentry>
3607 <term><synopsis>
3608 Range view.searchText(<parameter>Range <replaceable>range</replaceable></parameter>,
3609                       <parameter>String <replaceable>pattern</replaceable></parameter>,
3610                       <parameter>bool <replaceable>backwards</replaceable> = false</parameter>);
3611 </synopsis></term>
3612 <listitem><para>
3613 Search for the first occurrence of <replaceable>pattern</replaceable> in <replaceable>range</replaceable> and returns the matched range.
3614 Search is performed backwards if the optional boolean parameter <replaceable>backwards</replaceable> is set to <literal>true</literal>.
3615 </para>
3616 <para>
3617 The returned range is invalid (see Range.isValid()) if <replaceable>pattern</replaceable> is not found in <replaceable>range</replaceable>.
3618 </para>
3619 <para>Since: &kde-frameworks; 5.97</para>
3620 </listitem>
3621 </varlistentry>
3622 
3623 </variablelist>
3624 </para>
3625 </sect3>
3626 
3627 <sect3 id="dev-scripting-api-document">
3628 <title>The Document API</title>
3629 <para>
3630 Whenever a script is being executed, there is a global variable
3631 <quote><literal>document</literal></quote> representing the current active
3632 document. The following is a list of all available Document functions.
3633 
3634 <variablelist>
3635 
3636 <varlistentry>
3637 <term><synopsis>
3638 String document.fileName();
3639 </synopsis></term>
3640 <listitem><para>
3641 Returns the document's filename or an empty string for unsaved text buffers.
3642 </para></listitem>
3643 </varlistentry>
3644 
3645 
3646 <varlistentry>
3647 <term><synopsis>
3648 String document.url();
3649 </synopsis></term>
3650 <listitem><para>
3651 Returns the document's full &URL; or an empty string for unsaved text buffers.
3652 </para></listitem>
3653 </varlistentry>
3654 
3655 
3656 <varlistentry>
3657 <term><synopsis>
3658 String document.mimeType();
3659 </synopsis></term>
3660 <listitem><para>
3661 Returns the document's &MIME; type or the &MIME; type <literal>application/octet-stream</literal>
3662 if no appropriate &MIME; type could be found.
3663 </para></listitem>
3664 </varlistentry>
3665 
3666 
3667 <varlistentry>
3668 <term><synopsis>
3669 String document.encoding();
3670 </synopsis></term>
3671 <listitem><para>
3672 Returns the currently used encoding to save the file.
3673 </para></listitem>
3674 </varlistentry>
3675 
3676 <varlistentry>
3677 <term><synopsis>
3678 String document.highlightingMode();
3679 </synopsis></term>
3680 <listitem><para>
3681 Returns the global highlighting mode used for the whole document.
3682 </para></listitem>
3683 </varlistentry>
3684 
3685 <varlistentry>
3686 <term><synopsis>
3687 String document.highlightingModeAt(<parameter>Cursor <replaceable>pos</replaceable></parameter>);
3688 </synopsis></term>
3689 <listitem><para>
3690 Returns the highlighting mode used at the given position in the document.
3691 </para></listitem>
3692 </varlistentry>
3693 
3694 <varlistentry>
3695 <term><synopsis>
3696 Array document.embeddedHighlightingModes();
3697 </synopsis></term>
3698 <listitem><para>
3699 Returns an array of highlighting modes embedded in this document.
3700 </para></listitem>
3701 </varlistentry>
3702 
3703 <varlistentry>
3704 <term><synopsis>
3705 bool document.isModified();
3706 </synopsis></term>
3707 <listitem><para>
3708 Returns <literal>true</literal>, if the document has unsaved changes (modified), otherwise <literal>false</literal>.
3709 </para></listitem>
3710 </varlistentry>
3711 
3712 
3713 <varlistentry>
3714 <term><synopsis>
3715 String document.text();
3716 </synopsis></term>
3717 <listitem><para>
3718 Returns the entire content of the document in a single text string. Newlines
3719 are marked with the newline character <quote><literal>\n</literal></quote>.
3720 </para></listitem>
3721 </varlistentry>
3722 
3723 
3724 <varlistentry>
3725 <term><synopsis>
3726 String document.text(<parameter>int <replaceable>fromLine</replaceable></parameter>, <parameter>int <replaceable>fromColumn</replaceable></parameter>, <parameter>int <replaceable>toLine</replaceable></parameter>, <parameter>int <replaceable>toColumn</replaceable></parameter>);
3727 String document.text(<parameter>Cursor <replaceable>from</replaceable></parameter>, <parameter>Cursor <replaceable>to</replaceable></parameter>);
3728 String document.text(<parameter>Range <replaceable>range</replaceable></parameter>);
3729 </synopsis></term>
3730 <listitem><para>
3731     Returns the text in the given range. It is recommended to use the cursor
3732     and range based version for better readability of the source code.
3733 </para></listitem>
3734 </varlistentry>
3735 
3736 
3737 <varlistentry>
3738 <term><synopsis>
3739 String document.line(<parameter>int <replaceable>line</replaceable></parameter>);
3740 </synopsis></term>
3741 <listitem><para>
3742     Returns the given text line as string. The string is empty if the requested
3743     line is out of range.
3744 </para></listitem>
3745 </varlistentry>
3746 
3747 
3748 <varlistentry>
3749 <term><synopsis>
3750 String document.wordAt(<parameter>int <replaceable>line</replaceable></parameter>, <parameter>int <replaceable>column</replaceable></parameter>);
3751 String document.wordAt(<parameter>Cursor <replaceable>cursor</replaceable></parameter>);
3752 </synopsis></term>
3753 <listitem><para>
3754     Returns the word at the given cursor position.
3755 </para></listitem>
3756 </varlistentry>
3757 
3758 
3759 <varlistentry>
3760 <term>
3761 <synopsis>
3762 Range document.wordRangeAt(<parameter>int <replaceable>line</replaceable></parameter>, <parameter>int <replaceable>column</replaceable></parameter>);
3763 Range document.wordRangeAt(<parameter>Cursor <replaceable>cursor</replaceable></parameter>);
3764 </synopsis>
3765 </term>
3766 <listitem><para>
3767 Return the range of the word at the given cursor position. The returned range
3768 is invalid (see Range.isValid()), if the text position is after the end of a
3769 line. If there is no word at the given cursor, an empty range is returned.
3770 </para>
3771 <para>
3772   Since: &kde; 4.9
3773 </para>
3774 </listitem>
3775 </varlistentry>
3776 
3777 
3778 <varlistentry>
3779 <term><synopsis>
3780 String document.charAt(<parameter>int <replaceable>line</replaceable></parameter>, <parameter>int <replaceable>column</replaceable></parameter>);
3781 String document.charAt(<parameter>Cursor <replaceable>cursor</replaceable></parameter>);
3782 </synopsis></term>
3783 <listitem><para>
3784     Returns the character at the given cursor position.
3785 </para></listitem>
3786 </varlistentry>
3787 
3788 
3789 <varlistentry>
3790 <term><synopsis>
3791 String document.firstChar(<parameter>int <replaceable>line</replaceable></parameter>);
3792 </synopsis></term>
3793 <listitem><para>
3794     Returns the first character in the given <replaceable>line</replaceable>
3795     that is not a whitespace. The first character is at column 0. If the line
3796     is empty or only contains whitespace characters, the returned string is
3797     empty.
3798 </para></listitem>
3799 </varlistentry>
3800 
3801 
3802 <varlistentry>
3803 <term><synopsis>
3804 String document.lastChar(<parameter>int <replaceable>line</replaceable></parameter>);
3805 </synopsis></term>
3806 <listitem><para>
3807     Returns the last character in the given <replaceable>line</replaceable>
3808     that is not a whitespace. If the line is empty or only contains whitespace
3809     characters, the returned string is empty.
3810 </para></listitem>
3811 </varlistentry>
3812 
3813 
3814 <varlistentry>
3815 <term><synopsis>
3816 bool document.isSpace(<parameter>int <replaceable>line</replaceable></parameter>, <parameter>int <replaceable>column</replaceable></parameter>);
3817 bool document.isSpace(<parameter>Cursor <replaceable>cursor</replaceable></parameter>);
3818 </synopsis></term>
3819 <listitem><para>
3820     Returns <literal>true</literal>, if the character at the given cursor position is a whitespace,
3821     otherwise <literal>false</literal>.
3822 </para></listitem>
3823 </varlistentry>
3824 
3825 
3826 <varlistentry>
3827 <term><synopsis>
3828 bool document.matchesAt(<parameter>int <replaceable>line</replaceable></parameter>, <parameter>int <replaceable>column</replaceable></parameter>, <parameter>String <replaceable>text</replaceable></parameter>);
3829 bool document.matchesAt(<parameter>Cursor <replaceable>cursor</replaceable></parameter>, <parameter>String <replaceable>text</replaceable></parameter>);
3830 </synopsis></term>
3831 <listitem><para>
3832     Returns <literal>true</literal>, if the given <replaceable>text</replaceable> matches at the
3833     corresponding cursor position, otherwise <literal>false</literal>.
3834 </para></listitem>
3835 </varlistentry>
3836 
3837 
3838 <varlistentry>
3839 <term><synopsis>
3840 bool document.startsWith(<parameter>int <replaceable>line</replaceable></parameter>, <parameter>String <replaceable>text</replaceable></parameter>, <parameter>bool <replaceable>skipWhiteSpaces</replaceable></parameter>);
3841 </synopsis></term>
3842 <listitem><para>
3843     Returns <literal>true</literal>, if the line starts with <replaceable>text</replaceable>, otherwise <literal>false</literal>.
3844     The argument <replaceable>skipWhiteSpaces</replaceable> controls whether leading whitespaces are ignored.
3845 </para></listitem>
3846 </varlistentry>
3847 
3848 
3849 <varlistentry>
3850 <term><synopsis>
3851 bool document.endsWith(<parameter>int <replaceable>line</replaceable></parameter>, <parameter>String <replaceable>text</replaceable></parameter>, <parameter>bool <replaceable>skipWhiteSpaces</replaceable></parameter>);
3852 </synopsis></term>
3853 <listitem><para>
3854     Returns <literal>true</literal>, if the line ends with <replaceable>text</replaceable>, otherwise <literal>false</literal>.
3855     The argument <replaceable>skipWhiteSpaces</replaceable> controls whether trailing whitespaces are ignored.
3856 </para></listitem>
3857 </varlistentry>
3858 
3859 
3860 <varlistentry>
3861 <term><synopsis>
3862 bool document.setText(<parameter>String <replaceable>text</replaceable></parameter>);
3863 </synopsis></term>
3864 <listitem><para>
3865     Sets the entire document text.
3866 </para></listitem>
3867 </varlistentry>
3868 
3869 
3870 <varlistentry>
3871 <term><synopsis>
3872 bool document.clear();
3873 </synopsis></term>
3874 <listitem><para>
3875     Removes the entire text in the document.
3876 </para></listitem>
3877 </varlistentry>
3878 
3879 
3880 <varlistentry>
3881 <term><synopsis>
3882 bool document.truncate(<parameter>int <replaceable>line</replaceable></parameter>, <parameter>int <replaceable>column</replaceable></parameter>);
3883 bool document.truncate(<parameter>Cursor <replaceable>cursor</replaceable></parameter>);
3884 </synopsis></term>
3885 <listitem><para>
3886     Truncate the given line at the given column or cursor position. Returns <literal>true</literal>
3887     on success, or <literal>false</literal> if the given line is not part of the document range.
3888 </para></listitem>
3889 </varlistentry>
3890 
3891 
3892 <varlistentry>
3893 <term><synopsis>
3894 bool document.insertText(<parameter>int <replaceable>line</replaceable></parameter>, <parameter>int <replaceable>column</replaceable></parameter>, <parameter>String <replaceable>text</replaceable></parameter>);
3895 bool document.insertText(<parameter>Cursor <replaceable>cursor</replaceable></parameter>, <parameter>String <replaceable>text</replaceable></parameter>);
3896 </synopsis></term>
3897 <listitem><para>
3898     Inserts the <replaceable>text</replaceable> at the given cursor position.
3899     Returns <literal>true</literal> on success, or <literal>false</literal>, if the document is in read-only mode.
3900 </para></listitem>
3901 </varlistentry>
3902 
3903 
3904 <varlistentry>
3905 <term><synopsis>
3906 bool document.removeText(<parameter>int <replaceable>fromLine</replaceable></parameter>, <parameter>int <replaceable>fromColumn</replaceable></parameter>, <parameter>int <replaceable>toLine</replaceable></parameter>, <parameter>int <replaceable>toColumn</replaceable></parameter>);
3907 bool document.removeText(<parameter>Cursor <replaceable>from</replaceable></parameter>, <parameter>Cursor <replaceable>to</replaceable></parameter>);
3908 bool document.removeText(<parameter>Range <replaceable>range</replaceable></parameter>);
3909 </synopsis></term>
3910 <listitem><para>
3911     Removes the text in the given range. Returns <literal>true</literal> on success, or <literal>false</literal>, if
3912     the document is in read-only mode.
3913 </para></listitem>
3914 </varlistentry>
3915 
3916 
3917 <varlistentry>
3918 <term><synopsis>
3919 bool document.insertLine(<parameter>int <replaceable>line</replaceable></parameter>, <parameter>String <replaceable>text</replaceable></parameter>);
3920 </synopsis></term>
3921 <listitem><para>
3922     Inserts text in the given line. Returns <literal>true</literal> on success, or <literal>false</literal>, if the
3923     document is in read-only mode or the line is not in the document range.
3924 </para></listitem>
3925 </varlistentry>
3926 
3927 
3928 <varlistentry>
3929 <term><synopsis>
3930 bool document.removeLine(<parameter>int <replaceable>line</replaceable></parameter>);
3931 </synopsis></term>
3932 <listitem><para>
3933     Removes the given text line. Returns <literal>true</literal> on success, or <literal>false</literal>, if the
3934     document is in read-only mode or the line is not in the document range.
3935 </para></listitem>
3936 </varlistentry>
3937 
3938 
3939 <varlistentry>
3940 <term><synopsis>
3941 bool document.wrapLine(<parameter>int <replaceable>line</replaceable></parameter>, <parameter>int <replaceable>column</replaceable></parameter>);
3942 bool document.wrapLine(<parameter>Cursor <replaceable>cursor</replaceable></parameter>);
3943 </synopsis></term>
3944 <listitem><para>
3945 Wraps the line at the given cursor position. Returns <literal>true</literal> on success,
3946 otherwise <literal>false</literal>, &eg; if line &lt; 0.
3947 </para>
3948 <para>
3949   Since: &kde; 4.9
3950 </para>
3951 </listitem>
3952 </varlistentry>
3953 
3954 
3955 <varlistentry>
3956 <term><synopsis>
3957 void document.joinLines(<parameter>int <replaceable>startLine</replaceable></parameter>, <parameter>int <replaceable>endLine</replaceable></parameter>);
3958 </synopsis></term>
3959 <listitem><para>
3960     Joins the lines from <replaceable>startLine</replaceable> to <replaceable>endLine</replaceable>.
3961     Two succeeding text lines are always separated with a single space.
3962 </para></listitem>
3963 </varlistentry>
3964 
3965 
3966 <varlistentry>
3967 <term><synopsis>
3968 int document.lines();
3969 </synopsis></term>
3970 <listitem><para>
3971     Returns the number of lines in the document.
3972 </para></listitem>
3973 </varlistentry>
3974 
3975 
3976 <varlistentry>
3977 <term><synopsis>
3978 bool document.isLineModified(<parameter>int <replaceable>line</replaceable></parameter>);
3979 </synopsis></term>
3980 <listitem><para>
3981     Returns <literal>true</literal>, if <replaceable>line</replaceable> currently contains unsaved data.
3982 </para>
3983 <para>
3984     Since: &kde; 5.0
3985 </para></listitem>
3986 </varlistentry>
3987 
3988 
3989 <varlistentry>
3990 <term><synopsis>
3991 bool document.isLineSaved(<parameter>int <replaceable>line</replaceable></parameter>);
3992 </synopsis></term>
3993 <listitem><para>
3994     Returns <literal>true</literal>, if <replaceable>line</replaceable> was changed, but the document was saved.
3995     Hence, the line currently does not contain any unsaved data.
3996 </para>
3997 <para>
3998     Since: &kde; 5.0
3999 </para></listitem>
4000 </varlistentry>
4001 
4002 
4003 <varlistentry>
4004 <term><synopsis>
4005 bool document.isLineTouched(<parameter>int <replaceable>line</replaceable></parameter>);
4006 </synopsis></term>
4007 <listitem><para>
4008     Returns <literal>true</literal>, if <replaceable>line</replaceable> currently contains unsaved data or was changed before.
4009 </para>
4010 <para>
4011     Since: &kde; 5.0
4012 </para></listitem>
4013 </varlistentry>
4014 
4015 
4016 <varlistentry>
4017 <term><synopsis>
4018 bool document.findTouchedLine(<parameter>int <replaceable>startLine</replaceable></parameter>, <parameter>bool <replaceable>down</replaceable></parameter>);
4019 </synopsis></term>
4020 <listitem><para>
4021     Search for the next touched line starting at <replaceable>line</replaceable>.
4022     The search is performed either upwards or downwards depending on the search direction specified in <replaceable>down</replaceable>.
4023 </para>
4024 <para>
4025     Since: &kde; 5.0
4026 </para></listitem>
4027 </varlistentry>
4028 
4029 
4030 <varlistentry>
4031 <term><synopsis>
4032 int document.length();
4033 </synopsis></term>
4034 <listitem><para>
4035     Returns the number of characters in the document.
4036 </para></listitem>
4037 </varlistentry>
4038 
4039 
4040 <varlistentry>
4041 <term><synopsis>
4042 int document.lineLength(<parameter>int <replaceable>line</replaceable></parameter>);
4043 </synopsis></term>
4044 <listitem><para>
4045     Returns the <replaceable>line</replaceable>'s length.
4046 </para></listitem>
4047 </varlistentry>
4048 
4049 
4050 <varlistentry>
4051 <term><synopsis>
4052 void document.editBegin();
4053 </synopsis></term>
4054 <listitem><para>
4055     Starts an edit group for undo/redo grouping. Make sure to always call
4056     <function>editEnd()</function> as often as you call
4057     <function>editBegin()</function>. Calling <function>editBegin()</function>
4058     internally uses a reference counter, &ie;, this call can be nested.
4059 </para></listitem>
4060 </varlistentry>
4061 
4062 
4063 <varlistentry>
4064 <term><synopsis>
4065 void document.editEnd();
4066 </synopsis></term>
4067 <listitem><para>
4068     Ends an edit group. The last call of <function>editEnd()</function> (&ie;
4069     the one for the first call of <function>editBegin()</function>) finishes
4070     the edit step.
4071 </para></listitem>
4072 </varlistentry>
4073 
4074 
4075 <varlistentry>
4076 <term><synopsis>
4077 int document.firstColumn(<parameter>int <replaceable>line</replaceable></parameter>);
4078 </synopsis></term>
4079 <listitem><para>
4080     Returns the first non-whitespace column in the given <replaceable>line</replaceable>.
4081     If there are only whitespaces in the line, the return value is <literal>-1</literal>.
4082 </para></listitem>
4083 </varlistentry>
4084 
4085 
4086 <varlistentry>
4087 <term><synopsis>
4088 int document.lastColumn(<parameter>int <replaceable>line</replaceable></parameter>);
4089 </synopsis></term>
4090 <listitem><para>
4091     Returns the last non-whitespace column in the given <replaceable>line</replaceable>.
4092     If there are only whitespaces in the line, the return value is <literal>-1</literal>.
4093 </para></listitem>
4094 </varlistentry>
4095 
4096 
4097 <varlistentry>
4098 <term><synopsis>
4099 int document.prevNonSpaceColumn(<parameter>int <replaceable>line</replaceable></parameter>, <parameter>int <replaceable>column</replaceable></parameter>);
4100 int document.prevNonSpaceColumn(<parameter>Cursor <replaceable>cursor</replaceable></parameter>);
4101 </synopsis></term>
4102 <listitem><para>
4103     Returns the column with a non-whitespace character starting at the given
4104     cursor position and searching backwards.
4105 </para></listitem>
4106 </varlistentry>
4107 
4108 
4109 <varlistentry>
4110 <term><synopsis>
4111 int document.nextNonSpaceColumn(<parameter>int <replaceable>line</replaceable></parameter>, <parameter>int <replaceable>column</replaceable></parameter>);
4112 int document.nextNonSpaceColumn(<parameter>Cursor <replaceable>cursor</replaceable></parameter>);
4113 </synopsis></term>
4114 <listitem><para>
4115     Returns the column with a non-whitespace character starting at the given
4116     cursor position and searching forwards.
4117 </para></listitem>
4118 </varlistentry>
4119 
4120 
4121 <varlistentry>
4122 <term><synopsis>
4123 int document.prevNonEmptyLine(<parameter>int <replaceable>line</replaceable></parameter>);
4124 </synopsis></term>
4125 <listitem><para>
4126     Returns the next non-empty line containing non-whitespace characters
4127     searching backwards.
4128 </para></listitem>
4129 </varlistentry>
4130 
4131 
4132 <varlistentry>
4133 <term><synopsis>
4134 int document.nextNonEmptyLine(<parameter>int <replaceable>line</replaceable></parameter>);
4135 </synopsis></term>
4136 <listitem><para>
4137     Returns the next non-empty line containing non-whitespace characters
4138     searching forwards.
4139 </para></listitem>
4140 </varlistentry>
4141 
4142 
4143 <varlistentry>
4144 <term><synopsis>
4145 bool document.isInWord(<parameter>String <replaceable>character</replaceable></parameter>, <parameter>int <replaceable>attribute</replaceable></parameter>);
4146 </synopsis></term>
4147 <listitem><para>
4148     Returns <literal>true</literal>, if the given <replaceable>character</replaceable> with the
4149     given <replaceable>attribute</replaceable> can be part of a word, otherwise
4150     <literal>false</literal>.
4151 </para></listitem>
4152 </varlistentry>
4153 
4154 
4155 <varlistentry>
4156 <term><synopsis>
4157 bool document.canBreakAt(<parameter>String <replaceable>character</replaceable></parameter>, <parameter>int <replaceable>attribute</replaceable></parameter>);
4158 </synopsis></term>
4159 <listitem><para>
4160     Returns <literal>true</literal>, if the given <replaceable>character</replaceable> with the given
4161     <replaceable>attribute</replaceable> is suited to wrap a line, otherwise
4162     <literal>false</literal>.
4163 </para></listitem>
4164 </varlistentry>
4165 
4166 
4167 <varlistentry>
4168 <term><synopsis>
4169 bool document.canComment(<parameter>int <replaceable>startAttribute</replaceable></parameter>, <parameter>int <replaceable>endAttribute</replaceable></parameter>);
4170 </synopsis></term>
4171 <listitem><para>
4172     Returns <literal>true</literal>, if a range starting and ending with the given attributes is
4173     suited to be commented out, otherwise <literal>false</literal>.
4174 </para></listitem>
4175 </varlistentry>
4176 
4177 
4178 <varlistentry>
4179 <term><synopsis>
4180 String document.commentMarker(<parameter>int <replaceable>attribute</replaceable></parameter>);
4181 </synopsis></term>
4182 <listitem><para>
4183     Returns the comment marker for single line comments for a given <replaceable>attribute</replaceable>.
4184 </para></listitem>
4185 </varlistentry>
4186 
4187 
4188 <varlistentry>
4189 <term><synopsis>
4190 String document.commentStart(<parameter>int <replaceable>attribute</replaceable></parameter>);
4191 </synopsis></term>
4192 <listitem><para>
4193     Returns the comment marker for the start of multi-line comments for a given
4194     <replaceable>attribute</replaceable>.
4195 </para></listitem>
4196 </varlistentry>
4197 
4198 
4199 <varlistentry>
4200 <term><synopsis>
4201 String document.commentEnd(<parameter>int <replaceable>attribute</replaceable></parameter>);
4202 </synopsis></term>
4203 <listitem><para>
4204     Returns the comment marker for the end of multi-line comments for a given
4205     <replaceable>attribute</replaceable>.
4206 </para></listitem>
4207 </varlistentry>
4208 
4209 
4210 <varlistentry>
4211 <term><synopsis>
4212 Range document.documentRange();
4213 </synopsis></term>
4214 <listitem><para>
4215     Returns a range that encompasses the whole document.
4216 </para></listitem>
4217 </varlistentry>
4218 
4219 
4220 <varlistentry>
4221 <term><synopsis>
4222 Cursor documentEnd();
4223 </synopsis></term>
4224 <listitem><para>
4225     Returns a cursor positioned at the last column of the last line in the document.
4226 </para></listitem>
4227 </varlistentry>
4228 
4229 
4230 <varlistentry>
4231 <term><synopsis>
4232 bool isValidTextPosition(<parameter>int <replaceable>line</replaceable></parameter>, <parameter>int <replaceable>column</replaceable></parameter>);
4233 bool isValidTextPosition(<parameter>Cursor <replaceable>cursor</replaceable></parameter>);
4234 </synopsis></term>
4235 <listitem><para>
4236     Returns <literal>true</literal>, if the given cursor position is positioned at a valid text position.
4237     A text position is valid only if it locate at the start, in the middle, or the end of a valid line.
4238     Further, a text position is invalid if it is located in a Unicode surrogate.
4239 </para><para>
4240     Since: &kde; 5.0
4241 </para></listitem>
4242 </varlistentry>
4243 
4244 
4245 <varlistentry>
4246 <term><synopsis>
4247 int document.attribute(<parameter>int <replaceable>line</replaceable></parameter>, <parameter>int <replaceable>column</replaceable></parameter>);
4248 int document.attribute(<parameter>Cursor <replaceable>cursor</replaceable></parameter>);
4249 </synopsis></term>
4250 <listitem><para>
4251     Returns the attribute at the given cursor position.
4252 </para></listitem>
4253 </varlistentry>
4254 
4255 
4256 <varlistentry>
4257 <term><synopsis>
4258 bool document.isAttribute(<parameter>int <replaceable>line</replaceable></parameter>, <parameter>int <replaceable>column</replaceable></parameter>, <parameter>int <replaceable>attribute</replaceable></parameter>);
4259 bool document.isAttribute(<parameter>Cursor <replaceable>cursor</replaceable></parameter>, <parameter>int <replaceable>attribute</replaceable></parameter>);
4260 </synopsis></term>
4261 <listitem><para>
4262     Returns <literal>true</literal>, if the attribute at the given cursor position equals <replaceable>attribute</replaceable>,
4263     otherwise <literal>false</literal>.
4264 </para></listitem>
4265 </varlistentry>
4266 
4267 
4268 <varlistentry>
4269 <term><synopsis>
4270 String document.attributeName(<parameter>int <replaceable>line</replaceable></parameter>, <parameter>int <replaceable>column</replaceable></parameter>);
4271 String document.attributeName(<parameter>Cursor <replaceable>cursor</replaceable></parameter>);
4272 </synopsis></term>
4273 <listitem><para>
4274     Returns the attribute name as human readable text. This is equal to the
4275     <literal>itemData</literal> name in the syntax highlighting files.
4276 </para></listitem>
4277 </varlistentry>
4278 
4279 
4280 <varlistentry>
4281 <term><synopsis>
4282 bool document.isAttributeName(<parameter>int <replaceable>line</replaceable></parameter>, <parameter>int <replaceable>column</replaceable></parameter>, <parameter>String <replaceable>name</replaceable></parameter>);
4283 bool document.isAttributeName(<parameter>Cursor <replaceable>cursor</replaceable></parameter>, <parameter>String <replaceable>name</replaceable></parameter>);
4284 </synopsis></term>
4285 <listitem><para>
4286     Returns <literal>true</literal>, if the attribute name at a certain cursor position matches
4287     the given <replaceable>name</replaceable>, otherwise <literal>false</literal>.
4288 </para></listitem>
4289 </varlistentry>
4290 
4291 
4292 <varlistentry>
4293 <term><synopsis>
4294 String document.variable(<parameter>String <replaceable>key</replaceable></parameter>);
4295 </synopsis></term>
4296 <listitem><para>
4297     Returns the value of the requested document variable <replaceable>key</replaceable>.
4298     If the document variable does not exist, the return value is an empty string.
4299 </para></listitem>
4300 </varlistentry>
4301 
4302 
4303 <varlistentry>
4304 <term><synopsis>
4305 void document.setVariable(<parameter>String <replaceable>key</replaceable></parameter>, <parameter>String <replaceable>value</replaceable></parameter>);
4306 </synopsis></term>
4307 <listitem><para>
4308     Set the value of the requested document variable <replaceable>key</replaceable>.
4309 </para>
4310 <para>
4311     See also: <link linkend="config-variables">Kate document variables</link>
4312 </para>
4313 <para>
4314     Since: &kde; 4.8
4315 </para></listitem>
4316 </varlistentry>
4317 
4318 
4319 <varlistentry>
4320 <term><synopsis>
4321 int document.firstVirtualColumn(<parameter>int <replaceable>line</replaceable></parameter>);
4322 </synopsis></term>
4323 <listitem><para>
4324     Returns the virtual column of the first non-whitespace character in the given
4325     line or <literal>-1</literal>, if the line is empty or contains only whitespace characters.
4326 </para></listitem>
4327 </varlistentry>
4328 
4329 
4330 <varlistentry>
4331 <term><synopsis>
4332 int document.lastVirtualColumn(<parameter>int <replaceable>line</replaceable></parameter>);
4333 </synopsis></term>
4334 <listitem><para>
4335     Returns the virtual column of the last non-whitespace character in the given
4336     line or <literal>-1</literal>, if the line is empty or contains only whitespace characters.
4337 </para></listitem>
4338 </varlistentry>
4339 
4340 
4341 <varlistentry>
4342 <term><synopsis>
4343 int document.toVirtualColumn(<parameter>int <replaceable>line</replaceable></parameter>, <parameter>int <replaceable>column</replaceable></parameter>);
4344 int document.toVirtualColumn(<parameter>Cursor <replaceable>cursor</replaceable></parameter>);
4345 Cursor document.toVirtualCursor(<parameter>Cursor <replaceable>cursor</replaceable></parameter>);
4346 </synopsis></term>
4347 <listitem><para>
4348     Converts the given <quote>real</quote> cursor position to a virtual cursor position,
4349     either returning an int or a Cursor object.
4350 </para></listitem>
4351 </varlistentry>
4352 
4353 
4354 <varlistentry>
4355 <term><synopsis>
4356 int document.fromVirtualColumn(<parameter>int <replaceable>line</replaceable></parameter>, <parameter>int <replaceable>virtualColumn</replaceable></parameter>);
4357 int document.fromVirtualColumn(<parameter>Cursor <replaceable>virtualCursor</replaceable></parameter>);
4358 Cursor document.fromVirtualCursor(<parameter>Cursor <replaceable>virtualCursor</replaceable></parameter>);
4359 </synopsis></term>
4360 <listitem><para>
4361     Converts the given virtual cursor position to a <quote>real</quote> cursor position,
4362     either returning an int or a Cursor object.
4363 </para></listitem>
4364 </varlistentry>
4365 
4366 
4367 <varlistentry>
4368 <term><synopsis>
4369 Cursor document.anchor(<parameter>int <replaceable>line</replaceable></parameter>, <parameter>int <replaceable>column</replaceable></parameter>, <parameter>Char <replaceable>character</replaceable></parameter>);
4370 Cursor document.anchor(<parameter>Cursor <replaceable>cursor</replaceable></parameter>, <parameter>Char <replaceable>character</replaceable></parameter>);
4371 </synopsis></term>
4372 <listitem><para>
4373     Searches backward for the given character starting from the given cursor.
4374     As an example, if '(' is passed as character, this function will return the
4375     position of the opening '('. This reference counting, &ie; other '(...)'
4376     are ignored.
4377 </para></listitem>
4378 </varlistentry>
4379 
4380 
4381 <varlistentry>
4382 <term><synopsis>
4383 Cursor document.rfind(<parameter>int <replaceable>line</replaceable></parameter>, <parameter>int <replaceable>column</replaceable></parameter>, <parameter>String <replaceable>text</replaceable></parameter>, <parameter>int <replaceable>attribute</replaceable> = -1</parameter>);
4384 Cursor document.rfind(<parameter>Cursor <replaceable>cursor</replaceable></parameter>, <parameter>String <replaceable>text</replaceable></parameter>, <parameter>int <replaceable>attribute</replaceable> = -1</parameter>);
4385 </synopsis></term>
4386 <listitem><para>
4387     Find searching backwards the given text with the appropriate <replaceable>attribute</replaceable>.
4388     The argument <replaceable>attribute</replaceable> is ignored if it is set to
4389     <literal>-1</literal>. The returned cursor is invalid, if the text could not be found.
4390 </para></listitem>
4391 </varlistentry>
4392 
4393 
4394 <varlistentry>
4395 <term><synopsis>
4396 int document.defStyleNum(<parameter>int <replaceable>line</replaceable></parameter>, <parameter>int <replaceable>column</replaceable></parameter>);
4397 int document.defStyleNum(<parameter>Cursor <replaceable>cursor</replaceable></parameter>);
4398 </synopsis></term>
4399 <listitem><para>
4400     Returns the default style used at the given cursor position.
4401 </para></listitem>
4402 </varlistentry>
4403 
4404 
4405 <varlistentry>
4406 <term><synopsis>
4407 bool document.isCode(<parameter>int <replaceable>line</replaceable></parameter>, <parameter>int <replaceable>column</replaceable></parameter>);
4408 bool document.isCode(<parameter>Cursor <replaceable>cursor</replaceable></parameter>);
4409 </synopsis></term>
4410 <listitem><para>
4411     Returns <literal>true</literal>, if the attribute at the given cursor position is not equal
4412     to all of the following styles: <literal>dsComment</literal>,
4413     <literal>dsString</literal>, <literal>dsRegionMarker</literal>,
4414     <literal>dsChar</literal>, <literal>dsOthers</literal>.
4415 </para></listitem>
4416 </varlistentry>
4417 
4418 
4419 
4420 <varlistentry>
4421 <term><synopsis>
4422 bool document.isComment(<parameter>int <replaceable>line</replaceable></parameter>, <parameter>int <replaceable>column</replaceable></parameter>);
4423 bool document.isComment(<parameter>Cursor <replaceable>cursor</replaceable></parameter>);
4424 </synopsis></term>
4425 <listitem><para>
4426     Returns <literal>true</literal>, if the attribute of the character at the cursor position
4427     is <literal>dsComment</literal>, otherwise <literal>false</literal>.
4428 </para></listitem>
4429 </varlistentry>
4430 
4431 
4432 <varlistentry>
4433 <term><synopsis>
4434 bool document.isString(<parameter>int <replaceable>line</replaceable></parameter>, <parameter>int <replaceable>column</replaceable></parameter>);
4435 bool document.isString(<parameter>Cursor <replaceable>cursor</replaceable></parameter>);
4436 </synopsis></term>
4437 <listitem><para>
4438     Returns <literal>true</literal>, if the attribute of the character at the cursor position
4439     is <literal>dsString</literal>, otherwise <literal>false</literal>.
4440 </para></listitem>
4441 </varlistentry>
4442 
4443 
4444 <varlistentry>
4445 <term><synopsis>
4446 bool document.isRegionMarker(<parameter>int <replaceable>line</replaceable></parameter>, <parameter>int <replaceable>column</replaceable></parameter>);
4447 bool document.isRegionMarker(<parameter>Cursor <replaceable>cursor</replaceable></parameter>);
4448 </synopsis></term>
4449 <listitem><para>
4450     Returns <literal>true</literal>, if the attribute of the character at the cursor position
4451     is <literal>dsRegionMarker</literal>, otherwise <literal>false</literal>.
4452 </para></listitem>
4453 </varlistentry>
4454 
4455 
4456 <varlistentry>
4457 <term><synopsis>
4458 bool document.isChar(<parameter>int <replaceable>line</replaceable></parameter>, <parameter>int <replaceable>column</replaceable></parameter>);
4459 bool document.isChar(<parameter>Cursor <replaceable>cursor</replaceable></parameter>);
4460 </synopsis></term>
4461 <listitem><para>
4462     Returns <literal>true</literal>, if the attribute of the character at the cursor position
4463     is <literal>dsChar</literal>, otherwise <literal>false</literal>.
4464 </para></listitem>
4465 </varlistentry>
4466 
4467 
4468 <varlistentry>
4469 <term><synopsis>
4470 bool document.isOthers(<parameter>int <replaceable>line</replaceable></parameter>, <parameter>int <replaceable>column</replaceable></parameter>);
4471 bool document.isOthers(<parameter>Cursor <replaceable>cursor</replaceable></parameter>);
4472 </synopsis></term>
4473 <listitem><para>
4474     Returns <literal>true</literal>, if the attribute of the character at the cursor position
4475     is <literal>dsOthers</literal>, otherwise <literal>false</literal>.
4476 </para></listitem>
4477 </varlistentry>
4478 
4479 <varlistentry>
4480 <term><synopsis>
4481 void document.indent(<parameter>Range <replaceable>range</replaceable></parameter>, <parameter>int <replaceable>change</replaceable></parameter>);
4482 </synopsis></term>
4483 <listitem><para>
4484 Indents all lines in <replaceable>range</replaceable> by <replaceable>change</replaceable> tabs or <replaceable>change</replaceable> times <literal>tabSize</literal> spaces depending on the users preferences. The <replaceable>change</replaceable> parameter can be negative.
4485 </para></listitem>
4486 </varlistentry>
4487 
4488 </variablelist>
4489 </para>
4490 
4491 </sect3>
4492 
4493 <sect3 id="dev-scripting-api-editor">
4494 <title>The Editor API</title>
4495 <para>
4496 In addition to the document and view API, there is a general editor API that
4497 provides functions for general editor scripting functionality.
4498 
4499 <variablelist>
4500 
4501 <varlistentry>
4502 <term><synopsis>
4503 String editor.clipboardText();
4504 </synopsis></term>
4505 <listitem><para>
4506 Returns the text that currently is in the global clipboard.
4507 </para>
4508 <para>Since: &kde-frameworks; 5.50</para>
4509 </listitem>
4510 </varlistentry>
4511 
4512 <varlistentry>
4513 <term><synopsis>
4514 String editor.clipboardHistory();
4515 </synopsis></term>
4516 <listitem><para>
4517 The editor holds a clipboard history that contains up to 10 clipboard entries.
4518 This function returns all entries that currently are in the clipboard history.
4519 </para>
4520 <para>Since: &kde-frameworks; 5.50</para>
4521 </listitem>
4522 </varlistentry>
4523 
4524 <varlistentry>
4525 <term><synopsis>
4526 void editor.setClipboardText(<parameter>String <replaceable>text</replaceable></parameter>);
4527 </synopsis></term>
4528 <listitem><para>
4529 Set the contents of the clipboard to <replaceable>text</replaceable>.
4530 The <replaceable>text</replaceable> will be added to the clipboard history.
4531 </para>
4532 <para>Since: &kde-frameworks; 5.50</para>
4533 </listitem>
4534 </varlistentry>
4535 
4536 </variablelist>
4537 </para>
4538 </sect3>
4539 </sect2>
4540 
4541 </sect1>
4542 
4543 </chapter>