--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/keyboardMacros.rc Thu Oct 12 19:20:12 2006 +0200
@@ -0,0 +1,423 @@
+"*
+ * Encoding: iso8859-1
+ *
+ * $Header$
+ *
+ * MIMEType: application/x-smalltalk-source
+ *
+ * sample keyboardMacros.rc - file
+ *
+ * this file defines some keyboard macros
+ * Feel free to add your own.
+ * Here, only the macro-codes are defined;
+ * the actual binding of macro to a particular key is done in keyboard.rc.
+ *
+ * these are my personal preferrences which may not be
+ * correct for your environment.
+ *
+ * WARNING:
+ * please keep the expressions below free from manipulating
+ * global state.
+ * Reason: in multihead applications, this will be consulted for each
+ * new display screen.
+ *"
+
+|macros|
+
+macros := UserPreferences current functionKeySequences.
+
+"/
+"/ macro to replace a text selection by unix commands output
+"/
+macros at:#ReplaceSelectionByUnixCommandsOutput put:'
+ "replace selection by corresponding
+ unix commands output"
+
+ |sel|
+
+ sel := self selection.
+ sel notNil ifTrue:[
+ self replace:
+ (PipeStream readingFrom:(sel asString))
+ contents asString
+ ]
+'.
+
+"/
+"/ macro to paste the text generated by a block
+"/
+"/macros at:#PasteBlockEvaluationsOutput put:'
+"/ "replace selection by blocks output"
+"/
+"/ |sel s block|
+"/
+"/ sel := self selectionAsString.
+"/ sel notNil ifTrue:[
+"/ block := Compiler evaluate:sel asString string.
+"/ s := '''' writeStream.
+"/ block value:s.
+"/ self paste:s contents asString
+"/ ]
+"/'.
+
+"/
+"/ macro to toggle tabs
+"/
+macros at:#ToggleTabs put:'
+ "toggle between 4-col
+ and 8-col tabs"
+
+ (tabPositions == self class tab4Positions)
+ ifTrue:[self setTab8]
+ ifFalse:[self setTab4]
+'.
+
+"/
+"/ macro to indent by 4
+"/
+macros at:#IndentBy4 put:'
+ "indent selected line-range
+ by 4 spaces (i.e. to the right)"
+
+ |line1 line2|
+
+ line1 := self selectionStartLine.
+ line2 := self selectionEndLine.
+ line1 isNil ifTrue:[
+ line1 := self perform:#cursorLine ifNotUnderstood:nil.
+ line1 notNil ifTrue:[
+ line2 := line1+1
+ ]
+ ].
+ line1 notNil ifTrue:[
+ self withExecuteCursorDo:[
+ line1 to:line2-1 do:[:lineNr |
+ |line|
+
+ line := self listAt:lineNr.
+ line notNil ifTrue:[
+ line notEmpty ifTrue:[
+ line := '' '' , line.
+ self withoutRedrawAt:lineNr put:line.
+ ]
+ ]
+ ].
+ self textChanged.
+ line1 to:line2-1 do:[:lineNr |
+ self invalidateLine:lineNr.
+ ].
+ ].
+ ]
+'.
+
+"/
+"/ macro to undent by 4
+"/
+macros at:#UndentBy4 put:'
+ "undent selected line-range
+ by 4 spaces (i.e. to the left)"
+
+ |line1 line2|
+
+ line1 := self selectionStartLine.
+ line2 := self selectionEndLine.
+ line1 isNil ifTrue:[
+ line1 := self perform:#cursorLine ifNotUnderstood:nil.
+ line1 notNil ifTrue:[
+ line2 := line1+1
+ ]
+ ].
+ line1 notNil ifTrue:[
+ self withExecuteCursorDo:[
+ line1 to:line2-1 do:[:lineNr |
+ |line|
+
+ line := self listAt:lineNr.
+ line notNil ifTrue:[
+ line notEmpty ifTrue:[
+ (line startsWith:'' '') ifTrue:[
+ line := line copyFrom:5.
+ self withoutRedrawAt:lineNr put:line.
+ ]
+ ]
+ ]
+ ].
+ self textChanged.
+ line1 to:line2-1 do:[:lineNr |
+ self invalidateLine:lineNr.
+ ].
+ ].
+ ]
+'.
+
+"/
+"/ macro to indent by 1
+"/
+macros at:#IndentBy1 put:'
+ "indent selected line-range
+ by 1 space (i.e. to the right)"
+
+ |line1 line2|
+
+ line1 := self selectionStartLine.
+ line2 := self selectionEndLine.
+ line1 isNil ifTrue:[
+ line1 := self perform:#cursorLine ifNotUnderstood:nil.
+ line1 notNil ifTrue:[
+ line2 := line1+1
+ ]
+ ].
+ line1 notNil ifTrue:[
+ self withExecuteCursorDo:[
+ line1 to:line2-1 do:[:lineNr |
+ |line|
+
+ line := self listAt:lineNr.
+ line notNil ifTrue:[
+ line notEmpty ifTrue:[
+ line := '' '' , line.
+ self withoutRedrawAt:lineNr put:line.
+ ]
+ ]
+ ].
+ self textChanged.
+ line1 to:line2-1 do:[:lineNr |
+ self invalidateLine:lineNr.
+ ].
+ ]
+ ]
+'.
+
+"/
+"/ macro to undent by 1
+"/
+macros at:#UndentBy1 put:'
+ "undent selected line-range
+ by 1 space (i.e. to the left)"
+
+ |line1 line2|
+
+ line1 := self selectionStartLine.
+ line2 := self selectionEndLine.
+ line1 isNil ifTrue:[
+ line1 := self perform:#cursorLine ifNotUnderstood:nil.
+ line1 notNil ifTrue:[
+ line2 := line1+1
+ ]
+ ].
+ line1 notNil ifTrue:[
+ self withExecuteCursorDo:[
+ line1 to:line2-1 do:[:lineNr |
+ |line|
+
+ line := self listAt:lineNr.
+ line notNil ifTrue:[
+ line notEmpty ifTrue:[
+ (line startsWith:'' '') ifTrue:[
+ line := line copyFrom:2.
+ self withoutRedrawAt:lineNr put:line.
+ ]
+ ]
+ ]
+ ].
+ self textChanged.
+ line1 to:line2-1 do:[:lineNr |
+ self invalidateLine:lineNr.
+ ].
+ ].
+ ]
+'.
+
+"/
+"/ macro to convert selection to lowercase
+"/
+macros at:#ConvertSelectionToLowercase put:'
+ "to-lower selected text"
+
+ |line1 line2|
+
+ line1 := self selectionStartLine.
+ line2 := self selectionEndLine.
+ line1 isNil ifTrue:[
+ line1 := self perform:#cursorLine ifNotUnderstood:nil.
+ line1 notNil ifTrue:[
+ line2 := line1
+ ]
+ ].
+ line1 notNil ifTrue:[
+ line1 to:line2 do:[:lineNr |
+ |line col1 col2|
+
+ line := (self listAt:lineNr) copy.
+ line size > 0 ifTrue:[
+ lineNr == line1 ifTrue:[
+ col1 := selectionStartCol.
+ ] ifFalse:[
+ col1 := 1.
+ ].
+ lineNr == line2 ifTrue:[
+ col2 := selectionEndCol.
+ ] ifFalse:[
+ col2 := (self listAt:lineNr) size.
+ ].
+
+ col1 to:col2 do:[:col |
+ |ch|
+
+ ch := line at:col.
+ line at:col put:ch asLowercase.
+ ].
+ self withoutRedrawAt:lineNr put:line.
+ self invalidateLine:lineNr.
+ ].
+ ].
+ ]
+'.
+
+"/
+"/ macro to convert selection to uppercaseFirst words
+"/
+macros at:#ConvertSelectionToUppercaseFirst put:'
+ "to-lower selected text"
+
+ |line1 line2|
+
+ line1 := self selectionStartLine.
+ line2 := self selectionEndLine.
+ line1 isNil ifTrue:[
+ line1 := self perform:#cursorLine ifNotUnderstood:nil.
+ line1 notNil ifTrue:[
+ line2 := line1
+ ]
+ ].
+ line1 notNil ifTrue:[
+ line1 to:line2 do:[:lineNr |
+ |line col1 col2 state|
+
+ line := (self listAt:lineNr) copy.
+ line size > 0 ifTrue:[
+ lineNr == line1 ifTrue:[
+ col1 := selectionStartCol.
+ ] ifFalse:[
+ col1 := 1.
+ ].
+ lineNr == line2 ifTrue:[
+ col2 := selectionEndCol.
+ ] ifFalse:[
+ col2 := (self listAt:lineNr) size.
+ ].
+
+ state := #first.
+ col1 to:col2 do:[:col |
+ |ch|
+
+ ch := line at:col.
+ ch isSeparator ifFalse:[
+ state == #first ifTrue:[
+ line at:col put:ch asUppercase.
+ state := #skipRest
+ ]
+ ] ifTrue:[
+ state := #first
+ ]
+ ].
+ self withoutRedrawAt:lineNr put:line.
+ self invalidateLine:lineNr.
+ ].
+ ].
+ ]
+'.
+
+macros at:#ConvertSelectionToUppercase put:'
+ "to-lower selected text"
+
+ |line1 line2|
+
+ line1 := self selectionStartLine.
+ line2 := self selectionEndLine.
+ line1 isNil ifTrue:[
+ line1 := self perform:#cursorLine ifNotUnderstood:nil.
+ line1 notNil ifTrue:[
+ line2 := line1
+ ]
+ ].
+ line1 notNil ifTrue:[
+ line1 to:line2 do:[:lineNr |
+ |line col1 col2|
+
+ line := (self listAt:lineNr) copy.
+ line size > 0 ifTrue:[
+ lineNr == line1 ifTrue:[
+ col1 := selectionStartCol.
+ ] ifFalse:[
+ col1 := 1.
+ ].
+ lineNr == line2 ifTrue:[
+ col2 := selectionEndCol.
+ ] ifFalse:[
+ col2 := (self listAt:lineNr) size.
+ ].
+
+ col1 to:col2 do:[:col |
+ |ch|
+
+ ch := line at:col.
+ line at:col put:ch asUppercase.
+ ].
+ self withoutRedrawAt:lineNr put:line.
+ self invalidateLine:lineNr.
+ ].
+ ].
+ ]
+'.
+
+macros at:#ParenthizeSelection put:'
+ "place parenthesis around the selected text"
+
+ |line1 col1 line2 col2|
+
+ line1 := self selectionStartLine.
+ col1 := self selectionStartCol.
+ line2 := self selectionEndLine.
+ col2 := self selectionEndCol.
+ (line1 notNil
+ and:[ col1 notNil
+ and:[ line2 notNil
+ and:[ col2 notNil ]]])
+ ifTrue:[
+ self insertString:'')'' atLine:line2 col:col2+1.
+ self insertString:''('' atLine:line1 col:col1.
+ self selectFromLine:line1 col:col1 toLine:line2 col:col2+2.
+ ] ifFalse:[
+ self beep.
+ ]
+'.
+
+macros at:#UnparenthizeSelection put:'
+ "remove parenthesis in the selected text"
+
+ |line1 col1 line2 col2|
+
+ line1 := self selectionStartLine.
+ col1 := self selectionStartCol.
+ line2 := self selectionEndLine.
+ col2 := self selectionEndCol.
+ (line1 notNil
+ and:[ col1 notNil
+ and:[ line2 notNil
+ and:[ col2 notNil
+ and:[ (''({[<'' includes:(self characterAtLine:line1 col:col1))
+ and:[ (''>]})'' includes:(self characterAtLine:line2 col:col2)) ]]]]])
+ ifTrue:[
+ self deleteCharAtLine:line2 col:col2.
+ self deleteCharAtLine:line1 col:col1.
+ self selectFromLine:line1 col:col1 toLine:line2 col:col2-2.
+ ] ifFalse:[
+ self beep.
+ ]
+'.
+
+macros keys do:[:k |
+ Transcript showCR:k.
+].
+!