classification
Title: This is a python file, apply syntax highlighting
Type: enhancement Stage:
Components: IDLE Versions: Python 3.2
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: cvrebert, gagenellina, gert, taleinat, terry.reedy
Priority: normal Keywords:

Created on 2009-09-07 23:07 by gert, last changed 2010-08-02 07:20 by taleinat.

Messages (8)
msg92395 - (view) Author: gert cuykens (gert) Date: 2009-09-07 23:07
http://groups.google.be/group/comp.lang.python/browse_thread/thread/252fa1ccd0251977#

Menu option please, so I can highlight .wsgi .txt .xml files with python
code in it, does not matter if non python code gets wrongly highlighted too.
msg112325 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2010-08-01 13:45
Interesting idea.
msg112338 - (view) Author: Tal Einat (taleinat) (Python committer) Date: 2010-08-01 14:55
I'm +1 on adding such an option to the menu, if only to be able to highlight files including only Python code which don't happen to have the .py extension.

If support for files including not only Python code is important to anyone, some examples of such files would be very helpful. I've never seen such files and I don't know how common such uses are.

Supporting files with some Python code in between other stuff is a different matter. Non-Python code being wrongly highlighted may be fine, but we'll need to make sure that the syntax highlighting is robust enough to be able to withstand going through a lot of invalid syntax, and still correctly highlight most of the Python code found in between. If IDLE fails to highlight a file it could of course fail gracefully, give an error message and not highlight, so I don't foresee this causing any stability issues.
msg112339 - (view) Author: Tal Einat (taleinat) (Python committer) Date: 2010-08-01 14:56
In the last paragraph of my previous post, instead of "is a different matter" read "may be problematic".
msg112377 - (view) Author: gert cuykens (gert) Date: 2010-08-01 20:05
On Sun, Aug 1, 2010 at 4:55 PM, Tal Einat <report@bugs.python.org> wrote:
>
> Tal Einat <taleinat@gmail.com> added the comment:
>
> I'm +1 on adding such an option to the menu, if only to be able to highlight files including only Python code which don't happen to have the .py extension.
>
> If support for files including not only Python code is important to anyone, some examples of such files would be very helpful. I've never seen such files and I don't know how common such uses are.

Really, docs.python.org is full of examples with python code in it :)

Try to parse this html file
(http://docs.python.org/tutorial/controlflow.html)  for testing.

> Supporting files with some Python code in between other stuff is a different matter. Non-Python code being wrongly highlighted may be fine, but we'll need to make sure that the syntax highlighting is robust enough to be able to withstand going through a lot of invalid syntax, and still correctly highlight most of the Python code found in between. If IDLE fails to highlight a file it could of course fail gracefully, give an error message and not highlight, so I don't foresee this causing any stability issues.
>
msg112389 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2010-08-01 22:06
There are, perhaps 3 main issues with new features;

1. What is the specific proposal?

In particular, where should the new menu entry go and what should it say.

2. Will it hurt anything?
3. Will it be useful.

As to these, I suggest you try your own experiment. Rename x.html to x.py and pull into the editor.

Doing that with controlflow.html shows that this appears to be harmless. For this file, it is also useless:

a. My WinXP32 3.1.2 IDLE edit window does not have a horizontal scroll bar. It does not need one for <80 char lines. It also does not do autowrap, as that would be fatal for code. However, this file has some lines with a few hundred chars and there is no easy way to read them.

b. The html for Python code is not always what you see in a browser. Here is one line from your example: "<span class="k">print</span> <span class="n">x</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>" (no wrapping in the original).

I think Tal's case of .py-less Python files is a reason to add a menu entry, and let the user beware with anything else.
msg112401 - (view) Author: gert cuykens (gert) Date: 2010-08-01 23:11
On Mon, Aug 2, 2010 at 12:06 AM, Terry J. Reedy <report@bugs.python.org> wrote:
>
> Terry J. Reedy <tjreedy@udel.edu> added the comment:
>
> There are, perhaps 3 main issues with new features;
>
> 1. What is the specific proposal?
>
> In particular, where should the new menu entry go and what should it say.

edit -> syntax highlight

> 2. Will it hurt anything?

no

> 3. Will it be useful.

yes

> As to these, I suggest you try your own experiment. Rename x.html to x.py and pull into the editor.
>
> Doing that with controlflow.html shows that this appears to be harmless. For this file, it is also useless:

In this case useless it is. But try imagining some more <pre></pre>
friendly html. Would it not be asome if you could craft a file that
opens with your browser to see what it does before you run it with
python?

> a. My WinXP32 3.1.2 IDLE edit window does not have a horizontal scroll bar. It does not need one for <80 char lines. It also does not do autowrap, as that would be fatal for code. However, this file has some lines with a few hundred chars and there is no easy way to read them.

I can live with arrow keys

>
> b. The html for Python code is not always what you see in a browser. Here is one line from your example: "<span class="k">print</span> <span class="n">x</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>" (no wrapping in the original).
>
> I think Tal's case of .py-less Python files is a reason to add a menu entry, and let the user beware with anything else.
>

Not a warning message please. Just put it off by default on non py
files, like it currently does. Hilighting is harmless and does not
change the contents of the file.
msg112426 - (view) Author: Tal Einat (taleinat) (Python committer) Date: 2010-08-02 07:20
I think we are in agreement :)

Regarding the warning message, I was referring only to the case that the syntax highlighter fails completely and raises an exception. I'm not even sure if that can happen, but in case it does an informative message would be better than just not highlighting, and much better than IDLE dying. I'm bringing this up in this context because IMO if we allow highlighting of arbitrary files, we should at least ensure that this doesn't crash IDLE if the highlighting does fail.
History
Date User Action Args
2010-08-02 07:20:53taleinatsetmessages: + msg112426
2010-08-01 23:11:32gertsetmessages: + msg112401
2010-08-01 22:06:38terry.reedysetmessages: + msg112389
2010-08-01 20:05:41gertsetmessages: + msg112377
2010-08-01 14:56:59taleinatsetmessages: + msg112339
2010-08-01 14:55:37taleinatsetmessages: + msg112338
2010-08-01 13:45:27terry.reedysetmessages: + msg112325
2010-08-01 11:50:01BreamoreBoysetnosy: + terry.reedy, taleinat
2009-09-08 01:01:29gagenellinasetnosy: + gagenellina
2009-09-08 00:06:07cvrebertsetnosy: + cvrebert
2009-09-07 23:07:51gertcreate