diff --git a/juci/CMakeLists.txt b/juci/CMakeLists.txt index 5cd0026..f9e0e40 100644 --- a/juci/CMakeLists.txt +++ b/juci/CMakeLists.txt @@ -1,12 +1,17 @@ cmake_minimum_required (VERSION 2.8.4) set(project_name juci) set(module juci_to_python_api) - project (${project_name}) add_definitions(-DBOOST_LOG_DYN_LINK) -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -pthread") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -std=c++11 -pthread") set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_LIST_DIR}/cmake/Modules/") +#You are of course using Homebrew: +if(APPLE) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -L/usr/local/opt/gettext/lib -I/usr/local/opt/gettext/include -undefined dynamic_lookup") #TODO: fix this + set(CMAKE_MACOSX_RPATH 1) + set(ENV{PKG_CONFIG_PATH} "$ENV{PKG_CONFIG_PATH}:/usr/local/lib/pkgconfig:/opt/X11/lib/pkgconfig") +endif() INCLUDE(FindPkgConfig) message("Searcing for libclang") diff --git a/juci/api.cc b/juci/api.cc index ee5a634..cf1099d 100644 --- a/juci/api.cc +++ b/juci/api.cc @@ -12,7 +12,9 @@ PluginApi::PluginApi(Menu::Controller& menu_ctl_, menu_ = &menu_ctl_; notebook_ = ¬ebook_ctl_; DEBUG("Initiating plugins(from plugins.py).."); - InitPlugins(); +#ifndef __APPLE__ + InitPlugins(); //TODO: fix this +#endif DEBUG("Plugins initiated.."); } diff --git a/juci/source.cc b/juci/source.cc index c88d2a9..0704446 100644 --- a/juci/source.cc +++ b/juci/source.cc @@ -5,6 +5,7 @@ #include #include "notebook.h" #include "logging.h" +#include Source::Location:: Location(int line_number, int column_offset) : @@ -353,44 +354,38 @@ void Source::Controller::OnOpenFile(const string &filepath) { view().OnUpdateSyntax(model().ExtractTokens(start_offset, end_offset), model().config()); + //OnUpdateSyntax must happen in main thread, so the parse-thread + //sends a signal to the main thread that it is to call the following function: + parsing_done.connect([this](){ + INFO("Updating syntax"); + view(). + OnUpdateSyntax(model().ExtractTokens(0, std::min(buffer()->get_text().size(), raw_size)), + model().config()); + INFO("Syntax updated"); + }); + buffer()->signal_end_user_action().connect([this]() { - if (!go) { - std::thread parse([this]() { - if (parsing.try_lock()) { - INFO("Starting parsing"); - while (true) { - const std::string raw = buffer()->get_text().raw(); - std::map buffers; - notebook_->MapBuffers(&buffers); - buffers[model().file_path()] = raw; - if (model().ReParse(buffers) == 0 && - raw == buffer()->get_text().raw()) { - syntax.lock(); - go = true; - syntax.unlock(); - break; - } - } - parsing.unlock(); - INFO("Parsing completed"); - } - }); - parse.detach(); - } - }); - - buffer()->signal_begin_user_action().connect([this]() { - if (go) { - syntax.lock(); - INFO("Updating syntax"); - view(). - OnUpdateSyntax(model().ExtractTokens(0, buffer()->get_text().size()), - model().config()); - go = false; - INFO("Syntax updated"); - syntax.unlock(); + std::thread parse([this]() { + if (parsing.try_lock()) { + INFO("Starting parsing"); + while (true) { + const std::string raw = buffer()->get_text().raw(); + raw_size=raw.size(); + std::map buffers; + notebook_->MapBuffers(&buffers); + buffers[model().file_path()] = raw; + if (model().ReParse(buffers) == 0 && + raw == buffer()->get_text().raw()) { + break; + } + } + parsing.unlock(); + parsing_done(); + INFO("Parsing completed"); } }); + parse.detach(); + }); } } Glib::RefPtr Source::Controller::buffer() { diff --git a/juci/source.h b/juci/source.h index ee7ebbf..04ea352 100644 --- a/juci/source.h +++ b/juci/source.h @@ -162,9 +162,9 @@ namespace Source { private: void OnLineEdit(); void OnSaveFile(); - std::mutex syntax; std::mutex parsing; - bool go = false; + Glib::Dispatcher parsing_done; + size_t raw_size=0; bool is_saved_ = false; bool is_changed_ = false;