[Pythonmac-SIG] Re: syntax coloring

Rob Managan managan at llnl.gov
Tue Jul 29 12:19:37 EDT 2003


I looked through the archives and found this. In summary there is a 
simple edit to turn on syntax coloring. It is not robust so it is not 
the default.

I included a few references to other enhancements that may not work 
any longer either.

>Date: Thu, 30 Sep 1999 13:49:32 -0700
>From: "Joseph J. Strout" <joe at strout.net>
>
>OK, here's a patch (at http://www.strout.net/python/mac/) which
>extends the IDE's editor in a couple of ways:
>
>
>Syntax Coloring:
>
>This feature highlights keywords, strings, comments, etc. in various
>colors and styles. A new menu command in the pop-up menu above the
>vertical scrollbar lets you turn this on and off.  This feature is
>still a work in progress; and has several limitations:
>
>- It can get confused when multi-line strings are involved. If that
>happens, just turn coloring off and back on; that should fix it. (In
>the future we      may have a command key to do this more quickly.)
>
>- It assumes you have Profont installed, and want to use it. I can't
>imagine why you wouldn't, but if it's a problem let me know and we'll
>talk.
>

And the patches seem to have broken
>Wed Apr 25 15:18:33 2001

>I had applied the printing and AdvancedEditor patches to the IDE in
>Python 2.0 and that worked fine, but I can't seem to get syntax
>coloring to work after applying them to the IDE in 2.1. I've
>reapplied/rebuilt several times and Syntax Coloring is checked when I
>open a script in the IDE, but nothing is colorized. Any thoughts?
>
>Richard Gordon

But there is a note on how to fix them
>From: Donovan Preston <dp at ulaluma.com>

>Finally, about the advanced editor patch, it's simply a matter of changing
>all of the toolbox module imports from "import Blah" to "from Carbon import
>Blah"... Otherwise, I didn't have to change a thing to get the advanced
>editor to work. I will try to apply it to my fresh copy of the IDE I
>installed yesterday and post another step-by-step for people interested in
>having this functionality.
>

And
>From: Dan Grassi <dan at grassi.org>
>But there is another issue, AdvancedEditorPatch.py does not work but it
>is a simple fix.  The first insert:
>
>PyEdit.InsertAfter("			self.run_as_main = 0",
>"""		if self.settings.has_key("syntax_coloring"):
>			self.syntax_coloring = self.settings["syntax_coloring"]
>		else:
>			self.syntax_coloring = 1
>""")
>
>does not work because of changes in PyEdit.py in the 2.3 cvs tree. 
>Instead it needs to be:
>
>PyEdit.InsertAfter(r"""		self.run_as_main =
>self.settings.get("run_as_main", 0)""",
>r"""		self.syntax_coloring = self.settings.get("syntax_coloring", 0)
>""")
>
>Without this self.syntax_coloring is not created and the pop-up menu
>crashes the IDE when it is referenced.
>
>
>For completeness the changes in PyAdvancedEditor.py are:
>
>old:
>import Qd
>import Fm
>import Evt
>import Events
>change to:
>#from Carbon import Qd
>from Carbon import Fm
>from Carbon import Evt
>from Carbon import Events
>

And
>From: Just van Rossum <just at letterror.com>
>A bad implementation of syntax coloring has been hiding in the IDE 
>for a while:
>edit line 679 to read
>
>         self.do_fontify = 1
>
>(Re)start the IDE and you're laughing.
>
>It's bad in the sense that:
>
>   1) It doesn't do the right thing when editing triple quoted strings
>      (That's why there is a secret shortcut which recolors the entire
>      document:cmd-shift-d.)
>   2) It _sometimes_ traces back in PyFontify in some of the complex regexen
>      (this is probably due to sre, but I never bothered to research the
>      problem)
>   3) It is slow becuase it does it's work as idle callbacks, which are
>      scheduled fairly low-frequently by the event loop.
>   4) Neither fonts nor colors are settable with a GUI.
>
>I now think that the whole PyFontify approach is flawed, and that it's not
>really suitable for live coloring. Either we need to copy what IDLE is doing,
>or, and THAT would be a MAJORLY exciting enhancement of the IDE, is 
>to switch to
>Scintilla as the text component instead of waste. Then we get 
>_folding_ for free
>as well! I usually don't like to shout in emails, but THIS WOULD BE EXTREMELY
>COOL ;-) Scintilla is what PythonWin uses.
>
>Problem is: it needs to be ported to Carbon. Problem #2 for _me_ is: it's in
>C++, which I can't write. Anyone, please check out 
>http://www.scintilla.org/ if
>you're interested in a project.

This is now in line 681 of Wtext.py which is found at 
/Library/Frameworks/Python.framework/Versions/2.3/mac/Tools/IDE/Wtext.py
-- 
*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-*-*-*-*-*-*-
Rob Managan               email managan at llnl.gov
LLNL                      phone: 925-423-0903
P.O. Box 808, L-095       FAX:   925-422-3389
Livermore, CA  94551-0808




More information about the Pythonmac-SIG mailing list