Skip to content

Instantly share code, notes, and snippets.

@codebrainz
Created September 17, 2011 03:21
Show Gist options
  • Select an option

  • Save codebrainz/1223591 to your computer and use it in GitHub Desktop.

Select an option

Save codebrainz/1223591 to your computer and use it in GitHub Desktop.
support embedded languages
diff --git a/src/editor.c b/src/editor.c
index b8419a0..516c919 100644
--- a/src/editor.c
+++ b/src/editor.c
@@ -378,6 +378,17 @@ static gboolean is_style_php(gint style)
}
+static gboolean is_style_js(gint style)
+{
+ if (style >= SCE_HJ_DEFAULT && style <= SCE_HJ_REGEX)
+ {
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+
static gint editor_get_long_line_type(void)
{
if (app->project)
@@ -2855,7 +2866,7 @@ static gint get_multiline_comment_style(GeanyEditor *editor, gint line_start)
gint editor_do_uncomment(GeanyEditor *editor, gint line, gboolean toggle)
{
gint first_line, last_line, eol_char_len;
- gint x, i, line_start, line_len;
+ gint x, i, line_start, first_line_start, line_len;
gint sel_start, sel_end;
gint count = 0;
gsize co_len;
@@ -2885,12 +2896,29 @@ gint editor_do_uncomment(GeanyEditor *editor, gint line, gboolean toggle)
ft = editor->document->file_type;
eol_char_len = editor_get_eol_char_len(editor);
- /* detection of HTML vs PHP code, if non-PHP set filetype to XML */
- line_start = sci_get_position_from_line(editor->sci, first_line);
- if (ft->id == GEANY_FILETYPES_PHP)
+ first_line_start = sci_get_position_from_line(editor->sci, first_line);
+ line_start = sci_get_position_from_line(editor->sci,
+ sci_get_current_line(editor->sci));
+
+ switch (ft->id)
{
- if (! is_style_php(sci_get_style_at(editor->sci, line_start)))
- ft = filetypes[GEANY_FILETYPES_XML];
+ /* detection of HTML vs PHP code, if non-PHP set filetype to XML */
+ case GEANY_FILETYPES_PHP:
+ if (! is_style_php(sci_get_style_at(editor->sci, first_line_start)))
+ ft = filetypes[GEANY_FILETYPES_XML];
+ break;
+ /* see if we're inside one of HTML's embedable languages */
+ case GEANY_FILETYPES_HTML:
+ if (is_style_js(sci_get_style_at(editor->sci, line_start)))
+ {
+ ft = filetypes[GEANY_FILETYPES_JS];
+ filetypes_load_config(ft->id, FALSE);
+ }
+ /* TODO: check for other HTML-embedable languages supported by LexHTML */
+ break;
+ /* TODO: other multi-lingual Scintilla lexers (ex. LexOthers) */
+ default:
+ break;
}
co = ft->comment_single;
@@ -3006,7 +3034,7 @@ void editor_do_comment_toggle(GeanyEditor *editor)
gboolean first_line_was_comment = FALSE;
gsize co_len;
gsize tm_len = strlen(editor_prefs.comment_toggle_mark);
- GeanyFiletype *ft;
+ GeanyFiletype *ft, *real_ft;
g_return_if_fail(editor != NULL && editor->document->file_type != NULL);
@@ -3023,12 +3051,29 @@ void editor_do_comment_toggle(GeanyEditor *editor)
sci_get_selection_end(editor->sci) - editor_get_eol_char_len(editor));
last_line = MAX(first_line, last_line);
- /* detection of HTML vs PHP code, if non-PHP set filetype to XML */
first_line_start = sci_get_position_from_line(editor->sci, first_line);
- if (ft->id == GEANY_FILETYPES_PHP)
+ line_start = sci_get_position_from_line(editor->sci,
+ sci_get_current_line(editor->sci));
+
+ switch (ft->id)
{
- if (! is_style_php(sci_get_style_at(editor->sci, first_line_start)))
- ft = filetypes[GEANY_FILETYPES_XML];
+ /* detection of HTML vs PHP code, if non-PHP set filetype to XML */
+ case GEANY_FILETYPES_PHP:
+ if (! is_style_php(sci_get_style_at(editor->sci, first_line_start)))
+ ft = filetypes[GEANY_FILETYPES_XML];
+ break;
+ /* see if we're inside one of HTML's embedable languages */
+ case GEANY_FILETYPES_HTML:
+ if (is_style_js(sci_get_style_at(editor->sci, line_start)))
+ {
+ ft = filetypes[GEANY_FILETYPES_JS];
+ filetypes_load_config(ft->id, FALSE);
+ }
+ /* TODO: check for other HTML-embedable languages supported by LexHTML */
+ break;
+ /* TODO: other multi-lingual Scintilla lexers (ex. LexOthers) */
+ default:
+ break;
}
co = ft->comment_single;
@@ -3165,7 +3210,7 @@ void editor_do_comment_toggle(GeanyEditor *editor)
void editor_do_comment(GeanyEditor *editor, gint line, gboolean allow_empty_lines, gboolean toggle)
{
gint first_line, last_line, eol_char_len;
- gint x, i, line_start, line_len;
+ gint x, i, line_start, first_line_start, line_len;
gint sel_start, sel_end, co_len;
gchar sel[256], *co, *cc;
gboolean break_loop = FALSE, single_line = FALSE;
@@ -3193,12 +3238,29 @@ void editor_do_comment(GeanyEditor *editor, gint line, gboolean allow_empty_line
ft = editor->document->file_type;
eol_char_len = editor_get_eol_char_len(editor);
- /* detection of HTML vs PHP code, if non-PHP set filetype to XML */
- line_start = sci_get_position_from_line(editor->sci, first_line);
- if (ft->id == GEANY_FILETYPES_PHP)
+ first_line_start = sci_get_position_from_line(editor->sci, first_line);
+ line_start = sci_get_position_from_line(editor->sci,
+ sci_get_current_line(editor->sci));
+
+ switch (ft->id)
{
- if (! is_style_php(sci_get_style_at(editor->sci, line_start)))
- ft = filetypes[GEANY_FILETYPES_XML];
+ /* detection of HTML vs PHP code, if non-PHP set filetype to XML */
+ case GEANY_FILETYPES_PHP:
+ if (! is_style_php(sci_get_style_at(editor->sci, first_line_start)))
+ ft = filetypes[GEANY_FILETYPES_XML];
+ break;
+ /* see if we're inside one of HTML's embedable languages */
+ case GEANY_FILETYPES_HTML:
+ if (is_style_js(sci_get_style_at(editor->sci, line_start)))
+ {
+ ft = filetypes[GEANY_FILETYPES_JS];
+ filetypes_load_config(ft->id, FALSE);
+ }
+ /* TODO: check for other HTML-embedable languages supported by LexHTML */
+ break;
+ /* TODO: other multi-lingual Scintilla lexers (ex. LexOthers) */
+ default:
+ break;
}
co = ft->comment_single;
@@ -3956,7 +4018,7 @@ void editor_finalize()
/* wordchars: NULL or a string containing characters to match a word.
* Returns: the current selection or the current word.
- *
+ *
* Passing NULL as wordchars is NOT the same as passing GEANY_WORDCHARS: NULL means
* using Scintillas's word boundaries. */
gchar *editor_get_default_selection(GeanyEditor *editor, gboolean use_current_word,
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment