author | Claus Gittinger <cg@exept.de> |
Tue, 29 Sep 2009 18:01:18 +0200 | |
changeset 1068 | fd1c4a3e86fc |
parent 936 | f0563e73619a |
child 1070 | d3525fab5c67 |
permissions | -rw-r--r-- |
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. |
|
1068
fd1c4a3e86fc
F6 when only a single col is selected.
Claus Gittinger <cg@exept.de>
parents:
936
diff
changeset
|
405 |
col1 = col2 ifTrue:[ |
fd1c4a3e86fc
F6 when only a single col is selected.
Claus Gittinger <cg@exept.de>
parents:
936
diff
changeset
|
406 |
isAllLower := (line at:col1) isLowercase. |
fd1c4a3e86fc
F6 when only a single col is selected.
Claus Gittinger <cg@exept.de>
parents:
936
diff
changeset
|
407 |
isAllUpper := isUpperFirst := isAllLower not. |
fd1c4a3e86fc
F6 when only a single col is selected.
Claus Gittinger <cg@exept.de>
parents:
936
diff
changeset
|
408 |
] ifFalse:[ |
fd1c4a3e86fc
F6 when only a single col is selected.
Claus Gittinger <cg@exept.de>
parents:
936
diff
changeset
|
409 |
col1 to:col2 do:[:col | |
fd1c4a3e86fc
F6 when only a single col is selected.
Claus Gittinger <cg@exept.de>
parents:
936
diff
changeset
|
410 |
|ch| |
726 | 411 |
|
1068
fd1c4a3e86fc
F6 when only a single col is selected.
Claus Gittinger <cg@exept.de>
parents:
936
diff
changeset
|
412 |
ch := line at:col. |
fd1c4a3e86fc
F6 when only a single col is selected.
Claus Gittinger <cg@exept.de>
parents:
936
diff
changeset
|
413 |
ch isUppercase ifTrue:[ |
fd1c4a3e86fc
F6 when only a single col is selected.
Claus Gittinger <cg@exept.de>
parents:
936
diff
changeset
|
414 |
isAllLower := false. |
fd1c4a3e86fc
F6 when only a single col is selected.
Claus Gittinger <cg@exept.de>
parents:
936
diff
changeset
|
415 |
col ~~ col1 ifTrue:[ |
726 | 416 |
isUpperFirst := false. |
417 |
]. |
|
1068
fd1c4a3e86fc
F6 when only a single col is selected.
Claus Gittinger <cg@exept.de>
parents:
936
diff
changeset
|
418 |
] ifFalse:[ |
fd1c4a3e86fc
F6 when only a single col is selected.
Claus Gittinger <cg@exept.de>
parents:
936
diff
changeset
|
419 |
ch isLowercase ifTrue:[ |
fd1c4a3e86fc
F6 when only a single col is selected.
Claus Gittinger <cg@exept.de>
parents:
936
diff
changeset
|
420 |
isAllUpper := false. |
fd1c4a3e86fc
F6 when only a single col is selected.
Claus Gittinger <cg@exept.de>
parents:
936
diff
changeset
|
421 |
col == col1 ifTrue:[ |
fd1c4a3e86fc
F6 when only a single col is selected.
Claus Gittinger <cg@exept.de>
parents:
936
diff
changeset
|
422 |
isUpperFirst := false. |
fd1c4a3e86fc
F6 when only a single col is selected.
Claus Gittinger <cg@exept.de>
parents:
936
diff
changeset
|
423 |
]. |
fd1c4a3e86fc
F6 when only a single col is selected.
Claus Gittinger <cg@exept.de>
parents:
936
diff
changeset
|
424 |
] |
fd1c4a3e86fc
F6 when only a single col is selected.
Claus Gittinger <cg@exept.de>
parents:
936
diff
changeset
|
425 |
]. |
726 | 426 |
]. |
427 |
]. |
|
428 |
makeLowercase := makeUppercase := makeUppercaseFirst := false. |
|
429 |
isAllLower ifTrue:[ |
|
729 | 430 |
makeUppercase := true. |
726 | 431 |
] ifFalse:[ |
1068
fd1c4a3e86fc
F6 when only a single col is selected.
Claus Gittinger <cg@exept.de>
parents:
936
diff
changeset
|
432 |
(isAllUpper and:[col1 ~= col2]) ifTrue:[ |
729 | 433 |
makeUppercaseFirst := true. |
726 | 434 |
] ifFalse:[ |
435 |
makeLowercase := true. |
|
436 |
] |
|
437 |
]. |
|
438 |
col1 to:col2 do:[:col | |
|
439 |
|ch| |
|
440 |
||
441 |
ch := line at:col. |
|
442 |
ch := makeLowercase |
|
443 |
ifTrue:[ ch asLowercase ] |
|
444 |
ifFalse:[ |
|
445 |
makeUppercase |
|
446 |
ifTrue:[ ch asUppercase ] |
|
447 |
ifFalse:[ |
|
448 |
col == col1 |
|
449 |
ifTrue:[ ch asUppercase ] |
|
450 |
ifFalse:[ ch asLowercase ] |
|
451 |
] |
|
452 |
]. |
|
453 |
line at:col put:ch. |
|
454 |
]. |
|
455 |
self withoutRedrawAt:lineNr put:line. |
|
456 |
self invalidateLine:lineNr. |
|
457 |
]. |
|
458 |
]. |
|
459 |
] |
|
460 |
'. |
|
461 |
||
718 | 462 |
macros at:#ParenthizeSelection put:' |
463 |
"place parenthesis around the selected text" |
|
464 |
||
465 |
|line1 col1 line2 col2| |
|
466 |
||
467 |
line1 := self selectionStartLine. |
|
468 |
col1 := self selectionStartCol. |
|
469 |
line2 := self selectionEndLine. |
|
470 |
col2 := self selectionEndCol. |
|
471 |
(line1 notNil |
|
472 |
and:[ col1 notNil |
|
473 |
and:[ line2 notNil |
|
474 |
and:[ col2 notNil ]]]) |
|
475 |
ifTrue:[ |
|
476 |
self insertString:'')'' atLine:line2 col:col2+1. |
|
477 |
self insertString:''('' atLine:line1 col:col1. |
|
478 |
self selectFromLine:line1 col:col1 toLine:line2 col:col2+2. |
|
479 |
] ifFalse:[ |
|
480 |
self beep. |
|
481 |
] |
|
482 |
'. |
|
483 |
||
484 |
macros at:#UnparenthizeSelection put:' |
|
485 |
"remove parenthesis in the selected text" |
|
486 |
||
487 |
|line1 col1 line2 col2| |
|
488 |
||
489 |
line1 := self selectionStartLine. |
|
490 |
col1 := self selectionStartCol. |
|
491 |
line2 := self selectionEndLine. |
|
492 |
col2 := self selectionEndCol. |
|
493 |
(line1 notNil |
|
494 |
and:[ col1 notNil |
|
495 |
and:[ line2 notNil |
|
496 |
and:[ col2 notNil |
|
497 |
and:[ (''({[<'' includes:(self characterAtLine:line1 col:col1)) |
|
498 |
and:[ (''>]})'' includes:(self characterAtLine:line2 col:col2)) ]]]]]) |
|
499 |
ifTrue:[ |
|
500 |
self deleteCharAtLine:line2 col:col2. |
|
501 |
self deleteCharAtLine:line1 col:col1. |
|
502 |
self selectFromLine:line1 col:col1 toLine:line2 col:col2-2. |
|
503 |
] ifFalse:[ |
|
504 |
self beep. |
|
505 |
] |
|
506 |
'. |
|
507 |
||
936 | 508 |
macros at:#SingleQuoteSelection put:' |
509 |
"place single quotes around the selected text" |
|
510 |
||
511 |
|line1 col1 line2 col2| |
|
512 |
||
513 |
line1 := self selectionStartLine. |
|
514 |
col1 := self selectionStartCol. |
|
515 |
line2 := self selectionEndLine. |
|
516 |
col2 := self selectionEndCol. |
|
517 |
(line1 notNil |
|
518 |
and:[ col1 notNil |
|
519 |
and:[ line2 notNil |
|
520 |
and:[ col2 notNil ]]]) |
|
521 |
ifTrue:[ |
|
522 |
self insertString:Character quote asString atLine:line2 col:col2+1. |
|
523 |
self insertString:Character quote asString atLine:line1 col:col1. |
|
524 |
self selectFromLine:line1 col:col1 toLine:line2 col:col2+2. |
|
525 |
] ifFalse:[ |
|
526 |
self beep. |
|
527 |
] |
|
528 |
'. |
|
529 |
||
720 | 530 |
"/macros keys do:[:k | |
531 |
"/ Transcript showCR:k. |
|
532 |
"/]. |
|
718 | 533 |
! |