ajwillia-ms pushed a commit to branch master.

http://git.enlightenment.org/tools/edi.git/commit/?id=a0d6627f54113d15da22b863c8bac0da61cff537

commit a0d6627f54113d15da22b863c8bac0da61cff537
Author: Andy Williams <a...@andywilliams.me>
Date:   Mon Apr 20 01:21:03 2015 +0100

    elm_code: add a TODO/FIXME standard parser
    
    Corret some callback code and re-parse each time the file is saved.
    Use this to clean up save/parse code in EDI too
---
 elm_code/src/lib/elm_code_common.h        |  2 ++
 elm_code/src/lib/elm_code_file.c          |  7 +++++
 elm_code/src/lib/elm_code_parse.c         | 22 +++++++++++++
 elm_code/src/lib/elm_code_parse.h         |  1 +
 elm_code/src/lib/elm_code_private.h       |  2 ++
 elm_code/src/lib/elm_code_text.c          |  6 +++-
 elm_code/src/lib/widget/elm_code_widget.c |  3 ++
 elm_code/src/tests/elm_code_test_parse.c  | 26 ++++++++++++++++
 src/bin/editor/edi_editor.c               | 52 +++++++++----------------------
 9 files changed, 83 insertions(+), 38 deletions(-)

diff --git a/elm_code/src/lib/elm_code_common.h 
b/elm_code/src/lib/elm_code_common.h
index 2174f49..9c8ec5a 100644
--- a/elm_code/src/lib/elm_code_common.h
+++ b/elm_code/src/lib/elm_code_common.h
@@ -24,6 +24,8 @@ typedef enum {
    ELM_CODE_STATUS_TYPE_PASSED,
    ELM_CODE_STATUS_TYPE_FAILED,
 
+   ELM_CODE_STATUS_TYPE_TODO,
+
    ELM_CODE_STATUS_TYPE_COUNT
 } Elm_Code_Status_Type;
 
diff --git a/elm_code/src/lib/elm_code_file.c b/elm_code/src/lib/elm_code_file.c
index 1a72911..0b164bb 100644
--- a/elm_code/src/lib/elm_code_file.c
+++ b/elm_code/src/lib/elm_code_file.c
@@ -186,6 +186,13 @@ EAPI void elm_code_file_save(Elm_Code_File *file)
 
    ecore_file_mv(tmp, path);
    free(tmp);
+
+   if (file->parent)
+     {
+        _elm_code_parse_reset_file(file->parent, file);
+        _elm_code_parse_file(file->parent, file);
+        elm_code_callback_fire(file->parent, &ELM_CODE_EVENT_FILE_LOAD_DONE, 
file);
+     }
 }
 
 EAPI void elm_code_file_free(Elm_Code_File *file)
diff --git a/elm_code/src/lib/elm_code_parse.c 
b/elm_code/src/lib/elm_code_parse.c
index 408fd48..87627f7 100644
--- a/elm_code/src/lib/elm_code_parse.c
+++ b/elm_code/src/lib/elm_code_parse.c
@@ -45,6 +45,18 @@ _elm_code_parse_file(Elm_Code *code, Elm_Code_File *file)
      }
 }
 
+void
+_elm_code_parse_reset_file(Elm_Code *code, Elm_Code_File *file)
+{
+   Elm_Code_Line *line;
+   Eina_List *item;
+
+   EINA_LIST_FOREACH(file->lines, item, line)
+    {
+       _elm_code_parse_line(code, line);
+    }
+}
+
 static Elm_Code_Parser *
 _elm_code_parser_new(void (*parse_line)(Elm_Code_Line *, void *),
                      void (*parse_file)(Elm_Code_File *, void *))
@@ -164,9 +176,19 @@ _elm_code_parser_diff_parse_file(Elm_Code_File *file, void 
*data EINA_UNUSED)
      }
 }
 
+static void
+_elm_code_parser_todo_parse_line(Elm_Code_Line *line, void *data EINA_UNUSED)
+{
+   if (elm_code_line_text_strpos(line, "TODO", 0) != ELM_CODE_TEXT_NOT_FOUND)
+     elm_code_line_status_set(line, ELM_CODE_STATUS_TYPE_TODO);
+   else if (elm_code_line_text_strpos(line, "FIXME", 0) != 
ELM_CODE_TEXT_NOT_FOUND)
+     elm_code_line_status_set(line, ELM_CODE_STATUS_TYPE_TODO);
+}
+
 void
 _elm_code_parse_setup()
 {
    ELM_CODE_PARSER_STANDARD_DIFF = 
_elm_code_parser_new(_elm_code_parser_diff_parse_line,
                                                         
_elm_code_parser_diff_parse_file);
+   ELM_CODE_PARSER_STANDARD_TODO = 
_elm_code_parser_new(_elm_code_parser_todo_parse_line, NULL);
 }
