home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Overload
/
ShartewareOverload.cdr
/
progm
/
tptools.zip
/
FIRSTED.ZIP
/
EDTEXT.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1987-12-21
|
7KB
|
236 lines
{ EDTEXT.PAS
ED 4.0
Copyright (c) 1985, 87 by Borland International, Inc. }
{$I eddirect.inc}
unit EdText;
{-Text processing commands}
interface
uses
crt, {Basic video operations - standard unit}
Dos, {DOS calls - standard unit}
Errors, {Runtime error handler}
EdVars, {Global types and declarations}
EdScrn1, {Fast screen writing routines}
EdString, {String primitives}
EdPtrOp, {Primitive pointer operations}
EdCmds, {Maps keystrokes to commands}
int24, {DOS critical error handler}
Message, {Message system}
EdUser, {User keyboard input, line editing and error reporting}
EdMemOp, {Text buffer allocation and deallocation}
EdBack; {Background processes}
procedure EdPromptGotoCol;
{-Process goto col #n command}
procedure EdPromptGotoLine;
{-Process goto line #n command}
procedure EdShowMemory;
{-Show free memory for text}
procedure EdSetMarker(M : Byte);
{-Process set text marker command}
procedure EdSetUndoLimit;
{-Prompt for and set the global undo limit}
procedure EdTab;
{-Process tab command}
{==========================================================================}
implementation
{***}
procedure EdPromptGotoCol;
{-Process goto col #n command}
var
Cno : Integer;
begin {EdPromptGotoCol}
Cno := EdGetnumber(EdGetMessage(311), CurWin^.ColNo);
if (Cno > 0) and (Cno <= MaxLineLength) then
EdGotoColumn(Cno);
end; {EdPromptGotoCol}
{***}
procedure EdPromptGotoLine;
{-Process goto line #n command}
var
Lno : Word;
begin {EdPromptGotoLine}
{Assure line count is up to date}
IntrFlag := NoInterr;
EdGenLineNo;
IntrFlag := Interr;
Lno := EdGetnumber(EdGetMessage(312), CurWin^.Clineno);
if Lno > 0 then
EdGotoLine(Lno);
end; {EdPromptGotoLine}
procedure EdShowMemory;
{-Show free memory for text}
var
Ch : Char;
begin {EdShowMemory}
EdDisplayPromptWindow(EdCalcMemory+'-'+EdGetMessage(305), 1, [#27], Ch);
end; {EdShowMemory}
procedure EdSetMarker(M : Byte);
{-Process set text marker command}
begin {EdSetMarker}
if not(M in [0..MaxMarker]) then begin
EdErrormsg(28);
Exit;
end;
with Marker[M] do begin
{Reset any previous version of mark}
if EdPtrNotNil(Line) then
EdClrFlag(Line, InMark);
{Set new mark}
with CurWin^ do begin
if (Line = CurLine) and (Col = ColNo) then
{Setting mark on current mark, clears mark}
EdSetPtrNil(Line)
else begin
Line := CurLine;
Col := ColNo;
end;
end;
end;
{Turn on mark display}
MarkHide := True;
EdToggleTextMarker;
end; {EdSetMarker}
procedure EdSetUndoLimit;
{-Prompt for and set the global undo limit}
var
Empty : Boolean;
begin {EdSetUndoLimit}
EdSetNumber(UndoLimit, 361, 0, MaxInt, Empty);
if Abortcmd or GotError or Empty then
Exit;
SaveUndoLimit := UndoLimit;
end; {EdSetUndoLimit}
{***}
procedure EdTab;
{-Process tab command}
{***}
procedure EdInsertTab(TabPos : Integer);
{-Move current Colno to Tabpos by inserting spaces}
begin {EdInsertTab}
with CurWin^ do begin
{Insert the spaces when appropriate}
if InsertFlag and (ColNo <= EdTextLength(CurLine)) then
if not(EdInsertSpace(CurLine, ColNo, TabPos-ColNo)) then
Exit
else
Modified := True;
{Move cursor to tab position}
ColNo := TabPos;
end;
end; {EdInsertTab}
procedure EdSmartTab;
{-Process tab command ala Turbo Pascal "smart tabs"}
var
P : PlineDesc;
T : Integer;
function EdNextIndentCol(P : PlineDesc; Start : Integer) : Integer;
{-Return the column number where next tab past start is}
var
Next : Integer;
Len : Integer;
begin {EdNextIndentCol}
Len := EdTextLength(P);
if Len = 0 then
Next := 0
else if (Start <= Len) then begin
Next := Start;
with P^ do begin
if (Txt^[Start] <> Blank) then
{Start is in a word - advance to next blank}
while (Next <= Len) and (Txt^[Next] <> Blank) do
Inc(Next);
{In white space - advance to next non-blank}
while (Next <= Len) and (Txt^[Next] = Blank) do
Inc(Next);
end;
end else
{Positioned beyond end of line, tab "wraps"}
Next := 1;
EdNextIndentCol := Next;
end; {EdNextIndentCol}
function EdFollowingIndent : Integer;
{-Return the indent of any following non-blank line}
var
P : PlineDesc;
begin {EdFollowingIndent}
EdFollowingIndent := 0;
with CurWin^ do
if EdPtrNotNil(CurLine^.FwdLink) then begin
P := CurLine;
repeat
EdFwdPtr(P);
until EdPtrIsNil(P) or (EdTextLength(P) <> 0);
if EdPtrNotNil(P) then
EdFollowingIndent := EdNextIndentCol(P, 1);
end;
end; {EdFollowingIndent}
begin {EdSmartTab}
with CurWin^ do begin
{Check previous line}
P := CurLine^.Backlink;
if EdPtrNotNil(P) then
T := EdNextIndentCol(P, ColNo)
else
T := 0;
if T = 0 then begin
{Previous line blank or non-existent}
{Scan following lines for a non empty one}
T := EdFollowingIndent;
if T > ColNo then
EdInsertTab(T);
end else if T > ColNo then
{Insert spaces at the current cursor}
EdInsertTab(T)
else if (ColNo > EdTextLength(CurLine)) then begin
{Tab cursor to following line}
T := EdFollowingIndent;
if T > ColNo then
EdInsertTab(T);
end;
end;
end; {EdSmartTab}
begin {EdTab}
EdSmartTab;
end; {EdTab}
end.