1 | /****************************** Module Header *******************************
|
---|
2 | *
|
---|
3 | * Module Name: swaptext.e
|
---|
4 | *
|
---|
5 | * Copyright (c) Netlabs EPM Distribution Project 2002
|
---|
6 | *
|
---|
7 | * $Id: swaptext.e 3361 2018-12-17 19:38:32Z aschn $
|
---|
8 | *
|
---|
9 | * ===========================================================================
|
---|
10 | *
|
---|
11 | * This file is part of the Netlabs EPM Distribution package and is free
|
---|
12 | * software. You can redistribute it and/or modify it under the terms of the
|
---|
13 | * GNU General Public License as published by the Free Software
|
---|
14 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
15 | * Netlabs EPM Distribution. This library is distributed in the hope that it
|
---|
16 | * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
|
---|
17 | * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
18 | * General Public License for more details.
|
---|
19 | *
|
---|
20 | ****************************************************************************/
|
---|
21 |
|
---|
22 | ; ---------------------------------------------------------------------------
|
---|
23 | defc MoveLineUp
|
---|
24 | if .last < 2 then
|
---|
25 | return
|
---|
26 | endif
|
---|
27 | SavedAutosave = .autosave
|
---|
28 | .autosave = 0
|
---|
29 | call psave_mark( SavedMark)
|
---|
30 |
|
---|
31 | call NextCmdAltersText()
|
---|
32 | getfileid fid
|
---|
33 | Line = Max( .line - 1, 1)
|
---|
34 | call pset_mark( .line, .line, 1, MAXCOL, 'LINE', fid)
|
---|
35 | -- The destination for line mark movement is below the current line.
|
---|
36 | -- Therefore go one more line up.
|
---|
37 | .lineg = Line - 1 -- Go to line Line - 1 without scrolling
|
---|
38 | --call pmove_mark()
|
---|
39 | movemark
|
---|
40 | .lineg = Line -- Go to line Line without scrolling
|
---|
41 | .line = Line -- Scroll when outside of window
|
---|
42 |
|
---|
43 | call prestore_mark( SavedMark)
|
---|
44 | .autosave = SavedAutosave
|
---|
45 | return
|
---|
46 |
|
---|
47 | ; ---------------------------------------------------------------------------
|
---|
48 | defc MoveLineDown
|
---|
49 | if .last < 2 then
|
---|
50 | return
|
---|
51 | endif
|
---|
52 | SavedAutosave = .autosave
|
---|
53 | .autosave = 0
|
---|
54 | call psave_mark( SavedMark)
|
---|
55 |
|
---|
56 | call NextCmdAltersText()
|
---|
57 | getfileid fid
|
---|
58 | Line = Min( .line + 1, .last)
|
---|
59 | call pset_mark( .line, .line, 1, MAXCOL, 'LINE', fid)
|
---|
60 | .lineg = Line -- Go to line Line without scrolling
|
---|
61 | --call pmove_mark()
|
---|
62 | movemark
|
---|
63 | .lineg = Line -- Go to line Line without scrolling
|
---|
64 | .line = Line -- Scroll when outside of window
|
---|
65 |
|
---|
66 | call prestore_mark( SavedMark)
|
---|
67 | .autosave = SavedAutosave
|
---|
68 | return
|
---|
69 |
|
---|
70 | ; ---------------------------------------------------------------------------
|
---|
71 | defc MoveCharLeft
|
---|
72 | SavedAutosave = .autosave
|
---|
73 | .autosave = 0
|
---|
74 | call psave_mark( SavedMark)
|
---|
75 |
|
---|
76 | call NextCmdAltersText()
|
---|
77 | getfileid fid
|
---|
78 | call pset_mark( .line, .line, .col, .col, 'CHAR', fid)
|
---|
79 | OldCol = .col
|
---|
80 | left
|
---|
81 | if .col < OldCol then
|
---|
82 | movemark
|
---|
83 | endif
|
---|
84 |
|
---|
85 | call prestore_mark( SavedMark)
|
---|
86 | .autosave = SavedAutosave
|
---|
87 | return
|
---|
88 |
|
---|
89 | ; ---------------------------------------------------------------------------
|
---|
90 | defc MoveCharRight
|
---|
91 | SavedAutosave = .autosave
|
---|
92 | .autosave = 0
|
---|
93 | call psave_mark( SavedMark)
|
---|
94 |
|
---|
95 | call NextCmdAltersText()
|
---|
96 | getfileid fid
|
---|
97 | call pset_mark( .line, .line, .col, .col, 'CHAR', fid)
|
---|
98 | OldCol = .col
|
---|
99 | right
|
---|
100 | right
|
---|
101 | if .col > OldCol then
|
---|
102 | movemark
|
---|
103 | endif
|
---|
104 |
|
---|
105 | call prestore_mark( SavedMark)
|
---|
106 | .autosave = SavedAutosave
|
---|
107 | return
|
---|
108 |
|
---|
109 | ; ---------------------------------------------------------------------------
|
---|
110 | defc MoveExpressionRight
|
---|
111 | SeparatorList = arg( 1)
|
---|
112 | call MoveExpr( 'R', arg( 1))
|
---|
113 |
|
---|
114 | ; ---------------------------------------------------------------------------
|
---|
115 | defc MoveExpressionLeft
|
---|
116 | SeparatorList = arg( 1)
|
---|
117 | call MoveExpr( 'L', arg( 1))
|
---|
118 |
|
---|
119 | ; ---------------------------------------------------------------------------
|
---|
120 | defproc MoveExpr
|
---|
121 | Direction = upcase( arg( 1))
|
---|
122 | if not wordpos( Direction, 'R L') then
|
---|
123 | Direction = 'R'
|
---|
124 | endif
|
---|
125 | SeparatorList = arg( 2)
|
---|
126 | if SeparatorList = '' then
|
---|
127 | SeparatorList = ' ~`!%^&*()-+=][{}|\:;?/><,''"'\t
|
---|
128 | endif
|
---|
129 |
|
---|
130 | SavedAutosave = .autosave
|
---|
131 | .autosave = 0
|
---|
132 | call psave_mark( SavedMark)
|
---|
133 |
|
---|
134 | call NextCmdAltersText()
|
---|
135 | do once = 1 to 1
|
---|
136 | getline LineStr
|
---|
137 | CursorCol = .col
|
---|
138 | Len = length( LineStr)
|
---|
139 | RevLineStr = reverse( LineStr)
|
---|
140 |
|
---|
141 | -- Find first expression
|
---|
142 | EndCol1 = verify( LineStr, SeparatorList, 'M', .col)
|
---|
143 | if EndCol1 = CursorCol then
|
---|
144 | 'SayError On a separator, move cursor to an expression first.'
|
---|
145 | leave
|
---|
146 | endif
|
---|
147 | EndCol1 = EndCol1 - 1
|
---|
148 | if EndCol1 < 1 then
|
---|
149 | EndCol1 = Len
|
---|
150 | endif
|
---|
151 |
|
---|
152 | VerifyStart = Len - CursorCol + 1
|
---|
153 | RevEndCol1 = verify( RevLineStr, SeparatorList, 'M', VerifyStart)
|
---|
154 | RevEndCol1 = RevEndCol1 - 1
|
---|
155 | if RevEndCol1 < 1 then
|
---|
156 | RevEndCol1 = Len
|
---|
157 | endif
|
---|
158 | StartCol1 = Len - RevEndCol1 + 1
|
---|
159 | Len1 = EndCol1 - StartCol1 + 1
|
---|
160 | Expr1 = substr( LineStr, StartCol1, Len1)
|
---|
161 |
|
---|
162 | getfileid fid
|
---|
163 | call pset_mark( .line, .line, StartCol1, EndCol1, 'CHAR', fid)
|
---|
164 |
|
---|
165 | if Direction = 'R' then
|
---|
166 | -- Move right
|
---|
167 |
|
---|
168 | -- Find next expression
|
---|
169 | StartCol2 = verify( LineStr, SeparatorList, '', EndCol1 + 1)
|
---|
170 | if not StartCol2 then
|
---|
171 | 'SayError No second expression right from cursor found.'
|
---|
172 | leave
|
---|
173 | endif
|
---|
174 | EndCol2 = verify( LineStr, SeparatorList, 'M', StartCol2)
|
---|
175 | EndCol2 = EndCol2 - 1
|
---|
176 | if EndCol2 < 1 then
|
---|
177 | EndCol2 = Len
|
---|
178 | endif
|
---|
179 | Len2 = EndCol2 - StartCol2 + 1
|
---|
180 | Expr2 = substr( LineStr, StartCol2, Len2)
|
---|
181 | --dprintf( 'StartCol1 = 'StartCol1', EndCol1 = 'EndCol1', StartCol2 = 'StartCol2', EndCol2 = 'EndCol2 ||
|
---|
182 | -- ', ['Expr1'] ['Expr2']')
|
---|
183 |
|
---|
184 | .col = StartCol2
|
---|
185 | movemark
|
---|
186 | call pset_mark( .line, .line, StartCol2, EndCol2, 'CHAR', fid)
|
---|
187 | .col = StartCol1
|
---|
188 | movemark
|
---|
189 |
|
---|
190 | .col = EndCol2 - (EndCol1 - CursorCol)
|
---|
191 | else
|
---|
192 | -- Move left
|
---|
193 |
|
---|
194 | -- Find previous expression
|
---|
195 | VerifyStart = Len - StartCol1 + 2
|
---|
196 | RevEndCol2 = verify( RevLineStr, SeparatorList, '', VerifyStart)
|
---|
197 | if not RevEndCol2 then
|
---|
198 | 'SayError No second expression left from cursor found.'
|
---|
199 | leave
|
---|
200 | endif
|
---|
201 | EndCol2 = Len - RevEndCol2 + 1
|
---|
202 | RevEndCol2 = verify( RevLineStr, SeparatorList, 'M', RevEndCol2)
|
---|
203 | RevEndCol2 = RevEndCol2 - 1
|
---|
204 | if RevEndCol2 < 1 then
|
---|
205 | RevEndCol2 = Len
|
---|
206 | endif
|
---|
207 | StartCol2 = Len - RevEndCol2 + 1
|
---|
208 | Len2 = EndCol2 - StartCol2 + 1
|
---|
209 | Expr2 = substr( LineStr, StartCol2, Len2)
|
---|
210 | --dprintf( 'StartCol1 = 'StartCol1', EndCol1 = 'EndCol1', StartCol2 = 'StartCol2', EndCol2 = 'EndCol2 ||
|
---|
211 | -- ', ['Expr1'] ['Expr2']')
|
---|
212 |
|
---|
213 | .col = StartCol2
|
---|
214 | movemark
|
---|
215 | call pset_mark( .line, .line, StartCol2 + Len1, EndCol2 + Len1, 'CHAR', fid)
|
---|
216 | .col = StartCol1 + Len1
|
---|
217 | movemark
|
---|
218 |
|
---|
219 | .col = StartCol2 + CursorCol - StartCol1
|
---|
220 | endif
|
---|
221 | enddo
|
---|
222 |
|
---|
223 | call prestore_mark( SavedMark)
|
---|
224 | .autosave = SavedAutosave
|
---|
225 | return
|
---|
226 |
|
---|