Page MenuHomePhabricator

automatic mime/syntax support in elm_code on elm_code_file_open
Closed, InvalidPublic

Description

If one has elm_obj_code_widget_syntax_enabled_set to true, for syntax support. When a file is opened via elm_code_file_open, it should internally look at the mime and activate syntax support. That way consumers of elm_code, do not have to do the following over and over

mime = efreet_mime_type_get(file);
if(mime)
  {
    if(!strcasecmp(mime, "text/x-chdr") ||
       !strcasecmp(mime, "text/x-csrc") ||
       !strcasecmp(mime, "text/x-python"))
      syntax = elm_code_syntax_for_mime_get(mime);
    else if(!strcasecmp(mime, "text/x-diff") ||
            !strcasecmp(mime, "text/x-patch"))
     elm_code_parser_standard_add(doc->code,
                                  ELM_CODE_PARSER_STANDARD_DIFF);
    else if(strstr(mime, "text/"))
      syntax = elm_code_syntax_for_mime_get("text/plain");
    if(syntax)
      {
        elm_obj_code_widget_syntax_enabled_set(doc->widget, EINA_TRUE);
        elm_code_syntax_parse_file(syntax,doc->code->file);
      }
    else
      elm_obj_code_widget_syntax_enabled_set(doc->widget, EINA_FALSE);
  }
elm_code_file_open(doc->code,file);

I was able to reduce to the following, good enough for now

mime = efreet_mime_type_get(file);
if(mime)
  {
    if(!strcasecmp(mime, "text/x-diff") ||
       !strcasecmp(mime, "text/x-patch"))
     elm_code_parser_standard_add(doc->code,
                                  ELM_CODE_PARSER_STANDARD_DIFF);
    else if(strstr(mime, "text/"))
      elm_obj_code_widget_syntax_enabled_set(doc->widget, EINA_TRUE);
    else
      elm_obj_code_widget_syntax_enabled_set(doc->widget, EINA_FALSE);
  }
elm_code_file_open(doc->code,file);
wltjr closed this task as Invalid.Aug 18 2017, 1:00 PM