Board index » off-topic » try this...

try this...


2003-10-25 02:37:57 AM
off-topic8
This macro does everything you want, except you have to have the cursor *in front* of the opening brace.
void HideBlock(void)
{
int firstLine;
int lastLine;
int currLine;
int currCol;
// Save original position...
currLine = BufQCurrentLine();
currCol = BufQCurrentCol();
BraceMatch(0);
firstLine = BufQCurrentLine();
BraceFind(0);
lastLine = BufQCurrentLine();
if ((lastLine - firstLine)>1)
{
CollapseLines(firstLine + 1,lastLine - 1,
COLLAPSE_LINE_HIDE|
COLLAPSE_LINE_INCREASE);
}
// Restore position
MovAbs(currLine, currCol);
}
 
 

Re:try this...

Thanks. Is there any way to get rid of the minus characters in the
margin after the lines have been expanded again?
Graeme
On 24 Oct 2003 11:37:57 -0700, "D. Seekins" < XXXX@XXXXX.COM >
wrote:
Quote


This macro does everything you want, except you have to have the cursor *in front* of the opening brace.


void HideBlock(void)
{
int firstLine;
int lastLine;
int currLine;
int currCol;

// Save original position...
currLine = BufQCurrentLine();
currCol = BufQCurrentCol();

BraceMatch(0);

firstLine = BufQCurrentLine();

BraceFind(0);

lastLine = BufQCurrentLine();

if ((lastLine - firstLine)>1)
{
CollapseLines(firstLine + 1,lastLine - 1,
COLLAPSE_LINE_HIDE|
COLLAPSE_LINE_INCREASE);
}

// Restore position
MovAbs(currLine, currCol);
}
 

Re:try this...

no - not that I have found... other than shutting off Selective Display Mode ( WinDisplayMode(0x0000); or, right click on the text and then Display Mode->Normal ) - which uncollapses any remaining blocks and removes all the "-".
Selective display is meant to be a "mode" - where, for example, you collapse all functions, or you collapse all the #ifdefs, or all the blocks at a certain indention level - in an entire file - it really isn't meant to be used (in my opinion) in the way we are currently trying to use it.
Graeme Prentice < XXXX@XXXXX.COM >wrote:
Quote


Thanks. Is there any way to get rid of the minus characters in the
margin after the lines have been expanded again?

Graeme
 

{smallsort}

Re:try this...

The BraceMatch/BraceFind approach is a great find! Following is a tweaked
version. It scans up to find the first left brace as the stating point.
You are not restricted to having the cursor positioned at the brace when you
start. (Helpful when you get blurry-eyed.)
[API Macro:tlaHideBlock]
// -------------------------------------------------------------------------
--------------
// tlaHideBlock - Hide Current Block
// -------------------------------------------------------------------------
--------------
void tlaHideBlock(void)
{
int iPosition[2] = { BufQCurrentLine( ), BufQCurrentCol( ) };
int iBlock[2] ;
string strPrefix = "tlaHideBlock: " ;
if ( ! SrchFind( "^[ \t]*{", SEARCH_REGEX | SEARCH_MAXIMAL, 0 ) )
MsgError( strPrefix + "Starting brace not found." );
else
{
BraceMatch( 0 );
iBlock[0] = BufQCurrentLine( );
if ( ! BraceFind( 0 ) )
MsgError( strPrefix + "Ending brace not found." );
else
{
iBlock[1] = BufQCurrentLine( );
if ( ++iBlock[0]>= --iBlock[1] )
MsgError( strPrefix + "No statements found to hide." );
else
{
CollapseLines( iBlock[0], iBlock[1], COLLAPSE_LINE_HIDE |
COLLAPSE_LINE_INCREASE );
MsgMessage( strPrefix + "Block hidden." );
MovAbs( --iBlock[0], 1 );
return ;
}
}
}
SysBeep( );
MovAbs( iPosition[0], iPosition[1] );
return ;
}
// -------------------------------------------------------------------------
--------------
// 2003.10.25 06:22 Copyright ?1993-2003 - Thom Little Associates, Ltd. -
www.tlaNET.net
Changing the mode does not clean up after using the hiding function.
WinDisplayMode( WDM_NORMAL ) will make them invisible. If you then do
another hide function the location of the previous hides will be shown
again.
These "droppings" left at each point where you collapse/uncollapse are reset
if you reloading the file. The following will reload the file and maintain
the window and cursor locations. It requires a function in tlaTools to
maintain the window information.
[API Macro:tlaResetCurrent]
// -------------------------------------------------------------------------
--------------
// tlaResetCurrent - Reset Current Window - tlaTools Available on System
// -------------------------------------------------------------------------
--------------
void tlaResetCurrent(void)
{
int iPosition ;
string strFile ;
if ( ( BufQSysFlags( ) & BUFFER_MODIFIED ) && ( ! ( BufQSysFlags( ) &
BUFFER_READ_ONLY & BUFFER_SYSTEM ) ) )
{
if ( ( DlgYesNo( NULL, "tlaResetCurrent", "Save changes made to file
since last write?", 0xe066 ) ) == 0x0066 )
BufWrite( );
else
MovAbs( 1, 1 );
}
iPosition = tlaPosition( );
strFile = BufQFilename( );
BufDelBuffer( BufQCurrentBuffer( ) );
BufEditFileAuto( strFile, OPENFILE_AS_AUTO );
tlaPosition( iPosition );
return ;
}
// -------------------------------------------------------------------------
--------------
// 2003.10.25 04:51 Copyright ?1993-2003 - Thom Little Associates, Ltd. -
www.tlaNET.net
Resetting the edit buffer on a machine without tlaTools can be accomplished
with the following macro. It maintains the cursor position but
unfortunately can not maintain the window location. It should operate on
any 7.5 CodeWright.
[API Macro:tlaResetCurrentDist]
// -------------------------------------------------------------------------
--------------
// tlaResetCurrentDist - Reset Current Window - tlaTools Not Available
on System
// -------------------------------------------------------------------------
--------------
void tlaResetCurrentDist(void)
{
int iPosition[2] = { BufQCurrentLine( ), BufQCurrentCol( ) };
string strFile ;
if ( ( BufQSysFlags( ) & BUFFER_MODIFIED ) && ( ! ( BufQSysFlags( ) &
BUFFER_READ_ONLY & BUFFER_SYSTEM ) ) )
{
if ( ( DlgYesNo( NULL, "tlaResetCurrentDist", "Save changes made to
file since last write?", 0xe066 ) ) == 0x0066 )
BufWrite( );
else
iPosition[0] = iPosition[1] = 1 ;
}
strFile = BufQFilename( );
BufDelBuffer( BufQCurrentBuffer( ) );
BufEditFileAuto( strFile, OPENFILE_AS_AUTO );
MovAbs( iPosition[0], iPosition[1] );
return ;
}
// -------------------------------------------------------------------------
--------------
// 2003.10.25 04:51 Copyright ?1993-2003 - Thom Little Associates, Ltd. -
www.tlaNET.net
The BraceMatch/BraceFind approach is a real find. Thank you.
--
-- Thom Little -- www.tlaNET.net -- Thom Little Associates, Ltd.
 

Re:try this...

On Sat, 25 Oct 2003 06:29:20 -0400, "Thom Little" < XXXX@XXXXX.COM >
wrote:
Quote
The BraceMatch/BraceFind approach is a great find! Following is a tweaked
version. It scans up to find the first left brace as the stating point.
You are not restricted to having the cursor positioned at the brace when you
start. (Helpful when you get blurry-eyed.)

Thanks guys.
Graeme