From df51554ca0ab7f4f024535317d748e5b19da6cf8 Mon Sep 17 00:00:00 2001 From: eidheim Date: Sun, 1 Aug 2021 15:32:16 +0200 Subject: [PATCH] Cleanup of spellcheck_all boolean used to activate spellchecking on for instance markdown text --- src/source_generic.cpp | 17 +++-------------- src/source_generic.hpp | 2 +- src/source_spellcheck.cpp | 5 +++++ src/source_spellcheck.hpp | 3 ++- tests/source_test.cpp | 1 + 5 files changed, 12 insertions(+), 16 deletions(-) diff --git a/src/source_generic.cpp b/src/source_generic.cpp index 97b836f..3368016 100644 --- a/src/source_generic.cpp +++ b/src/source_generic.cpp @@ -9,8 +9,6 @@ #include Source::GenericView::GenericView(const boost::filesystem::path &file_path, const Glib::RefPtr &language) : BaseView(file_path, language), View(file_path, language, true), autocomplete(this, interactive_completion, last_keyval, false) { - spellcheck_all = true; - if(language) { auto language_manager = LanguageManager::get_default(); auto search_paths = language_manager->get_search_path(); @@ -30,14 +28,11 @@ Source::GenericView::GenericView(const boost::filesystem::path &file_path, const boost::property_tree::ptree pt; try { boost::property_tree::xml_parser::read_xml(language_file.string(), pt); + parse_language_file(pt); } catch(const std::exception &e) { Terminal::get().print("\e[31mError\e[m: error parsing language file " + filesystem::get_short_path(language_file).string() + ": " + e.what() + '\n', true); } - bool has_context_class = false; - parse_language_file(has_context_class, pt); - if(!has_context_class || language->get_id() == "cmake") // TODO: no longer use the spellcheck_all flag? - spellcheck_all = false; } } @@ -52,7 +47,7 @@ Source::GenericView::~GenericView() { autocomplete.thread.join(); } -void Source::GenericView::parse_language_file(bool &has_context_class, const boost::property_tree::ptree &pt) { +void Source::GenericView::parse_language_file(const boost::property_tree::ptree &pt) { bool case_insensitive = false; for(auto &node : pt) { if(node.first == "") { @@ -70,14 +65,8 @@ void Source::GenericView::parse_language_file(bool &has_context_class, const boo keywords.emplace(data); } } - else if(!has_context_class && node.first == "context") { - auto class_attribute = node.second.get(".class", ""); - auto class_disabled_attribute = node.second.get(".class-disabled", ""); - if(class_attribute.size() > 0 || class_disabled_attribute.size() > 0) - has_context_class = true; - } try { - parse_language_file(has_context_class, node.second); + parse_language_file(node.second); } catch(const std::exception &e) { } diff --git a/src/source_generic.hpp b/src/source_generic.hpp index 3e462fa..bb6ce53 100644 --- a/src/source_generic.hpp +++ b/src/source_generic.hpp @@ -12,7 +12,7 @@ namespace Source { ~GenericView(); private: - void parse_language_file(bool &has_context_class, const boost::property_tree::ptree &pt); + void parse_language_file(const boost::property_tree::ptree &pt); std::set keywords; diff --git a/src/source_spellcheck.cpp b/src/source_spellcheck.cpp index 591478c..5071931 100644 --- a/src/source_spellcheck.cpp +++ b/src/source_spellcheck.cpp @@ -7,6 +7,11 @@ AspellConfig *Source::SpellCheckView::spellcheck_config = nullptr; Source::SpellCheckView::SpellCheckView(const boost::filesystem::path &file_path, const Glib::RefPtr &language) : BaseView(file_path, language) { + if(!language || // Spellcheck all words if no spec is found + is_language({"markdown", "latex", // Spellcheck all non-symbol words (not only string or comment context classes) + "go"})) // Go spec does not contain string or comment context classes + spellcheck_all = true; + if(!spellcheck_config) spellcheck_config = new_aspell_config(); spellcheck_checker = nullptr; diff --git a/src/source_spellcheck.hpp b/src/source_spellcheck.hpp index 5d4d755..43d482d 100644 --- a/src/source_spellcheck.hpp +++ b/src/source_spellcheck.hpp @@ -23,7 +23,6 @@ namespace Source { /// None of the comment characters, for instance //, are code iters. /// Otherwise, strings and comments should return false. bool is_code_iter(const Gtk::TextIter &iter); - bool spellcheck_all = false; guint last_keyval = 0; Glib::RefPtr comment_tag; @@ -31,6 +30,8 @@ namespace Source { Glib::RefPtr no_spellcheck_tag; private: + bool spellcheck_all = false; + Glib::RefPtr spellcheck_error_tag; sigc::connection signal_tag_added_connection; diff --git a/tests/source_test.cpp b/tests/source_test.cpp index 9066502..1cec392 100644 --- a/tests/source_test.cpp +++ b/tests/source_test.cpp @@ -180,6 +180,7 @@ int main() { { auto buffer = view.get_buffer(); view.is_bracket_language = true; + view.spellcheck_all = false; std::string source = "test(1, test(10), \"100\");"; buffer->set_text(source); {