An enhanced version of this macro was added in Release 3.00.445. It is left here as an example. You can compare this code to the one found in the main.pte to see how little had to be done to add the release enhancements.
Macro Features:
- Starts out with an empty search string and defaults to searching from the current cursor position down
- Every printable character you hit is appended to the search string and the search performed with the new search pattern
- Backspace key removes characters from the end of the search string
- Up key moves the cursor one line up and changes search direction to up and re-applies the search pattern, also has the effect of moving to a previous occurrence of the search string
- Down key does the opposite of up: changes the direction of the search down and has the effect of moving the cursor to the next occurrence,
- Left/Right same as up/down except they move the cursor left/right and too have the effect of moving to prev/next occurrence respectively.
- Escape restores the cursor to where it was when incremental search was invoked (cancels all cursor movements)
- Enter leaves the cursor where it is (accepts the current position) but also leaves the original cursor position stored on the stack so you can recall it using ex [pop cursor] from the command line or by hitting the Shift+Alt+N key which is defined to pop the cursor from the top of the stack.
- Displays the current search direction and the search string in the command line and additionally displays it in light yellow if pattern is non-empty and was not found else light green (if empty or found).
- The cursor will be moved to the next/prev occurrence of the search string (not case sensitive) and if not found will loop around to top or bottom of file and search from there just in case there is an occurrence there.
- The macro is assigned to the Ctrl+I key in the default template. (c-i means Ctrl+I)
- Search is case insensitive.
- Will perform incremental search of the command line text if the cursor is in the command line when incremental search is started.
Instructions:
If the instructions are not clear then you may want to read the Quick Review on the parent page.
To give it a test flight:
- Select and copy the Macro Text below to the clipboard and add it to a new file in WinPTE.
- On the command line execute the macro command.
- The Ctrl+I key is now defined to start the incremental search.
To make it available every time you run WinPTE:
This is functionlity is part of the relase version as of 3.00.445. The instructions are only left here because they are useful for other macros. Do not make this version of the macro part of you standard installation unless you are running version 3.00.441 or earlier.
- Select and copy the text below to the clipboard and add it to your custom.pte file (in the installation directory, create a new file if it does not exist)
- NOTE:
C++ template and VB/Lotus Script templates define their own macros for the Ctrl+I key to eliminate the C/C++ specific definition and use this one instead, add the following line to your custom.pte file or assign the incremental search to another key:
define c-i.cpp =
- Similarly add a line:
define c-i.bas =
to remove the VB/Lotus Script specific definition and use this one.
- Restart WinPTE
- You now have the Ctrl+I key defined to start the incremental search.
Macro Text
Line
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
|
* File: incrsearch.pte, lines 1 to 109
* incremental search macro
begindef c-i
[push cursor]
[set envir 200]'' * search string
[set envir 203][eval]'0b10001110'
[set envir 205]''
[set envir 206]'(down)'
[push cursor]
[do]
[clear flag 200] * direction key pressed, don't loop around
[error #][envir 203]'Incremental Search '&[envir 206]&': '&[envir 200]&'|'
[set envir 201][key name]
[if escape]
* drop modified position
[drop cursor]
* recall original
[pop cursor]
[exit loop]
[endif]
[clear next key]
[set envir 202][string length][envir 201]
[if eval]'$202>1'
[if equal]'enter'[envir 201]
* drop modified position
[drop cursor]
[exit loop]
[else if equal]'backspace'[envir 201]
* remove one key
[set envir 202][string length][envir 200]
[set envir 200][left string #][eval]'$202-1'[envir 200]
[else if equal]'space'[envir 201]
[set envir 200][envir 200]&' '
[else if equal]'down'[envir 201]
[if][down][endif]
[set flag 200]
[set envir 205]''
[set envir 206]'(down)'
[else if equal]'right'[envir 201]
[if][right][endif]
[set flag 200]
[set envir 205]''
[set envir 206]'(down)'
[else if equal]'up'[envir 201]
[if][up][endif]
[set flag 200]
[set envir 205]'-'
[set envir 206]'(up)'
[drop cursor]
[push cursor]
[else if equal]'left'[envir 201]
[if][left]
[else if][up]
[end line]
[endif]
[set flag 200]
[set envir 205]'-'
[set envir 206]'(up)'
[endif]
[else]
* add it to the search
[set envir 200][envir 200]&[envir 201]
[endif]
[if flag 200]
[drop cursor]
[push cursor]
[endif]
[set envir 201]''
[recall cursor]
[set envir 203][eval]'0b10001110'
[if not equal]''[envir 200]
[if not][locate][envir 200][envir 205]
[if not flag 200]
[if equal]''[envir 205]
[top][begin line]
[else]
[bottom][end line]
[endif]
[if not][locate][envir 200][envir 205]
[set envir 203][eval]'0b10001101'
[recall cursor]
[else]
[center line]
[endif]
[else]
[set envir 203][eval]'0b10001101'
[endif]
[else]
[center line]
[endif]
[endif]
[loop]
[error] * clear the error
* cursor left on stack so it can be recalled with sa-n
*[drop cursor]
enddef
|