From 4ff0a9734cff5a85437df3d95c6cd7e51d98c3f3 Mon Sep 17 00:00:00 2001 From: Pritpal Bedi Date: Thu, 9 Aug 2012 03:09:15 +0000 Subject: [PATCH] 2012-08-08 19:56 UTC-0800 Pritpal Bedi (bedipritpal@hotmail.com) * contrib/hbide/edit.prg + Implemented: auto insertions of statements closing structure. IF, FOR, DO CASE, DO WHILE, SWITCH The moment you type SPACE after the statement, the next elements are inserted automatically. The cursor stays at where . is shown: IF . Is it logical to insert ELSEIF ? ENDIF FOR . NEXT DO CASE CASE . CASE can be configured to CASE allign the DO CASE indentation CASE or one more tab to the right. OTHERWISE Also number of CASE stements. ENDCASE DO WHILE . ENDDO SWITCH . CASE can be configured to CASE allign the SWITCH indentation EXIT or one more tab to the right. CASE Also number of CASE stements. EXIT CASE EXIT ENDSWITCH --- harbour/ChangeLog | 32 ++++++++++ harbour/contrib/hbide/edit.prg | 110 ++++++++++++++++++++++++++++++++- 2 files changed, 139 insertions(+), 3 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 5881dad1eb..2bb5e85d82 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -16,6 +16,38 @@ The license applies to all entries newer than 2009-04-28. */ +2012-08-08 19:56 UTC-0800 Pritpal Bedi (bedipritpal@hotmail.com) + * contrib/hbide/edit.prg + + Implemented: auto insertions of statements closing structure. + IF, FOR, DO CASE, DO WHILE, SWITCH + The moment you type SPACE after the statement, the next + elements are inserted automatically. The cursor stays at + where . is shown: + IF . Is it logical to insert ELSEIF ? + ENDIF + + FOR . + NEXT + + DO CASE + CASE . CASE can be configured to + CASE allign the DO CASE indentation + CASE or one more tab to the right. + OTHERWISE Also number of CASE stements. + ENDCASE + + DO WHILE . + ENDDO + + SWITCH . CASE can be configured to + CASE allign the SWITCH indentation + EXIT or one more tab to the right. + CASE Also number of CASE stements. + EXIT + CASE + EXIT + ENDSWITCH + 2012-08-08 17:49 UTC-0800 Pritpal Bedi (bedipritpal@hotmail.com) * contrib/hbide/edit.prg * contrib/hbide/hbide.qrc diff --git a/harbour/contrib/hbide/edit.prg b/harbour/contrib/hbide/edit.prg index ac83480e41..094636acdd 100644 --- a/harbour/contrib/hbide/edit.prg +++ b/harbour/contrib/hbide/edit.prg @@ -2325,31 +2325,52 @@ METHOD IdeEdit:reformatLine( nPos, nDeleted, nAdded ) ENDIF IF empty( cPPWord ) .AND. cCWord == " " - IF hbide_isStartingKeyword( cPWord, ::oIde ) + IF hbide_isStartingKeyword( cPWord, ::oIde ) /* FUNCTION PROCEDURE CLASS */ qCursor:movePosition( QTextCursor_StartOfBlock ) qCursor:movePosition( QTextCursor_NextCharacter, QTextCursor_KeepAnchor, nCPrev ) qCursor:removeSelectedText() - ELSEIF hbide_isMinimumIndentableKeyword( cPWord, ::oIde ) .AND. ::oINI:lAutoIndent + ELSEIF hbide_isMinimumIndentableKeyword( cPWord, ::oIde ) .AND. ::oINI:lAutoIndent /* LOCAL STATIC DEFAULT PRIVATE PUBLIC ENDCLASS RETURN */ qCursor:movePosition( QTextCursor_StartOfBlock ) qCursor:movePosition( QTextCursor_NextCharacter, QTextCursor_KeepAnchor, nCPrev ) qCursor:removeSelectedText() qCursor:insertText( space( ::nTabSpaces ) ) + qCursor:movePosition( QTextCursor_EndOfLine ) - ELSEIF hbide_isIndentableKeyword( cPWord, ::oIde ) .AND. ::oINI:lAutoIndent + ELSEIF hbide_isIndentableKeyword( cPWord, ::oIde ) .AND. ::oINI:lAutoIndent /* IF SWITCH FOR DO */ IF nCPrev < ::nTabSpaces nOff := ::nTabSpaces - nCPrev qCursor:movePosition( QTextCursor_StartOfBlock ) qCursor:insertText( space( nOff ) ) + qCursor:movePosition( QTextCursor_EndOfLine ) + ELSEIF ( nOff := nCPrev % ::nTabSpaces ) > 0 qCursor:movePosition( QTextCursor_StartOfBlock ) qCursor:movePosition( QTextCursor_NextCharacter, QTextCursor_KeepAnchor, nOff ) qCursor:removeSelectedText() + qCursor:movePosition( QTextCursor_EndOfLine ) + ENDIF ENDIF ENDIF + IF .T. /* CONFIGURABLE */ + IF cCWord == " " .AND. nAdded == 1 + IF Lower( cPWord ) == "if" + hbide_appendEndif( qCursor, hbide_getFrontSpacesAndWord( qCursor:block():text() ), qCursor:position() ) + ELSEIF Lower( cPWord ) == "for" + hbide_appendFor( qCursor, hbide_getFrontSpacesAndWord( qCursor:block():text() ), qCursor:position() ) + ELSEIF Lower( cPWord ) == "switch" /* CASE indentation: CONFIGURABLE */ + hbide_appendSwitch( qCursor, hbide_getFrontSpacesAndWord( qCursor:block():text() ), qCursor:position(), ::nTabSpaces ) + ELSEIF Lower( cPPWord ) == "do" .AND. Lower( cPWord ) == "case" /* CASE indentation: CONFIGURABLE */ + hbide_appendCase( qCursor, hbide_getFrontSpacesAndWord( qCursor:block():text() ), qCursor:position() ) + ELSEIF Lower( cPPWord ) == "do" .AND. Lower( cPWord ) == "while" + hbide_appendWhile( qCursor, hbide_getFrontSpacesAndWord( qCursor:block():text() ), qCursor:position() ) + ENDIF + ENDIF + ENDIF + ::qEdit:setTextCursor( qCursor ) qCursor:endEditBlock() ENDIF @@ -2377,6 +2398,89 @@ METHOD IdeEdit:reformatLine( nPos, nDeleted, nAdded ) /*----------------------------------------------------------------------*/ +STATIC FUNCTION hbide_appendCase( qCursor, nIndent, nCurPos ) + LOCAL i + LOCAL nCases := 3 /* CONFIGURABLE */ + + qCursor:beginEditBlock() + qCursor:movePosition( QTextCursor_EndOfBlock ) + FOR i := 1 TO nCases + qCursor:insertBlock() + qCursor:insertText( Space( nIndent ) + "CASE " ) + NEXT + qCursor:insertBlock() + qCursor:insertText( Space( nIndent ) + "OTHERWISE" ) + qCursor:insertBlock() + qCursor:insertText( Space( nIndent ) + "ENDCASE" ) + qCursor:setPosition( nCurPos ) + qCursor:movePosition( QTextCursor_NextBlock ) + qCursor:movePosition( QTextCursor_EndOfLine ) + qCursor:endEditBlock() + + RETURN NIL + +/*----------------------------------------------------------------------*/ + +STATIC FUNCTION hbide_appendSwitch( qCursor, nIndent, nCurPos, nTabSpaces ) + LOCAL i + LOCAL nCases := 3 /* CONFIGURABLE */ + + qCursor:beginEditBlock() + qCursor:movePosition( QTextCursor_EndOfBlock ) + FOR i := 1 TO nCases + qCursor:insertBlock() + qCursor:insertText( Space( nIndent ) + "CASE " ) + qCursor:insertBlock() + qCursor:insertText( Space( nIndent + nTabSpaces ) + "EXIT" ) + NEXT + qCursor:insertBlock() + qCursor:insertText( Space( nIndent ) + "ENDSWITCH" ) + qCursor:setPosition( nCurPos ) + qCursor:endEditBlock() + + RETURN NIL + +/*----------------------------------------------------------------------*/ + +STATIC FUNCTION hbide_appendWhile( qCursor, nIndent, nCurPos ) + + qCursor:beginEditBlock() + qCursor:movePosition( QTextCursor_EndOfBlock ) + qCursor:insertBlock() + qCursor:insertText( Space( nIndent ) + "ENDDO" ) + qCursor:setPosition( nCurPos ) + qCursor:endEditBlock() + + RETURN NIL + +/*----------------------------------------------------------------------*/ + +STATIC FUNCTION hbide_appendFor( qCursor, nIndent, nCurPos ) + + qCursor:beginEditBlock() + qCursor:movePosition( QTextCursor_EndOfBlock ) + qCursor:insertBlock() + qCursor:insertText( Space( nIndent ) + "NEXT" ) + qCursor:setPosition( nCurPos ) + qCursor:endEditBlock() + + RETURN NIL + +/*----------------------------------------------------------------------*/ + +STATIC FUNCTION hbide_appendEndif( qCursor, nIndent, nCurPos ) + + qCursor:beginEditBlock() + qCursor:movePosition( QTextCursor_EndOfBlock ) + qCursor:insertBlock() + qCursor:insertText( Space( nIndent ) + "ENDIF" ) + qCursor:setPosition( nCurPos ) + qCursor:endEditBlock() + + RETURN NIL + +/*----------------------------------------------------------------------*/ + METHOD IdeEdit:handlePreviousWord( lUpdatePrevWord ) LOCAL qCursor, qTextBlock, cText, cWord, nB, nL, qEdit, lPrevOnly, nCol, nSpace, nSpaces, nOff