focus-editor / focus

A simple and fast text editor
GNU General Public License v3.0
1.72k stars 93 forks source link

Feature request: Basic user defined languages #105

Open Sanian-Creations opened 1 year ago

Sanian-Creations commented 1 year ago

Request

I know you're accepting PRs for highlighting, but that is highlighting which is built into the editor. I think a simple format for adding basic highlighting to languages that are not natively supported by the editor would go a long way into making it more pleasant to use. It could work through a separate file or folder for user defined languages and have syntax similar to the focus-config file.

I get that this is a big ask and not some small feature than can be easily added, but it's something to think about.

Example

Here's how one such file could look like.

[file extensions]
.somelanguage .sl

[operations]
words                   reinterpret_cast const_cast dynamic_cast
symbols                 + - * / % == != ! = && & || | >> > >= < << <=

[keywords]
break case continue do else enum for if return struct switch union while 

[types]
bool char int short long float double signed unsigned void

[values]
true false null

[comments]
# This one's a bit weird, perhaps in this file you shouldn't be allowed to put comments on the same line as statements, 
# that way # can be used anywhere as a symbol without having to be escaped in weird ways
line_comment                #
block_comment               /* */
nested_block_comment        /* */
# block_comment is the c-type block comment, nested_block_comment is the jai-type block comment.
# these should probably be mutually exclusive

[strings]
# May provide multiple kinds of strings, as languages often have multiple types of strings.
# Providing an escape character is optional  
single_line_string          " \
single_line_string          ' \
multiline_string            """ \
multiline_string            ` \

# I'm not sure how to add support for the other colors.
# Perhaps these just don't get supported for user defined languages

[highlights]
# ???

[functions]
# ???

[punctuations]
# ???
focus-editor commented 1 year ago

Something like that is planned, yes

On Fri, Jul 21, 2023, 11:26 AM Sanian @.***> wrote:

Request

I know you're accepting PRs for highlighting, but that is highlighting which is built into the editor. I think a simple format for adding basic highlighting to languages that are not natively supported by the editor would go a long way into making it more pleasant to use. It could work through a separate file or folder for user defined languages and have syntax similar to the focus-config file.

I get that this is a big ask and not some small feature than can be easily added, but it's something to think about. Example

Here's how one such file could look like.

[file extensions] .somelanguage .sl

[operations] words reinterpret_cast const_cast dynamic_cast symbols + - * / % == != ! = && & || | >> > >= < << <=

[keywords] break case continue do else enum for if return struct switch union while

[types] bool char int short long float double signed unsigned void

[values] true false null

[comments]

This one's a bit weird, perhaps in this file you shouldn't be allowed to put comments on the same line as statements,

that way # can be used anywhere as a symbol without having to be escaped in weird ways

line_comment # block_comment / / nested_block_comment / /

block_comment is the c-type block comment, nested_block_comment is the jai-type block comment.

these should probably be mutually exclusive

[strings]

May provide multiple kinds of strings, as languages often have multiple types of strings.

Providing an escape character is optional

single_line_string " \ single_line_string ' \ multiline_string """ \ multiline_string ` \

I'm not sure how to add support for the other colors.

Perhaps these just don't get supported for user defined languages

[highlights]

???

[functions]

???

[punctuations]

???

— Reply to this email directly, view it on GitHub https://github.com/focus-editor/focus/issues/105, or unsubscribe https://github.com/notifications/unsubscribe-auth/A4OX77VEPUC3VRXTUOTA3UTXRG5EHANCNFSM6AAAAAA2SDA6OA . You are receiving this because you are subscribed to this thread.Message ID: @.***>

CookedNick commented 1 year ago

Decent ideas for syntax!

jmrico01 commented 8 months ago

Looking forward to this! I'll probably wait for this feature before fully switching to use Focus, as I'd like syntax highlighting for Zig, but I don't have the jai compiler so I can't really test out modifications to the source code (unless someone PRs src/langs/zig.jai in the meantime).

focus-editor commented 8 months ago

Fyi the very first version of focus was written in Zig and had highlighting https://github.com/obiwanus/focus-zig :)

It didn't have any other features though, such as global search or mouse support, since that one was strictly for myself and I wanted a keyboard-focused editor

On Tue, Jan 16, 2024, 6:16 AM José M Rico @.***> wrote:

Looking forward to this! I'll probably wait for this feature before fully switching to use Focus, as I'd like syntax highlighting for Zig https://ziglang.org/, but I don't have the jai compiler so I can't really test out modifications to the source code (unless someone PRs src/langs/zig.jai in the meantime).

— Reply to this email directly, view it on GitHub https://github.com/focus-editor/focus/issues/105#issuecomment-1892541693, or unsubscribe https://github.com/notifications/unsubscribe-auth/A4OX77VP2HZ3COKW2MFDWKTYOVP5BAVCNFSM6AAAAAA2SDA6OCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQOJSGU2DCNRZGM . You are receiving this because you commented.Message ID: @.***>