summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpommicket <pommicket@gmail.com>2023-03-02 10:44:11 -0500
committerpommicket <pommicket@gmail.com>2023-03-02 10:44:11 -0500
commiteddcc7e8c6c02970ac658024b3a8c6b5f416c8a5 (patch)
tree542e3eb5536cf4abb9592a88ff779fc0d2763103
parent595cc50b7985ec67c49c6e2ffc649cb04692a318 (diff)
comment-start and comment-end settings
-rw-r--r--buffer.c12
-rw-r--r--config.c2
-rw-r--r--development.md9
-rw-r--r--main.c3
-rw-r--r--syntax.c40
-rw-r--r--ted.cfg26
-rw-r--r--ted.h8
7 files changed, 43 insertions, 57 deletions
diff --git a/buffer.c b/buffer.c
index 5852c68..8371c7c 100644
--- a/buffer.c
+++ b/buffer.c
@@ -3023,8 +3023,8 @@ void buffer_dedent_cursor_line(TextBuffer *buffer) {
void buffer_comment_lines(TextBuffer *buffer, u32 first_line, u32 last_line) {
- Language lang = buffer_language(buffer);
- const char *start = language_comment_start(lang), *end = language_comment_end(lang);
+ Settings *settings = buffer_settings(buffer);
+ const char *start = settings->comment_start, *end = settings->comment_end;
if (!start[0] && !end[0])
return;
String32 start32 = str32_from_utf8(start), end32 = str32_from_utf8(end);
@@ -3078,8 +3078,8 @@ static bool buffer_line_ends_with_ascii(TextBuffer *buffer, u32 line_idx, const
}
void buffer_uncomment_lines(TextBuffer *buffer, u32 first_line, u32 last_line) {
- Language lang = buffer_language(buffer);
- const char *start = language_comment_start(lang), *end = language_comment_end(lang);
+ Settings *settings = buffer_settings(buffer);
+ const char *start = settings->comment_start, *end = settings->comment_end;
if (!start[0] && !end[0])
return;
u32 start_len = (u32)strlen(start), end_len = (u32)strlen(end);
@@ -3102,8 +3102,8 @@ void buffer_uncomment_lines(TextBuffer *buffer, u32 first_line, u32 last_line) {
}
void buffer_toggle_comment_lines(TextBuffer *buffer, u32 first_line, u32 last_line) {
- Language lang = buffer_language(buffer);
- const char *start = language_comment_start(lang), *end = language_comment_end(lang);
+ Settings *settings = buffer_settings(buffer);
+ const char *start = settings->comment_start, *end = settings->comment_end;
if (!start[0] && !end[0])
return;
// if first line is a comment, uncomment lines, otherwise, comment lines
diff --git a/config.c b/config.c
index c5f6c31..1fd2675 100644
--- a/config.c
+++ b/config.c
@@ -122,6 +122,8 @@ static SettingString const settings_string[] = {
{"root-identifiers", settings_zero.root_identifiers, sizeof settings_zero.root_identifiers, true},
{"lsp", settings_zero.lsp, sizeof settings_zero.lsp, true},
{"lsp-configuration", settings_zero.lsp_configuration, sizeof settings_zero.lsp_configuration, true},
+ {"comment-start", settings_zero.comment_start, sizeof settings_zero.comment_start, true},
+ {"comment-end", settings_zero.comment_end, sizeof settings_zero.comment_end, true},
};
diff --git a/development.md b/development.md
index ea3d0f5..80b7c3b 100644
--- a/development.md
+++ b/development.md
@@ -72,11 +72,12 @@ go to `command.c` and add the name of the command to the
`command_names` array,
and implement the command in the `command_execute` function.
-## Adding languages
+## Adding (built-in) languages
-Add a new member to the `Language` enum in `base.h`.
-After that you should get a bunch of compiler warnings and errors
-which will tell you what you need to add.
+Add a new member to the `Language` enum in `ted.h`.
+Update `syntax_register_builtin_languages` accordingly.
+Make sure to define `comment-start` and `comment-end`
+for the language in `ted.cfg`.
### Syntax highlighting
diff --git a/main.c b/main.c
index 5031f93..5180282 100644
--- a/main.c
+++ b/main.c
@@ -1,7 +1,4 @@
/*
-@TODO:
-- check validity in CMD_SET_LANGUAGE
-- comment-start & comment-end settings
FUTURE FEATURES:
- manual.md
- CSS highlighting
diff --git a/syntax.c b/syntax.c
index e1ced05..7a2dc3a 100644
--- a/syntax.c
+++ b/syntax.c
@@ -97,46 +97,6 @@ const char *language_to_str(Language language) {
return "???";
}
-// start of single line comment for language l -- used for comment/uncomment selection
-const char *language_comment_start(Language l) {
- switch (l) {
- case LANG_C:
- case LANG_RUST:
- case LANG_CPP:
- case LANG_JAVASCRIPT:
- case LANG_TYPESCRIPT:
- case LANG_JSON: // JSON technically doesn't have comments but apparently some parsers support this so might as well have this here
- case LANG_JAVA:
- case LANG_GO:
- case LANG_GLSL:
- return "// ";
- case LANG_CONFIG:
- case LANG_TED_CFG:
- case LANG_PYTHON:
- return "# ";
- case LANG_TEX:
- return "% ";
- case LANG_HTML:
- case LANG_XML:
- return "<!-- ";
- case LANG_NONE:
- case LANG_MARKDOWN:
- case LANG_TEXT:
- break;
- }
- return "";
-}
-
-// end of single line comment for language l
-const char *language_comment_end(Language l) {
- switch (l) {
- case LANG_HTML:
- return " -->";
- default:
- return "";
- }
-}
-
ColorSetting syntax_char_type_to_color_setting(SyntaxCharType t) {
switch (t) {
case SYNTAX_NORMAL: return COLOR_TEXT;
diff --git a/ted.cfg b/ted.cfg
index 517c206..82fd2eb 100644
--- a/ted.cfg
+++ b/ted.cfg
@@ -115,12 +115,15 @@ root-identifiers = .ted-root, .ted-root.out, Cargo.toml, make.bat, CMakeLists.tx
[C.core]
lsp = "clangd --log=error"
+comment-start = "// "
[C++.core]
lsp = "clangd --log=error"
+comment-start = "// "
[Go.core]
lsp = "gopls"
+comment-start = "// "
[Java.core]
lsp = "jdtls"
@@ -132,29 +135,52 @@ lsp-configuration = `{
}
}
}`
+comment-start = "// "
[JavaScript.core]
lsp = "typescript-language-server --stdio"
+comment-start = "// "
[TypeScript.core]
lsp = "typescript-language-server --stdio"
+comment-start = "// "
+
+[JSON.core]
+comment-start = "// "
+
+[GLSL.core]
+comment-start = "// "
[Python.core]
lsp = "pylsp"
+comment-start = "# "
[Rust.core]
lsp = "rust-analyzer"
+comment-start = "// "
[Tex.core]
lsp = "texlab"
+comment-start = "% "
+
+[HTML.core]
+comment-start = "<!-- "
+comment-end = " -->"
+
+[XML.core]
+comment-start = "<!-- "
+comment-end = " -->"
+
# phantom completions are just annoying if you're not actually programming
[Markdown.core]
phantom-completions = off
[TedCfg.core]
phantom-completions = off
+comment-start = "# "
[Config.core]
phantom-completions = off
+comment-start = "# "
[Text.core]
phantom-completions = off
diff --git a/ted.h b/ted.h
index 35c35b0..82b123d 100644
--- a/ted.h
+++ b/ted.h
@@ -262,6 +262,10 @@ typedef struct {
u8 tags_max_depth;
GlRcSAB *bg_shader;
GlRcTexture *bg_texture;
+ /// string used to start comments
+ char comment_start[16];
+ /// string used to end comments
+ char comment_end[16];
/// Comma-separated list of file names which identify the project root
char root_identifiers[4096];
/// LSP server command
@@ -1496,10 +1500,6 @@ bool language_is_valid(Language language);
Language language_from_str(const char *str);
/// convert language to string
const char *language_to_str(Language language);
-/// string which should be put before comments in the given language
-const char *language_comment_start(Language l);
-/// string which should be put after comments in the given language
-const char *language_comment_end(Language l);
/// get the color setting associated with the given syntax highlighting type
ColorSetting syntax_char_type_to_color_setting(SyntaxCharType t);
/// returns ')' for '(', etc., or 0 if c is not an opening bracket