[squeak-dev] [ANN] true unicode left arrows without clobbering underscores (cs)

Michal michal-list at auf.net
Sun Oct 3 14:44:34 UTC 2010


hi - 

Attached is a changeset that gives you back the left arrow for assignement, without clobbering the underscore charcode and without hacking fonts. It also preserves ansi assignment in the change file and in fileOuts. Practically, this means that whenever you type := in a code editor, and accept it, you will see a left arrow, but the source file will preserve the ':='.

It does that by using the unicode character for left arrow (instead of hijacking the underscore), and rewriting that unicode character as := on write out. This is a tiny changeset (3 lines of code, basically), which I have made for my personal use, but I'm posting it here both for comments/ameliorations/criticisms, and in case it is useful to anyone. This is by far not an area of the image that I am familiar with, so I welcome criticism and pointers (and of course(I can package it for the inbox in case there is interest).

In order to benefit from this changeset, you must be using a font that has the unicode left arrow. The default fonts that come with squeak 4.2a don't have it, so you will need to install the FreeType package first and choose a font such as Times New Roman or Arial Unicode MS, etc. (To see a left arrow, do a PrintIt on 'Character value: 8592', and make sure that the chosen font is installed as the default code font (World Menu > appearances > system fonts > code font)).

Whenever I have a moment, I will add the up arrow, and also a preference for converting underscore assignments to true unicode left arrows. If there is interest, I will post that too.

Michal
-------------- next part --------------
'From Squeak4.2alpha of 22 September 2010 [latest update: #10548] on 3 October 2010 at 4:28:37 pm'!
"Change Set:		trueLeftArrowModest
Date:			3 October 2010
Author:			mist

Display a left arrow for assignment, using the appropriate unicode character and without hacking underscores. Also preserve ansi assignment in the change file and in fileOuts, making the arrow is a purely visual/ethetic effect.

This is done by 3 lines of change:
1. tell shout to replace := with the appropriate unicode character (in #convertAssignmentsToLeftArrow:)
2. tell the scanner that the unicode arrow is a valid assignment character (in #typeTableAt:)
3. tell the fileOut code to convert the unicode arrow into := (in #logMethodSource:forMethodWithNode:inCategory:withStamp:notifying:)
"!


!ClassDescription methodsFor: 'private' stamp: 'mist 10/3/2010 15:42'!
logMethodSource: aText forMethodWithNode: aCompiledMethodWithNode inCategory: category withStamp: changeStamp notifying: requestor
	| priorMethodOrNil newText |
	priorMethodOrNil := self compiledMethodAt: aCompiledMethodWithNode selector ifAbsent: [].
	newText := (requestor notNil
						and: [Preferences confirmFirstUseOfStyle])
			ifTrue: [aText askIfAddStyle: priorMethodOrNil req: requestor]
			ifFalse: [aText].
	(newText indexOf: (Character value: 8592)) > 0 ifTrue: [
		newText := newText copyReplaceTokens: (Character value: 8592) asString with: ':='].
	aCompiledMethodWithNode method putSource: newText
		fromParseNode: aCompiledMethodWithNode node
		class: self category: category withStamp: changeStamp 
		inFile: 2 priorMethod: priorMethodOrNil.! !


!SHTextStylerST80 methodsFor: 'private' stamp: 'mist 10/3/2010 12:38'!
convertAssignmentsToLeftArrow: aText
	"If the Preference is to show leftArrowAssignments then answer a copy of  <aText> where each ansi assignment (:=) is replaced with a left arrow. A parser is used so that each ':=' is only replaced if it actually occurs within an assigment statement"

	^self replaceStringForRangesWithType: #ansiAssignment with: (Character value: 8592) asString in: aText! !


!Scanner methodsFor: 'multi-character scans' stamp: 'mist 10/3/2010 13:29'!
typeTableAt: aCharacter
	aCharacter charCode == 8592 ifTrue: [^#xUnderscore].
	^typeTable at: aCharacter charCode ifAbsent:[#xLetter]! !

"Postscript:
"

Preferences setPreference: #syntaxHighlightingAsYouTypeLeftArrowAssignment toValue: true.
!



More information about the Squeak-dev mailing list