xref: /minix3/external/bsd/nvi/dist/perl_api/VI.pod (revision 84d9c625bfea59e274550651111ae9edfdc40fbd)
1*84d9c625SLionel Sambuc=head1 NAME
2*84d9c625SLionel Sambuc
3*84d9c625SLionel SambucVI - VI module within perl embedded nvi
4*84d9c625SLionel Sambuc
5*84d9c625SLionel Sambuc=head1 SYNOPSIS
6*84d9c625SLionel Sambuc
7*84d9c625SLionel Sambuc    sub wc {
8*84d9c625SLionel Sambuc      my $words;
9*84d9c625SLionel Sambuc      $i = $VI::StartLine;
10*84d9c625SLionel Sambuc      while ($i <= $VI::StopLine) {
11*84d9c625SLionel Sambuc	$_ = $curscr->GetLine($i++);
12*84d9c625SLionel Sambuc        $words+=split;
13*84d9c625SLionel Sambuc      }
14*84d9c625SLionel Sambuc      $curscr->Msg("$words words");
15*84d9c625SLionel Sambuc    }
16*84d9c625SLionel Sambuc
17*84d9c625SLionel Sambuc=head1 DESCRIPTION
18*84d9c625SLionel Sambuc
19*84d9c625SLionel SambucThis pseudo module is available to perl programs run from within nvi and
20*84d9c625SLionel Sambucprovides access to the files being edited and some internal data.
21*84d9c625SLionel Sambuc
22*84d9c625SLionel SambucBeware that you should not use this module from within a C<perldo> or
23*84d9c625SLionel Sambucfrom within an C<END> block or a C<DESTROY> method.
24*84d9c625SLionel Sambuc
25*84d9c625SLionel Sambuc=head2 Variables
26*84d9c625SLionel Sambuc
27*84d9c625SLionel SambucThese are set by nvi before starting each perl command.
28*84d9c625SLionel Sambuc
29*84d9c625SLionel Sambuc=over 8
30*84d9c625SLionel Sambuc
31*84d9c625SLionel Sambuc=item * $curscr
32*84d9c625SLionel Sambuc
33*84d9c625SLionel SambucObject that represents the current screen.
34*84d9c625SLionel SambucIt can be used as the ScreenId parameter of the functions below,
35*84d9c625SLionel Sambucor you can use object oriented syntax.
36*84d9c625SLionel Sambuc
37*84d9c625SLionel Sambuc	# the following two are equivalent
38*84d9c625SLionel Sambuc	$curscr->DelLine(57);
39*84d9c625SLionel Sambuc	VI::DelLine($curscr, 57);
40*84d9c625SLionel Sambuc
41*84d9c625SLionel Sambuc=item * $StartLine
42*84d9c625SLionel Sambuc
43*84d9c625SLionel SambucLine number of the first line of the selected range or of the file if no
44*84d9c625SLionel Sambucrange was specified.
45*84d9c625SLionel Sambuc
46*84d9c625SLionel Sambuc=item * $StopLine
47*84d9c625SLionel Sambuc
48*84d9c625SLionel SambucLine number of the last line of the selected range or of the file if no
49*84d9c625SLionel Sambucrange was specified.
50*84d9c625SLionel Sambuc
51*84d9c625SLionel Sambuc=back
52*84d9c625SLionel Sambuc
53*84d9c625SLionel Sambuc=head2 Functions
54*84d9c625SLionel Sambuc
55*84d9c625SLionel Sambuc=over 8
56*84d9c625SLionel Sambuc
57*84d9c625SLionel Sambuc=item * AppendLine
58*84d9c625SLionel Sambuc
59*84d9c625SLionel Sambuc    VI::AppendLine(screenId,lineNumber,text);
60*84d9c625SLionel Sambuc
61*84d9c625SLionel SambucAppend the string text after the line in lineNumber.
62*84d9c625SLionel Sambuc
63*84d9c625SLionel Sambuc=item * DelLine
64*84d9c625SLionel Sambuc
65*84d9c625SLionel Sambuc    VI::DelLine(screenId,lineNum);
66*84d9c625SLionel Sambuc
67*84d9c625SLionel SambucDelete lineNum.
68*84d9c625SLionel Sambuc
69*84d9c625SLionel Sambuc=item * EndScreen
70*84d9c625SLionel Sambuc
71*84d9c625SLionel SambucVI::EndScreen(screenId);
72*84d9c625SLionel Sambuc
73*84d9c625SLionel SambucEnd a screen.
74*84d9c625SLionel Sambuc
75*84d9c625SLionel Sambuc=item * FindScreen
76*84d9c625SLionel Sambuc
77*84d9c625SLionel Sambuc    VI::FindScreen(file);
78*84d9c625SLionel Sambuc
79*84d9c625SLionel SambucReturn the screen id associated with file name.
80*84d9c625SLionel Sambuc
81*84d9c625SLionel Sambuc=item * GetCursor
82*84d9c625SLionel Sambuc
83*84d9c625SLionel Sambuc    ($line, $column) = VI::GetCursor(screenId);
84*84d9c625SLionel Sambuc
85*84d9c625SLionel SambucReturn the current cursor position as a list with two elements.
86*84d9c625SLionel Sambuc
87*84d9c625SLionel Sambuc=item * GetLine
88*84d9c625SLionel Sambuc
89*84d9c625SLionel Sambuc    VI::GetLine(screenId,lineNumber);
90*84d9c625SLionel Sambuc
91*84d9c625SLionel SambucReturn lineNumber.
92*84d9c625SLionel Sambuc
93*84d9c625SLionel Sambuc=item * GetMark
94*84d9c625SLionel Sambuc
95*84d9c625SLionel Sambuc    ($line, $column) = VI::GetMark(screenId,mark);
96*84d9c625SLionel Sambuc
97*84d9c625SLionel SambucReturn the mark's cursor position as a list with two elements.
98*84d9c625SLionel Sambuc
99*84d9c625SLionel Sambuc=item * GetOpt
100*84d9c625SLionel Sambuc
101*84d9c625SLionel Sambuc    VI::GetOpt(screenId,option);
102*84d9c625SLionel Sambuc
103*84d9c625SLionel SambucReturn the value of an option.
104*84d9c625SLionel Sambuc
105*84d9c625SLionel Sambuc=item * InsertLine
106*84d9c625SLionel Sambuc
107*84d9c625SLionel Sambuc    VI::InsertLine(screenId,lineNumber,text);
108*84d9c625SLionel Sambuc
109*84d9c625SLionel SambucInsert the string text before the line in lineNumber.
110*84d9c625SLionel Sambuc
111*84d9c625SLionel Sambuc=item * LastLine
112*84d9c625SLionel Sambuc
113*84d9c625SLionel Sambuc    VI::LastLine(screenId);
114*84d9c625SLionel Sambuc
115*84d9c625SLionel SambucReturn the last line in the screen.
116*84d9c625SLionel Sambuc
117*84d9c625SLionel Sambuc=item * MapKey
118*84d9c625SLionel Sambuc
119*84d9c625SLionel Sambuc    VI::MapKey(screenId,key,perlproc);
120*84d9c625SLionel Sambuc
121*84d9c625SLionel SambucAssociate a key with a perl procedure.
122*84d9c625SLionel Sambuc
123*84d9c625SLionel Sambuc=item * Msg
124*84d9c625SLionel Sambuc
125*84d9c625SLionel Sambuc    VI::Msg(screenId,text);
126*84d9c625SLionel Sambuc
127*84d9c625SLionel SambucSet the message line to text.
128*84d9c625SLionel Sambuc
129*84d9c625SLionel Sambuc=item * NewScreen
130*84d9c625SLionel Sambuc
131*84d9c625SLionel Sambuc    VI::NewScreen(screenId);
132*84d9c625SLionel Sambuc    VI::NewScreen(screenId,file);
133*84d9c625SLionel Sambuc
134*84d9c625SLionel SambucCreate a new screen.  If a filename is specified then the screen is
135*84d9c625SLionel Sambucopened with that file.
136*84d9c625SLionel Sambuc
137*84d9c625SLionel Sambuc=item * Run
138*84d9c625SLionel Sambuc
139*84d9c625SLionel Sambuc    VI::Run(screenId,cmd);
140*84d9c625SLionel Sambuc
141*84d9c625SLionel SambucRun the ex command cmd.
142*84d9c625SLionel Sambuc
143*84d9c625SLionel Sambuc=item * SetCursor
144*84d9c625SLionel Sambuc
145*84d9c625SLionel Sambuc    VI::SetCursor(screenId,line,column);
146*84d9c625SLionel Sambuc
147*84d9c625SLionel SambucSet the cursor to the line and column numbers supplied.
148*84d9c625SLionel Sambuc
149*84d9c625SLionel Sambuc=item * SetLine
150*84d9c625SLionel Sambuc
151*84d9c625SLionel Sambuc    VI::SetLine(screenId,lineNumber,text);
152*84d9c625SLionel Sambuc
153*84d9c625SLionel SambucSet lineNumber to the text supplied.
154*84d9c625SLionel Sambuc
155*84d9c625SLionel Sambuc=item * SetMark
156*84d9c625SLionel Sambuc
157*84d9c625SLionel Sambuc    VI::SetMark(screenId,mark,line,column);
158*84d9c625SLionel Sambuc
159*84d9c625SLionel SambucSet the mark to the line and column numbers supplied.
160*84d9c625SLionel Sambuc
161*84d9c625SLionel Sambuc=item * SetOpt
162*84d9c625SLionel Sambuc
163*84d9c625SLionel Sambuc    VI::SetOpt(screenId,command);
164*84d9c625SLionel Sambuc
165*84d9c625SLionel SambucSet an option.
166*84d9c625SLionel Sambuc
167*84d9c625SLionel Sambuc=item * SwitchScreen
168*84d9c625SLionel Sambuc
169*84d9c625SLionel Sambuc    VI::SwitchScreen(screenId,screenId);
170*84d9c625SLionel Sambuc
171*84d9c625SLionel SambucChange the current focus to screen.
172*84d9c625SLionel Sambuc
173*84d9c625SLionel Sambuc=item * TagQ
174*84d9c625SLionel Sambuc
175*84d9c625SLionel Sambuc    $screen->TagQ("tag identification string")
176*84d9c625SLionel Sambuc
177*84d9c625SLionel SambucCreates a new tag queue object associated to $screen
178*84d9c625SLionel Sambucto which "tags" can be added.
179*84d9c625SLionel SambucSee further about methods you can use on tag queues.
180*84d9c625SLionel Sambuc
181*84d9c625SLionel Sambuc=item * UnmapKey
182*84d9c625SLionel Sambuc
183*84d9c625SLionel Sambuc    VI::UnmmapKey(screenId,key);
184*84d9c625SLionel Sambuc
185*84d9c625SLionel SambucUnmap a key.
186*84d9c625SLionel Sambuc
187*84d9c625SLionel Sambuc=item * Warn
188*84d9c625SLionel Sambuc
189*84d9c625SLionel SambucThis is the default warning handler.
190*84d9c625SLionel SambucIt adds any warnings to the error string.
191*84d9c625SLionel Sambuc
192*84d9c625SLionel Sambuc=item * Opt
193*84d9c625SLionel Sambuc
194*84d9c625SLionel Sambuc    $screen->Opt;
195*84d9c625SLionel Sambuc
196*84d9c625SLionel SambucReturns a tied hash representing the options of the screen.
197*84d9c625SLionel SambucNote that you can only retrieve and set hash elements.
198*84d9c625SLionel Sambuc
199*84d9c625SLionel Sambuc=item * Map
200*84d9c625SLionel Sambuc
201*84d9c625SLionel Sambuc    $screen->Map;
202*84d9c625SLionel Sambuc
203*84d9c625SLionel SambucReturns a tied hash representing the mappings of the screen.
204*84d9c625SLionel SambucNote that you can only retrieve, set and delete hash elements.
205*84d9c625SLionel Sambuc
206*84d9c625SLionel Sambuc=item * Mark
207*84d9c625SLionel Sambuc
208*84d9c625SLionel Sambuc    $screen->Mark;
209*84d9c625SLionel Sambuc
210*84d9c625SLionel SambucReturns a tied hash representing the marks of the screen.
211*84d9c625SLionel Sambuc
212*84d9c625SLionel Sambuc=item * Line
213*84d9c625SLionel Sambuc
214*84d9c625SLionel Sambuc    $screen->Line;
215*84d9c625SLionel Sambuc
216*84d9c625SLionel SambucReturns a tied array representing the lines of the screen.
217*84d9c625SLionel Sambuc
218*84d9c625SLionel Sambuc=back
219*84d9c625SLionel Sambuc
220*84d9c625SLionel Sambuc=head2 Tag queue methods
221*84d9c625SLionel Sambuc
222*84d9c625SLionel Sambuc=item * Add
223*84d9c625SLionel Sambuc
224*84d9c625SLionel Sambuc    $tagq->Add($filename, $searchstring, $msg)
225*84d9c625SLionel Sambuc
226*84d9c625SLionel SambucAdds a tag to the tag queue.
227*84d9c625SLionel SambucThe $searchstring argument is (line)number or
228*84d9c625SLionel Sambuca string representing a regular expression.
229*84d9c625SLionel Sambuc
230*84d9c625SLionel Sambuc=item * Push
231*84d9c625SLionel Sambuc
232*84d9c625SLionel Sambuc    $tagq->Push()
233*84d9c625SLionel Sambuc
234*84d9c625SLionel SambucPushes the tag queue onto its associated screen.
235*84d9c625SLionel SambucThe result of the operation is as if the user had enter the
236*84d9c625SLionel Sambuctag command and nvi had found the locations that were added
237*84d9c625SLionel Sambucusing the Add method.
238*84d9c625SLionel Sambuc
239*84d9c625SLionel SambucFor an example, see the make.pl script.
240*84d9c625SLionel Sambuc
241*84d9c625SLionel Sambuc=back
242*84d9c625SLionel Sambuc
243*84d9c625SLionel Sambuc=head1 EXAMPLES
244*84d9c625SLionel Sambuc
245*84d9c625SLionel Sambuc    sub showmarks {
246*84d9c625SLionel Sambuc      my ($mark, $all);
247*84d9c625SLionel Sambuc      for $mark ('a' .. 'z') {
248*84d9c625SLionel Sambuc        eval {VI::GetMark($VI::ScreenId, $mark)};
249*84d9c625SLionel Sambuc        $all .= $mark unless ($@);
250*84d9c625SLionel Sambuc      }
251*84d9c625SLionel Sambuc      VI::Msg($VI::ScreenId,"Set marks: $all");
252*84d9c625SLionel Sambuc    }
253*84d9c625SLionel Sambuc
254*84d9c625SLionel Sambuc    sub forall {
255*84d9c625SLionel Sambuc      my ($code) = shift;
256*84d9c625SLionel Sambuc      my ($i) = $VI::StartLine-1;
257*84d9c625SLionel Sambuc      while (++$i <= $VI::StopLine) {
258*84d9c625SLionel Sambuc        $_ = VI::GetLine($VI::ScreenId, $i);
259*84d9c625SLionel Sambuc        VI::SetLine($VI::ScreenId, $i, $_) if(&$code);
260*84d9c625SLionel Sambuc      }
261*84d9c625SLionel Sambuc    }
262*84d9c625SLionel Sambuc
263*84d9c625SLionel SambucNow you can do
264*84d9c625SLionel Sambuc
265*84d9c625SLionel Sambuc    :perl forall sub{s/perlre/substitution/}
266*84d9c625SLionel Sambuc
267*84d9c625SLionel SambucAlthough you'll probably use
268*84d9c625SLionel Sambuc
269*84d9c625SLionel Sambuc    :perldo s/perlre/substitution/
270*84d9c625SLionel Sambuc
271*84d9c625SLionel Sambucinstead.
272*84d9c625SLionel Sambuc
273*84d9c625SLionel SambucSee L<perlre> for perl regular expressions.
274*84d9c625SLionel Sambuc
275*84d9c625SLionel Sambuc=head1 SEE ALSO
276*84d9c625SLionel Sambuc
277*84d9c625SLionel SambucL<nviperl>
278*84d9c625SLionel Sambuc
279*84d9c625SLionel Sambuc=head1 AUTHOR
280*84d9c625SLionel Sambuc
281*84d9c625SLionel SambucSven Verdoolaege <skimo@kotnet.org>
282