diff --git a/elm_code/src/lib/elm_code_parse.h 
b/elm_code/src/lib/elm_code_parse.h
index d991345..bc674f8 100644
--- a/elm_code/src/lib/elm_code_parse.h
+++ b/elm_code/src/lib/elm_code_parse.h
@@ -13,6 +13,7 @@ extern "C" {
 typedef struct _Elm_Code_Parser Elm_Code_Parser;
 
 EAPI Elm_Code_Parser *ELM_CODE_PARSER_STANDARD_DIFF; /**< A provided parser 
that will mark up diff text */
+EAPI Elm_Code_Parser *ELM_CODE_PARSER_STANDARD_TODO; /**< A provided parser 
that will highlight TODO and FIXME lines */
 
 /**
  * @brief Parser helper functions.
diff --git a/elm_code/src/lib/elm_code_private.h 
b/elm_code/src/lib/elm_code_private.h
index fed2ff4..1f16c8f 100644
--- a/elm_code/src/lib/elm_code_private.h
+++ b/elm_code/src/lib/elm_code_private.h
@@ -32,5 +32,7 @@ void _elm_code_parse_line(Elm_Code *code, Elm_Code_Line 
*line);
 
 void _elm_code_parse_file(Elm_Code *code, Elm_Code_File *file);
 
+void _elm_code_parse_reset_file(Elm_Code *code, Elm_Code_File *file);
+
 
 #endif
diff --git a/elm_code/src/lib/elm_code_text.c b/elm_code/src/lib/elm_code_text.c
index 8b22f3a..f51569c 100644
--- a/elm_code/src/lib/elm_code_text.c
+++ b/elm_code/src/lib/elm_code_text.c
@@ -38,7 +38,11 @@ elm_code_line_text_set(Elm_Code_Line *line, const char 
*chars, unsigned int leng
    line->length = length;
 
    file = line->file;
-   elm_code_callback_fire(file->parent, &ELM_CODE_EVENT_LINE_LOAD_DONE, line);
+   if (file->parent)
+     {
+        _elm_code_parse_line(file->parent, line);
+        elm_code_callback_fire(file->parent, &ELM_CODE_EVENT_LINE_LOAD_DONE, 
line);
+     }
 }
 
 EAPI int
diff --git a/elm_code/src/lib/widget/elm_code_widget.c 
b/elm_code/src/lib/widget/elm_code_widget.c
index 4c1edc4..e9c0344 100644
--- a/elm_code/src/lib/widget/elm_code_widget.c
+++ b/elm_code/src/lib/widget/elm_code_widget.c
@@ -1299,6 +1299,9 @@ _elm_code_widget_setup_palette(Evas_Object *o)
    evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, 
ELM_CODE_STATUS_TYPE_FAILED,
                                     96, 54, 54, 255);
 
+   evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, 
ELM_CODE_STATUS_TYPE_TODO,
+                                    54, 54, 96, 255);
+
    // setup token colors
    evas_object_textgrid_palette_set(o, EVAS_TEXTGRID_PALETTE_STANDARD, 
ELM_CODE_TOKEN_TYPE_DEFAULT,
                                     205, 205, 205, 255);
diff --git a/elm_code/src/tests/elm_code_test_parse.c 
b/elm_code/src/tests/elm_code_test_parse.c
index a5349a5..e91845c 100644
--- a/elm_code/src/tests/elm_code_test_parse.c
+++ b/elm_code/src/tests/elm_code_test_parse.c
@@ -60,9 +60,35 @@ START_TEST (elm_code_parse_hook_file_test)
 }
 END_TEST
 
+START_TEST (elm_code_parse_todo_test)
+{
+   Elm_Code *code;
+   Elm_Code_File *file;
+   Elm_Code_Line *line;
+
+   elm_code_init();
+
+   code = elm_code_create();
+   elm_code_parser_standard_add(code, ELM_CODE_PARSER_STANDARD_TODO);
+   file = elm_code_file_new(code);
+
+   elm_code_file_line_append(file, "xxx TODO line", 13, NULL);
+   line = elm_code_file_line_get(file, 1);
+   ck_assert_int_eq(ELM_CODE_STATUS_TYPE_TODO, line->status);
+
+   elm_code_line_text_set(line, "FIXME too", 9);
+   ck_assert_int_eq(ELM_CODE_STATUS_TYPE_TODO, line->status);
+
+   elm_code_line_text_set(line, "TOFIX", 5);
+   ck_assert_int_eq(ELM_CODE_STATUS_TYPE_DEFAULT, line->status);
+   elm_code_shutdown();
+}
+END_TEST
+
 void elm_code_test_parse(TCase *tc)
 {
    tcase_add_test(tc, elm_code_parse_hook_memory_test);
    tcase_add_test(tc, elm_code_parse_hook_file_test);
+   tcase_add_test(tc, elm_code_parse_todo_test);
 }
 
diff --git a/src/bin/editor/edi_editor.c b/src/bin/editor/edi_editor.c
index 092dc62..8d36407 100644
--- a/src/bin/editor/edi_editor.c
+++ b/src/bin/editor/edi_editor.c
@@ -27,9 +27,6 @@ typedef struct
    Edi_Location end;
 } Edi_Range;
 
-static void
-_reset_highlight(Edi_Editor *editor);
-
 void
 edi_editor_save(Edi_Editor *editor)
 {
@@ -38,10 +35,8 @@ edi_editor_save(Edi_Editor *editor)
 
    editor->save_time = time(NULL);
    edi_mainview_save();
-   _reset_highlight(editor);
 
    editor->modified = EINA_FALSE;
-
    ecore_timer_del(editor->save_timer);
    editor->save_timer = NULL;
 }
@@ -483,7 +478,8 @@ _clang_load_errors(const char *path EINA_UNUSED, Edi_Editor 
*editor)
               break;
           }
         CXString str = clang_getDiagnosticSpelling(diag);
-        _edi_line_status_set(editor, line, status, clang_getCString(str));
+        if (status != ELM_CODE_STATUS_TYPE_DEFAULT)
+          _edi_line_status_set(editor, line, status, clang_getCString(str));
         clang_disposeString(str);
 
         clang_disposeDiagnostic(diag);
@@ -535,35 +531,6 @@ _edi_clang_dispose(Edi_Editor *editor)
 #endif
 
 static void
-_reset_highlight(Edi_Editor *editor)
-{
-   Eina_List *item;
-   Elm_Code *code;
-   Elm_Code_Line *line;
-
-   if (!editor->show_highlight)
-     return;
-
-   eo_do(editor->entry,
-         code = elm_code_widget_code_get());
-   EINA_LIST_FOREACH(code->file->lines, item, line)
-     {
-        elm_code_line_tokens_clear(line);
-        elm_code_line_status_clear(line);
-     }
-
-#if HAVE_LIBCLANG
-   pthread_attr_t attr;
-   pthread_t thread_id;
-
-   if (pthread_attr_init(&attr) != 0)
-     perror("pthread_attr_init");
-   if (pthread_create(&thread_id, &attr, _edi_clang_setup, editor) != 0)
-     perror("pthread_create");
-#endif
-}
-
-static void
 _unfocused_cb(void *data, Evas_Object *obj EINA_UNUSED, void *event_info 
EINA_UNUSED)
 {
    Edi_Editor *editor;
@@ -592,7 +559,16 @@ _edi_editor_parse_file_cb(Elm_Code_File *file EINA_UNUSED, 
void *data)
    Edi_Editor *editor;
 
    editor = (Edi_Editor *)data;
-   _reset_highlight(editor);
+
+#if HAVE_LIBCLANG
+   pthread_attr_t attr;
+   pthread_t thread_id;
+
+   if (pthread_attr_init(&attr) != 0)
+     perror("pthread_attr_init");
+   if (pthread_create(&thread_id, &attr, _edi_clang_setup, editor) != 0)
+     perror("pthread_create");
+#endif
 }
 
 static Eina_Bool
@@ -664,7 +640,9 @@ edi_editor_add(Evas_Object *parent, Edi_Mainview_Item *item)
 */
    evas_object_smart_callback_add(widget, "unfocused", _unfocused_cb, editor);
 
-   elm_code_parser_add(code, NULL, _edi_editor_parse_file_cb, editor);
+   elm_code_parser_standard_add(code, ELM_CODE_PARSER_STANDARD_TODO);
+   if (editor->show_highlight)
+     elm_code_parser_add(code, NULL, _edi_editor_parse_file_cb, editor);
    elm_code_file_open(code, item->path);
 
    evas_object_size_hint_weight_set(widget, EVAS_HINT_EXPAND, 
EVAS_HINT_EXPAND);

-- 


Reply via email to