summaryrefslogtreecommitdiff
path: root/setedit/cfgfiles/macros.slp
blob: 0a93a30630ea6e8683034122583ae4c8ba9dc4b1 (plain)
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
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
; Copyright 1996-2005 by Salvador E. Tropea [SET],
; see copyrigh file for details
;
;;;
;;; Here are 3 macros converted from TEML to sLisp
;;;
;******************************************************************
;
; MACRO:   MakeFuncText: Sample macro to comment a function
;
; USE:     Put the cursor immediately after a function name which is
;          at the left of the screen, then press Alt-T. Do not include
;          the return type or parameters before using this macro.
;
;******************************************************************

(defmacro 'Make Function Text'
 (eval
  ; add white space
  (InsertText '\n\n')
  ; go before beginning of intended function name
  (SendCommands cmcLineUp cmcLineUp cmcLineStart
  ; mark function name
                cmcSelectOn cmcWordRight cmcSelectOff)
  ; copy for prototyping
  (SendCommands cmcLineStart cmcLineDown cmcCopyBlock cmcLineUp cmcLineStart)
  ; add "Function" to comment area
  (InsertText '\nFunction: ')
  ; put in comment lines before and after
  (SendCommands cmcLineEnd cmcLineUp cmcLineStart)
  (InsertText '/*****************************************************')
  (SendCommands cmcLineStart cmcLineDown cmcLineEnd)
  (InsertText '\n\n')
  (SendCommands cmcLineStart)
  (InsertText 'Description:\n')
  (SendCommands cmcLineStart)
  (InsertText '*****************************************************/\n')
  ; go back to end of name
  (SendCommands cmcLineDown cmcLineEnd)
  )
)

;*******************************************************************
;
; MACRO:       MakeStub
;
; DESCRIPTION: Creates a stub, based on a user-entered function name.
;   It assumes the cursor is positioned immediately after the name,
;   and the name is at the left of the screen.
;
;*******************************************************************

(defmacro 'Make Stub'
 (eval
  ; go before beginning of intended function name
  (SendCommands cmcLineStart)
  ; void return type
  (InsertText "void ")
  (SendCommands cmcLineEnd)
  ; void parameter
  (InsertText "( void )\n{\n")
  (InsertText "printf(\"This is ")
  (SendCommands cmcLineUp cmcLineUp cmcLineStart cmcWordRight)
  (SendCommands cmcSelectOn cmcWordRight cmcCharLeft cmcCharLeft cmcSelectOff)
  (SendCommands cmcLineDown cmcLineDown cmcLineEnd)
  (InsertText " ")
  (SendCommands cmcCopyBlock cmcHideSelect cmcLineEnd)
  (InsertText "\\n\");")
  (InsertText "\n}")
 )
)

;*******************************************************************
;
; MACRO:       MainCIO
;
; DESCRIPTION: Inserts outline of main program for C that uses STDIO.H
;
;*******************************************************************/

(defmacro 'Main C STDIO'
 (eval
  (InsertText "#include <stdio.h>\n\n")
  (InsertText "int main(void)\n{\n\n  return 0;\n")
  (SendCommands cmcLineStart)
  (InsertText "}")
  (SendCommands cmcLineUp cmcLineUp cmcCharRight)
 )
)

;*******************************************************************
;
; MACRO:   Test RunProgam
;
; DESCRIPTION: Example of how to call an external program, in this
; example the editor will call ls and put the directory list in the
; Message Window.
;
;*******************************************************************/

(defmacro 'Test RunProgram'
 (eval
  (InsertText
   (RunProgramRedir
    (AskString "The output of the program will be inserted" "External program")
   )
  )
 )
)

;*******************************************************************
;
; MACRO:   Test RunProgam Filter
;
; DESCRIPTION: Example of how to use an external filter program, it
; takes the current selection, sends it to an external program (using
; the shell input redirection) and collects the output of the
; program. Finally the selected text is replaced by the output of
; the filter.
;
;*******************************************************************/

(defmacro 'Test RunProgram Filter'
 (eval
  (setv "input" (GetSelection))
  (if (length input)
   ; Call the filter
   (eval
    (setv "program" (AskString "The output of the filter will replace the selection" "External filter"))
    (if (length program)
     (eval
      (setv "output" (RunProgramRedir program input))
      (if (length output)
       (eval
        (SendCommands cmcCut)
        (InsertText output 1)
       )
       ; Inform we didn't get text
       (MessageBox "No output from the filter")
      )
     )
     ; Ask the user to enter something
     (MessageBox "Please enter the filter to use")
    )
   )
   ; Ask the user to select something firt
   (MessageBox "Please select a text first")
  )
 )
)

