source: trunk/src/netlabs/macros/swaptext.e@ 3282

Last change on this file since 3282 was 3282, checked in by Andreas Schnellbacher, 6 years ago
  • Property svn:keywords set to Date Revision Author HeadURL Id
File size: 7.2 KB
Line 
1/****************************** Module Header *******************************
2*
3* Module Name: swaptext.e
4*
5* Copyright (c) Netlabs EPM Distribution Project 2002
6*
7* $Id: swaptext.e 3282 2018-12-01 23:22:31Z 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; ---------------------------------------------------------------------------
23defc 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 l = 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 = l - 1 -- Go to line l - 1 without scrolling
38 --call pmove_mark()
39 move_mark
40 .lineg = l -- Go to line l without scrolling
41 .line = l -- Scroll when outside of window
42
43 call prestore_mark( SavedMark)
44 .autosave = SavedAutosave
45 return
46
47; ---------------------------------------------------------------------------
48defc 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 l = min( .line + 1, .last)
59 call pset_mark( .line, .line, 1, MAXCOL, 'LINE', fid)
60 .lineg = l -- Go to line l without scrolling
61 --call pmove_mark()
62 move_mark
63 .lineg = l -- Go to line l without scrolling
64 .line = l -- Scroll when outside of window
65
66 call prestore_mark( SavedMark)
67 .autosave = SavedAutosave
68 return
69
70; ---------------------------------------------------------------------------
71defc MoveCharLeft
72 SavedAutosave = .autosave
73 .autosave = 0
74 if not insert_state() then
75 -- Switch to insert mode
76 insert_toggle
77 fOverWrite = 1
78 else
79 fOverWrite = 0
80 endif
81
82 call NextCmdAltersText()
83 getline LineStr
84 Char = substr( LineStr, .col, 1)
85 deletechar
86 left
87 keyin Char
88 left
89
90 if fOverWrite then
91 insert_toggle
92 endif
93 .autosave = SavedAutosave
94 return
95
96; ---------------------------------------------------------------------------
97defc MoveCharRight
98 SavedAutosave = .autosave
99 .autosave = 0
100 if not insert_state() then
101 -- Switch to insert mode
102 insert_toggle
103 fOverWrite = 1
104 else
105 fOverWrite = 0
106 endif
107
108 call NextCmdAltersText()
109 getline LineStr
110 Char = substr( LineStr, .col, 1)
111 deletechar
112 right
113 keyin Char
114 left
115
116 if fOverWrite then
117 insert_toggle
118 endif
119 .autosave = SavedAutosave
120 return
121
122; ---------------------------------------------------------------------------
123defc MoveExpressionRight
124 SeparatorList = arg( 1)
125 call MoveExpr( 'R', arg( 1))
126
127; ---------------------------------------------------------------------------
128defc MoveExpressionLeft
129 SeparatorList = arg( 1)
130 call MoveExpr( 'L', arg( 1))
131
132; ---------------------------------------------------------------------------
133defproc MoveExpr
134 Direction = upcase( arg( 1))
135 if not wordpos( Direction, 'R L') then
136 Direction = 'R'
137 endif
138 SeparatorList = arg( 2)
139 if SeparatorList = '' then
140 SeparatorList = ' ~`!%^&*()-+=][{}|\:;?/><,''"'\t
141 endif
142
143 SavedAutosave = .autosave
144 .autosave = 0
145 if not insert_state() then
146 -- Switch to insert mode
147 insert_toggle
148 fOverWrite = 1
149 else
150 fOverWrite = 0
151 endif
152
153 call NextCmdAltersText()
154 do once = 1 to 1
155 getline LineStr
156 CursorCol = .col
157 Len = length( LineStr)
158 RevLineStr = reverse( LineStr)
159
160 -- Find first expression
161 EndCol1 = verify( LineStr, SeparatorList, 'M', .col)
162 if EndCol1 = CursorCol then
163 'SayError On a separator, move cursor to an expression first.'
164 leave
165 endif
166 EndCol1 = EndCol1 - 1
167 if EndCol1 < 1 then
168 EndCol1 = Len
169 endif
170
171 VerifyStart = Len - CursorCol + 1
172 RevEndCol1 = verify( RevLineStr, SeparatorList, 'M', VerifyStart)
173 RevEndCol1 = RevEndCol1 - 1
174 if RevEndCol1 < 1 then
175 RevEndCol1 = Len
176 endif
177 StartCol1 = Len - RevEndCol1 + 1
178 Expr1 = substr( LineStr, StartCol1, EndCol1 - StartCol1 + 1)
179
180 if Direction = 'R' then
181
182 -- Find next expression
183 StartCol2 = verify( LineStr, SeparatorList, '', EndCol1 + 1)
184 if not StartCol2 then
185 'SayError No second expression right from cursor found.'
186 leave
187 endif
188 EndCol2 = verify( LineStr, SeparatorList, 'M', StartCol2)
189 EndCol2 = EndCol2 - 1
190 if EndCol2 < 1 then
191 EndCol2 = Len
192 endif
193 Expr2 = substr( LineStr, StartCol2, EndCol2 - StartCol2 + 1)
194 --dprintf( 'StartCol1 = 'StartCol1', EndCol1 = 'EndCol1', StartCol2 = 'StartCol2', EndCol2 = 'EndCol2 ||
195 -- ', ['Expr1'] ['Expr2']')
196
197 -- Build NewLineStr
198 First = substr( LineStr, 1, StartCol1 - 1)
199 Mid = substr( LineStr, EndCol1 + 1, StartCol2 - EndCol1 - 1)
200 Last = substr( LineStr, EndCol2 + 1)
201 NewLineStr = First''Expr2''Mid''Expr1''Last
202 replaceline NewLineStr
203 .col = length( First) + length( Expr2) + length( Mid) + (CursorCol - StartCol1) + 1
204
205 else
206
207 -- Find previous expression
208 VerifyStart = Len - StartCol1 + 2
209 RevEndCol2 = verify( RevLineStr, SeparatorList, '', VerifyStart)
210 if not RevEndCol2 then
211 'SayError No second expression left from cursor found.'
212 leave
213 endif
214 EndCol2 = Len - RevEndCol2 + 1
215 RevEndCol2 = verify( RevLineStr, SeparatorList, 'M', RevEndCol2)
216 RevEndCol2 = RevEndCol2 - 1
217 if RevEndCol2 < 1 then
218 RevEndCol2 = Len
219 endif
220 StartCol2 = Len - RevEndCol2 + 1
221 Expr2 = substr( LineStr, StartCol2, EndCol2 - StartCol2 + 1)
222 --dprintf( 'StartCol1 = 'StartCol1', EndCol1 = 'EndCol1', StartCol2 = 'StartCol2', EndCol2 = 'EndCol2 ||
223 -- ', ['Expr1'] ['Expr2']')
224
225 -- Build NewLineStr
226 First = substr( LineStr, 1, StartCol2 - 1)
227 Mid = substr( LineStr, EndCol2 + 1, StartCol1 - EndCol2 - 1)
228 Last = substr( LineStr, EndCol1 + 1)
229 NewLineStr = First''Expr1''Mid''Expr2''Last
230 replaceline NewLineStr
231 .col = length( First) + (CursorCol - StartCol1) + 1
232
233 endif
234 enddo
235
236 if fOverWrite then
237 insert_toggle
238 endif
239 .autosave = SavedAutosave
240 return
241
Note: See TracBrowser for help on using the repository browser.