Alexey-T / CudaText

Cross-platform text editor, written in Free Pascal
Mozilla Public License 2.0
2.54k stars 174 forks source link

[Question] How to make the default lexer for CudaText? #4991

Closed MGYBY closed 1 year ago

MGYBY commented 1 year ago

Hello all,

I need to set C++ syntax of CudaText as the default highlighting, because I am working on some coding with C++ syntax, but without .C or .H extension. It seems that CudaText cannot recognise these files as C++ texts. Therefore, I would like to simply set the default lexer as C++ when I open any text file. Where can I edit the .json configuration file to implement this feature?

Any suggestion is welcome. Thank you in advance.

BYY

Alexey-T commented 1 year ago

User config, https://wiki.freepascal.org/CudaText#Configs

Options "newdoc_xxxx" .

Alexey-T commented 1 year ago

The user-config gives way - but files need to have some fixed extension(s) https://wiki.freepascal.org/CudaText#File_types_config

Alexey-T commented 1 year ago

And plugin 'Modeline' can help.

Plugin for CudaText.
Handles modeline processing, specific to CudaText.
Similar to VIM modelines https://howtoforge.com/tutorial/vim-modeline-settings but using a different syntax.
# CudaText: lexer_file=None; tab_size=2; tab_spaces=Yes;

Author: bogen85
Homepage: https://github.com/bogen85
Plugin homepage: https://github.com/bogen85/CudaText_modeline_plugin

Modeline will only be checked for if the file size is <= "ui_max_size_lexer" (in MB).

Modeline will typically be in a comment.

If the file only contains 10 lines or less, then all lines will be checked.
Otherwise the top 5 lines will checked for first, and if not found, then the bottom 5 lines will be checked.

Modeline is read from the remainder of the first line containing " CudaText: " (no quotes).

Modeline uses the HTML Cookie list format.
See https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cookie#syntax

Values with spaces in them, like some lexer names have, need to have double quotes around the value.

Property names are the same as the property names in the  in the CudaText API without the leading PROP_ prefix
https://wiki.lazarus.freepascal.org/CudaText_API#Properties

Property names are treated with case-insensitivity.

Currently only 4 properties are accepted.

Name        Value type                          Description
----        ----------                          -----------
lexer_file  string                              lexer name
tab_size    integer                             tab width in spaces
tab_spaces  boolean (or fuzzy equivalent)       true for soft tabs (spaces), false for hard tabs.
newline     string (one of "cr", "lf", "crlf")  line endings

Boolean and newline values are treated with case-insensitivity.
Lexer name is case-sensitive.

boolean matches are:

True:  "on", "yes", "1", "true", "enable", "enabled"
False: "off", "no", "0", "false", "disable", "disabled"

Examples:

# python file with a tab width of 4 using soft tabs and CRLF line endings
# CudaText: lexer_file=Python; tab_size=4; tab_spaces=Yes; newline=CRLF;

# Makefile with a tab width of 8 using hard tabs
# CudaText: lexer_file=Makefile; tab_size=8; tab_spaces=No;

# bash script with a tab width of 2 using soft tabs
# CudaText: lexer_file="Bash script"; tab_size=2; tab_spaces=Yes;

// Rust source file with a tab width of 2 using soft tabs and LF line endings
// CudaText: lexer_file=Rust; tab_size=2; tab_spaces=Yes; newline=LF;
MGYBY commented 1 year ago

@Alexey-T Thanks for the suggestion. I have modified the detect_line option in the user-config file and it worked quite well.