-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScriptDebugger Library.applescript
More file actions
343 lines (297 loc) · 8.97 KB
/
ScriptDebugger Library.applescript
File metadata and controls
343 lines (297 loc) · 8.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
(*
--===============================================================================
Name: ScriptDebugger Library
Description: This library provides several useful editor functions for ScriptDebugger
Author: Kevin Funderburg
Revised: 10/19/18
Version: 1.0
--===============================================================================
*)
use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions
property name : "ScriptDebugger Library"
property id : "com.kfunderburg.library.scriptDebuggerLibrary"
property version : "1.0.0"
property sourceText : missing value
property theSelection : missing value
property theLocation : missing value
property theRange : missing value
property endOfSelection : missing value
property n : missing value
property post : missing value
property pre : missing value
on run
tell application "Script Debugger"
tell front document
set {theLocation, theRange} to (get character range of selection)
set sourceText to source text
set endOfSelection to theLocation + theRange
set n to 0
set post to ""
set pre to ""
end tell
end tell
end run
-- @description
-- Selects, copies, cuts, deletes current line
-- @params: "select", "copy", "cut", "delete"
--
on lineAction(action)
set delims to return & linefeed
tell me to run
tell application "Script Debugger"
tell front document
repeat
considering case
if post = "" then
set forward to character (endOfSelection + n) of sourceText
if forward is in delims then
set post to n
if n = 0 then set n to n + 1
end if
end if
if pre = "" then
set backward to character (endOfSelection - n) of sourceText
if backward is in delims then set pre to n - 1
end if
if post ≠ "" and pre ≠ "" then exit repeat
set n to n + 1
end considering
end repeat
set theLocation to endOfSelection - (pre)
set theRange to pre + post
set theSelection to {theLocation, theRange}
if action = "select" then
set selection to theSelection
else if action contains "copy" or action contains "cut" then
set the clipboard to characters theLocation thru (theLocation + theRange - 1) of sourceText as string
if action contains "copy" then
display notification (the clipboard) with title "Copied"
else
set action to "delete"
end if
end if
if action contains "delete" then
set selection to {theLocation, theRange + 1}
set selection to ""
end if
end tell
end tell
end lineAction
-- @description
-- Moves a line up or down
-- @params: "up", "down"
--
on moveLine(direction)
set delims to return & linefeed
tell me to run
tell application "Script Debugger"
tell front document
set firstPara to ""
repeat
considering case
if post = "" then
set forward to character (endOfSelection + n) of sourceText
if forward is in delims then
if direction is "down" then
if firstPara is "" then
set firstPara to n
else
set post to n
if n = 0 then set n to n + 1
end if
else
set post to n
if n = 0 then set n to n + 1
end if
end if
end if
if pre = "" then
set backward to character (endOfSelection - n) of sourceText
if backward is in delims then
if direction is "down" then
if n ≠ 0 then set pre to n - 1
else
if firstPara is "" then
set firstPara to n
else
set pre to n - 1
end if
end if
end if
end if
if post ≠ "" and pre ≠ "" then exit repeat
set n to n + 1
end considering
end repeat
set theLocation to endOfSelection - (pre)
set theRange to pre + post
set selection to {theLocation, theRange}
set sel to selection
set p1 to paragraph 1 of sel
set p2 to paragraph 2 of sel
set selection to p2 & return & p1
if direction is "up" then
set {theLocation, theRange} to (get character range of selection)
set selection to {theLocation - ((length of p1) + 1), 0}
end if
end tell
end tell
end moveLine
-- @description
-- Selects, copies, cuts, deletes word under cursor
-- @params: "select", "copy", "cut", "delete"
--
on wordAction(action)
set delims to " :{},()\"" & return & tab & linefeed
tell me to run
tell application "Script Debugger"
tell front document
repeat
considering case
if post = "" then
set forward to character (endOfSelection + n) of sourceText
if forward is in delims then set post to n
end if
if pre = "" then
set backward to character (endOfSelection - n) of sourceText
if backward is in delims then
if n > 0 then set pre to n - 1
end if
end if
if post ≠ "" and pre ≠ "" then exit repeat
set n to n + 1
end considering
end repeat
set theLocation to endOfSelection - pre
set theRange to pre + post
set theSelection to {theLocation, theRange}
if action = "select" then
set selection to theSelection
else if action contains "copy" or action contains "cut" then
set the clipboard to characters theLocation thru (theLocation + theRange - 1) of sourceText as string
if action contains "copy" then
display notification (the clipboard) with title "Copied"
else
set action to "delete"
end if
end if
if action contains "delete" then
set selection to {theLocation, theRange}
set selection to ""
end if
end tell
end tell
end wordAction
-- @description
-- Selects, copies, cuts, deletes words in camelHumps mode
-- @params: "delete to word end", "delete to word start", "move cursor to next word",
-- "move cursor to next word with selection", "move cursor to previous word",
-- "move cursor to previous word with selection"
--
on camelCaseMode(action)
set delims to " :{},()." & tab & return & linefeed
set caps to "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
set invisibles to space & tab & return & linefeed
tell me to run
tell application "Script Debugger"
tell front document
if action contains "delete to word end" then
repeat
set char to character (endOfSelection + n) of sourceText
if n ≠ 0 then
considering case
if char is in caps or char is in delims then exit repeat
end considering
end if
set n to n + 1
end repeat
set selection to {theLocation, theRange + n}
set selection to ""
else if action contains "delete to word start" then
repeat
set char to character (theLocation - n) of sourceText
if n > 1 then
considering case
if char is in caps or char is in delims then
if char is in delims then set n to n - 1
exit repeat
end if
end considering
end if
set n to n + 1
end repeat
set selection to {theLocation - n, theRange + n}
set selection to ""
else if action is "move cursor to next word" then
repeat
set char to character (theLocation + n) of sourceText
if n ≠ 0 then
considering case
if char is in caps or char is in delims then exit repeat
end considering
end if
set n to n + 1
end repeat
set selection to {theLocation + n, 0}
else if action is "move cursor to next word with selection" then
repeat
set char to character (endOfSelection + n) of sourceText
if n ≠ 0 then
considering case
if char is in caps or char is in delims then exit repeat
end considering
end if
set n to n + 1
end repeat
set selection to {theLocation, theRange + n}
else if action is "move cursor to previous word" then
repeat
set char to character (theLocation - n) of sourceText
if n > 1 then
considering case
if char is in caps then
exit repeat
else if char is in delims then
exit repeat
else if char is in invisibles then
set n to n - 1
if character (theLocation - (n - 1)) of sourceText is not tab then
set n to n - 1
exit repeat
end if
end if
end considering
end if
set n to n + 1
end repeat
set selection to {theLocation - n, 0}
else if action is "move cursor to previous word with selection" then
repeat
set char to character (theLocation - n) of sourceText
if n > 1 then
considering case
if char is in caps then
exit repeat
else if char is in delims then
if character (theLocation - (n - 1)) of sourceText is tab then
-- do nothing
else
set n to n - 1
exit repeat
end if
else if char is in invisibles then
if character (theLocation - (n - 1)) of sourceText is not tab then
set n to n - 1
exit repeat
end if
end if
end considering
end if
set n to n + 1
end repeat
set selection to {theLocation - n, theRange + n}
end if
end tell
end tell
end camelCaseMode