Skip to content

Commit

Permalink
extended API and added syntax sugar for defining syntax highlighting
Browse files Browse the repository at this point in the history
  • Loading branch information
curlpipe committed Jul 22, 2024
1 parent 13d8a50 commit 0ecfd7b
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 15 deletions.
31 changes: 18 additions & 13 deletions .todo.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
- [ ] Plugin refresh - 0.4.2
- [ ] Custom syntax highlighting rules
- [ ] Plugin management
- [ ] Expanded editor API
- [ ] Update documentation
- [X] Fields
- [X] visibility of help message
- [X] ox version
- [X] number of documents open
- [X] current document id
- [X] file type
- [ ] Investigate panics in plug-ins
- [ ] Update documentation
- [ ] New API
- [ ] User defined syntax highlighting
- [X] README update
- [X] Fix string error
- [X] Transfer built-in commands to lua & fix borrowmut panic
- [X] Custom syntax highlighting
- [X] Expanded editor API
- [X] Methods
- [X] Get character
- [X] Get line
Expand All @@ -21,16 +20,22 @@
- [X] Hide the help message
- [X] Set file type
- [X] Set read only status
- [X] README update
- [X] Fix string error
- [X] Transfer built-in commands to lua & fix borrowmut panic
- [X] Fields
- [X] visibility of help message
- [X] ox version
- [X] number of documents open
- [X] current document id
- [X] file type
- [X] length of current document
- [X] Custom syntax highlighting syntax sugar

- [ ] Editing improvements - 0.4.3
- [ ] Better editor navigation (see github issues)
- [ ] Line swapping
- [ ] Bracket and Quote Pairs
- [ ] Auto indentation
- [ ] Delete word command
- [ ] Add documentation on how to use/see/import/package plugins

- [ ] UI/UX improvements - 0.4.4
- [ ] Replace command needs to update syntax
Expand Down
10 changes: 8 additions & 2 deletions config/.oxrc
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ event_mapping = {
editor:open_command_line()
end,
["ctrl_h"] = function()
editor:set_read_only(false)
editor:display_info(editor.document_length)
end,
}

Expand Down Expand Up @@ -218,7 +218,13 @@ syntax:new(
-- New syntax highlighting for files with the extensions psi and psix
{"psi", "psix"},
{
syntax:keyword("keyword", "pub"),
-- Add multiple patterns to make a keyword token
syntax:keywords("keyword", {
"\\b(pub)\\b", "\\b(fn)\\b", "\\b(return)\\b",
}),
-- Define digits
syntax:keyword("digit", "([0-9]+)"),
-- Create a bounded token for strings (that can be escaped)
syntax:bounded("string", "\"", "\"", true),
}
)
Expand Down
11 changes: 11 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,13 @@ impl SyntaxHighlighting {

impl LuaUserData for SyntaxHighlighting {
fn add_methods<'lua, M: LuaUserDataMethods<'lua, Self>>(methods: &mut M) {
methods.add_method_mut("keywords", |lua, _, (name, pattern): (String, Vec<String>)| {
let table = lua.create_table()?;
table.set("kind", "keyword")?;
table.set("name", name)?;
table.set("pattern", format!("({})", pattern.join("|")))?;
Ok(table)
});
methods.add_method_mut("keyword", |lua, _, (name, pattern): (String, String)| {
let table = lua.create_table()?;
table.set("kind", "keyword")?;
Expand Down Expand Up @@ -725,6 +732,10 @@ impl LuaUserData for Editor {
let name = editor.doc().file_name.clone();
Ok(name)
});
fields.add_field_method_get("document_length", |_, editor| {
let len = editor.doc().len_lines();
Ok(len)
});
fields.add_field_method_get("version", |_, _| {
Ok(VERSION)
});
Expand Down

0 comments on commit 0ecfd7b

Please sign in to comment.