;*******************************************************************
;
; MACRO:   Word Count
;
; DESCRIPTION: Example to show how to execute an external tool and
; parse the output using regex.
;
;*******************************************************************/

(defmacro 'Word Count'
 (eval
  (setv "input" (GetSelection))
  (if (length input)
   (eval
    (setv "output" (RunProgramRedir "wc" input))
    (if (length output)
     (eval
      (if (prex output "\\s*(\\d+)\\s*(\\d+)\\s*(\\d+)")
       (ShowInStatusLine (+ "Lines: " _1 " Words: " _2 " Characters: " _3))
      )
     )
     ; Inform we didn't get text
     (MessageBox "No output from wc")
    )
   )
   ; Ask the user to select something firt
   (MessageBox "Please select a text first")
  )
 )
)

;*******************************************************************
;
; Macro to search and replace in all opened windows.
;
;*******************************************************************

(defmacro 'S&R all opened'
 (eval
  ; Memorize the current window
  (setv "curWin" (GetCurWindowNumber))
  ; Search & Replace in window 2
  (SelectWindowNumber 2)
  (SendCommands cmcPushCursorPos cmcTextStart cmcReplace cmcPopCursorPos)
  ; Repeat the search in the others
  (setv "n" 3)
  (loop
   (if (not (SelectWindowNumber n)) (exitloop))
   (SendCommands cmcPushCursorPos cmcTextStart cmcSearchAgain cmcPopCursorPos)
   (setv "n" (+ n 1))
  )
  ; Restore the original window
  (SelectWindowNumber curWin)
  1
 )
)

;*******************************************************************
;
; Macro to search and replace in all project items.
;
;*******************************************************************

(defmacro 'S&R all project'
 (eval
  ; Memorize the current window
  (setv "curWin" (GetCurWindowNumber))
  (setv "maxPrj" (GetMaxProjectItem))
  (setv "firstWin" 1)
  (setv "n" 0)
  (loop
   (if (== n maxPrj) (exitloop))
   (setv "opened" (OpenFile (GetProjectItem n) 1))
   (if (or (== opened 1) (== opened 2))
    (if (== firstWin 1)
     (eval
      (setv "firstWin" 0)
      (SendCommands cmcPushCursorPos cmcTextStart cmcReplace cmcPopCursorPos)
     )
     (SendCommands cmcPushCursorPos cmcTextStart cmcSearchAgain cmcPopCursorPos)
    )
   )
   (if (== opened 1)
    (CloseWindowNumber (GetCurWindowNumber))
   )
   (setv "n" (+ n 1))
  )
  ; Restore the original window
  (SelectWindowNumber curWin)
  1
 )
)

;*******************************************************************
;
; These macro were created by Rolf Campbell (Endlisnis)
; email: s257m@unb.ca Endlisnis@hotmail.com
; and uses an external program provided by him.
;
; MACRO:   Prototype
;
; DESCRIPTION: Look ups the function under the cursor to report the
; prototype, even when partially typed.
;
; http://www.geocities.com/CollegePark/Quad/1974/LEMUR02.ZIP
; As Lemur is currently unavailable I commented these macros.
;
;*******************************************************************/

; (defmacro 'List Members'
;  (eval
;   (RunProgram (+ "lemur " (WhichEditor) " -s " (WordUnderCursor 256 1)))
;   (SendCommands cmcGoEndOfWord)
;  )
; )
; 
; (defmacro 'Prototype'
;  (eval
;   (ShowInStatusLine
;    (RunProgramRedir
;     (+ "lemur " (WhichEditor) " " (WordUnderCursor 256 1))
;    )
;   )
;  )
; )
; 
; (defmacro 'Prototype Complete'
;  (eval
;   (setv "proto"
;    (RunProgramRedir
;     (+ "lemur " (WhichEditor) " -c " (WordUnderCursor 256 1))
;    )
;   )
;   (SendCommands cmcGoEndOfWord)
;   (InsertText (+ proto "(") 1)
;   (ShowInStatusLine (+ "Added: " proto))
;  )
; )

;*******************************************************************
;
;    These examples were contributed by Thiago F.G. Albuquerque
;  <tfga@terra.com.br>.
;    I added them commented to save memory, you can uncoment them
;  using the "Indent uncommenting" editor command found in Tool&Ops|
;  Un/Indent block menu.
;
;*******************************************************************

(defmacro 'DuplicateLineOrSelection'
  (if (SelectionExists)  (InsertText (GetSelection))

                         (progn  ; else
                                 (SendCommands cmcPushCursorPos cmcLineStart cmcSelectOn cmcLineEnd
                                               cmcSelectOff)
                                 (= "temp" (GetSelection))
                                 (SendCommands cmcLineEnd)
                                 (InsertText (+ "\n" temp))
                                 (SendCommands cmcPopCursorPos cmcLineDown)
                         )
  )
)

