718
|
1 |
"*
|
|
2 |
* Encoding: iso8859-1
|
|
3 |
*
|
|
4 |
* $Header$
|
|
5 |
*
|
|
6 |
* MIMEType: application/x-smalltalk-source
|
|
7 |
*
|
|
8 |
* sample keyboardMacros.rc - file
|
|
9 |
*
|
|
10 |
* this file defines some keyboard macros
|
|
11 |
* Feel free to add your own.
|
|
12 |
* Here, only the macro-codes are defined;
|
|
13 |
* the actual binding of macro to a particular key is done in keyboard.rc.
|
|
14 |
*
|
|
15 |
* these are my personal preferrences which may not be
|
|
16 |
* correct for your environment.
|
|
17 |
*
|
|
18 |
* WARNING:
|
|
19 |
* please keep the expressions below free from manipulating
|
|
20 |
* global state.
|
|
21 |
* Reason: in multihead applications, this will be consulted for each
|
|
22 |
* new display screen.
|
|
23 |
*"
|
|
24 |
|
|
25 |
|macros|
|
|
26 |
|
|
27 |
macros := UserPreferences current functionKeySequences.
|
|
28 |
|
|
29 |
"/
|
|
30 |
"/ macro to replace a text selection by unix commands output
|
|
31 |
"/
|
|
32 |
macros at:#ReplaceSelectionByUnixCommandsOutput put:'
|
|
33 |
"replace selection by corresponding
|
|
34 |
unix commands output"
|
|
35 |
|
|
36 |
|sel|
|
|
37 |
|
|
38 |
sel := self selection.
|
|
39 |
sel notNil ifTrue:[
|
|
40 |
self replace:
|
|
41 |
(PipeStream readingFrom:(sel asString))
|
|
42 |
contents asString
|
|
43 |
]
|
|
44 |
'.
|
|
45 |
|
|
46 |
"/
|
|
47 |
"/ macro to paste the text generated by a block
|
|
48 |
"/
|
|
49 |
"/macros at:#PasteBlockEvaluationsOutput put:'
|
|
50 |
"/ "replace selection by blocks output"
|
|
51 |
"/
|
|
52 |
"/ |sel s block|
|
|
53 |
"/
|
|
54 |
"/ sel := self selectionAsString.
|
|
55 |
"/ sel notNil ifTrue:[
|
|
56 |
"/ block := Compiler evaluate:sel asString string.
|
|
57 |
"/ s := '''' writeStream.
|
|
58 |
"/ block value:s.
|
|
59 |
"/ self paste:s contents asString
|
|
60 |
"/ ]
|
|
61 |
"/'.
|
|
62 |
|
|
63 |
"/
|
|
64 |
"/ macro to toggle tabs
|
|
65 |
"/
|
|
66 |
macros at:#ToggleTabs put:'
|
|
67 |
"toggle between 4-col
|
|
68 |
and 8-col tabs"
|
|
69 |
|
|
70 |
(tabPositions == self class tab4Positions)
|
|
71 |
ifTrue:[self setTab8]
|
|
72 |
ifFalse:[self setTab4]
|
|
73 |
'.
|
|
74 |
|
|
75 |
"/
|
|
76 |
"/ macro to indent by 4
|
|
77 |
"/
|
|
78 |
macros at:#IndentBy4 put:'
|
|
79 |
"indent selected line-range
|
|
80 |
by 4 spaces (i.e. to the right)"
|
|
81 |
|
|
82 |
|line1 line2|
|
|
83 |
|
|
84 |
line1 := self selectionStartLine.
|
|
85 |
line2 := self selectionEndLine.
|
|
86 |
line1 isNil ifTrue:[
|
|
87 |
line1 := self perform:#cursorLine ifNotUnderstood:nil.
|
|
88 |
line1 notNil ifTrue:[
|
|
89 |
line2 := line1+1
|
|
90 |
]
|
|
91 |
].
|
|
92 |
line1 notNil ifTrue:[
|
|
93 |
self withExecuteCursorDo:[
|
|
94 |
line1 to:line2-1 do:[:lineNr |
|
|
95 |
|line|
|
|
96 |
|
|
97 |
line := self listAt:lineNr.
|
|
98 |
line notNil ifTrue:[
|
|
99 |
line notEmpty ifTrue:[
|
|
100 |
line := '' '' , line.
|
|
101 |
self withoutRedrawAt:lineNr put:line.
|
|
102 |
]
|
|
103 |
]
|
|
104 |
].
|
|
105 |
self textChanged.
|
|
106 |
line1 to:line2-1 do:[:lineNr |
|
|
107 |
self invalidateLine:lineNr.
|
|
108 |
].
|
|
109 |
].
|
|
110 |
]
|
|
111 |
'.
|
|
112 |
|
|
113 |
"/
|
|
114 |
"/ macro to undent by 4
|
|
115 |
"/
|
|
116 |
macros at:#UndentBy4 put:'
|
|
117 |
"undent selected line-range
|
|
118 |
by 4 spaces (i.e. to the left)"
|
|
119 |
|
|
120 |
|line1 line2|
|
|
121 |
|
|
122 |
line1 := self selectionStartLine.
|
|
123 |
line2 := self selectionEndLine.
|
|
124 |
line1 isNil ifTrue:[
|
|
125 |
line1 := self perform:#cursorLine ifNotUnderstood:nil.
|
|
126 |
line1 notNil ifTrue:[
|
|
127 |
line2 := line1+1
|
|
128 |
]
|
|
129 |
].
|
|
130 |
line1 notNil ifTrue:[
|
|
131 |
self withExecuteCursorDo:[
|
|
132 |
line1 to:line2-1 do:[:lineNr |
|
|
133 |
|line|
|
|
134 |
|
|
135 |
line := self listAt:lineNr.
|
|
136 |
line notNil ifTrue:[
|
|
137 |
line notEmpty ifTrue:[
|
|
138 |
(line startsWith:'' '') ifTrue:[
|
|
139 |
line := line copyFrom:5.
|
|
140 |
self withoutRedrawAt:lineNr put:line.
|
|
141 |
]
|
|
142 |
]
|
|
143 |
]
|
|
144 |
].
|
|
145 |
self textChanged.
|
|
146 |
line1 to:line2-1 do:[:lineNr |
|
|
147 |
self invalidateLine:lineNr.
|
|
148 |
].
|
|
149 |
].
|
|
150 |
]
|
|
151 |
'.
|
|
152 |
|
|
153 |
"/
|
|
154 |
"/ macro to indent by 1
|
|
155 |
"/
|
|
156 |
macros at:#IndentBy1 put:'
|
|
157 |
"indent selected line-range
|
|
158 |
by 1 space (i.e. to the right)"
|
|
159 |
|
|
160 |
|line1 line2|
|
|
161 |
|
|
162 |
line1 := self selectionStartLine.
|
|
163 |
line2 := self selectionEndLine.
|
|
164 |
line1 isNil ifTrue:[
|
|
165 |
line1 := self perform:#cursorLine ifNotUnderstood:nil.
|
|
166 |
line1 notNil ifTrue:[
|
|
167 |
line2 := line1+1
|
|
168 |
]
|
|
169 |
].
|
|
170 |
line1 notNil ifTrue:[
|
|
171 |
self withExecuteCursorDo:[
|
|
172 |
line1 to:line2-1 do:[:lineNr |
|
|
173 |
|line|
|
|
174 |
|
|
175 |
line := self listAt:lineNr.
|
|
176 |
line notNil ifTrue:[
|
|
177 |
line notEmpty ifTrue:[
|
|
178 |
line := '' '' , line.
|
|
179 |
self withoutRedrawAt:lineNr put:line.
|
|
180 |
]
|
|
181 |
]
|
|
182 |
].
|
|
183 |
self textChanged.
|
|
184 |
line1 to:line2-1 do:[:lineNr |
|
|
185 |
self invalidateLine:lineNr.
|
|
186 |
].
|
|
187 |
]
|
|
188 |
]
|
|
189 |
'.
|
|
190 |
|
|
191 |
"/
|
|
192 |
"/ macro to undent by 1
|
|
193 |
"/
|
|
194 |
macros at:#UndentBy1 put:'
|
|
195 |
"undent selected line-range
|
|
196 |
by 1 space (i.e. to the left)"
|
|
197 |
|
|
198 |
|line1 line2|
|
|
199 |
|
|
200 |
line1 := self selectionStartLine.
|
|
201 |
line2 := self selectionEndLine.
|
|
202 |
line1 isNil ifTrue:[
|
|
203 |
line1 := self perform:#cursorLine ifNotUnderstood:nil.
|
|
204 |
line1 notNil ifTrue:[
|
|
205 |
line2 := line1+1
|
|
206 |
]
|
|
207 |
].
|
|
208 |
line1 notNil ifTrue:[
|
|
209 |
self withExecuteCursorDo:[
|
|
210 |
line1 to:line2-1 do:[:lineNr |
|
|
211 |
|line|
|
|
212 |
|
|
213 |
line := self listAt:lineNr.
|
|
214 |
line notNil ifTrue:[
|
|
215 |
line notEmpty ifTrue:[
|
|
216 |
(line startsWith:'' '') ifTrue:[
|
|
217 |
line := line copyFrom:2.
|
|
218 |
self withoutRedrawAt:lineNr put:line.
|
|
219 |
]
|
|
220 |
]
|
|
221 |
]
|
|
222 |
].
|
|
223 |
self textChanged.
|
|
224 |
line1 to:line2-1 do:[:lineNr |
|
|
225 |
self invalidateLine:lineNr.
|
|
226 |
].
|
|
227 |
].
|
|
228 |
]
|
|
229 |
'.
|
|
230 |
|
|
231 |
"/
|
|
232 |
"/ macro to convert selection to lowercase
|
|
233 |
"/
|
|
234 |
macros at:#ConvertSelectionToLowercase put:'
|
|
235 |
"to-lower selected text"
|
|
236 |
|
|
237 |
|line1 line2|
|
|
238 |
|
|
239 |
line1 := self selectionStartLine.
|
|
240 |
line2 := self selectionEndLine.
|
|
241 |
line1 isNil ifTrue:[
|
|
242 |
line1 := self perform:#cursorLine ifNotUnderstood:nil.
|
|
243 |
line1 notNil ifTrue:[
|
|
244 |
line2 := line1
|
|
245 |
]
|
|
246 |
].
|
|
247 |
line1 notNil ifTrue:[
|
|
248 |
line1 to:line2 do:[:lineNr |
|
|
249 |
|line col1 col2|
|
|
250 |
|
|
251 |
line := (self listAt:lineNr) copy.
|
|
252 |
line size > 0 ifTrue:[
|
|
253 |
lineNr == line1 ifTrue:[
|
|
254 |
col1 := selectionStartCol.
|
|
255 |
] ifFalse:[
|
|
256 |
col1 := 1.
|
|
257 |
].
|
|
258 |
lineNr == line2 ifTrue:[
|
|
259 |
col2 := selectionEndCol.
|
|
260 |
] ifFalse:[
|
|
261 |
col2 := (self listAt:lineNr) size.
|
|
262 |
].
|
|
263 |
|
|
264 |
col1 to:col2 do:[:col |
|
|
265 |
|ch|
|
|
266 |
|
|
267 |
ch := line at:col.
|
|
268 |
line at:col put:ch asLowercase.
|
|
269 |
].
|
|
270 |
self withoutRedrawAt:lineNr put:line.
|
|
271 |
self invalidateLine:lineNr.
|
|
272 |
].
|
|
273 |
].
|
|
274 |
]
|
|
275 |
'.
|
|
276 |
|
|
277 |
"/
|
|
278 |
"/ macro to convert selection to uppercaseFirst words
|
|
279 |
"/
|
|
280 |
macros at:#ConvertSelectionToUppercaseFirst put:'
|
|
281 |
"to-lower selected text"
|
|
282 |
|
|
283 |
|line1 line2|
|
|
284 |
|
|
285 |
line1 := self selectionStartLine.
|
|
286 |
line2 := self selectionEndLine.
|
|
287 |
line1 isNil ifTrue:[
|
|
288 |
line1 := self perform:#cursorLine ifNotUnderstood:nil.
|
|
289 |
line1 notNil ifTrue:[
|
|
290 |
line2 := line1
|
|
291 |
]
|
|
292 |
].
|
|
293 |
line1 notNil ifTrue:[
|
|
294 |
line1 to:line2 do:[:lineNr |
|
|
295 |
|line col1 col2 state|
|
|
296 |
|
|
297 |
line := (self listAt:lineNr) copy.
|
|
298 |
line size > 0 ifTrue:[
|
|
299 |
lineNr == line1 ifTrue:[
|
|
300 |
col1 := selectionStartCol.
|
|
301 |
] ifFalse:[
|
|
302 |
col1 := 1.
|
|
303 |
].
|
|
304 |
lineNr == line2 ifTrue:[
|
|
305 |
col2 := selectionEndCol.
|
|
306 |
] ifFalse:[
|
|
307 |
col2 := (self listAt:lineNr) size.
|
|
308 |
].
|
|
309 |
|
|
310 |
state := #first.
|
|
311 |
col1 to:col2 do:[:col |
|
|
312 |
|ch|
|
|
313 |
|
|
314 |
ch := line at:col.
|
|
315 |
ch isSeparator ifFalse:[
|
|
316 |
state == #first ifTrue:[
|
|
317 |
line at:col put:ch asUppercase.
|
|
318 |
state := #skipRest
|
|
319 |
]
|
|
320 |
] ifTrue:[
|
|
321 |
state := #first
|
|
322 |
]
|
|
323 |
].
|
|
324 |
self withoutRedrawAt:lineNr put:line.
|
|
325 |
self invalidateLine:lineNr.
|
|
326 |
].
|
|
327 |
].
|
|
328 |
]
|
|
329 |
'.
|
|
330 |
|
|
331 |
macros at:#ConvertSelectionToUppercase put:'
|
|
332 |
"to-lower selected text"
|
|
333 |
|
|
334 |
|line1 line2|
|
|
335 |
|
|
336 |
line1 := self selectionStartLine.
|
|
337 |
line2 := self selectionEndLine.
|
|
338 |
line1 isNil ifTrue:[
|
|
339 |
line1 := self perform:#cursorLine ifNotUnderstood:nil.
|
|
340 |
line1 notNil ifTrue:[
|
|
341 |
line2 := line1
|
|
342 |
]
|
|
343 |
].
|
|
344 |
line1 notNil ifTrue:[
|
|
345 |
line1 to:line2 do:[:lineNr |
|
|
346 |
|line col1 col2|
|
|
347 |
|
|
348 |
line := (self listAt:lineNr) copy.
|
|
349 |
line size > 0 ifTrue:[
|
|
350 |
lineNr == line1 ifTrue:[
|
|
351 |
col1 := selectionStartCol.
|
|
352 |
] ifFalse:[
|
|
353 |
col1 := 1.
|
|
354 |
].
|
|
355 |
lineNr == line2 ifTrue:[
|
|
356 |
col2 := selectionEndCol.
|
|
357 |
] ifFalse:[
|
|
358 |
col2 := (self listAt:lineNr) size.
|
|
359 |
].
|
|
360 |
|
|
361 |
col1 to:col2 do:[:col |
|
|
362 |
|ch|
|
|
363 |
|
|
364 |
ch := line at:col.
|
|
365 |
line at:col put:ch asUppercase.
|
|
366 |
].
|
|
367 |
self withoutRedrawAt:lineNr put:line.
|
|
368 |
self invalidateLine:lineNr.
|
|
369 |
].
|
|
370 |
].
|
|
371 |
]
|
|
372 |
'.
|
|
373 |
|
726
|
374 |
macros at:#ConvertSelectionToLowercaseOrUppercaseOrUppercaseFirst put:'
|
|
375 |
"to-lower selected text"
|
|
376 |
|
|
377 |
|line1 line2|
|
|
378 |
|
|
379 |
line1 := self selectionStartLine.
|
|
380 |
line2 := self selectionEndLine.
|
|
381 |
line1 isNil ifTrue:[
|
|
382 |
line1 := self perform:#cursorLine ifNotUnderstood:nil.
|
|
383 |
line1 notNil ifTrue:[
|
|
384 |
line2 := line1
|
|
385 |
]
|
|
386 |
].
|
|
387 |
line1 notNil ifTrue:[
|
|
388 |
line1 to:line2 do:[:lineNr |
|
|
389 |
|line col1 col2 isAllLower isAllUpper isUpperFirst
|
|
390 |
makeLowercase makeUppercase makeUppercaseFirst|
|
|
391 |
|
|
392 |
line := (self listAt:lineNr) copy.
|
|
393 |
line size > 0 ifTrue:[
|
|
394 |
lineNr == line1 ifTrue:[
|
|
395 |
col1 := selectionStartCol.
|
|
396 |
] ifFalse:[
|
|
397 |
col1 := 1.
|
|
398 |
].
|
|
399 |
lineNr == line2 ifTrue:[
|
|
400 |
col2 := selectionEndCol.
|
|
401 |
] ifFalse:[
|
|
402 |
col2 := (self listAt:lineNr) size.
|
|
403 |
].
|
|
404 |
isAllLower := isAllUpper := isUpperFirst := true.
|
|
405 |
col1 to:col2 do:[:col |
|
|
406 |
|ch|
|
|
407 |
|
|
408 |
ch := line at:col.
|
|
409 |
ch isUppercase ifTrue:[
|
|
410 |
isAllLower := false.
|
|
411 |
col ~~ col1 ifTrue:[
|
|
412 |
isUpperFirst := false.
|
|
413 |
].
|
|
414 |
] ifFalse:[
|
|
415 |
ch isLowercase ifTrue:[
|
|
416 |
isAllUpper := false.
|
|
417 |
col == col1 ifTrue:[
|
|
418 |
isUpperFirst := false.
|
|
419 |
].
|
|
420 |
]
|
|
421 |
].
|
|
422 |
].
|
|
423 |
makeLowercase := makeUppercase := makeUppercaseFirst := false.
|
|
424 |
isAllLower ifTrue:[
|
729
|
425 |
makeUppercase := true.
|
726
|
426 |
] ifFalse:[
|
729
|
427 |
isAllUpper ifTrue:[
|
|
428 |
makeUppercaseFirst := true.
|
726
|
429 |
] ifFalse:[
|
|
430 |
makeLowercase := true.
|
|
431 |
]
|
|
432 |
].
|
|
433 |
col1 to:col2 do:[:col |
|
|
434 |
|ch|
|
|
435 |
|
|
436 |
ch := line at:col.
|
|
437 |
ch := makeLowercase
|
|
438 |
ifTrue:[ ch asLowercase ]
|
|
439 |
ifFalse:[
|
|
440 |
makeUppercase
|
|
441 |
ifTrue:[ ch asUppercase ]
|
|
442 |
ifFalse:[
|
|
443 |
col == col1
|
|
444 |
ifTrue:[ ch asUppercase ]
|
|
445 |
ifFalse:[ ch asLowercase ]
|
|
446 |
]
|
|
447 |
].
|
|
448 |
line at:col put:ch.
|
|
449 |
].
|
|
450 |
self withoutRedrawAt:lineNr put:line.
|
|
451 |
self invalidateLine:lineNr.
|
|
452 |
].
|
|
453 |
].
|
|
454 |
]
|
|
455 |
'.
|
|
456 |
|
718
|
457 |
macros at:#ParenthizeSelection put:'
|
|
458 |
"place parenthesis around the selected text"
|
|
459 |
|
|
460 |
|line1 col1 line2 col2|
|
|
461 |
|
|
462 |
line1 := self selectionStartLine.
|
|
463 |
col1 := self selectionStartCol.
|
|
464 |
line2 := self selectionEndLine.
|
|
465 |
col2 := self selectionEndCol.
|
|
466 |
(line1 notNil
|
|
467 |
and:[ col1 notNil
|
|
468 |
and:[ line2 notNil
|
|
469 |
and:[ col2 notNil ]]])
|
|
470 |
ifTrue:[
|
|
471 |
self insertString:'')'' atLine:line2 col:col2+1.
|
|
472 |
self insertString:''('' atLine:line1 col:col1.
|
|
473 |
self selectFromLine:line1 col:col1 toLine:line2 col:col2+2.
|
|
474 |
] ifFalse:[
|
|
475 |
self beep.
|
|
476 |
]
|
|
477 |
'.
|
|
478 |
|
|
479 |
macros at:#UnparenthizeSelection put:'
|
|
480 |
"remove parenthesis in the selected text"
|
|
481 |
|
|
482 |
|line1 col1 line2 col2|
|
|
483 |
|
|
484 |
line1 := self selectionStartLine.
|
|
485 |
col1 := self selectionStartCol.
|
|
486 |
line2 := self selectionEndLine.
|
|
487 |
col2 := self selectionEndCol.
|
|
488 |
(line1 notNil
|
|
489 |
and:[ col1 notNil
|
|
490 |
and:[ line2 notNil
|
|
491 |
and:[ col2 notNil
|
|
492 |
and:[ (''({[<'' includes:(self characterAtLine:line1 col:col1))
|
|
493 |
and:[ (''>]})'' includes:(self characterAtLine:line2 col:col2)) ]]]]])
|
|
494 |
ifTrue:[
|
|
495 |
self deleteCharAtLine:line2 col:col2.
|
|
496 |
self deleteCharAtLine:line1 col:col1.
|
|
497 |
self selectFromLine:line1 col:col1 toLine:line2 col:col2-2.
|
|
498 |
] ifFalse:[
|
|
499 |
self beep.
|
|
500 |
]
|
|
501 |
'.
|
|
502 |
|
720
|
503 |
"/macros keys do:[:k |
|
|
504 |
"/ Transcript showCR:k.
|
|
505 |
"/].
|
718
|
506 |
!
|