Lexers

Lexers (syntax highlighters) from SynWrite editor are used. Used EControl.ru syntax parser with mods. Main mod is support for folding in Python (and other lexers with indent-based folding).

  • Dialog "Lexer properties" allows to config props of current lexer (selected via statusbar panel in CudaText). You can config: lexer name, file types, commenting for language, colors of tokens, font-styles (bold/italic/underline), borders around tokens.
  • Dialog "Lexer library" shows list of installed lexers. Dialog shows lexers which are in the folder "data/lexlib".

cudatext-lexer-library.png

Dialog "Lexer library" has hotkeys:

  • Enter: same as "Configure" button
  • Delete: same as "Delete" button
  • Space: same as "Hide/Show" button
  • Esc: close dialog

Lexers on SourceForge

Preinstalled lexer library has limited set of lexers.Other lexers, which are compatiable with SynWrite editor, are hosted on SF.net:http://sourceforge.net/projects/synwrite-addons/files/Lexers/

These zip packages can be installed in CudaText: open any zip file via "File / Open" and confirm installation.

Lexers editing

You can modify/create lexers. But not in CudaText. Install SynWrite (needed Wine on Linux) and in it you have lexer editor dialog.

  • In SynWrite call menu "Options / Addons manager / Install", install needed lexer from web. SynWrite lexer-library must have lexer before you edit it.
  • In SynWrite call "Lexer prop" dialog and edit all you need. Or make new lexer.
  • In SynWrite install "ExLexer" addon. Call it in "Plugins" menu, select needed lexer. You have exported zip file.
  • In CudaText open this zip file. Confirm installation of lexer.

Screenshot of SynWrite dialog:

synwrite-lexer-editor.png

How to setup styles of hidden sublexer

Some lexers are distributed in packages together with sub-lexer, and sub-lexer is hidden. Example: "HTML Django" with sub-lexer "HTML Django internal" (the second one isn't visible in the Lexers menu, so it's called hidden). Users, which have option "ui_lexer_themes" off, want to configure styles of all lexers. How to access hidden ones?

  • Open "Lexer library" dialog (menu: Options / Lexer / Lexer library).
  • In dialog, focus needed lexer, press "Configure" button
  • Dialog "Lexer properties" will open for selected lexer
  • In dialog's "Styles" tab, configure all you need

You can change visibility of lexer in SynWrite lexer editor (the checkbox will write line "Internal = True" at the end of .lcf file).

How to create distributive of new lexer

In SynWrite, you've created .lcf file in folder SynWrite/Data/LexLib.If you configured "Commenting" options, also file .cuda-lexmap is created.Now you need to create .zip installation of lexer, for both editors: SynWrite, CudaText.

  • In lexer file, replace system colors to usual colors: replace "clWindowText" to "clBlack" (clWindowText may be light on CudaText on Linux); replace "clInfoText" and "clInfoBk" too.
  • In SynWrite, in Addon Manager, install plugin "ExLexer".
  • In SynWrite, run menu item "Plugins / ExLexer", to create .zip for your lexer.
  • In CudaText, open this new zip file, this installs lexer to CudaText.
  • In CudaText, activate your lexer, dialog should show: "Lexer style mapping". Fill items in this dialog.
  • In CudaText, test this "lexer style map" in action: open file with your lexer active, and activate "default" UI theme, then activate "sub" UI theme. Main themes must show nice colors in your syntax file. Call dialog "Options / Lexers / Lexer style mapping" to fix colors.
  • In prev step, you configured .cuda-lexmap file, in folder CudaText/data/lexlib. Copy this file to zip installation of your lexer.
  • Zip must contain: install.inf, .lcf file(s), .cuda-lexmap file per each lexer.

Lite lexers

Lite lexers are lexers is special format (internally it's JSON file), with very limited features. They don't support code-tree, folding, don't support multi-line comments, don't have rich highlighting (e.g. background highlight of string 12+$var with additional highlight for 12 and $var inside). And they don't keep tokens information in memory (positions of found tokens in text). But they work very fast for any file size (with average line length). Lite lexers have " ^" suffix in name. Currently few lite lexers are made: XML ^, JSON ^, Log files ^, SQL ^. You can also choose them, from the usual lexers menu (they are visible by suffix).

Lite lexers are auto used for big files, if file size is bigger than option "ui_max_size_lexer". And for small files, if normal lexer not found.

Differences in lexer support in CudaText/SynWrite

  • SynWrite handles \S regex (non space chars) ok, while CudaText not
  • SynWrite lexers need constructs like \x0D\x0A, or \z (EOL), while CudaText is ok with simple \n (CudaText text never has CR char)
  • For CudaText avoid "system colors" in lexer styles (e.g. "window background", "window text", "hint background"), because OSes have different system colors
  • SynWrite lexer settings are not used in CudaText:
    • Default style
    • Selection mark style
    • Search mark style
    • Current line style
    • Collapse mark style
    • Character set
    • Multiline border
    • options in groups "Syntax tree decoration", "Pen"