only clean out gs when last window goes
[nvi.git] / perl_api / VI.pod
bloba87e24d911d83570e051d3de23c9013c3cc447d6
1 =head1 NAME
3 VI - VI module within perl embedded nvi
5 =head1 SYNOPSIS
7     sub wc {
8       my $words;
9       $i = $VI::StartLine;
10       while ($i <= $VI::StopLine) {
11         $_ = VI::GetLine($VI::ScreenId, $i++);
12         $words+=split;
13       }
14       VI::Msg($VI::ScreenId,"$words words");
15     }
17 =head1 DESCRIPTION
19 This pseudo module is available to perl programs run from within nvi and
20 provides access to the files being edited and some internal data.
22 Beware that you should not use this module from within a C<perldo> or
23 from within an C<END> block or a C<DESTROY> method.
25 =head2 Variables
27 These are set by nvi before starting each perl command.
29 =over 8
31 =item * $ScreenId
33 Screen id of the current screen.
35 =item * $StartLine
37 Line number of the first line of the selected range or of the file if no
38 range was specified.
40 =item * $StopLine
42 Line number of the last line of the selected range or of the file if no
43 range was specified.
45 =back
47 =head2 Functions
49 =over 8
51 =item * AppendLine
53     VI::AppendLine(screenId,lineNumber,text);
55 Append the string text after the line in lineNumber.
57 =item * DelLine
59     VI::DelLine(screenId,lineNum);
61 Delete lineNum.
63 =item * EndScreen
65 VI::EndScreen(screenId);
67 End a screen.
69 =item * FindScreen
71     VI::FindScreen(file);
73 Return the screen id associated with file name.
75 =item * GetCursor
77     ($line, $column) = VI::GetCursor(screenId);
79 Return the current cursor position as a list with two elements.
81 =item * GetLine
83     VI::GetLine(screenId,lineNumber);
85 Return lineNumber.
87 =item * GetMark
89     ($line, $column) = VI::GetMark(screenId,mark);
91 Return the mark's cursor position as a list with two elements.
93 =item * GetOpt
95     VI::GetOpt(screenId,option);
97 Return the value of an option.
99 =item * InsertLine
101     VI::InsertLine(screenId,lineNumber,text);
103 Insert the string text before the line in lineNumber.
105 =item * LastLine
107     VI::LastLine(screenId);
109 Return the last line in the screen.
111 =item * MapKey
113     VI::MapKey(screenId,key,perlproc);
115 Associate a key with a perl procedure.
117 =item * Msg
119     VI::Msg(screenId,text);
121 Set the message line to text.
123 =item * NewScreen
125     VI::NewScreen(screenId);
126     VI::NewScreen(screenId,file);
128 Create a new screen.  If a filename is specified then the screen is
129 opened with that file.
131 =item * Run
133     VI::Run(screenId,cmd);
135 Run the ex command cmd.
137 =item * SetCursor
139     VI::SetCursor(screenId,line,column);
141 Set the cursor to the line and column numbers supplied.
143 =item * SetLine
145     VI::SetLine(screenId,lineNumber,text);
147 Set lineNumber to the text supplied.
149 =item * SetMark
151     VI::SetMark(screenId,mark,line,column);
153 Set the mark to the line and column numbers supplied.
155 =item * SetOpt
157     VI::SetOpt(screenId,command);
159 Set an option.
161 =item * SwitchScreen
163     VI::SwitchScreen(screenId,screenId);
165 Change the current focus to screen.
167 =item * UnmapKey
169     VI::UnmmapKey(screenId,key);
171 Unmap a key.
173 =item * Warn
175 This is the default warning handler.
176 It adds any warnings to the error string.
178 =back
180 =head1 EXAMPLES
182     sub showmarks {
183       my ($mark, $all);
184       for $mark ('a' .. 'z') {
185         eval {VI::GetMark($VI::ScreenId, $mark)};
186         $all .= $mark unless ($@);
187       }
188       VI::Msg($VI::ScreenId,"Set marks: $all");
189     }
191     sub forall {
192       my ($code) = shift;
193       my ($i) = $VI::StartLine-1;
194       while (++$i <= $VI::StopLine) {
195         $_ = VI::GetLine($VI::ScreenId, $i);
196         VI::SetLine($VI::ScreenId, $i, $_) if(&$code);
197       }
198     }
200 Now you can do
202     :perl forall sub{s/perlre/substitution/}
204 Although you'll probably use
206     :perldo s/perlre/substitution/
208 instead.
210 See L<perlre> for perl regular expressions.
212 =head1 SEE ALSO
214 L<nviperl>
216 =head1 AUTHOR
218 Sven Verdoolaege <skimo@dns.ufsia.ac.be>