/****************************** Module Header ******************************* * * Module Name: indentblock.e * * Copyright (c) Netlabs EPM Distribution Project 2004 * * $Id$ * * =========================================================================== * * This file is part of the Netlabs EPM Distribution package and is free * software. You can redistribute it and/or modify it under the terms of the * GNU General Public License as published by the Free Software * Foundation, in version 2 as it comes in the "COPYING" file of the * Netlabs EPM Distribution. This library is distributed in the hope that it * will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * ****************************************************************************/ compile if not defined( SMALL) -- If compiled separately define INCLUDING_FILE = 'INDENTBLOCK.E' include 'stdconst.e' const tryinclude 'mycnf.e' const compile if not defined( NLS_LANGUAGE) NLS_LANGUAGE = 'ENGLISH' compile endif include NLS_LANGUAGE'.e' defmain 'IndentBlock 'arg( 1) compile endif ; --------------------------------------------------------------------------- defc IndentBlock universal indent -- current syntaxindent call NextCmdAltersText() parse arg Direction if abbrev( upcase( Direction), 'U') then IndentMode = 'UNDENT' else IndentMode = 'INDENT' endif SyntaxIndent = indent if SyntaxIndent = '' then SyntaxIndent = word( .tabs, 1) endif call psave_pos( SavedPos) fWasMarked = FileIsMarked() -- Get mark for later restore getmark svfirstline, svlastline, svfirstcol, svlastcol, svfid svmt = marktype() -- Get indent of current line call pfirst_nonblank() StartIndent = .col - 1 if fWasMarked then MarkToLineMark() else MarkLineSetAtCursor() endif -- Get minimum indent of current block if IndentMode = 'UNDENT' then getmark mkfirstline, mklastline, mkfirstcol, mklastcol, mkfid mt = marktype() --dprintf( mkfirstline',' mklastline',' mkfirstcol',' mklastcol',' mt) MinIndent = MAXCOL do l = mkfirstline to mklastline getline LineStr, l CurIndent = max( 1, verify( LineStr, ' '\t)) - 1 -- Don't count indent of empty lines if substr( LineStr, CurIndent + 1) = '' then iterate endif if CurIndent < MinIndent then MinIndent = CurIndent endif enddo --dprintf( 'MinIndent = 'MinIndent) endif -- Indent or undent current line or block do i = 1 to SyntaxIndent if IndentMode = 'UNDENT' then -- Don't delete chars at the left edge if i > MinIndent then leave endif if fWasMarked = 0 then if i > StartIndent then leave endif endif shiftleft else shiftright endif enddo call prestore_pos( SavedPos) if fWasMarked = 1 then call pset_mark( svfirstline, svlastline, svfirstcol, svlastcol, svmt, svfid) endif