2 * highlighting.c - this file is part of Geany, a fast and lightweight IDE
4 * Copyright 2005-2012 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>
5 * Copyright 2006-2012 Nick Treleaven <nick(dot)treleaven(at)btinternet(dot)com>
6 * Copyright 2011-2012 Colomban Wendling <ban(at)herbesfolles(dot)org>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 * @file highlighting.h
25 * Syntax highlighting for the different filetypes, using the Scintilla lexers.
32 #include "highlighting.h"
33 #include "highlightingmappings.h"
39 #include "filetypesprivate.h"
40 #include "sciwrappers.h"
52 #include <glib/gprintf.h>
55 #define GEANY_COLORSCHEMES_SUBDIR "colorschemes"
57 /* Whitespace has to be set after setting wordchars. */
58 #define GEANY_WHITESPACE_CHARS " \t" "!\"#$%&'()*+,-./:;<=>?@[\\]^`{|}~"
61 static gchar
*whitespace_chars
= NULL
;
66 gsize count
; /* number of styles */
67 GeanyLexerStyle
*styling
; /* array of styles, NULL if not used or uninitialised */
69 gchar
*wordchars
; /* NULL used for style sets with no styles */
70 gchar
**property_keys
;
71 gchar
**property_values
;
74 /* each filetype has a styleset but GEANY_FILETYPES_NONE uses common_style_set for styling */
75 static StyleSet
*style_sets
= NULL
;
78 enum /* Geany common styling */
84 GCS_MARGIN_LINENUMBER
,
86 GCS_FOLD_SYMBOL_HIGHLIGHT
,
91 GCS_LINE_WRAP_VISUALS
,
97 GCS_MARKER_TRANSLUCENCY
,
106 GeanyLexerStyle styling
[GCS_MAX
];
108 /* icon style, 1-4 */
110 /* vertical line style, 0-2 */
112 /* horizontal line when folded, 0-2 */
116 } common_style_set
= { { { 0 } }, 0, 0, 0, NULL
};
119 /* For filetypes.common [named_styles] section.
121 * e.g. "comment" => &GeanyLexerStyle{0x0000d0, 0xffffff, FALSE, FALSE} */
122 static GHashTable
*named_style_hash
= NULL
;
124 /* 0xBBGGRR format, set by "default" named style. */
125 static GeanyLexerStyle gsd_default
= {0x000000, 0xffffff, FALSE
, FALSE
};
128 /* filetypes should use the filetypes.foo [lexer_properties] group instead of hardcoding */
129 static void sci_set_property(ScintillaObject
*sci
, const gchar
*name
, const gchar
*value
)
131 SSM(sci
, SCI_SETPROPERTY
, (uptr_t
) name
, (sptr_t
) value
);
135 static void new_styleset(guint file_type_id
, gsize styling_count
)
137 StyleSet
*set
= &style_sets
[file_type_id
];
139 set
->count
= styling_count
;
140 set
->styling
= g_new0(GeanyLexerStyle
, styling_count
);
144 static void free_styleset(guint file_type_id
)
147 style_ptr
= &style_sets
[file_type_id
];
149 style_ptr
->count
= 0;
150 g_free(style_ptr
->styling
);
151 style_ptr
->styling
= NULL
;
152 g_strfreev(style_ptr
->keywords
);
153 style_ptr
->keywords
= NULL
;
154 g_free(style_ptr
->wordchars
);
155 style_ptr
->wordchars
= NULL
;
156 g_strfreev(style_ptr
->property_keys
);
157 style_ptr
->property_keys
= NULL
;
158 g_strfreev(style_ptr
->property_values
);
159 style_ptr
->property_values
= NULL
;
163 static void get_keyfile_keywords(GKeyFile
*config
, GKeyFile
*configh
,
164 const gchar
*key
, guint ft_id
, guint pos
)
166 style_sets
[ft_id
].keywords
[pos
] =
167 utils_get_setting(string
, configh
, config
, "keywords", key
, "");
171 static void get_keyfile_wordchars(GKeyFile
*config
, GKeyFile
*configh
, gchar
**wordchars
,
172 const gchar
*default_wordchars
)
174 *wordchars
= utils_get_setting(string
, configh
, config
,
175 "settings", "wordchars", default_wordchars
);
179 static gboolean
read_named_style(const gchar
*named_style
, GeanyLexerStyle
*style
)
182 gchar
*comma
, *name
= NULL
;
183 const gchar
*bold
= NULL
;
184 const gchar
*italic
= NULL
;
186 g_return_val_if_fail(named_style
, FALSE
);
187 name
= utils_strdupa(named_style
); /* named_style must not be written to, may be a static string */
189 comma
= strstr(name
, ",");
192 bold
= strstr(comma
, ",bold");
193 italic
= strstr(comma
, ",italic");
194 *comma
= '\0'; /* terminate name to make lookup work */
196 cs
= g_hash_table_lookup(named_style_hash
, name
);
202 style
->bold
= !style
->bold
;
204 style
->italic
= !style
->italic
;
208 *style
= gsd_default
;
214 /* Parses a color in `str` which can be an HTML color (ex. #0099cc),
215 * an abbreviated HTML color (ex. #09c) or a hex string color
216 * (ex. 0x0099cc). The result of the conversion is stored into the
217 * location pointed to by `clr`. */
218 static void parse_color(GKeyFile
*kf
, const gchar
*str
, gint
*clr
)
221 gchar
*named_color
= NULL
;
223 g_return_if_fail(clr
!= NULL
);
225 if (G_UNLIKELY(EMPTY(str
)))
228 named_color
= g_key_file_get_string(kf
, "named_colors", str
, NULL
);
232 c
= utils_parse_color_to_bgr(str
);
234 geany_debug("Bad color '%s'", str
);
242 static void parse_keyfile_style(GKeyFile
*kf
, gchar
**list
,
243 const GeanyLexerStyle
*default_style
, GeanyLexerStyle
*style
)
247 g_return_if_fail(default_style
);
248 g_return_if_fail(style
);
250 *style
= *default_style
;
255 len
= g_strv_length(list
);
260 gchar
**items
= g_strsplit(list
[0], ",", 0);
263 if (g_strv_length(items
) > 0)
265 if (g_hash_table_lookup(named_style_hash
, items
[0]) != NULL
)
267 if (!read_named_style(list
[0], style
))
268 geany_debug("Unable to read named style '%s'", items
[0]);
272 else if (strchr(list
[0], ',') != NULL
)
274 geany_debug("Unknown named style '%s'", items
[0]);
286 style
->italic
= utils_atob(list
[3]);
288 style
->bold
= utils_atob(list
[2]);
290 parse_color(kf
, list
[1], &style
->background
);
292 parse_color(kf
, list
[0], &style
->foreground
);
297 static void get_keyfile_style(GKeyFile
*config
, GKeyFile
*configh
,
298 const gchar
*key_name
, GeanyLexerStyle
*style
)
303 g_return_if_fail(config
);
304 g_return_if_fail(configh
);
305 g_return_if_fail(key_name
);
306 g_return_if_fail(style
);
308 list
= g_key_file_get_string_list(configh
, "styling", key_name
, &len
, NULL
);
311 list
= g_key_file_get_string_list(config
, "styling", key_name
, &len
, NULL
);
312 parse_keyfile_style(config
, list
, &gsd_default
, style
);
315 parse_keyfile_style(configh
, list
, &gsd_default
, style
);
321 static void convert_int(const gchar
*int_str
, gint
*val
)
324 gint v
= strtol(int_str
, &end
, 10);
331 /* Get first and second integer numbers, store in foreground and background fields of @a style. */
332 static void get_keyfile_int(GKeyFile
*config
, GKeyFile
*configh
, const gchar
*section
,
333 const gchar
*key
, gint fdefault_val
, gint sdefault_val
,
334 GeanyLexerStyle
*style
)
338 GeanyLexerStyle def
= {fdefault_val
, sdefault_val
, FALSE
, FALSE
};
340 g_return_if_fail(config
);
341 g_return_if_fail(configh
);
342 g_return_if_fail(section
);
343 g_return_if_fail(key
);
345 list
= g_key_file_get_string_list(configh
, section
, key
, &len
, NULL
);
347 list
= g_key_file_get_string_list(config
, section
, key
, &len
, NULL
);
355 convert_int(list
[0], &style
->foreground
);
358 convert_int(list
[1], &style
->background
);
365 /* first or second can be NULL. */
366 static void get_keyfile_ints(GKeyFile
*config
, GKeyFile
*configh
, const gchar
*section
,
368 gint fdefault_val
, gint sdefault_val
,
369 gint
*first
, gint
*second
)
371 GeanyLexerStyle tmp_style
;
373 get_keyfile_int(config
, configh
, section
, key
, fdefault_val
, sdefault_val
, &tmp_style
);
375 *first
= tmp_style
.foreground
;
377 *second
= tmp_style
.background
;
381 static guint
invert(guint icolour
)
383 if (interface_prefs
.highlighting_invert_all
)
384 return 0xffffff - icolour
;
390 static GeanyLexerStyle
*get_style(guint ft_id
, guint styling_index
)
392 g_assert(ft_id
< filetypes_array
->len
);
394 if (G_UNLIKELY(ft_id
== GEANY_FILETYPES_NONE
))
396 g_assert(styling_index
< GCS_MAX
);
397 return &common_style_set
.styling
[styling_index
];
401 StyleSet
*set
= &style_sets
[ft_id
];
403 g_assert(styling_index
< set
->count
);
404 return &set
->styling
[styling_index
];
409 static void set_sci_style(ScintillaObject
*sci
, guint style
, guint ft_id
, guint styling_index
)
411 GeanyLexerStyle
*style_ptr
= get_style(ft_id
, styling_index
);
413 SSM(sci
, SCI_STYLESETFORE
, style
, invert(style_ptr
->foreground
));
414 SSM(sci
, SCI_STYLESETBACK
, style
, invert(style_ptr
->background
));
415 SSM(sci
, SCI_STYLESETBOLD
, style
, style_ptr
->bold
);
416 SSM(sci
, SCI_STYLESETITALIC
, style
, style_ptr
->italic
);
420 void highlighting_free_styles(void)
424 for (i
= 0; i
< filetypes_array
->len
; i
++)
427 if (named_style_hash
)
428 g_hash_table_destroy(named_style_hash
);
435 get_keyfile_whitespace_chars(GKeyFile
*config
, GKeyFile
*configh
)
437 return utils_get_setting(string
, configh
, config
,
438 "settings", "whitespace_chars", GEANY_WHITESPACE_CHARS
);
442 static void add_named_style(GKeyFile
*config
, const gchar
*key
)
444 const gchar group
[] = "named_styles";
448 list
= g_key_file_get_string_list(config
, group
, key
, &len
, NULL
);
449 /* we allow a named style to reference another style above it */
450 if (list
&& len
>= 1)
452 GeanyLexerStyle
*style
= g_new0(GeanyLexerStyle
, 1);
454 parse_keyfile_style(config
, list
, &gsd_default
, style
);
455 g_hash_table_insert(named_style_hash
, g_strdup(key
), style
);
461 static void get_named_styles(GKeyFile
*config
)
463 const gchar group
[] = "named_styles";
464 gchar
**keys
= g_key_file_get_keys(config
, group
, NULL
, NULL
);
472 const gchar
*key
= *ptr
;
477 /* don't replace already read default style with system one */
478 if (!g_str_equal(key
, "default"))
479 add_named_style(config
, key
);
487 static GKeyFile
*utils_key_file_new(const gchar
*filename
)
489 GKeyFile
*config
= g_key_file_new();
491 g_key_file_load_from_file(config
, filename
, G_KEY_FILE_KEEP_COMMENTS
, NULL
);
496 static void load_named_styles(GKeyFile
*config
, GKeyFile
*config_home
)
498 const gchar
*scheme
= editor_prefs
.color_scheme
;
499 gboolean free_kf
= FALSE
;
501 if (named_style_hash
)
502 g_hash_table_destroy(named_style_hash
); /* reloading */
504 named_style_hash
= g_hash_table_new_full(g_str_hash
, g_str_equal
, g_free
, g_free
);
508 gchar
*path
, *path_home
;
510 path
= g_build_path(G_DIR_SEPARATOR_S
, app
->datadir
, GEANY_COLORSCHEMES_SUBDIR
, scheme
, NULL
);
511 path_home
= g_build_path(G_DIR_SEPARATOR_S
, app
->configdir
, GEANY_COLORSCHEMES_SUBDIR
, scheme
, NULL
);
513 if (g_file_test(path
, G_FILE_TEST_EXISTS
) || g_file_test(path_home
, G_FILE_TEST_EXISTS
))
515 config
= utils_key_file_new(path
);
516 config_home
= utils_key_file_new(path_home
);
519 /* if color scheme is missing, use default */
523 /* first set default to the "default" named style */
524 add_named_style(config
, "default");
525 read_named_style("default", &gsd_default
); /* in case user overrides but not with both colors */
526 add_named_style(config_home
, "default");
527 read_named_style("default", &gsd_default
);
529 get_named_styles(config
);
530 /* home overrides any system named style */
531 get_named_styles(config_home
);
535 g_key_file_free(config
);
536 g_key_file_free(config_home
);
541 static void styleset_common_init(GKeyFile
*config
, GKeyFile
*config_home
)
543 load_named_styles(config
, config_home
);
545 get_keyfile_style(config
, config_home
, "default", &common_style_set
.styling
[GCS_DEFAULT
]);
546 get_keyfile_style(config
, config_home
, "selection", &common_style_set
.styling
[GCS_SELECTION
]);
547 get_keyfile_style(config
, config_home
, "brace_good", &common_style_set
.styling
[GCS_BRACE_GOOD
]);
548 get_keyfile_style(config
, config_home
, "brace_bad", &common_style_set
.styling
[GCS_BRACE_BAD
]);
549 get_keyfile_style(config
, config_home
, "margin_linenumber", &common_style_set
.styling
[GCS_MARGIN_LINENUMBER
]);
550 get_keyfile_style(config
, config_home
, "margin_folding", &common_style_set
.styling
[GCS_MARGIN_FOLDING
]);
551 get_keyfile_style(config
, config_home
, "fold_symbol_highlight", &common_style_set
.styling
[GCS_FOLD_SYMBOL_HIGHLIGHT
]);
552 get_keyfile_style(config
, config_home
, "current_line", &common_style_set
.styling
[GCS_CURRENT_LINE
]);
553 get_keyfile_style(config
, config_home
, "caret", &common_style_set
.styling
[GCS_CARET
]);
554 get_keyfile_style(config
, config_home
, "indent_guide", &common_style_set
.styling
[GCS_INDENT_GUIDE
]);
555 get_keyfile_style(config
, config_home
, "white_space", &common_style_set
.styling
[GCS_WHITE_SPACE
]);
556 get_keyfile_style(config
, config_home
, "marker_line", &common_style_set
.styling
[GCS_MARKER_LINE
]);
557 get_keyfile_style(config
, config_home
, "marker_search", &common_style_set
.styling
[GCS_MARKER_SEARCH
]);
558 get_keyfile_style(config
, config_home
, "marker_mark", &common_style_set
.styling
[GCS_MARKER_MARK
]);
559 get_keyfile_style(config
, config_home
, "calltips", &common_style_set
.styling
[GCS_CALLTIPS
]);
560 get_keyfile_style(config
, config_home
, "indicator_error", &common_style_set
.styling
[GCS_INDICATOR_ERROR
]);
562 get_keyfile_ints(config
, config_home
, "styling", "folding_style",
563 1, 1, &common_style_set
.fold_marker
, &common_style_set
.fold_lines
);
564 get_keyfile_ints(config
, config_home
, "styling", "folding_horiz_line",
565 2, 0, &common_style_set
.fold_draw_line
, NULL
);
566 get_keyfile_ints(config
, config_home
, "styling", "caret_width",
567 1, 0, &common_style_set
.styling
[GCS_CARET
].background
, NULL
); /* caret.foreground used earlier */
568 get_keyfile_int(config
, config_home
, "styling", "line_wrap_visuals",
569 3, 0, &common_style_set
.styling
[GCS_LINE_WRAP_VISUALS
]);
570 get_keyfile_int(config
, config_home
, "styling", "line_wrap_indent",
571 0, 0, &common_style_set
.styling
[GCS_LINE_WRAP_INDENT
]);
572 get_keyfile_int(config
, config_home
, "styling", "translucency",
573 256, 256, &common_style_set
.styling
[GCS_TRANSLUCENCY
]);
574 get_keyfile_int(config
, config_home
, "styling", "marker_translucency",
575 256, 256, &common_style_set
.styling
[GCS_MARKER_TRANSLUCENCY
]);
576 get_keyfile_int(config
, config_home
, "styling", "line_height",
577 0, 0, &common_style_set
.styling
[GCS_LINE_HEIGHT
]);
579 g_free(common_style_set
.wordchars
);
580 get_keyfile_wordchars(config
, config_home
, &common_style_set
.wordchars
, GEANY_WORDCHARS
);
581 g_free(whitespace_chars
);
582 whitespace_chars
= get_keyfile_whitespace_chars(config
, config_home
);
586 static void set_character_classes(ScintillaObject
*sci
, guint ft_id
)
588 const gchar
*word
= (ft_id
== GEANY_FILETYPES_NONE
?
589 common_style_set
.wordchars
: style_sets
[ft_id
].wordchars
);
593 SSM(sci
, SCI_SETWORDCHARS
, 0, (sptr_t
) word
);
595 /* setting wordchars resets character classes, so we have to set whitespaces after
596 * wordchars, but we want wordchars to have precenence over whitepace chars */
597 whitespace
= g_malloc0(strlen(whitespace_chars
) + 1);
598 for (i
= 0, j
= 0; whitespace_chars
[i
] != 0; i
++)
600 if (! strchr(word
, whitespace_chars
[i
]))
601 whitespace
[j
++] = whitespace_chars
[i
];
605 SSM(sci
, SCI_SETWHITESPACECHARS
, 0, (sptr_t
) whitespace
);
611 static void styleset_common(ScintillaObject
*sci
, guint ft_id
)
613 GeanyLexerStyle
*style
;
615 SSM(sci
, SCI_STYLECLEARALL
, 0, 0);
617 set_character_classes(sci
, ft_id
);
619 /* caret colour, style and width */
620 SSM(sci
, SCI_SETCARETFORE
, invert(common_style_set
.styling
[GCS_CARET
].foreground
), 0);
621 SSM(sci
, SCI_SETCARETWIDTH
, common_style_set
.styling
[GCS_CARET
].background
, 0);
622 if (common_style_set
.styling
[GCS_CARET
].bold
)
623 SSM(sci
, SCI_SETCARETSTYLE
, CARETSTYLE_BLOCK
, 0);
625 SSM(sci
, SCI_SETCARETSTYLE
, CARETSTYLE_LINE
, 0);
628 SSM(sci
, SCI_SETEXTRAASCENT
, common_style_set
.styling
[GCS_LINE_HEIGHT
].foreground
, 0);
629 SSM(sci
, SCI_SETEXTRADESCENT
, common_style_set
.styling
[GCS_LINE_HEIGHT
].background
, 0);
631 /* colourise the current line */
632 SSM(sci
, SCI_SETCARETLINEBACK
, invert(common_style_set
.styling
[GCS_CURRENT_LINE
].background
), 0);
633 /* bold=enable current line */
634 SSM(sci
, SCI_SETCARETLINEVISIBLE
, common_style_set
.styling
[GCS_CURRENT_LINE
].bold
, 0);
636 /* Translucency for current line and selection */
637 SSM(sci
, SCI_SETCARETLINEBACKALPHA
, common_style_set
.styling
[GCS_TRANSLUCENCY
].foreground
, 0);
638 SSM(sci
, SCI_SETSELALPHA
, common_style_set
.styling
[GCS_TRANSLUCENCY
].background
, 0);
640 /* line wrapping visuals */
641 SSM(sci
, SCI_SETWRAPVISUALFLAGS
,
642 common_style_set
.styling
[GCS_LINE_WRAP_VISUALS
].foreground
, 0);
643 SSM(sci
, SCI_SETWRAPVISUALFLAGSLOCATION
,
644 common_style_set
.styling
[GCS_LINE_WRAP_VISUALS
].background
, 0);
645 SSM(sci
, SCI_SETWRAPSTARTINDENT
, common_style_set
.styling
[GCS_LINE_WRAP_INDENT
].foreground
, 0);
646 SSM(sci
, SCI_SETWRAPINDENTMODE
, common_style_set
.styling
[GCS_LINE_WRAP_INDENT
].background
, 0);
648 /* Error indicator */
649 SSM(sci
, SCI_INDICSETSTYLE
, GEANY_INDICATOR_ERROR
, INDIC_SQUIGGLEPIXMAP
);
650 SSM(sci
, SCI_INDICSETFORE
, GEANY_INDICATOR_ERROR
,
651 invert(common_style_set
.styling
[GCS_INDICATOR_ERROR
].foreground
));
653 /* Search indicator, used for 'Mark' matches */
654 SSM(sci
, SCI_INDICSETSTYLE
, GEANY_INDICATOR_SEARCH
, INDIC_ROUNDBOX
);
655 SSM(sci
, SCI_INDICSETFORE
, GEANY_INDICATOR_SEARCH
,
656 invert(common_style_set
.styling
[GCS_MARKER_SEARCH
].background
));
657 SSM(sci
, SCI_INDICSETALPHA
, GEANY_INDICATOR_SEARCH
, 60);
659 /* Snippet cursor indicator, when inserting snippets with multiple
660 * cursor positions. */
661 SSM(sci
, SCI_INDICSETSTYLE
, GEANY_INDICATOR_SNIPPET
, INDIC_DOTBOX
);
662 SSM(sci
, SCI_INDICSETALPHA
, GEANY_INDICATOR_SNIPPET
, 60);
664 /* define marker symbols
665 * 0 -> line marker */
666 SSM(sci
, SCI_MARKERDEFINE
, 0, SC_MARK_SHORTARROW
);
667 SSM(sci
, SCI_MARKERSETFORE
, 0, invert(common_style_set
.styling
[GCS_MARKER_LINE
].foreground
));
668 SSM(sci
, SCI_MARKERSETBACK
, 0, invert(common_style_set
.styling
[GCS_MARKER_LINE
].background
));
669 SSM(sci
, SCI_MARKERSETALPHA
, 0, common_style_set
.styling
[GCS_MARKER_TRANSLUCENCY
].foreground
);
671 /* 1 -> user marker */
672 SSM(sci
, SCI_MARKERDEFINE
, 1, SC_MARK_PLUS
);
673 SSM(sci
, SCI_MARKERSETFORE
, 1, invert(common_style_set
.styling
[GCS_MARKER_MARK
].foreground
));
674 SSM(sci
, SCI_MARKERSETBACK
, 1, invert(common_style_set
.styling
[GCS_MARKER_MARK
].background
));
675 SSM(sci
, SCI_MARKERSETALPHA
, 1, common_style_set
.styling
[GCS_MARKER_TRANSLUCENCY
].background
);
677 /* 2 -> folding marker, other folding settings */
678 SSM(sci
, SCI_SETMARGINTYPEN
, 2, SC_MARGIN_SYMBOL
);
679 SSM(sci
, SCI_SETMARGINMASKN
, 2, SC_MASK_FOLDERS
);
681 /* drawing a horizontal line when text if folded */
682 switch (common_style_set
.fold_draw_line
)
686 SSM(sci
, SCI_SETFOLDFLAGS
, 4, 0);
691 SSM(sci
, SCI_SETFOLDFLAGS
, 16, 0);
696 SSM(sci
, SCI_SETFOLDFLAGS
, 0, 0);
701 /* choose the folding style - boxes or circles, I prefer boxes, so it is default ;-) */
702 SSM(sci
, SCI_MARKERDEFINE
, SC_MARKNUM_FOLDEREND
, SC_MARK_EMPTY
);
703 SSM(sci
, SCI_MARKERDEFINE
, SC_MARKNUM_FOLDEROPENMID
, SC_MARK_EMPTY
);
704 switch (common_style_set
.fold_marker
)
707 SSM(sci
, SCI_MARKERDEFINE
, SC_MARKNUM_FOLDEROPEN
, SC_MARK_CIRCLEMINUS
);
708 SSM(sci
, SCI_MARKERDEFINE
, SC_MARKNUM_FOLDER
, SC_MARK_CIRCLEPLUS
);
709 SSM(sci
, SCI_MARKERDEFINE
, SC_MARKNUM_FOLDEREND
, SC_MARK_CIRCLEPLUSCONNECTED
);
710 SSM(sci
, SCI_MARKERDEFINE
, SC_MARKNUM_FOLDEROPENMID
, SC_MARK_CIRCLEMINUSCONNECTED
);
713 SSM(sci
, SCI_MARKERDEFINE
, SC_MARKNUM_FOLDEROPEN
, SC_MARK_BOXMINUS
);
714 SSM(sci
, SCI_MARKERDEFINE
, SC_MARKNUM_FOLDER
, SC_MARK_BOXPLUS
);
715 SSM(sci
, SCI_MARKERDEFINE
, SC_MARKNUM_FOLDEREND
, SC_MARK_BOXPLUSCONNECTED
);
716 SSM(sci
, SCI_MARKERDEFINE
, SC_MARKNUM_FOLDEROPENMID
, SC_MARK_BOXMINUSCONNECTED
);
719 SSM(sci
, SCI_MARKERDEFINE
, SC_MARKNUM_FOLDEROPEN
, SC_MARK_ARROWDOWN
);
720 SSM(sci
, SCI_MARKERDEFINE
, SC_MARKNUM_FOLDER
, SC_MARK_ARROW
);
723 SSM(sci
, SCI_MARKERDEFINE
, SC_MARKNUM_FOLDEROPEN
, SC_MARK_MINUS
);
724 SSM(sci
, SCI_MARKERDEFINE
, SC_MARKNUM_FOLDER
, SC_MARK_PLUS
);
728 /* choose the folding style - straight or curved, I prefer straight, so it is default ;-) */
729 switch (common_style_set
.fold_lines
)
732 SSM(sci
, SCI_MARKERDEFINE
, SC_MARKNUM_FOLDERMIDTAIL
, SC_MARK_TCORNERCURVE
);
733 SSM(sci
, SCI_MARKERDEFINE
, SC_MARKNUM_FOLDERTAIL
, SC_MARK_LCORNERCURVE
);
734 SSM(sci
, SCI_MARKERDEFINE
, SC_MARKNUM_FOLDERSUB
, SC_MARK_VLINE
);
737 SSM(sci
, SCI_MARKERDEFINE
, SC_MARKNUM_FOLDERMIDTAIL
, SC_MARK_TCORNER
);
738 SSM(sci
, SCI_MARKERDEFINE
, SC_MARKNUM_FOLDERTAIL
, SC_MARK_LCORNER
);
739 SSM(sci
, SCI_MARKERDEFINE
, SC_MARKNUM_FOLDERSUB
, SC_MARK_VLINE
);
742 SSM(sci
, SCI_MARKERDEFINE
, SC_MARKNUM_FOLDERMIDTAIL
, SC_MARK_EMPTY
);
743 SSM(sci
, SCI_MARKERDEFINE
, SC_MARKNUM_FOLDERTAIL
, SC_MARK_EMPTY
);
744 SSM(sci
, SCI_MARKERDEFINE
, SC_MARKNUM_FOLDERSUB
, SC_MARK_EMPTY
);
749 SC_MARKNUM_FOLDEROPEN
,
751 SC_MARKNUM_FOLDERSUB
,
752 SC_MARKNUM_FOLDERTAIL
,
753 SC_MARKNUM_FOLDEREND
,
754 SC_MARKNUM_FOLDEROPENMID
,
755 SC_MARKNUM_FOLDERMIDTAIL
759 foreach_range(i
, G_N_ELEMENTS(markers
))
761 SSM(sci
, SCI_MARKERSETFORE
, markers
[i
],
762 invert(common_style_set
.styling
[GCS_FOLD_SYMBOL_HIGHLIGHT
].foreground
));
763 SSM(sci
, SCI_MARKERSETBACK
, markers
[i
],
764 invert(common_style_set
.styling
[GCS_MARGIN_FOLDING
].foreground
));
768 /* set some common defaults */
769 sci_set_property(sci
, "fold", "1");
770 sci_set_property(sci
, "fold.compact", "0");
771 sci_set_property(sci
, "fold.comment", "1");
772 sci_set_property(sci
, "fold.preprocessor", "1");
773 sci_set_property(sci
, "fold.at.else", "1");
775 style
= &common_style_set
.styling
[GCS_SELECTION
];
776 if (!style
->bold
&& !style
->italic
)
778 geany_debug("selection style is set to invisible - ignoring!");
779 style
->italic
= TRUE
;
780 style
->background
= 0xc0c0c0;
782 /* bold (3rd argument) is whether to override default foreground selection */
783 SSM(sci
, SCI_SETSELFORE
, style
->bold
, invert(style
->foreground
));
784 /* italic (4th argument) is whether to override default background selection */
785 SSM(sci
, SCI_SETSELBACK
, style
->italic
, invert(style
->background
));
787 SSM(sci
, SCI_SETSTYLEBITS
, SSM(sci
, SCI_GETSTYLEBITSNEEDED
, 0, 0), 0);
789 SSM(sci
, SCI_SETFOLDMARGINCOLOUR
, 1, invert(common_style_set
.styling
[GCS_MARGIN_FOLDING
].background
));
790 SSM(sci
, SCI_SETFOLDMARGINHICOLOUR
, 1, invert(common_style_set
.styling
[GCS_MARGIN_FOLDING
].background
));
791 set_sci_style(sci
, STYLE_LINENUMBER
, GEANY_FILETYPES_NONE
, GCS_MARGIN_LINENUMBER
);
792 set_sci_style(sci
, STYLE_BRACELIGHT
, GEANY_FILETYPES_NONE
, GCS_BRACE_GOOD
);
793 set_sci_style(sci
, STYLE_BRACEBAD
, GEANY_FILETYPES_NONE
, GCS_BRACE_BAD
);
794 set_sci_style(sci
, STYLE_INDENTGUIDE
, GEANY_FILETYPES_NONE
, GCS_INDENT_GUIDE
);
796 /* bold = common whitespace settings enabled */
797 SSM(sci
, SCI_SETWHITESPACEFORE
, common_style_set
.styling
[GCS_WHITE_SPACE
].bold
,
798 invert(common_style_set
.styling
[GCS_WHITE_SPACE
].foreground
));
799 SSM(sci
, SCI_SETWHITESPACEBACK
, common_style_set
.styling
[GCS_WHITE_SPACE
].italic
,
800 invert(common_style_set
.styling
[GCS_WHITE_SPACE
].background
));
802 if (common_style_set
.styling
[GCS_CALLTIPS
].bold
)
803 SSM(sci
, SCI_CALLTIPSETFORE
, invert(common_style_set
.styling
[GCS_CALLTIPS
].foreground
), 1);
804 if (common_style_set
.styling
[GCS_CALLTIPS
].italic
)
805 SSM(sci
, SCI_CALLTIPSETBACK
, invert(common_style_set
.styling
[GCS_CALLTIPS
].background
), 1);
809 /* Merge & assign global typedefs and user secondary keywords.
810 * keyword_idx is used for both style_sets[].keywords and scintilla keyword style number */
811 static void merge_type_keywords(ScintillaObject
*sci
, guint ft_id
, guint keyword_idx
)
813 const gchar
*user_words
= style_sets
[ft_id
].keywords
[keyword_idx
];
816 s
= symbols_find_typenames_as_string(filetypes
[ft_id
]->lang
, TRUE
);
817 if (G_UNLIKELY(s
== NULL
))
818 s
= g_string_sized_new(200);
820 g_string_append_c(s
, ' '); /* append a space as delimiter to the existing list of words */
822 g_string_append(s
, user_words
);
824 sci_set_keywords(sci
, keyword_idx
, s
->str
);
825 g_string_free(s
, TRUE
);
829 static void styleset_init_from_mapping(guint ft_id
, GKeyFile
*config
, GKeyFile
*config_home
,
830 const HLStyle
*styles
, gsize n_styles
,
831 const HLKeyword
*keywords
, gsize n_keywords
)
836 new_styleset(ft_id
, n_styles
);
837 foreach_range(i
, n_styles
)
839 GeanyLexerStyle
*style
= &style_sets
[ft_id
].styling
[i
];
841 get_keyfile_style(config
, config_home
, styles
[i
].name
, style
);
846 style_sets
[ft_id
].keywords
= NULL
;
849 style_sets
[ft_id
].keywords
= g_new(gchar
*, n_keywords
+ 1);
850 foreach_range(i
, n_keywords
)
851 get_keyfile_keywords(config
, config_home
, keywords
[i
].key
, ft_id
, i
);
852 style_sets
[ft_id
].keywords
[i
] = NULL
;
857 /* STYLE_DEFAULT will be set to match the first style. */
858 static void styleset_from_mapping(ScintillaObject
*sci
, guint ft_id
, guint lexer
,
859 const HLStyle
*styles
, gsize n_styles
,
860 const HLKeyword
*keywords
, gsize n_keywords
,
861 const HLProperty
*properties
, gsize n_properties
)
865 g_assert(ft_id
!= GEANY_FILETYPES_NONE
);
868 sci_set_lexer(sci
, lexer
);
871 styleset_common(sci
, ft_id
);
874 /* first style is also default one */
875 set_sci_style(sci
, STYLE_DEFAULT
, ft_id
, 0);
876 foreach_range(i
, n_styles
)
878 if (styles
[i
].fill_eol
)
879 SSM(sci
, SCI_STYLESETEOLFILLED
, styles
[i
].style
, TRUE
);
880 set_sci_style(sci
, styles
[i
].style
, ft_id
, i
);
885 foreach_range(i
, n_keywords
)
887 if (keywords
[i
].merge
)
888 merge_type_keywords(sci
, ft_id
, i
);
890 sci_set_keywords(sci
, keywords
[i
].id
, style_sets
[ft_id
].keywords
[i
]);
894 foreach_range(i
, n_properties
)
895 sci_set_property(sci
, properties
[i
].property
, properties
[i
].value
);
900 static void styleset_default(ScintillaObject
*sci
, guint ft_id
)
902 sci_set_lexer(sci
, SCLEX_NULL
);
904 /* we need to set STYLE_DEFAULT before we call SCI_STYLECLEARALL in styleset_common() */
905 set_sci_style(sci
, STYLE_DEFAULT
, GEANY_FILETYPES_NONE
, GCS_DEFAULT
);
907 styleset_common(sci
, ft_id
);
911 static void get_key_values(GKeyFile
*config
, const gchar
*group
, gchar
**keys
, gchar
**values
)
915 gchar
*str
= g_key_file_get_string(config
, group
, *keys
, NULL
);
918 SETPTR(*values
, str
);
926 static void read_properties(GeanyFiletype
*ft
, GKeyFile
*config
, GKeyFile
*configh
)
928 gchar group
[] = "lexer_properties";
930 gchar
**keysh
= g_key_file_get_keys(configh
, group
, NULL
, NULL
);
933 /* remove overridden keys from system keyfile */
934 foreach_strv(ptr
, keysh
)
935 g_key_file_remove_key(config
, group
, *ptr
, NULL
);
937 /* merge sys and user keys */
938 keys
= g_key_file_get_keys(config
, group
, NULL
, NULL
);
939 keys
= utils_strv_join(keys
, keysh
);
943 gchar
**values
= g_new0(gchar
*, g_strv_length(keys
) + 1);
945 style_sets
[ft
->id
].property_keys
= keys
;
946 style_sets
[ft
->id
].property_values
= values
;
948 get_key_values(config
, group
, keys
, values
);
949 get_key_values(configh
, group
, keys
, values
);
954 static guint
get_lexer_filetype(GeanyFiletype
*ft
)
956 ft
= FALLBACK(ft
->lexer_filetype
, ft
);
961 #define init_styleset_case(LANG_NAME) \
962 case (GEANY_FILETYPES_##LANG_NAME): \
963 styleset_init_from_mapping(filetype_idx, config, configh, \
964 highlighting_styles_##LANG_NAME, \
965 HL_N_ENTRIES(highlighting_styles_##LANG_NAME), \
966 highlighting_keywords_##LANG_NAME, \
967 HL_N_ENTRIES(highlighting_keywords_##LANG_NAME)); \
970 /* Called by filetypes_load_config(). */
971 void highlighting_init_styles(guint filetype_idx
, GKeyFile
*config
, GKeyFile
*configh
)
973 GeanyFiletype
*ft
= filetypes
[filetype_idx
];
974 guint lexer_id
= get_lexer_filetype(ft
);
978 style_sets
= g_new0(StyleSet
, filetypes_array
->len
);
980 /* Clear old information if necessary - e.g. when reloading config */
981 free_styleset(filetype_idx
);
983 read_properties(ft
, config
, configh
);
984 /* If a default style exists, check it uses a named style
985 * Note: almost all filetypes have a "default" style, except HTML ones */
986 default_str
= utils_get_setting(string
, configh
, config
,
987 "styling", "default", "default");
988 ft
->priv
->warn_color_scheme
= !g_ascii_isalpha(*default_str
);
991 /* None filetype handled specially */
992 if (filetype_idx
== GEANY_FILETYPES_NONE
)
994 styleset_common_init(config
, configh
);
997 /* All stylesets depend on filetypes.common */
998 filetypes_load_config(GEANY_FILETYPES_NONE
, FALSE
);
1002 init_styleset_case(ABAQUS
);
1003 init_styleset_case(ADA
);
1004 init_styleset_case(ASM
);
1005 init_styleset_case(BASIC
);
1006 init_styleset_case(BATCH
);
1007 init_styleset_case(C
);
1008 init_styleset_case(CAML
);
1009 init_styleset_case(CMAKE
);
1010 init_styleset_case(COBOL
);
1011 init_styleset_case(COFFEESCRIPT
);
1012 init_styleset_case(CONF
);
1013 init_styleset_case(CSS
);
1014 init_styleset_case(D
);
1015 init_styleset_case(DIFF
);
1016 init_styleset_case(LISP
);
1017 init_styleset_case(ERLANG
);
1018 init_styleset_case(DOCBOOK
);
1019 init_styleset_case(FERITE
);
1020 init_styleset_case(F77
);
1021 init_styleset_case(FORTH
);
1022 init_styleset_case(FORTRAN
);
1023 init_styleset_case(GO
);
1024 init_styleset_case(HASKELL
);
1025 init_styleset_case(HAXE
);
1026 init_styleset_case(AS
);
1027 init_styleset_case(HTML
);
1028 init_styleset_case(JAVA
);
1029 init_styleset_case(JS
);
1030 init_styleset_case(LATEX
);
1031 init_styleset_case(LUA
);
1032 init_styleset_case(MAKE
);
1033 init_styleset_case(MATLAB
);
1034 init_styleset_case(MARKDOWN
);
1035 init_styleset_case(NSIS
);
1036 init_styleset_case(OBJECTIVEC
);
1037 init_styleset_case(PASCAL
);
1038 init_styleset_case(PERL
);
1039 init_styleset_case(PHP
);
1040 init_styleset_case(PO
);
1041 init_styleset_case(POWERSHELL
);
1042 init_styleset_case(PYTHON
);
1043 init_styleset_case(R
);
1044 init_styleset_case(RUBY
);
1045 init_styleset_case(RUST
);
1046 init_styleset_case(SH
);
1047 init_styleset_case(SQL
);
1048 init_styleset_case(TCL
);
1049 init_styleset_case(TXT2TAGS
);
1050 init_styleset_case(VHDL
);
1051 init_styleset_case(VERILOG
);
1052 init_styleset_case(XML
);
1053 init_styleset_case(YAML
);
1054 init_styleset_case(ZEPHIR
);
1056 if (ft
->lexer_filetype
)
1057 geany_debug("Filetype %s has a recursive lexer_filetype %s set!",
1058 ft
->name
, ft
->lexer_filetype
->name
);
1061 /* should be done in filetypes.c really: */
1062 get_keyfile_wordchars(config
, configh
, &style_sets
[filetype_idx
].wordchars
,
1063 common_style_set
.wordchars
);
1067 #define styleset_case(LANG_NAME) \
1068 case (GEANY_FILETYPES_##LANG_NAME): \
1069 styleset_from_mapping(sci, ft->id, highlighting_lexer_##LANG_NAME, \
1070 highlighting_styles_##LANG_NAME, \
1071 HL_N_ENTRIES(highlighting_styles_##LANG_NAME), \
1072 highlighting_keywords_##LANG_NAME, \
1073 HL_N_ENTRIES(highlighting_keywords_##LANG_NAME), \
1074 highlighting_properties_##LANG_NAME, \
1075 HL_N_ENTRIES(highlighting_properties_##LANG_NAME)); \
1078 /** Sets up highlighting and other visual settings.
1079 * @param sci Scintilla widget.
1080 * @param ft Filetype settings to use. */
1082 void highlighting_set_styles(ScintillaObject
*sci
, GeanyFiletype
*ft
)
1084 guint lexer_id
= get_lexer_filetype(ft
);
1086 filetypes_load_config(ft
->id
, FALSE
); /* load filetypes.ext */
1090 styleset_case(ABAQUS
);
1093 styleset_case(BASIC
);
1094 styleset_case(BATCH
);
1096 styleset_case(CAML
);
1097 styleset_case(CMAKE
);
1098 styleset_case(COBOL
);
1099 styleset_case(COFFEESCRIPT
);
1100 styleset_case(CONF
);
1103 styleset_case(DIFF
);
1104 styleset_case(LISP
);
1105 styleset_case(ERLANG
);
1106 styleset_case(DOCBOOK
);
1107 styleset_case(FERITE
);
1109 styleset_case(FORTH
);
1110 styleset_case(FORTRAN
);
1112 styleset_case(HASKELL
);
1113 styleset_case(HAXE
);
1115 styleset_case(HTML
);
1116 styleset_case(JAVA
);
1118 styleset_case(LATEX
);
1120 styleset_case(MAKE
);
1121 styleset_case(MARKDOWN
);
1122 styleset_case(MATLAB
);
1123 styleset_case(NSIS
);
1124 styleset_case(OBJECTIVEC
);
1125 styleset_case(PASCAL
);
1126 styleset_case(PERL
);
1129 styleset_case(POWERSHELL
);
1130 styleset_case(PYTHON
);
1132 styleset_case(RUBY
);
1133 styleset_case(RUST
);
1137 styleset_case(TXT2TAGS
);
1138 styleset_case(VHDL
);
1139 styleset_case(VERILOG
);
1141 styleset_case(YAML
);
1142 styleset_case(ZEPHIR
);
1143 case GEANY_FILETYPES_NONE
:
1145 styleset_default(sci
, ft
->id
);
1147 /* [lexer_properties] settings */
1148 if (style_sets
[ft
->id
].property_keys
)
1150 gchar
**prop
= style_sets
[ft
->id
].property_keys
;
1151 gchar
**val
= style_sets
[ft
->id
].property_values
;
1155 sci_set_property(sci
, *prop
, *val
);
1163 /** Retrieves a style @a style_id for the filetype @a ft_id.
1164 * If the style was not already initialised
1165 * (e.g. by by opening a file of this type), it will be initialised. The returned pointer is
1166 * owned by Geany and must not be freed.
1167 * @param ft_id Filetype ID, e.g. @c GEANY_FILETYPES_DIFF.
1168 * @param style_id A Scintilla lexer style, e.g. @c SCE_DIFF_ADDED. See scintilla/include/SciLexer.h.
1169 * @return A pointer to the style struct.
1170 * @see Scintilla messages @c SCI_STYLEGETFORE, etc, for use with scintilla_send_message(). */
1172 const GeanyLexerStyle
*highlighting_get_style(gint ft_id
, gint style_id
)
1174 g_return_val_if_fail(ft_id
>= 0 && (guint
) ft_id
< filetypes_array
->len
, NULL
);
1175 g_return_val_if_fail(style_id
>= 0, NULL
);
1177 /* ensure filetype loaded */
1178 filetypes_load_config((guint
) ft_id
, FALSE
);
1180 /* TODO: style_id might not be the real array index (Scintilla styles are not always synced
1181 * with array indices) */
1182 return get_style((guint
) ft_id
, (guint
) style_id
);
1193 static void on_color_scheme_changed(GtkTreeSelection
*treesel
, gpointer dummy
)
1195 GtkTreeModel
*model
;
1200 if (!gtk_tree_selection_get_selected(treesel
, &model
, &iter
))
1202 gtk_tree_model_get(model
, &iter
, SCHEME_FILE
, &fname
, -1);
1204 /* check if default item */
1207 SETPTR(editor_prefs
.color_scheme
, NULL
);
1211 SETPTR(fname
, utils_get_locale_from_utf8(fname
));
1213 /* fname is just the basename from the menu item, so prepend the custom files path */
1214 path
= g_build_path(G_DIR_SEPARATOR_S
, app
->configdir
, GEANY_COLORSCHEMES_SUBDIR
, fname
, NULL
);
1215 if (!g_file_test(path
, G_FILE_TEST_EXISTS
))
1217 /* try the system path */
1219 path
= g_build_path(G_DIR_SEPARATOR_S
, app
->datadir
, GEANY_COLORSCHEMES_SUBDIR
, fname
, NULL
);
1221 if (g_file_test(path
, G_FILE_TEST_EXISTS
))
1223 SETPTR(editor_prefs
.color_scheme
, fname
);
1229 SETPTR(fname
, utils_get_utf8_from_locale(fname
));
1230 ui_set_statusbar(TRUE
, _("Could not find file '%s'."), fname
);
1237 static gchar
*utils_get_setting_locale_string(GKeyFile
*keyfile
,
1238 const gchar
*group
, const gchar
*key
, const gchar
*default_value
)
1240 gchar
*result
= g_key_file_get_locale_string(keyfile
, group
, key
, NULL
, NULL
);
1242 return FALLBACK(result
, g_strdup(default_value
));
1246 static void add_color_scheme_item(GtkListStore
*store
,
1247 gchar
*name
, gchar
*desc
, const gchar
*fn
, GtkTreeIter
*current_iter
)
1252 /* reuse parameters */
1253 name
= g_markup_escape_text(name
, -1);
1254 desc
= g_markup_escape_text(desc
, -1);
1255 markup
= g_strdup_printf("<big><b>%s</b></big>\n%s", name
, desc
);
1259 gtk_list_store_append(store
, &iter
);
1260 gtk_list_store_set(store
, &iter
, SCHEME_MARKUP
, markup
,
1261 SCHEME_FILE
, fn
, -1);
1264 /* select the current iter if the the color scheme matches, or if it's the
1265 * default (fn == NULL), in case of bad config file. the default theme is
1266 * first anyway so if a later scheme matches it will override default */
1267 if ((! fn
|| utils_str_equal(fn
, editor_prefs
.color_scheme
)) && current_iter
)
1268 *current_iter
= iter
;
1272 static void add_color_scheme_file(GtkListStore
*store
, const gchar
*fname
, GtkTreeIter
*current_iter
)
1274 GKeyFile
*hkeyfile
, *skeyfile
;
1275 gchar
*path
, *theme_name
, *theme_desc
;
1276 gchar
*theme_fn
= utils_get_utf8_from_locale(fname
);
1278 path
= g_build_filename(app
->configdir
, GEANY_COLORSCHEMES_SUBDIR
, fname
, NULL
);
1279 hkeyfile
= utils_key_file_new(path
);
1280 SETPTR(path
, g_build_filename(app
->datadir
, GEANY_COLORSCHEMES_SUBDIR
, fname
, NULL
));
1281 skeyfile
= utils_key_file_new(path
);
1283 theme_name
= utils_get_setting(locale_string
, hkeyfile
, skeyfile
, "theme_info", "name", theme_fn
);
1284 theme_desc
= utils_get_setting(locale_string
, hkeyfile
, skeyfile
, "theme_info", "description", NULL
);
1285 add_color_scheme_item(store
, theme_name
, theme_desc
, theme_fn
, current_iter
);
1291 g_key_file_free(hkeyfile
);
1292 g_key_file_free(skeyfile
);
1296 static gboolean
add_color_scheme_items(GtkListStore
*store
, GtkTreeIter
*current_iter
)
1298 GSList
*list
, *node
;
1300 add_color_scheme_item(store
, _("Default"), _("Default"), NULL
, current_iter
);
1301 list
= utils_get_config_files(GEANY_COLORSCHEMES_SUBDIR
);
1303 foreach_slist(node
, list
)
1305 gchar
*fname
= node
->data
;
1307 if (g_str_has_suffix(fname
, ".conf"))
1308 add_color_scheme_file(store
, fname
, current_iter
);
1313 return list
!= NULL
;
1317 static void on_color_scheme_dialog_response(GtkWidget
*dialog
,
1318 gint response
, gpointer
*dialog_ptr
)
1321 gtk_widget_destroy(dialog
);
1325 void highlighting_show_color_scheme_dialog(void)
1327 static GtkWidget
*dialog
= NULL
;
1328 GtkListStore
*store
= gtk_list_store_new(SCHEME_COLUMNS
,
1329 G_TYPE_STRING
, G_TYPE_STRING
);
1330 GtkCellRenderer
*text_renderer
;
1331 GtkTreeViewColumn
*column
;
1332 GtkTreeSelection
*treesel
;
1333 GtkTreeIter current_iter
;
1335 GtkWidget
*vbox
, *swin
, *tree
;
1338 doc
= document_get_current();
1339 if (doc
&& doc
->file_type
->priv
->warn_color_scheme
)
1340 dialogs_show_msgbox_with_secondary(GTK_MESSAGE_WARNING
,
1341 _("The current filetype overrides the default style."),
1342 _("This may cause color schemes to display incorrectly."));
1344 tree
= gtk_tree_view_new_with_model(GTK_TREE_MODEL(store
));
1345 g_object_unref(store
);
1346 gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(tree
), TRUE
);
1347 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(tree
), FALSE
);
1349 text_renderer
= gtk_cell_renderer_text_new();
1350 g_object_set(text_renderer
, "wrap-mode", PANGO_WRAP_WORD
, NULL
);
1351 column
= gtk_tree_view_column_new_with_attributes(
1352 NULL
, text_renderer
, "markup", SCHEME_MARKUP
, NULL
);
1353 gtk_tree_view_append_column(GTK_TREE_VIEW(tree
), column
);
1355 add_color_scheme_items(store
, ¤t_iter
);
1357 treesel
= gtk_tree_view_get_selection(GTK_TREE_VIEW(tree
));
1358 gtk_tree_selection_select_iter(treesel
, ¤t_iter
);
1359 path
= gtk_tree_model_get_path(GTK_TREE_MODEL(store
), ¤t_iter
);
1360 gtk_tree_view_scroll_to_cell(GTK_TREE_VIEW(tree
), path
, NULL
, FALSE
, 0, 0);
1361 gtk_tree_path_free(path
);
1362 g_signal_connect(treesel
, "changed", G_CALLBACK(on_color_scheme_changed
), NULL
);
1364 /* old dialog may still be showing */
1366 gtk_widget_destroy(dialog
);
1367 dialog
= gtk_dialog_new_with_buttons(_("Color Schemes"),
1368 GTK_WINDOW(main_widgets
.window
), GTK_DIALOG_DESTROY_WITH_PARENT
,
1369 GTK_STOCK_CLOSE
, GTK_RESPONSE_CLOSE
, NULL
);
1370 vbox
= ui_dialog_vbox_new(GTK_DIALOG(dialog
));
1371 gtk_box_set_spacing(GTK_BOX(vbox
), 6);
1372 gtk_widget_set_name(dialog
, "GeanyDialog");
1373 gtk_window_set_default_size(GTK_WINDOW(dialog
),
1374 GEANY_DEFAULT_DIALOG_HEIGHT
* 7/4, GEANY_DEFAULT_DIALOG_HEIGHT
);
1376 swin
= gtk_scrolled_window_new(NULL
, NULL
);
1377 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(swin
), GTK_SHADOW_IN
);
1378 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(swin
),
1379 GTK_POLICY_AUTOMATIC
, GTK_POLICY_AUTOMATIC
);
1380 gtk_container_add(GTK_CONTAINER(swin
), tree
);
1381 gtk_box_pack_start(GTK_BOX(vbox
), swin
, TRUE
, TRUE
, 0);
1382 g_signal_connect(dialog
, "response", G_CALLBACK(on_color_scheme_dialog_response
), &dialog
);
1383 gtk_widget_show_all(dialog
);
1387 /** Checks whether the given style is a string for the given lexer.
1389 * @param lexer Scintilla lexer type (@c SCLEX_*).
1390 * @param style Scintilla style (@c SCE_*).
1392 * @return @c TRUE if the style is a string, @c FALSE otherwise.
1395 gboolean
highlighting_is_string_style(gint lexer
, gint style
)
1397 /* Don't forget STRINGEOL, to prevent completion whilst typing a string with no closing char. */
1402 return (style
== SCE_C_CHARACTER
||
1403 style
== SCE_C_STRING
||
1404 style
== SCE_C_STRINGEOL
||
1405 style
== SCE_C_STRINGRAW
||
1406 style
== SCE_C_VERBATIM
||
1407 style
== SCE_C_USERLITERAL
||
1408 style
== SCE_C_TRIPLEVERBATIM
||
1409 style
== SCE_C_REGEX
||
1410 style
== SCE_C_HASHQUOTEDSTRING
||
1411 style
== SCE_C_ESCAPESEQUENCE
);
1414 return (style
== SCE_PAS_CHARACTER
||
1415 style
== SCE_PAS_STRING
||
1416 style
== SCE_PAS_STRINGEOL
);
1419 return (style
== SCE_D_STRING
||
1420 style
== SCE_D_STRINGEOL
||
1421 style
== SCE_D_CHARACTER
||
1422 style
== SCE_D_STRINGB
||
1423 style
== SCE_D_STRINGR
);
1426 return (style
== SCE_P_STRING
||
1427 style
== SCE_P_TRIPLE
||
1428 style
== SCE_P_TRIPLEDOUBLE
||
1429 style
== SCE_P_CHARACTER
||
1430 style
== SCE_P_FSTRING
||
1431 style
== SCE_P_FCHARACTER
||
1432 style
== SCE_P_FTRIPLE
||
1433 style
== SCE_P_FTRIPLEDOUBLE
||
1434 style
== SCE_P_STRINGEOL
);
1438 return (style
== SCE_F_STRING1
||
1439 style
== SCE_F_STRING2
||
1440 style
== SCE_F_STRINGEOL
);
1443 return (style
== SCE_PL_STRING
||
1444 style
== SCE_PL_CHARACTER
||
1445 style
== SCE_PL_HERE_DELIM
||
1446 style
== SCE_PL_HERE_Q
||
1447 style
== SCE_PL_HERE_QQ
||
1448 style
== SCE_PL_HERE_QX
||
1449 style
== SCE_PL_POD
||
1450 style
== SCE_PL_STRING_Q
||
1451 style
== SCE_PL_STRING_QQ
||
1452 style
== SCE_PL_STRING_QX
||
1453 style
== SCE_PL_STRING_QR
||
1454 style
== SCE_PL_STRING_QW
||
1455 style
== SCE_PL_POD_VERB
||
1456 style
== SCE_PL_REGEX
||
1457 style
== SCE_PL_REGEX_VAR
||
1458 style
== SCE_PL_XLAT
1459 /* we don't include any STRING_*_VAR for autocompletion */);
1462 return (style
== SCE_PO_MSGCTXT_TEXT
||
1463 style
== SCE_PO_MSGCTXT_TEXT_EOL
||
1464 style
== SCE_PO_MSGID_TEXT
||
1465 style
== SCE_PO_MSGID_TEXT_EOL
||
1466 style
== SCE_PO_MSGSTR_TEXT
||
1467 style
== SCE_PO_MSGSTR_TEXT_EOL
);
1470 return (style
== SCE_R_STRING
);
1473 return (style
== SCE_RB_CHARACTER
||
1474 style
== SCE_RB_STRING
||
1475 style
== SCE_RB_HERE_DELIM
||
1476 style
== SCE_RB_HERE_Q
||
1477 style
== SCE_RB_HERE_QQ
||
1478 style
== SCE_RB_HERE_QX
||
1479 style
== SCE_RB_REGEX
||
1480 style
== SCE_RB_STRING_Q
||
1481 style
== SCE_RB_STRING_QQ
||
1482 style
== SCE_RB_STRING_QX
||
1483 style
== SCE_RB_STRING_QR
||
1484 style
== SCE_RB_STRING_QW
||
1485 style
== SCE_RB_POD
);
1488 return (style
== SCE_SH_STRING
);
1491 return (style
== SCE_SQL_STRING
);
1494 return (style
== SCE_TCL_IN_QUOTE
);
1497 return (style
== SCE_LUA_LITERALSTRING
||
1498 style
== SCE_LUA_CHARACTER
||
1499 style
== SCE_LUA_STRINGEOL
||
1500 style
== SCE_LUA_STRING
);
1503 case SCLEX_LITERATEHASKELL
:
1504 return (style
== SCE_HA_CHARACTER
||
1505 style
== SCE_HA_STRINGEOL
||
1506 style
== SCE_HA_STRING
);
1508 case SCLEX_FREEBASIC
:
1509 return (style
== SCE_B_STRING
||
1510 style
== SCE_B_STRINGEOL
);
1513 return (style
== SCE_MATLAB_STRING
||
1514 style
== SCE_MATLAB_DOUBLEQUOTESTRING
);
1518 case SCLEX_PHPSCRIPT
:
1520 style
== SCE_HBA_STRING
||
1521 style
== SCE_HBA_STRINGEOL
||
1522 style
== SCE_HB_STRING
||
1523 style
== SCE_HB_STRINGEOL
||
1524 style
== SCE_H_CDATA
||
1525 style
== SCE_H_DOUBLESTRING
||
1526 style
== SCE_HJA_DOUBLESTRING
||
1527 style
== SCE_HJA_SINGLESTRING
||
1528 style
== SCE_HJA_STRINGEOL
||
1529 style
== SCE_HJA_REGEX
||
1530 style
== SCE_HJ_DOUBLESTRING
||
1531 style
== SCE_HJ_SINGLESTRING
||
1532 style
== SCE_HJ_STRINGEOL
||
1533 style
== SCE_HJ_REGEX
||
1534 style
== SCE_HPA_CHARACTER
||
1535 style
== SCE_HPA_STRING
||
1536 style
== SCE_HPA_TRIPLE
||
1537 style
== SCE_HPA_TRIPLEDOUBLE
||
1538 style
== SCE_HP_CHARACTER
||
1539 style
== SCE_HPHP_HSTRING
|| /* HSTRING is a heredoc */
1540 style
== SCE_HPHP_HSTRING_VARIABLE
||
1541 style
== SCE_HPHP_SIMPLESTRING
||
1542 style
== SCE_HP_STRING
||
1543 style
== SCE_HP_TRIPLE
||
1544 style
== SCE_HP_TRIPLEDOUBLE
||
1545 style
== SCE_H_SGML_DOUBLESTRING
||
1546 style
== SCE_H_SGML_SIMPLESTRING
||
1547 style
== SCE_H_SINGLESTRING
);
1550 return (style
== SCE_CMAKE_STRINGDQ
||
1551 style
== SCE_CMAKE_STRINGLQ
||
1552 style
== SCE_CMAKE_STRINGRQ
||
1553 style
== SCE_CMAKE_STRINGVAR
);
1556 return (style
== SCE_NSIS_STRINGDQ
||
1557 style
== SCE_NSIS_STRINGLQ
||
1558 style
== SCE_NSIS_STRINGRQ
||
1559 style
== SCE_NSIS_STRINGVAR
);
1562 return (style
== SCE_ADA_CHARACTER
||
1563 style
== SCE_ADA_STRING
||
1564 style
== SCE_ADA_CHARACTEREOL
||
1565 style
== SCE_ADA_STRINGEOL
);
1568 return (style
== SCE_ABAQUS_STRING
);
1571 return (style
== SCE_RUST_CHARACTER
||
1572 style
== SCE_RUST_BYTECHARACTER
||
1573 style
== SCE_RUST_STRING
||
1574 style
== SCE_RUST_STRINGR
||
1575 style
== SCE_RUST_BYTESTRING
||
1576 style
== SCE_RUST_BYTESTRINGR
||
1577 style
== SCE_RUST_LEXERROR
);
1579 case SCLEX_COFFEESCRIPT
:
1580 return (style
== SCE_COFFEESCRIPT_CHARACTER
||
1581 style
== SCE_COFFEESCRIPT_STRING
||
1582 style
== SCE_COFFEESCRIPT_REGEX
||
1583 style
== SCE_COFFEESCRIPT_VERBOSE_REGEX
||
1584 style
== SCE_COFFEESCRIPT_STRINGEOL
);
1587 return (style
== SCE_V_STRING
);
1590 return (style
== SCE_CAML_CHAR
||
1591 style
== SCE_CAML_STRING
);
1594 return (style
== SCE_CSS_DOUBLESTRING
||
1595 style
== SCE_CSS_SINGLESTRING
);
1598 return (style
== SCE_ERLANG_STRING
||
1599 style
== SCE_ERLANG_CHARACTER
);
1602 return (style
== SCE_LISP_STRING
||
1603 style
== SCE_LISP_STRINGEOL
);
1606 return (style
== SCE_FORTH_STRING
);
1608 case SCLEX_POWERSHELL
:
1609 return (style
== SCE_POWERSHELL_STRING
||
1610 style
== SCE_POWERSHELL_CHARACTER
);
1615 case SCLEX_MAKEFILE
:
1616 case SCLEX_MARKDOWN
:
1617 case SCLEX_PROPERTIES
:
1618 case SCLEX_TXT2TAGS
:
1620 /* there is no string type in those lexers, listing here just for completeness */
1627 /** Checks whether the given style is a comment for the given lexer.
1629 * @param lexer Scintilla lexer type (@c SCLEX_*).
1630 * @param style Scintilla style (@c SCE_*).
1632 * @return @c TRUE if the style is a comment, @c FALSE otherwise.
1635 gboolean
highlighting_is_comment_style(gint lexer
, gint style
)
1641 return (style
== SCE_C_COMMENT
||
1642 style
== SCE_C_COMMENTLINE
||
1643 style
== SCE_C_COMMENTDOC
||
1644 style
== SCE_C_PREPROCESSORCOMMENT
||
1645 style
== SCE_C_PREPROCESSORCOMMENTDOC
||
1646 style
== SCE_C_COMMENTLINEDOC
||
1647 style
== SCE_C_COMMENTDOCKEYWORD
||
1648 style
== SCE_C_COMMENTDOCKEYWORDERROR
||
1649 style
== SCE_C_TASKMARKER
);
1652 return (style
== SCE_PAS_COMMENT
||
1653 style
== SCE_PAS_COMMENT2
||
1654 style
== SCE_PAS_COMMENTLINE
);
1657 return (style
== SCE_D_COMMENT
||
1658 style
== SCE_D_COMMENTLINE
||
1659 style
== SCE_D_COMMENTDOC
||
1660 style
== SCE_D_COMMENTNESTED
||
1661 style
== SCE_D_COMMENTLINEDOC
||
1662 style
== SCE_D_COMMENTDOCKEYWORD
||
1663 style
== SCE_D_COMMENTDOCKEYWORDERROR
);
1666 return (style
== SCE_P_COMMENTLINE
||
1667 style
== SCE_P_COMMENTBLOCK
);
1671 return (style
== SCE_F_COMMENT
);
1674 return (style
== SCE_PL_COMMENTLINE
);
1676 case SCLEX_PROPERTIES
:
1677 return (style
== SCE_PROPS_COMMENT
);
1680 return (style
== SCE_PO_COMMENT
||
1681 style
== SCE_PO_PROGRAMMER_COMMENT
);
1684 return (style
== SCE_L_COMMENT
||
1685 style
== SCE_L_COMMENT2
);
1687 case SCLEX_MAKEFILE
:
1688 return (style
== SCE_MAKE_COMMENT
);
1691 return (style
== SCE_RB_COMMENTLINE
);
1694 return (style
== SCE_SH_COMMENTLINE
);
1697 return (style
== SCE_R_COMMENT
);
1700 return (style
== SCE_SQL_COMMENT
||
1701 style
== SCE_SQL_COMMENTLINE
||
1702 style
== SCE_SQL_COMMENTDOC
||
1703 style
== SCE_SQL_COMMENTLINEDOC
||
1704 style
== SCE_SQL_COMMENTDOCKEYWORD
||
1705 style
== SCE_SQL_COMMENTDOCKEYWORDERROR
);
1708 return (style
== SCE_TCL_COMMENT
||
1709 style
== SCE_TCL_COMMENTLINE
||
1710 style
== SCE_TCL_COMMENT_BOX
||
1711 style
== SCE_TCL_BLOCK_COMMENT
);
1714 return (style
== SCE_MATLAB_COMMENT
);
1717 return (style
== SCE_LUA_COMMENT
||
1718 style
== SCE_LUA_COMMENTLINE
||
1719 style
== SCE_LUA_COMMENTDOC
);
1722 case SCLEX_LITERATEHASKELL
:
1723 return (style
== SCE_HA_COMMENTLINE
||
1724 style
== SCE_HA_COMMENTBLOCK
||
1725 style
== SCE_HA_COMMENTBLOCK2
||
1726 style
== SCE_HA_COMMENTBLOCK3
||
1727 style
== SCE_HA_LITERATE_COMMENT
||
1728 style
== SCE_HA_LITERATE_CODEDELIM
);
1730 case SCLEX_FREEBASIC
:
1731 return (style
== SCE_B_COMMENT
||
1732 style
== SCE_B_COMMENTBLOCK
||
1733 style
== SCE_B_DOCLINE
||
1734 style
== SCE_B_DOCBLOCK
||
1735 style
== SCE_B_DOCKEYWORD
);
1738 return (style
== SCE_YAML_COMMENT
);
1742 case SCLEX_PHPSCRIPT
:
1744 style
== SCE_HBA_COMMENTLINE
||
1745 style
== SCE_HB_COMMENTLINE
||
1746 style
== SCE_H_COMMENT
||
1747 style
== SCE_HJA_COMMENT
||
1748 style
== SCE_HJA_COMMENTDOC
||
1749 style
== SCE_HJA_COMMENTLINE
||
1750 style
== SCE_HJ_COMMENT
||
1751 style
== SCE_HJ_COMMENTDOC
||
1752 style
== SCE_HJ_COMMENTLINE
||
1753 style
== SCE_HPA_COMMENTLINE
||
1754 style
== SCE_HP_COMMENTLINE
||
1755 style
== SCE_HPHP_COMMENT
||
1756 style
== SCE_HPHP_COMMENTLINE
||
1757 style
== SCE_H_SGML_COMMENT
);
1760 return (style
== SCE_CMAKE_COMMENT
);
1763 return (style
== SCE_NSIS_COMMENT
||
1764 style
== SCE_NSIS_COMMENTBOX
);
1767 return (style
== SCE_ADA_COMMENTLINE
);
1770 return (style
== SCE_ABAQUS_COMMENT
||
1771 style
== SCE_ABAQUS_COMMENTBLOCK
);
1774 return (style
== SCE_ASM_COMMENT
||
1775 style
== SCE_ASM_COMMENTBLOCK
||
1776 style
== SCE_ASM_COMMENTDIRECTIVE
);
1779 return (style
== SCE_RUST_COMMENTBLOCK
||
1780 style
== SCE_RUST_COMMENTLINE
||
1781 style
== SCE_RUST_COMMENTBLOCKDOC
||
1782 style
== SCE_RUST_COMMENTLINEDOC
);
1784 case SCLEX_COFFEESCRIPT
:
1785 return (style
== SCE_COFFEESCRIPT_COMMENTLINE
||
1786 style
== SCE_COFFEESCRIPT_COMMENTBLOCK
||
1787 style
== SCE_COFFEESCRIPT_VERBOSE_REGEX_COMMENT
);
1790 return (style
== SCE_V_COMMENT
||
1791 style
== SCE_V_COMMENTLINE
||
1792 style
== SCE_V_COMMENTLINEBANG
||
1793 style
== SCE_V_COMMENT_WORD
);
1796 return (style
== SCE_VHDL_COMMENT
||
1797 style
== SCE_VHDL_COMMENTLINEBANG
||
1798 style
== SCE_VHDL_BLOCK_COMMENT
);
1801 return (style
== SCE_BAT_COMMENT
);
1804 return (style
== SCE_CAML_COMMENT
||
1805 style
== SCE_CAML_COMMENT1
||
1806 style
== SCE_CAML_COMMENT2
||
1807 style
== SCE_CAML_COMMENT3
);
1810 return (style
== SCE_ERLANG_COMMENT
||
1811 style
== SCE_ERLANG_COMMENT_FUNCTION
||
1812 style
== SCE_ERLANG_COMMENT_MODULE
||
1813 style
== SCE_ERLANG_COMMENT_DOC
||
1814 style
== SCE_ERLANG_COMMENT_DOC_MACRO
);
1817 return (style
== SCE_FORTH_COMMENT
||
1818 style
== SCE_FORTH_COMMENT_ML
);
1821 return (style
== SCE_CSS_COMMENT
);
1824 return (style
== SCE_DIFF_COMMENT
);
1827 return (style
== SCE_LISP_COMMENT
||
1828 style
== SCE_LISP_MULTI_COMMENT
);
1830 case SCLEX_POWERSHELL
:
1831 return (style
== SCE_POWERSHELL_COMMENT
||
1832 style
== SCE_POWERSHELL_COMMENTSTREAM
||
1833 style
== SCE_POWERSHELL_COMMENTDOCKEYWORD
);
1835 case SCLEX_TXT2TAGS
:
1836 return (style
== SCE_TXT2TAGS_COMMENT
);
1838 case SCLEX_MARKDOWN
:
1839 /* there is no comment type in those lexers, listing here just for completeness */
1846 /** Checks whether the given style is normal code (not string, comment, preprocessor, etc).
1848 * @param lexer Scintilla lexer type (@c SCLEX_*).
1849 * @param style Scintilla style (@c SCE_*).
1851 * @return @c TRUE if the style is code, @c FALSE otherwise.
1854 gboolean
highlighting_is_code_style(gint lexer
, gint style
)
1860 if (style
== SCE_C_PREPROCESSOR
)
1865 case SCLEX_LITERATEHASKELL
:
1867 if (style
== SCE_HA_PREPROCESSOR
)
1873 if (style
== SCE_V_PREPROCESSOR
)
1878 return !(highlighting_is_comment_style(lexer
, style
) ||
1879 highlighting_is_string_style(lexer
, style
));