Levente, I will try your script when I get close to shipping:) Thank you so much! I think I may just add this one to my &#39;do...&#39; menu, since I plan to be hauling a bunch of code back and forth from Cuis and Squeak.<br>
<br><div class="gmail_quote">On Fri, May 13, 2011 at 4:07 PM, Levente Uzonyi <span dir="ltr">&lt;<a href="mailto:leves@elte.hu">leves@elte.hu</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div class="im">On Fri, 13 May 2011, Casey Ransberger wrote:<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hello everyone,<br>
<br>
I have some code I wrote for Cuis, where we prefer underscore (left arrow)<br>
assignment, which I&#39;ve had occasion to start porting to Squeak. Without the<br>
left-arrow glyph, the underscores look really awful, and I&#39;d like to be able<br>
to swap them for ANSI assignment if I release the code for platforms other<br>
than Cuis. I&#39;ve googled a bit and searched the projects on SqueakSource, but<br>
I&#39;m not finding FixUnderscores.<br>
<br>
Also, I was wondering if FixUnderscores had any gotchas I might want to<br>
worry about.<br>
</blockquote>
<br></div>
As I wrote it recently, FixUnderscores is crap. FixUnderscores2 is a lot better (properly fixes underscores, doesn&#39;t modify your fonts, etc).<br>
But it&#39;s pretty easy to write such code in Squeak without subclassing Scanner, so I hacked together the following (evaluate it in a workspace):<br>
<br>
fixUnderScoresInSourceString := [ :methodString |<br>
        String streamContents: [ :stream |<br>
                | previousUnderscoreIndex |<br>
                previousUnderscoreIndex := 0.<br>
                Scanner new<br>
                        scanTokenPositionsIn: methodString<br>
                        into: [ :startPosition :endPosition |<br>
                                (startPosition = endPosition and: [<br>
                                        (methodString at: startPosition) == $_ ]) ifTrue: [<br>
                                                stream<br>
                                                        next: startPosition - previousUnderscoreIndex - 1<br>
                                                        putAll: methodString<br>
                                                        startingAt: previousUnderscoreIndex + 1;<br>
                                                        nextPutAll: &#39;:=&#39;.<br>
                                                previousUnderscoreIndex := startPosition ] ].<br>
                stream<br>
                        next: methodString size - previousUnderscoreIndex<br>
                        putAll: methodString<br>
                        startingAt: previousUnderscoreIndex + 1 ] ].<br>
<br>
fixUnderScoresInMethod := [ :compiledMethod |<br>
        | source fixedSource |<br>
        source := compiledMethod getSource asString.<br>
        fixedSource := fixUnderScoresInSourceString value: source.<br>
        source = fixedSource<br>
                ifTrue: [ false ]<br>
                ifFalse: [<br>
                        compiledMethod methodClass<br>
                                compile: fixedSource<br>
                                classified: (compiledMethod methodClass organization categoryOfElement: compiledMethod selector)<br>
                                withStamp: compiledMethod timeStamp<br>
                                notifying: nil.<br>
                        true ] ].<br>
<br>
testMethodString := &#39;testMethod<br>
        &quot;This_is_a_comment_with_underscores.&quot;<br>
<br>
        | x |<br>
        x _ $_.<br>
        ^x = &#39;&#39;_&#39;&#39; first and: [ x = #&#39;&#39;_&#39;&#39; first and: [ x = #(_) first first ] ]&#39;.<br>
<br>
underscoresTest := Object subclass: #UnderscoresTest<br>
        instanceVariableNames: &#39;&#39;<br>
        classVariableNames: &#39;&#39;<br>
        poolDictionaries: &#39;&#39;<br>
        category: &#39;UnderscoresTest&#39;.<br>
<br>
underscoresTest compile: testMethodString classified: &#39;instance side method&#39;.<br>
underscoresTest class compile: testMethodString classified: &#39;class side method&#39;.<br>
Object compile: testMethodString classified: &#39;*UnderscoresTest&#39;.<br>
<br>
CurrentReadOnlySourceFiles cacheDuring: [<br>
        ((PackageInfo named: &#39;UnderscoresTest&#39;) methods select: [ :each |<br>
                fixUnderScoresInMethod value: each compiledMethod ]) explore ]<br>
&quot;add your assertions here :)&quot;<br><font color="#888888">
<br>
<br>
Levente</font><div><div></div><div class="h5"><br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
Thanks in advance for any pointers you can give!<br>
<br>
-- <br>
Casey Ransberger<br>
<br>
</blockquote>
<br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br>Casey Ransberger<br>