Browse Source

Cleanup of spellcheck_all boolean used to activate spellchecking on for instance markdown text

pipelines/353213535
eidheim 4 years ago
parent
commit
df51554ca0
  1. 17
      src/source_generic.cpp
  2. 2
      src/source_generic.hpp
  3. 5
      src/source_spellcheck.cpp
  4. 3
      src/source_spellcheck.hpp
  5. 1
      tests/source_test.cpp

17
src/source_generic.cpp

@ -9,8 +9,6 @@
#include <boost/algorithm/string.hpp>
Source::GenericView::GenericView(const boost::filesystem::path &file_path, const Glib::RefPtr<Gsv::Language> &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 == "<xmlcomment>") {
@ -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<std::string>("<xmlattr>.class", "");
auto class_disabled_attribute = node.second.get<std::string>("<xmlattr>.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) {
}

2
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<std::string> keywords;

5
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<Gsv::Language> &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;

3
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<Gtk::TextTag> comment_tag;
@ -31,6 +30,8 @@ namespace Source {
Glib::RefPtr<Gtk::TextTag> no_spellcheck_tag;
private:
bool spellcheck_all = false;
Glib::RefPtr<Gtk::TextTag> spellcheck_error_tag;
sigc::connection signal_tag_added_connection;

1
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);
{

Loading…
Cancel
Save