(defmacro 'EvalSelection_Print'
 (InsertText (+ "\n" (EvalString (GetSelection))))
)

(defmacro 'EvalSelection_StatusLine'
 (ShowInStatusLine (EvalString (GetSelection)))
)

; (defmacro 'EvalSelection_MessageWindow'
;  (eval
;   (ShowInMessageWindow "Return value:" 1)
;   (ShowInMessageWindow (EvalString (GetSelection)))
;  )
; )
;
;
; This example shows how to choose a compiler according to the file type.
;
; (defmacro 'Compile'
;  (progn
;   (setv "name" (WhichEditor edfWENameNoExt)) ; name without extension
;   (setv "ext"  (WhichEditor edfWEExtension)) ; extension
; 
;   (cond (== (GetSyntaxLang) 'C/C++') (RunProgram (+ "make obj/" (WhichEditor edfWENameNoExt) ".o"))
;         (== (GetSyntaxLang) 'Perl')  (RunProgram (+ "perl -cw " name ext) 0 'Perl')
;         (== (GetSyntaxLang) 'PHP')   (RunProgram (+ "php -l " name ext) 0 'PHP')
;         (== (GetSyntaxLang) 'TeX')   (RunProgram (+ "latex \'\\scrollmode\\input\' " name ext))
;   )
;  )
; )
; 
; (defmacro 'Make'
;  (eval
;   (RunProgram "make")
;  )
; )
;
; If you are editing a file named "stuff.cpp",
; this macro takes you to "stuff.h" and vice-versa.
; (OpenFile) checks first if the file is already open,
; in which case it just switches to the right window.
;
; (defmacro 'Switch-cpp-h'
;  (eval
;   (setv "name" (WhichEditor edfWENameNoExt)) ; name without extension
;   (setv "ext"  (WhichEditor edfWEExtension)) ; extension
;   (cond (not (strcmp ext ".cpp"))  (OpenFile (+ name ".h"))
;         (not (strcmp ext ".h"))    (OpenFile (+ name ".cpp"))
;   )
;  )
; )
; 
; This is an implementation of pseudo-macros in sLisp.
; Assign to Ctrl-Space.
;
; (defmacro 'pmacro'
;  (progn
;   (SendCommands cmcSelectOn cmcCharLeft cmcCharLeft cmcSelectOff)
;   (setv "str" (GetSelection))
;   (SendCommands cmcClear)
;   (cond (not (strcmp str "#I"))    (progn  (InsertText '#include ".h"')
;                                            (SendCommands cmcCharLeft cmcCharLeft cmcCharLeft)
;                                    )
; 
;         (not (strcmp str "#i"))    (progn  (InsertText '#include <.h>')
;                                            (SendCommands cmcCharLeft cmcCharLeft cmcCharLeft)
;                                    )
; 
;         (not (strcmp str "#d"))    (InsertText '#define ')
;
;         (not (strcmp str "pr"))    (progn  (InsertText 'printf("");')
;                                            (SendCommands cmcCharLeft cmcCharLeft cmcCharLeft)
;                                    )
; 
;         (not (strcmp str "re"))    (progn  (InsertText 'return ;')
;                                            (SendCommands cmcCharLeft)
;                                    )
; 
;         (not (strcmp str "{}"))    (progn  (InsertText "{}")
;                                            (SendCommands cmcCharLeft cmcNewLine cmcNewLine cmcLineUp)
;                                            (InsertText "    ")
;                                    )
; 
;         (not (strcmp str "//"))    (progn (InsertText "///////////////////////////////////////////////////////////////////////////")
;                                           (SendCommands cmcNewLine)
;                                    )
; 
;         (not (strcmp str "/*"))    (progn (InsertText "/****************************************************************************")
;                                           (SendCommands cmcNewLine cmcNewLine)
;                                           (InsertText "*****************************************************************************/")
;                                           (SendCommands cmcNewLine cmcLineUp cmcLineUp)
;                                    )
; 
;         (not (strcmp str "in"))    (progn (InsertText "#ifndef \n")
;                                           (InsertText "#define \n")
;                                           (InsertText "\n")
;                                           (InsertText "#endif")
;                                           (SendCommands cmcLineUp cmcLineUp cmcLineUp cmcLineEnd)
;                                    )
;
;         (not (strcmp str ".h"))    (progn
;                                           (setv "filename" (+ (WhichEditor edfWENameNoExt) "_h_____"))
;                                           (InsertText (+ "#ifndef " filename "\n"))
;                                           (InsertText (+ "#define " filename "\n"))
;                                           (InsertText "\n")
;                                           (InsertText "#endif")
;                                    )
; 
;         (not (strcmp str "fo"))    (progn (InsertText "for (int i=0; i<; i++)")
;                                           (SendCommands cmcNewLine)
;                                           (InsertText "{}")
;                                           (SendCommands cmcCharLeft cmcNewLine cmcNewLine cmcLineUp)
;                                           (InsertText "    ")
;                                    )
; 
;         (not (strcmp str "ma"))    (progn (InsertText "int main(int argc, char *argv[])\n")
;                                           (InsertText "{\n")
;                                           (InsertText "\n")
;                                           (InsertText "    return 0;\n")
;                                           (InsertText "}")
;                                           (SendCommands cmcLineUp cmcLineUp
;                                                         cmcCharRight cmcCharRight cmcCharRight)
;                                    )
; 
;         (not (strcmp str "cl"))    (progn (InsertText "class\n")
;                                           (InsertText "{\n")
;                                           (InsertText " public:\n")
;                                           (InsertText " // Data\n")
;                                           (InsertText " \n")
;                                           (InsertText " // Construction\n")
;                                           (InsertText " \n")
;                                           (InsertText " // Methods\n")
;                                           (InsertText " \n")
;                                           (InsertText " // Operators\n")
;                                           (InsertText "};")
;                                           (SendCommands cmcLineUp cmcLineUp cmcLineUp cmcLineUp cmcLineUp cmcLineUp cmcLineUp cmcLineUp cmcLineUp cmcLineUp
;                                                         cmcLineEnd cmcCharRight)
;                                    )
; 
;         1                          (InsertText str)
;   )
;  )
; )
;
; I assigned this to TAB and then I assigned cmcUnIndentBlk to Shift-Tab.
;
; (defmacro 'IndentLineOrBlock'
;  (if (SelectionExists)
;   (SendCommands cmcIndentBlk)
;   (InsertText "    ")
;  )
; )
;
; (defmacro 'Test_Loop'
;  (eval
;   (setv "i" 0)
;   (loop
;    (InsertText (tostr i))
;    (if (== i 5) (exitloop))
;    (setv "i" (++ i))
;   )
;  )
; )
;
;-------------------------------------------------------------------------------------------
;
; More macros from Thiago, they are short and funny so I let them uncommented.
;
;-------------------------------------------------------------------------------------------
; These 2 macros make cmcIndentBlk and cmcUnIndentBlk behave like
; cmcCommentIndent and cmcCommentUnIndent, i.e.: if there's no selection,
; indent/unindent the current line.

