View previous topic :: View next topic |
Author |
Message |
Kurmis n00b
Joined: 04 Jun 2010 Posts: 38 Location: LV
|
Posted: Sun Mar 12, 2017 1:56 pm Post subject: XFCE - File type define by extension |
|
|
I often work with Octave/Matlab files, which have extension *.m
Thunar and PCmanFM detect *.m files as "Objective C"
As i open any *.m file with gedit/geany/... default syntax Hi-Lite is treated as "Objective C"
So, i have to manually specify that opened file is Octave or Matlab code.
BTW Octave and Matlab syntax Hi-Lites can slightly differ in some editors.
How i can fix this behavior, and system wide define that extensoin *.m means Octave (at least Matlab) ?
I prefer system wide solution, not user-specific.
In file /usr/share/mime/packages/freedesktop.org.xml two file types
Code: | <mime-type type="text/x-matlab">
<mime-type type="text/x-objcsrc"> |
are associated to extension *.m Code: | <glob pattern="*.m"/> |
Tnx in advance @ all. |
|
Back to top |
|
|
krinn Watchman
Joined: 02 May 2003 Posts: 7470
|
Posted: Sun Mar 12, 2017 2:34 pm Post subject: |
|
|
you can put a header stating the code type to use highlight
/* -*- Mode: Octave; tab-width: 6 -*- */ |
|
Back to top |
|
|
Kurmis n00b
Joined: 04 Jun 2010 Posts: 38 Location: LV
|
Posted: Mon Mar 13, 2017 7:17 pm Post subject: |
|
|
krinn wrote: | you can put a header stating the code type to use highlight
/* -*- Mode: Octave; tab-width: 6 -*- */ |
No, i can not.
If i try to execute octave file with this line, then i gotta error.
May be for syntax Hi-Lite it helps, but with this line whole file is unusable. |
|
Back to top |
|
|
cboldt Veteran
Joined: 24 Aug 2005 Posts: 1046
|
Posted: Mon Mar 13, 2017 8:07 pm Post subject: |
|
|
Just poking around starting with `man mimetype` ...
Interesting that the file /usr/share/mime/globs also has "text/x-objcsrc:*.m"
The /usr/share/mime/globs file has this opening admonishment to the reader ...
Code: | # This file was automatically generated by the
# update-mime-database command. DO NOT EDIT! |
That assignment exists in /usr/share/mime/packages/freedesktop.org.xml which means this collision is built in to the mime definitions.
On my system, a similar assignment exists in /usr/share/doc/imagemagick-6.9.7.4/html/www/source/mime.xml in the first place (found by `grep -r text/x-objsrc /usr/*), but I have no idea if (and "if", then "how") this assignment is propagated to /usr/share/mime/globs.
So, here is what I did ...
Open /usr/share/mime/packages/freedesktop.org.xml with an editor
Comment out the assignment of *.m to Objective-C source code. The "<!--" and "-->" strings delimit the commenting out
Code: | <!--
<mime-type type="text/x-objcsrc">
<comment>Objective-C source code</comment>
<sub-class-of type="text/x-csrc"/>
<magic priority="30">
<match value="#import" type="string" offset="0"/>
</magic>
<glob pattern="*.m"/>
</mime-type>
--> |
Run `update-mime-database /usr/share/mime`
Check for success with `grep \*\.m$ /usr/share/mime/*`
Let us know if that works for you ... |
|
Back to top |
|
|
Kurmis n00b
Joined: 04 Jun 2010 Posts: 38 Location: LV
|
Posted: Mon Mar 13, 2017 8:59 pm Post subject: |
|
|
cboldt wrote: | Let us know if that works for you ... |
Yes, ir works. Code: | cp /usr/share/mime/packages/freedesktop.org.xml /usr/share/mime/packages/freedesktop.org.xml.bak00
mcedit /usr/share/mime/packages/freedesktop.org.xml |
I have Objective C glob pattern changed from *.m to *.mm
Code: | diff /usr/share/mime/packages/freedesktop.org.xml /usr/share/mime/packages/freedesktop.org.xml.bak00
30896c30896
< <glob pattern="*.mm"/>
---
> <glob pattern="*.m"/> |
Afer Code: | update-mime-database /usr/share/mime | i have closed Thunar and pcmanFM, and opened 'em again.
Both of 'em *.m files now show as -MATLAB script/function-.
BTW, Gedit now open .m files as Octave, not Matlab.
It is OK for me. |
|
Back to top |
|
|
cboldt Veteran
Joined: 24 Aug 2005 Posts: 1046
|
Posted: Mon Mar 13, 2017 9:08 pm Post subject: |
|
|
Thanks for the report. Turns out there are quite a few collisions in the mimetype list, including 6 instances of *.ogg, , and at least 50 extensions that have more than one entry. Maybe there is a mechanism that accounts for this, depending on the app, and I have to assume there is. Out of those collision cases, I also don't know how many reflect disparate filetypes, like the situation you were dealing with. |
|
Back to top |
|
|
cboldt Veteran
Joined: 24 Aug 2005 Posts: 1046
|
Posted: Mon Mar 13, 2017 9:36 pm Post subject: |
|
|
I don't use geany, but found this tidbit online ...
Quote: | You can override the list of file extensions that Geany uses to detect filetypes using the user filetype_extensions.conf file. |
http://geany.org/manual/dev/#filetype-extensions
The mime system clearly envision "collisions" or duplicate use of extension, as denoting more than one filetype. Thunar likely has a way to deal with these exceptional cases too, considering that different users have different default preferences, and the fact that more than one application has adopted certain extensions. |
|
Back to top |
|
|
Hu Administrator
Joined: 06 Mar 2007 Posts: 21856
|
Posted: Tue Mar 14, 2017 1:43 am Post subject: |
|
|
Kurmis wrote: | I have Objective C glob pattern changed from *.m to *.mm | By tradition, *.mm refers to Objective-C++. This should not matter for you if you never use either Objective-C or Objective-C++. If you do use Objective-C++, then your choice may cause similar confusion between Objective-C and Objective-C++. |
|
Back to top |
|
|
Kurmis n00b
Joined: 04 Jun 2010 Posts: 38 Location: LV
|
Posted: Tue Mar 14, 2017 7:43 am Post subject: |
|
|
Quote: | By tradition, *.mm refers to Objective-C++. This should not matter for you if you never use either Objective-C or Objective-C++. If you do use Objective-C++, then your choice may cause similar confusion between Objective-C and Objective-C++. | I do not use Objective C.
If one day i will prefer Objective C over Octave, i will know how i can set 'em as default
system wide and for geany.
How it works for gedit i found here :
http://askubuntu.com/questions/44730/can-i-set-a-default-syntax-highlighting-in-gedit Quote: | You can at least add file extensions in the html syntax coloring scheme by editing html.lang in /usr/share/gtksourceview-2.0/language-specs/ as a super user. So say you want to add HTML syntax highlighting to cfm files, you'd change this
<property name="globs">*.html;*.htm</property>
(default html.lang) into this
<property name="globs">*.html;*.htm;*.cfm</property> |
Tnx for excelent explanation. |
|
Back to top |
|
|
|