Bug 20444 - Add text/x-prolog
Summary: Add text/x-prolog
Status: RESOLVED MOVED
Alias: None
Product: shared-mime-info
Classification: Unclassified
Component: freedesktop.org.xml (show other bugs)
Version: unspecified
Hardware: Other All
: medium enhancement
Assignee: Shared Mime Info group
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-03-03 06:33 UTC by Ignacio Casal Quinteiro
Modified: 2018-10-13 10:41 UTC (History)
2 users (show)

See Also:
i915 platform:
i915 features:


Attachments
testcase prolog (853 bytes, text/plain)
2009-03-05 10:59 UTC, Ignacio Casal Quinteiro
Details
Patch (4.55 KB, patch)
2010-12-02 10:46 UTC, Fernando Brito
Details | Splinter Review
Patch 2 (5.94 KB, patch)
2010-12-02 18:16 UTC, Fernando Brito
Details | Splinter Review

Description Ignacio Casal Quinteiro 2009-03-03 06:33:32 UTC
I need something like this for gtksourceview:

  <mime-type type="text/x-prolog">
    <_comment>Prolog source code</_comment>
    <sub-class-of type="text/plain"/>
    <glob pattern="*.prolog"/>
  </mime-type>

Thanks.
Comment 1 Pino Toscano 2009-03-05 09:30:29 UTC
Could you please provide a sample testcase?
Any documentation of the file format?
Comment 2 Ignacio Casal Quinteiro 2009-03-05 10:59:56 UTC
Created attachment 23565 [details]
testcase prolog

As you can see here: http://filext.com/file-extension/pl

Theorically the pl is the extension used by swi-prolog. The problem is that this extension is used too for perl files.
Vim and kate uses the extension .prolog for prolog files, so I think it could be the extension we should use. Anyway if there is a way to use the pl extension for prolog files maybe would be better.
Comment 3 Ignacio Casal Quinteiro 2009-03-05 11:12:05 UTC
BTW, my mistake vim uses .pl for prolog files.
Comment 4 Ignacio Casal Quinteiro 2009-08-14 11:08:47 UTC
Time to ping here.
BTW vim makes the detection for .pl for prolog and files with .pl that starts with #/usr.../perl changes the mime detection to perl
Comment 5 Bastien Nocera 2010-12-01 09:05:55 UTC
(In reply to comment #4)
> Time to ping here.
> BTW vim makes the detection for .pl for prolog and files with .pl that starts
> with #/usr.../perl changes the mime detection to perl

Please follow the instructions in the HACKING file about providing patches.
http://cgit.freedesktop.org/xdg/shared-mime-info/plain/HACKING
Comment 6 Fernando Brito 2010-12-02 10:46:21 UTC
Created attachment 40748 [details] [review]
Patch

Please take a look in my patch and give me some feedback.

I also noticed that there are no tests for perl.
Comment 7 Fernando Brito 2010-12-02 10:54:26 UTC
I think that this line on tests/list:
  test.pl  text/x-prolog
should be:
  test.pl  text/x-prolog ox

Right? I am having problems running/understanding the tests :(
Comment 8 Bastien Nocera 2010-12-02 10:59:56 UTC
(In reply to comment #7)
> I think that this line on tests/list:
>   test.pl  text/x-prolog
> should be:
>   test.pl  text/x-prolog ox
> 
> Right? I am having problems running/understanding the tests :(

Did you run the test suite? How it install the necessary bits are mentioned in the HACKING file, and the parameters to each line in the file explained at the top of tests/list.

You would also need to add a Perl test case. I really don't expect this to work as easily as you think, given that you have the same glob as perl (*.pl).
Comment 9 Fernando Brito 2010-12-02 11:02:23 UTC
Is there any way to add regex in <match> tag?

What we want to do is:
- Every .prolog file is text/x-prolog
- Every .pro file is text/x-prolog
- Every .pl file that doesn't have the word "perl" on the first line is
text/x-prolog

Do you have any hints on how can we achieve that?
Comment 10 Fernando Brito 2010-12-02 12:20:41 UTC
So, this is how I did:

  <mime-type type="text/x-prolog">
    <_comment>Prolog source file</_comment>
    <sub-class-of type="text/plain"/>
    <glob pattern="*.pl"/>
    <glob pattern="*.pro"/>
    <glob pattern="*.prolog"/>
  </mime-type>
  <mime-type type="application/x-perl">
    <_comment>Perl script</_comment>
    <sub-class-of type="application/x-executable"/>
    <sub-class-of type="text/plain"/>
    <generic-icon name="text-x-script"/>
    <magic priority="80">
      <match type="string" value='eval \"exec /usr/local/bin/perl' offset="0"/>
      <match type="string" value="/bin/perl" offset="1:16"/>
      <match type="string" value="/bin/env perl" offset="1:16"/>
    </magic>
    <!-- <glob pattern="*.pl"/> -->
    <glob pattern="*.pm"/><!-- module -->
    <glob pattern="*.al"/><!-- autoloader -->
    <glob pattern="*.perl"/>
  </mime-type>


This seems to work really well. Check out the results using the "mimetype" tool:
http://pastie.org/1342469

But I am having problems with the tests.

  test.pro text/x-prolog ox
  test.prolog text/x-prolog ox
  test-prolog.pl  text/x-prolog ox

Those 3 tests are working fine, but here comes the problem:

  test-perl.pl application/x-perl xoo

The last "o" is failing.

In my understanding:
first letter is just checking filename. This fails (because it returns x-prolog)
second letter is just content (magic). This is passing
third letter is all together. This should pass but is failing.

When I use "mimetype" on that file, it returns "x-perl", but on the test this is failing. How is that possible? 

Thank you :)
Comment 11 Fernando Brito 2010-12-02 12:32:04 UTC
Please give me an answer so I can provide a git formated patch.
Thank you!
Comment 12 Fernando Brito 2010-12-02 18:16:47 UTC
Created attachment 40752 [details] [review]
Patch 2

Here it is a patch.
Comment 13 Andre Klapper 2011-01-11 15:45:43 UTC
Could the patch get a review, please?
Comment 14 Bastien Nocera 2011-05-25 06:58:58 UTC
Review of attachment 40752 [details] [review]:

::: freedesktop.org.xml.in
@@ +2568,3 @@
+    <_comment>Prolog source file</_comment>
+    <sub-class-of type="text/plain"/>
+    <glob pattern="*.pl"/>

This and...

@@ +2582,3 @@
       <match type="string" value="/bin/env perl" offset="1:16"/>
     </magic>
+    <!-- <glob pattern="*.pl"/> -->

this, are obviously wrong. This means that "*.pl" files will *always* be detected as Prolog files.

Either the glob should have a priority, or neither should have a glob for it. The former is obviously more desirable, and Perl files should be the ones with the highest priority.
Comment 15 GitLab Migration User 2018-10-13 10:41:48 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to freedesktop.org's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.freedesktop.org/xdg/shared-mime-info/issues/90.


Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.