(defmacro 'IndentLineOrSelection'
  (if (SelectionExists)     (SendCommands cmcIndentBlk)
                            (SendCommands cmcPushCursorPos
                             cmcLineStart cmcSelectOn cmcLineEnd cmcSelectOff
                             cmcIndentBlk
                             cmcPopCursorPos )
  )
)

(defmacro 'UnIndentLineOrSelection'
  (if (SelectionExists)     (SendCommands cmcUnIndentBlk)
                            (SendCommands cmcPushCursorPos
                             cmcLineStart cmcSelectOn cmcLineEnd cmcSelectOff
                             cmcUnIndentBlk
                             cmcPopCursorPos )
  )
)

;-------------------------------------------------------------------------------------------
; ^Ins and no selection -> copy current word

(defmacro 'CopySelectionOrCurWord'
  (if (SelectionExists)     (SendCommands cmcCopy)
                            (SendCommands cmcMarkWord cmcCopy)
  )
)

;-------------------------------------------------------------------------------------------
; Select the entire text

(defmacro 'SelectAll'
    (SendCommands cmcTextStart cmcSelectOn cmcTextEnd cmcSelectOff)
)

;-------------------------------------------------------------------------------------------
; New (and simpler) version of CopyLine: uses cmcMarkLine now

(defmacro 'CopyLine'
          (SendCommands cmcMarkLine
                        cmcCopy
          )
)

; CommentIndent uses the current syntax highlight to get the comment string
; (e.g.: "//" for C++, "#" for Perl, etc.). If the current file has no syntax
; highlight, it does nothing. In that case, you have to call ArbitraryIndent
; and provide the comment string yourself. This macro makes this automatic.

(defmacro 'CommentIndent'
 (progn
    (if (not (SelectionExists))    (SendCommands cmcMarkLine))

    (if (== (GetSyntaxLang) '' )    (SendCommands cmcArbitraryIndent)
                                    (SendCommands cmcCommentIndent)
    )
 )
)