From f469a4160111bd810dc4f94abfe8fdfe75755264 Mon Sep 17 00:00:00 2001 From: eidheim Date: Wed, 22 Jul 2020 09:16:29 +0200 Subject: [PATCH] Can now enable word wrap for specific languages --- CMakeLists.txt | 2 +- src/config.cpp | 2 +- src/config.hpp | 2 +- src/files.hpp | 3 ++- src/source.cpp | 17 ++++++++++++----- 5 files changed, 17 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 73a8e14..a54af48 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required (VERSION 2.8.8) project(juci) -set(JUCI_VERSION "1.6.0.4") +set(JUCI_VERSION "1.6.0.5") set(CPACK_PACKAGE_NAME "jucipp") set(CPACK_PACKAGE_CONTACT "Ole Christian Eidheim ") diff --git a/src/config.cpp b/src/config.cpp index f6ca554..6360905 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -164,7 +164,7 @@ void Config::read(const boost::property_tree::ptree &cfg) { source.default_tab_size = source_json.get("default_tab_size"); source.auto_tab_char_and_size = source_json.get("auto_tab_char_and_size"); source.tab_indents_line = source_json.get("tab_indents_line"); - source.wrap_lines = source_json.get("wrap_lines"); + source.word_wrap = source_json.get("word_wrap"); source.highlight_current_line = source_json.get("highlight_current_line"); source.show_line_numbers = source_json.get("show_line_numbers"); source.enable_multiple_cursors = source_json.get("enable_multiple_cursors"); diff --git a/src/config.hpp b/src/config.hpp index 1f87cf3..ddc78ef 100644 --- a/src/config.hpp +++ b/src/config.hpp @@ -85,7 +85,7 @@ public: char default_tab_char; unsigned default_tab_size; bool tab_indents_line; - bool wrap_lines; + std::string word_wrap; bool highlight_current_line; bool show_line_numbers; bool enable_multiple_cursors; diff --git a/src/files.hpp b/src/files.hpp index d4b271a..01596ed 100644 --- a/src/files.hpp +++ b/src/files.hpp @@ -57,7 +57,8 @@ const std::string default_config_file = R"RAW({ "default_tab_char": " ", "default_tab_size": 2, "tab_indents_line": true, - "wrap_lines": false, + "word_wrap_comment": "Specify language ids that should enable word wrap, for instance: chdr, c, cpphdr, cpp, js, python, or all to enable word wrap for all languages", + "word_wrap": "markdown, latex", "highlight_current_line": true, "show_line_numbers": true, "enable_multiple_cursors": false, diff --git a/src/source.cpp b/src/source.cpp index eb4f547..8e2833c 100644 --- a/src/source.cpp +++ b/src/source.cpp @@ -437,11 +437,18 @@ void Source::View::configure() { } set_draw_spaces(parse_show_whitespace_characters(Config::get().source.show_whitespace_characters)); - - if(Config::get().source.wrap_lines || (language && (language->get_id() == "markdown" || language->get_id() == "latex"))) - set_wrap_mode(Gtk::WrapMode::WRAP_WORD_CHAR); - else - set_wrap_mode(Gtk::WrapMode::WRAP_NONE); + { // Set Word Wrap + auto language_id = language ? language->get_id() : ""; + namespace qi = boost::spirit::qi; + std::set word_wrap_language_ids; + qi::phrase_parse(Config::get().source.word_wrap.begin(), Config::get().source.word_wrap.end(), (+(~qi::char_(','))) % ',', qi::space, word_wrap_language_ids); + if(std::any_of(word_wrap_language_ids.begin(), word_wrap_language_ids.end(), [&language_id](const std::string &word_wrap_language_id) { + return word_wrap_language_id == language_id || word_wrap_language_id == "all"; + })) + set_wrap_mode(Gtk::WrapMode::WRAP_WORD_CHAR); + else + set_wrap_mode(Gtk::WrapMode::WRAP_NONE); + } property_highlight_current_line() = Config::get().source.highlight_current_line; line_renderer->set_visible(Config::get().source.show_line_numbers);