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 'do...' 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"><<a href="mailto:leves@elte.hu">leves@elte.hu</a>></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've had occasion to start porting to Squeak. Without the<br>
left-arrow glyph, the underscores look really awful, and I'd like to be able<br>
to swap them for ANSI assignment if I release the code for platforms other<br>
than Cuis. I've googled a bit and searched the projects on SqueakSource, but<br>
I'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't modify your fonts, etc).<br>
But it'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: ':='.<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 := 'testMethod<br>
"This_is_a_comment_with_underscores."<br>
<br>
| x |<br>
x _ $_.<br>
^x = ''_'' first and: [ x = #''_'' first and: [ x = #(_) first first ] ]'.<br>
<br>
underscoresTest := Object subclass: #UnderscoresTest<br>
instanceVariableNames: ''<br>
classVariableNames: ''<br>
poolDictionaries: ''<br>
category: 'UnderscoresTest'.<br>
<br>
underscoresTest compile: testMethodString classified: 'instance side method'.<br>
underscoresTest class compile: testMethodString classified: 'class side method'.<br>
Object compile: testMethodString classified: '*UnderscoresTest'.<br>
<br>
CurrentReadOnlySourceFiles cacheDuring: [<br>
((PackageInfo named: 'UnderscoresTest') methods select: [ :each |<br>
fixUnderScoresInMethod value: each compiledMethod ]) explore ]<br>
"add your assertions here :)"<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>