Re: [gedit-list] Syntax highlighting for file with wrong filetype



Ed Greenberg a écrit le 2011-01-26 12:59 :
> I have a circumstance under which I have to edit python source in files
> of type .txt.   Not all the .txt files on my system are python files.
> 
> Can anybody think of a way to bring up syntax highlighting?   Is there a
> comment I can put at the top of the file, for example?

I suppose you know that you can manually select highlight mode in the
menu "View > Highlight Mode" when your file is open.

But if you want that your Python files written in .txt files have
automatically Python highlight mode, I don't know how to do this with a
comment at the top of the file, but if you have control on the files
name, you could name them .py.txt and add a Python MIME type for .py.txt.

In resume, if your files must end by .txt, you could actually end them
by .py.txt and add a MIME type to recognize .py.txt files as Python files.

To do that, put the attached file in the following folder (create it if
it doesn't exist):

/home/YOU/.local/share/mime/packages/

and update MIME type database with the following command:

$ update-mime-database /home/YOU/.local/share/mime

Regards,

Jean-Philippe
<?xml version="1.0" encoding="UTF-8"?>
<mime-info xmlns="http://www.freedesktop.org/standards/shared-mime-info";>
  <mime-type type="text/x-python">
    <comment>Python script in .txt file</comment>
    <comment xml:lang="fr">Script Python dans un fichier .txt</comment>
    <sub-class-of type="application/x-executable"/>
    <sub-class-of type="text/plain"/>
    <glob pattern="*.py.txt"/>
  </mime-type>
</mime-info>


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]