diff --git a/src/config.cc b/src/config.cc index ece1f5a..07271d0 100644 --- a/src/config.cc +++ b/src/config.cc @@ -186,6 +186,7 @@ void Config::get_source() { source.font=source_json.get("font"); source.cleanup_whitespace_characters=source_json.get("cleanup_whitespace_characters"); + source.draw_spaces=source_json.get("draw_spaces"); source.show_map = source_json.get("show_map"); source.map_font_size = source_json.get("map_font_size"); diff --git a/src/config.h b/src/config.h index e6f6d82..3ce7373 100644 --- a/src/config.h +++ b/src/config.h @@ -56,6 +56,7 @@ public: std::string spellcheck_language; bool cleanup_whitespace_characters; + std::string draw_spaces; bool show_map; std::string map_font_size; diff --git a/src/files.h b/src/files.h index da3e171..250503a 100644 --- a/src/files.h +++ b/src/files.h @@ -37,6 +37,8 @@ const std::string configjson = #endif " \"cleanup_whitespace_characters_comment\": \"Remove trailing whitespace characters on save, and add trailing newline if missing\",\n" " \"cleanup_whitespace_characters\": false,\n" +" \"draw_spaces_comment\": \"Determines what kind of whitespaces should be drawn. Use comma-separated list of: space, tab, newline, nbsp, leading, text, trailing or all\",\n" +" \"draw_spaces\": \"space, tab, nbsp, trailing\",\n" " \"show_map\": true,\n" " \"map_font_size\": \"1\",\n" " \"spellcheck_language_comment\": \"Use \\\"\\\" to set language from your locale settings\",\n" diff --git a/src/source.cc b/src/source.cc index ee24f4b..b69b3be 100644 --- a/src/source.cc +++ b/src/source.cc @@ -1,11 +1,16 @@ -#include "source.h" #include "config.h" +#include "filesystem.h" +#include "source.h" +#include "terminal.h" + #include -#include +#include + #include + +#include #include -#include "filesystem.h" -#include "terminal.h" +#include namespace sigc { #ifndef SIGC_FUNCTORS_DEDUCE_RESULT_TYPE_WITH_DECLTYPE @@ -374,6 +379,34 @@ void Source::View::set_tab_char_and_size(char tab_char, unsigned tab_size) { tab+=tab_char; } +Gsv::DrawSpacesFlags parse_draw_spaces(std::string text) +{ + namespace qi = boost::spirit::qi; + + qi::symbols options; + options.add + ("space", Gsv::DRAW_SPACES_SPACE) + ("tab", Gsv::DRAW_SPACES_TAB) + ("newline", Gsv::DRAW_SPACES_NEWLINE) + ("nbsp", Gsv::DRAW_SPACES_NBSP) + ("leading", Gsv::DRAW_SPACES_LEADING) + ("text", Gsv::DRAW_SPACES_TEXT) + ("trailing", Gsv::DRAW_SPACES_TRAILING) + ("all", Gsv::DRAW_SPACES_ALL); + + auto begin = text.begin(); + auto end = text.end(); + + std::set out; + + // parse comma-separated list of options + qi::phrase_parse(begin, end, options % ',', qi::space, out); + + return out.count(Gsv::DRAW_SPACES_ALL) ? + Gsv::DRAW_SPACES_ALL : + static_cast(std::accumulate(out.begin(), out.end(), 0)); +} + void Source::View::configure() { //TODO: Move this to notebook? Might take up too much memory doing this for every tab. auto style_scheme_manager=Gsv::StyleSchemeManager::get_default(); @@ -388,6 +421,8 @@ void Source::View::configure() { Terminal::get().print("Error: Could not find gtksourceview style: "+Config::get().source.style+'\n', true); } + set_draw_spaces(parse_draw_spaces(Config::get().source.draw_spaces)); + if(Config::get().source.wrap_lines) set_wrap_mode(Gtk::WrapMode::WRAP_CHAR); else