Community
    • Login

    Right Justifying Paragraphs

    Scheduled Pinned Locked Moved General Discussion
    24 Posts 6 Posters 8.3k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • chcgC
      chcg
      last edited by

      If it is just about how the visual aspect, maybe you want to try https://github.com/dail8859/ElasticTabstops (further explanation here http://nickgravgaard.com/elastic-tabstops/)

      1 Reply Last reply Reply Quote 4
      • dinkumoilD
        dinkumoil
        last edited by dinkumoil

        @hoji-afzal

        Seems like you are an “extreme aligner”… ;-)

        I wrote a VBScript that does the job. To get it to work you need to install the Pork2Sausage plugin of @donho and two tiny companion scripts.

        This is the VBScript, save it as CodeAlign.vbs:

        Option Explicit
        
        Const LVALUE = 0
        Const RVALUE = 1
        
        Dim strCode, arrCode, arrInLine, arrLValueTokens, strRValueTokens, intPrevMaxIdx
        Dim arrLine, arrMaxTokenLen, intLineIdx, intTokenIdx, intMaxRValueLen
        Dim intCnt, strLine, strToken, strOutput
        
        If Not WScript.StdIn.AtEndOfStream Then
          strCode = WScript.StdIn.ReadAll
        
          arrCode         = Split(strCode, vbNewLine)
          intMaxRValueLen = 0
          arrMaxTokenLen  = Array()
          arrLine         = Array()
          strOutput       = ""
        
          For intLineIdx = 0 To UBound(arrCode)
            If arrCode(intLineIdx) <> "" Then
              arrInLine       = Split(arrCode(intLineIdx), "=")
              arrLValueTokens = Split(Trim(arrInLine(0)), " ")
              strRValueTokens = Trim(arrInLine(1))
        
              If Len(strRValueTokens) > intMaxRValueLen Then
                intMaxRValueLen = Len(strRValueTokens)
              End If
        
              If UBound(arrLValueTokens) > UBound(arrMaxTokenLen) Then
                intPrevMaxIdx = UBound(arrMaxTokenLen)
                ReDim Preserve arrMaxTokenLen(UBound(arrLValueTokens))
        
                If intPrevMaxIdx < 0 Then
                  arrMaxTokenLen(UBound(arrMaxTokenLen)) = 0
                Else
                  arrMaxTokenLen(UBound(arrMaxTokenLen)) = arrMaxTokenLen(intPrevMaxIdx)
        
                  For intCnt = intPrevMaxIdx To UBound(arrMaxTokenLen) - 1
                    arrMaxTokenLen(intCnt) = 0
                  Next
                End If
              End If
        
              For intCnt = 0 To UBound(arrLValueTokens)
                If intCnt < UBound(arrLValueTokens) Then
                  If Len(arrLValueTokens(intCnt)) > arrMaxTokenLen(intCnt) Then
                    arrMaxTokenLen(intCnt) = Len(arrLValueTokens(intCnt))
                  End If
                Else
                  If Len(arrLValueTokens(intCnt)) > arrMaxTokenLen(UBound(arrMaxTokenLen)) Then
                    arrMaxTokenLen(UBound(arrMaxTokenLen)) = Len(arrLValueTokens(intCnt))
                  End If
                End If
              Next
        
              ReDim Preserve arrLine(UBound(arrLine) + 1)
              arrLine(UBound(arrLine)) = Array(arrLValueTokens, strRValueTokens)
            End If
          Next
        
          For intLineIdx = 0 To UBound(arrLine)
            strLine  = ""
            strToken = arrLine(intLineIdx)(RVALUE)
        
            If IsNumeric(Left(strToken, Len(strToken) - 1)) Then
              strLine  = "= " & Right(String(intMaxRValueLen, " ") & strToken, intMaxRValueLen)
            Else
              strLine  = "= " & strToken
            End If
        
            For intTokenIdx = UBound(arrMaxTokenLen) To 0 Step -1
              If intTokenIdx = UBound(arrMaxTokenLen) Then
                strToken = arrLine(intLineIdx)(LVALUE)(UBound(arrLine(intLineIdx)(LVALUE)))
                strLine  = Left(strToken & String(arrMaxTokenLen(intTokenIdx), " "), arrMaxTokenLen(intTokenIdx)) & " " & strLine
        
              ElseIf UBound(arrLine(intLineIdx)(LVALUE)) > intTokenIdx Then
                strToken = arrLine(intLineIdx)(LVALUE)(intTokenIdx)
                strLine  = Left(strToken & String(arrMaxTokenLen(intTokenIdx), " "), arrMaxTokenLen(intTokenIdx)) & " " & strLine
        
              Else
                strLine = String(arrMaxTokenLen(intTokenIdx), " ") & " " & strLine
              End If
            Next
        
            strOutput = strOutput & strLine & vbNewLine
          Next
        
          WScript.StdOut.Write strOutput
        End If
        

        At next you need a script that can retrieve the clipboard content and stream it to StdOut. It’s a one-liner in JavaScript, save it as pclip.js.

        WSH.Echo(WSH.CreateObject('htmlfile').parentWindow.clipboardData.getData('text'));
        

        At next you need a binding to PorkToSausage. It’s a Batch script, save it as CodeAlign.cmd.

        @echo off
        
        pushd "%~dp0"
        cscript /nologo /e:JScript pclip.js | cscript /nologo "CodeAlign.vbs"
        popd
        

        Put the files CodeAlign.vbs, pclip.js and CodeAlign.cmd together in one directory and move it to <Notepad++-installation-directory>\plugins\Pork2Sausage\CodeAlign.

        Finally you need to add the following to the config file of Pork2Sausage. The plugin provides the ability to load its own config file for editing.

        [CodeAlign]
        progPath=<Notepad++-installation-directory>\plugins\Pork2Sausage\CodeAlign\CodeAlign.cmd
        progCmd=CodeAlign
        workDir=<Notepad++-installation-directory>\plugins\Pork2Sausage\CodeAlign
        replaceSelection=true
        

        The Pork2Sausage plugin will add a menu entry named CodeAlign to its submenu of Plugins menu. You can assign a keyboard shortcut to this entry to simplify things.

        Please note that you have to configure the right path of your Notepad++ installation directory. If you already use Notepad++ v7.6 you should put the directory with the three scripts to the new plugin folder under %UserProfile%\AppData\Local\Notepad++\plugins\PorkToSausage. Of course you have to change the paths in the Pork2Sausage config file accordingly.

        To use the script select the code you want to align and copy it to the clipboard. Then press the keyboard shortcut you assigned to the script’s menu entry. It does its job and the result is automatically pasted to the selected block of lines in the Notepad++ window.

        If you (or another person) is able to write Python scripts, you/(s)he can port the VBScript code to Python and you can use the Python plugin to execute it. This way you wouldn’t need so much script files.

        1 Reply Last reply Reply Quote 2
        • dinkumoilD
          dinkumoil
          last edited by

          @hoji-afzal

          Update: VBScript improved

          • Can handle and keep empty lines
          • Can handle and keep lines without equal sign
          • Code commented now
          Option Explicit
          
          Const LVALUE = 0
          Const RVALUE = 1
          
          Dim arrCode, arrInLine, arrLValueTokens, strRValueTokens, intPrevMaxIdx
          Dim arrLine, arrMaxTokenLen, intLineIdx, intTokenIdx, intMaxRValueLen
          Dim intCnt, strLine, strToken, strOutput
          
          'Read input from StdIn
          If Not WScript.StdIn.AtEndOfStream Then
            'Split input into lines and store them in array
            arrCode = Split(WScript.StdIn.ReadAll, vbNewLine)
          
            'Delete empty trailing line
            If arrCode(UBound(arrCode)) = "" Then
              ReDim Preserve arrCode(UBound(arrCode) - 1)
            End If
            
            arrLine         = Array()
            arrMaxTokenLen  = Array()
            intMaxRValueLen = 0
            strOutput       = ""
          
            'Process all lines
            For intLineIdx = 0 To UBound(arrCode)
              'If current line is empty create empty variables for LValue and RValue
              If arrCode(intLineIdx) = "" Then
                arrLValueTokens = Array("")
                strRValueTokens = ""
              Else
                'Split line in LValue and RValue, delete preceding and trailing space
                'characters and split LValue in tokens
                arrInLine       = Split(arrCode(intLineIdx), "=")
                arrLValueTokens = Split(Trim(arrInLine(0)), " ")
                
                'RValue could be empty
                If UBound(arrInLine) > 0 Then
                  strRValueTokens = Trim(arrInLine(1))
                Else
                  strRValueTokens = ""
                End IF
          
                'Remember maximum length of all RValues
                If Len(strRValueTokens) > intMaxRValueLen Then
                  intMaxRValueLen = Len(strRValueTokens)
                End If
          
                'Build array with a table containing the maximum length of all tokens
                'in the same column.
          
                'If the number of tokens of the current LValue is greater than the number
                'of columns of the table it has to be enlarged.
                If UBound(arrLValueTokens) > UBound(arrMaxTokenLen) Then
                  'Remember index of currently last table cell and enlarge it
                  intPrevMaxIdx = UBound(arrMaxTokenLen)
                  ReDim Preserve arrMaxTokenLen(UBound(arrLValueTokens))
          
                  'Shift the value of the last table cell before enlargement
                  'to the last cell after enlargement
                  If intPrevMaxIdx < 0 Then
                    'If the table had been empty before enlargement set the new element to 0
                    arrMaxTokenLen(UBound(arrMaxTokenLen)) = 0
                  Else
                    'Set the currently last cell of the table to the value
                    'of the previously last cell
                    arrMaxTokenLen(UBound(arrMaxTokenLen)) = arrMaxTokenLen(intPrevMaxIdx)
          
                    'Set the newly added cells to 0
                    For intCnt = intPrevMaxIdx To UBound(arrMaxTokenLen) - 1
                      arrMaxTokenLen(intCnt) = 0
                    Next
                  End If
                End If
          
                'If the current line contains longer tokens in any column than the lines
                'processed before remember the greater length
                For intCnt = 0 To UBound(arrLValueTokens)
                  'If we do not inspect the last table cell compare the same columns of
                  'the LValue tokens and the maximum token length table
                  If intCnt < UBound(arrLValueTokens) Then
                    If Len(arrLValueTokens(intCnt)) > arrMaxTokenLen(intCnt) Then
                      arrMaxTokenLen(intCnt) = Len(arrLValueTokens(intCnt))
                    End If
                  'I we inspect the last LValue token alway compare it with the last cell
                  'of the maximum token length table
                  Else
                    If Len(arrLValueTokens(intCnt)) > arrMaxTokenLen(UBound(arrMaxTokenLen)) Then
                      arrMaxTokenLen(UBound(arrMaxTokenLen)) = Len(arrLValueTokens(intCnt))
                    End If
                  End If
                Next
              End If
          
              'Enlarge ouput array and store array with LValue tokens and RValue string
              ReDim Preserve arrLine(UBound(arrLine) + 1)
              arrLine(UBound(arrLine)) = Array(arrLValueTokens, strRValueTokens)
            Next
            
            'Iterate over output array of loop above and build up an output line from
            'LValue tokens and the RValue. The output line gets assembled from right to left.
            For intLineIdx = 0 To UBound(arrLine)
              strLine  = ""
              
              'Get RValue of current line
              strToken = arrLine(intLineIdx)(RVALUE)
          
              'Add equal sign and RValue only to the output line if RValue is not empty
              If strToken <> "" Then
                'If the RValue is a number right align it otherwise take it as is
                If IsNumeric(Left(strToken, Len(strToken) - 1)) Then
                  strLine = "= " & Right(String(intMaxRValueLen, " ") & strToken, intMaxRValueLen)
                Else
                  strLine = "= " & strToken
                End If
              End If
              
              'Iterate over the maximum token length table starting with last column
              For intTokenIdx = UBound(arrMaxTokenLen) To 0 Step -1
                'When processing the last column, take the last LValue token of the
                'current line, right-pad it with space characters to bring it to the
                'lenght of the longest token in this column and prepend it to output line
                If intTokenIdx = UBound(arrMaxTokenLen) Then
                  strToken = arrLine(intLineIdx)(LVALUE)(UBound(arrLine(intLineIdx)(LVALUE)))
                  strLine  = Left(strToken & String(arrMaxTokenLen(intTokenIdx), " "), arrMaxTokenLen(intTokenIdx)) & " " & strLine
          
                'When processing a column where the current LValue has a token, right-pad
                'it with space characters to bring it to the lenght of the longest token
                'in this column and prepend it to output line
                ElseIf UBound(arrLine(intLineIdx)(LVALUE)) > intTokenIdx Then
                  strToken = arrLine(intLineIdx)(LVALUE)(intTokenIdx)
                  strLine  = Left(strToken & String(arrMaxTokenLen(intTokenIdx), " "), arrMaxTokenLen(intTokenIdx)) & " " & strLine
          
                'When processing a column where the current LValue has no token, pad with
                'space characters to bring it to the lenght of the longest token in this
                'column and prepend it to output line
                Else
                  strLine = String(arrMaxTokenLen(intTokenIdx), " ") & " " & strLine
                End If
              Next
          
              'Avoid appending of lines which contain solely space characters
              If Trim(strLine) = "" Then strLine = Trim(strLine)
              
              'Append output line to output string
              strOutput = strOutput & strLine
          
              'Dont terminate last line with EOL because it's added automatically
              If intLineIdx < UBound(arrLine) Then
                strOutput = strOutput & vbNewLine
              End If
            Next
          
            'Stream output string to StdOut
            WScript.StdOut.Write strOutput
          End If
          
          1 Reply Last reply Reply Quote 0
          • hoji afzalH
            hoji afzal
            last edited by hoji afzal

            Oh man, thanks so much guys for your input!
            I will try these once my manager stops with his “so how much progress did you make?” :)

            I am a fanatic aligner, just bordering having a disease. But usually don’t have time to go that “extreme”. And by extreme I am sure you refer to my right aligning the whole numbers hahaha

            Thanks.

            1 Reply Last reply Reply Quote 0
            • dinkumoilD
              dinkumoil
              last edited by

              @hoji-afzal said:

              I will try these once my manager stops with his “so how much progress did you make?” :)

              Oh yeah, the managers…

              Since you seem interested I have another update of the VBScript for you:

              • Improved handling of aligning lines containing no assignment operator
              • Delimiter and assignment operator configurable by constant in script
              • Keeps indentation
              • Improved detection of empty lines
              • Avoiding superfluous output lines and output lines filled solely with space characters
              Option Explicit
              
              Const LVALUE   = 0
              Const RVALUE   = 1
              Const DelimChr = " "
              Const AssignOp = "="
              
              Dim arrCode, arrInLine, arrLValueTokens, strRValueTokens, intPrevMaxIdx
              Dim arrLine, arrMaxTokenLen, intLineIdx, intTokenIdx, intMaxRValueLen
              Dim intCnt, strLine, strToken, strOutput
              
              'Read input from StdIn
              If Not WScript.StdIn.AtEndOfStream Then
                'Split input into lines and store them in array
                arrCode = Split(WScript.StdIn.ReadAll, vbNewLine)
              
                'Delete empty trailing line
                If arrCode(UBound(arrCode)) = "" Then
                  ReDim Preserve arrCode(UBound(arrCode) - 1)
                End If
                
                arrLine         = Array()
                arrMaxTokenLen  = Array()
                intMaxRValueLen = 0
                strOutput       = ""
              
                'Process all lines
                For intLineIdx = 0 To UBound(arrCode)
                  'If current line is empty create empty variables for LValue and RValue
                  If Trim(arrCode(intLineIdx)) = "" Then
                    arrLValueTokens = Array("")
                    strRValueTokens = ""
                  Else
                    'Split line in LValue and RValue, keep indentation of LValue but delete
                    'preceding and trailing space characters of RValue and split LValue in
                    'tokens
                    arrInLine       = Split(arrCode(intLineIdx), AssignOp)
                    arrLValueTokens = Split(RTrim(arrInLine(0)), DelimChr)
                    
                    'There could be no RValue
                    If UBound(arrInLine) > 0 Then
                      strRValueTokens = Trim(arrInLine(1))
                    Else
                      strRValueTokens = ""
                    End IF
              
                    'Remember maximum length of all RValues
                    If Len(strRValueTokens) > intMaxRValueLen Then
                      intMaxRValueLen = Len(strRValueTokens)
                    End If
              
                    'Build a maximum token length table containing the maximum length of all
                    'LValue tokens in the same column
              
                    'If the number of tokens of the current LValue is greater than the number
                    'of columns of the table it has to be enlarged.
                    If UBound(arrLValueTokens) > UBound(arrMaxTokenLen) Then
                      'Remember index of currently last table cell and enlarge table
                      intPrevMaxIdx = UBound(arrMaxTokenLen)
                      ReDim Preserve arrMaxTokenLen(UBound(arrLValueTokens))
              
                      'Shift the value of the last table cell before enlargement
                      'to the last cell after enlargement
                      If intPrevMaxIdx < 0 Or strRValueTokens = "" Then
                        'If the table had been empty before enlargement set new cell to 0
                        arrMaxTokenLen(UBound(arrMaxTokenLen)) = 0
                      Else
                        'Set the currently last cell of the table to the value of the
                        'previously last cell
                        arrMaxTokenLen(UBound(arrMaxTokenLen)) = arrMaxTokenLen(intPrevMaxIdx)
              
                        'Set the newly added cells to 0
                        For intCnt = intPrevMaxIdx To UBound(arrMaxTokenLen) - 1
                          arrMaxTokenLen(intCnt) = 0
                        Next
                      End If
                    End If
              
                    'If the current line contains longer tokens in any column than the lines
                    'processed before, remember the greater length
                    For intCnt = 0 To UBound(arrLValueTokens)
                      'If we do not inspect the last table cell, compare the same columns of
                      'the LValue tokens and the maximum token length table
                      If intCnt < UBound(arrLValueTokens) Or strRValueTokens = "" Then
                        If Len(arrLValueTokens(intCnt)) > arrMaxTokenLen(intCnt) Then
                          arrMaxTokenLen(intCnt) = Len(arrLValueTokens(intCnt))
                        End If
                      'I we inspect the last LValue token, always compare it with the last cell
                      'of the maximum token length table
                      Else
                        If Len(arrLValueTokens(intCnt)) > arrMaxTokenLen(UBound(arrMaxTokenLen)) Then
                          arrMaxTokenLen(UBound(arrMaxTokenLen)) = Len(arrLValueTokens(intCnt))
                        End If
                      End If
                    Next
                  End If
              
                  'Enlarge ouput array and store array with LValue tokens and RValue string
                  ReDim Preserve arrLine(UBound(arrLine) + 1)
                  arrLine(UBound(arrLine)) = Array(arrLValueTokens, strRValueTokens)
                Next
                
                'Iterate over output array of loop above and build up an output line from
                'LValue tokens and the RValue. The output line gets assembled from right to left.
                For intLineIdx = 0 To UBound(arrLine)
                  strLine  = ""
                  
                  'Get RValue of current line
                  strToken = arrLine(intLineIdx)(RVALUE)
              
                  'Add assignment operator and RValue to output line only if RValue is not empty
                  If strToken <> "" Then
                    'If the RValue is a number right align it otherwise take it as is
                    If IsNumeric(Left(strToken, Len(strToken) - 1)) Then
                      strLine = AssignOp & " " & Right(String(intMaxRValueLen, " ") & strToken, intMaxRValueLen)
                    Else
                      strLine = AssignOp & " " & strToken
                    End If
                  End If
                  
                  'Iterate over the maximum token length table starting with last column
                  For intTokenIdx = UBound(arrMaxTokenLen) To 0 Step -1
                    'When processing the last column, take the last LValue token of the
                    'current line, right-pad it with space characters to bring it to the
                    'lenght of the longest token in this column and prepend it to output line
                    If intTokenIdx = UBound(arrMaxTokenLen) And arrLine(intLineIdx)(RVALUE) <> "" Then
                      strToken = arrLine(intLineIdx)(LVALUE)(UBound(arrLine(intLineIdx)(LVALUE)))
                      strLine  = Left(strToken & String(arrMaxTokenLen(intTokenIdx), " "), arrMaxTokenLen(intTokenIdx)) & DelimChr & strLine
              
                    'When processing a column where the current LValue has a token, right-pad
                    'it with space characters to bring it to the lenght of the longest token
                    'in this column and prepend it to output line
                    ElseIf (UBound(arrLine(intLineIdx)(LVALUE)) > intTokenIdx) Or _
                           (UBound(arrLine(intLineIdx)(LVALUE)) = intTokenIdx And arrLine(intLineIdx)(RVALUE) = "") Then
                      strToken = arrLine(intLineIdx)(LVALUE)(intTokenIdx)
                      
                      If intTokenIdx = UBound(arrMaxTokenLen) And arrLine(intLineIdx)(RVALUE) = "" Then
                        strLine  = Left(strToken & String(arrMaxTokenLen(intTokenIdx), " "), arrMaxTokenLen(intTokenIdx))
                      Else
                        strLine  = Left(strToken & String(arrMaxTokenLen(intTokenIdx), " "), arrMaxTokenLen(intTokenIdx)) & DelimChr & strLine
                      End If
              
                    'When processing a column where the current LValue has no token, pad with
                    'space characters to bring it to the lenght of the longest token in this
                    'column and prepend it to output line
                    Else
                      If intTokenIdx = UBound(arrMaxTokenLen) And arrLine(intLineIdx)(RVALUE) = "" Then
                        strLine = String(arrMaxTokenLen(intTokenIdx), " ")
                      Else
                        strLine = String(arrMaxTokenLen(intTokenIdx), " ") & DelimChr & strLine
                      End If
                    End If
                  Next
              
                  'Avoid appending of lines which contain solely space characters
                  If Trim(strLine) = "" Then strLine = ""
                  
                  'Append output line to output string
                  strOutput = strOutput & strLine
              
                  'Dont terminate last line with EOL because it is added automatically
                  If intLineIdx < UBound(arrLine) Then
                    strOutput = strOutput & vbNewLine
                  End If
                Next
              
                'Stream output string to StdOut
                WScript.StdOut.Write strOutput
              End If
              

              Unfortunately the Pork2Sausage plugin currently has a bug, it streams at maximum 1024 bytes/characters back to Notepad++. I’ve already created a pull request with a fix, let’s see if and when it will be published.

              1 Reply Last reply Reply Quote 0
              • hoji afzalH
                hoji afzal
                last edited by

                Thanks for the code. But I’m sorry I still haven’t had a chance to try it. Plus, I am not very experienced with scripts.

                However, I did try TextFX and find its tool useful. I have set up a shortcut for it which I have been using. It’s TextFX > TextFX Edit > E: Line up multiple lines by (Clipboard Character). Unfortunately it doesn’t accept either space (perhaps the most useful character) or a pattern of characters. But still it’s Okay.
                Having said that, that menu is nowhere near as powerful or useful as a context menu to select a block and set it either right or left justified.

                Hoji

                1 Reply Last reply Reply Quote 0
                • guy038G
                  guy038
                  last edited by guy038

                  Hello @hoji-afzal @peterjones, @dinkumoil, @scott-sumner, @chcg and All,

                  I’ve found out a solution to line up with the space character :-)) Nevertheless, it’s just a work-around which could be rather tedious, if you want to line up a lot of small blocks of text :-(( Just have a try !

                  It does not imply any script, just the TextFX plugin of course, and the native N++ Search/Replacement feature ;-))


                  Here are, below, the different steps to follow :

                  • First, anywhere in a file, on an empty location, hold down the ALT key and type, successively, on keys 0, 3 and 1, of the numeric keypad, then release the ALT key

                  => A control character US, with code-point = \x1F, should be displayed, in reverse video !

                  • Copy this single character in the clipboard

                  • Select all the ( not aligned ) text of your previous example

                  public byte PUSH = 1;
                  private const int STOP = 0;
                  public const double SECS_TO_START = 10;
                  public int SEPARATOR = 21;
                  
                  • Now, open the Replace dialog ( Ctrl + H )

                  • SEARCH \x20+

                  • REPLACE \x1f

                  • Check the In selection option, ( on the left of the Replace All button ) IMPORTANT

                  • Select the Regular expression search mode

                  • Click on the Replace All button

                  => At once, all range of consecutive space characters, in the selection, are replaced with the control character US

                  • Then, click on the TextFX menu, leaving the Replace dialog in the background

                  • Select the option TextFX > TextFX Edit > Line up multiple lines by (Clipboard Character)

                  => Now, most of the US characters should be aligned !

                  • Click back on the Replace dialog ( Note that your text is still selected )

                  • SEARCH \x1f

                  • REPLACE \x20

                  • Keep the same options as above

                  • Click on the Replace All button

                  => You should get the result, below :

                  public  byte  PUSH      =             1;
                  private const int       STOP          = 0;
                  public  const double    SECS_TO_START = 10;
                  public  int   SEPARATOR =             21;
                  

                  At first sight, we remark that some words are quite aligned, but not exactly in the way you would !:-(( The problem comes from the expressions Const int and Const double that you consider as single entities whereas the TextFX plugin considers, logically, that there are two consecutive words, separated with a space char !

                  So, regarding your very simple block of code, I would say that the rule is : when a space character, is located after the word const, in lower-case, it should not be replaced with the US control char

                  Thus, if you re-execute all the previous steps, replacing the first search regex \x20+ with the regex (?-i)(?<!\bconst)\x20+, you should be left with the expected text, below :

                  public  byte         PUSH          = 1;
                  private const int    STOP          = 0;
                  public  const double SECS_TO_START = 10;
                  public  int          SEPARATOR     = 21;
                  

                  Nice, isn’t it ? Note you still have to align the numbers, at the end of the lines !

                  REMEMBER : When using the line up feature, the TextFX plugin does not consider any ,, = or clipboard character which are between two double quotes "........" nor between two simple quotes '........' !


                  If you are interested to go further on, @hoji-afzal, just tell me all the multi-words expressions which need to be considered as a single word and I’ll try to get the appropriate regex, which preserves space characters, in these expressions :-))

                  Best Regards,

                  guy038

                  hoji afzalH 1 Reply Last reply Reply Quote 3
                  • hoji afzalH
                    hoji afzal @guy038
                    last edited by hoji afzal

                    @guy038

                    Thanks a lot; I just tried your steps and they work pretty well.

                    If anyone else wants to try it, be sure to use the **numeric **keypad to enter 031.

                    I will try (?-i)(?<!\bconst)\x20+ later on. And after that will brush up on my regular expressions :)

                    Appreciate your time!

                    Hoji

                    1 Reply Last reply Reply Quote 2
                    • guy038G
                      guy038
                      last edited by guy038

                      Hi, @hoji-afzal and All,

                      In my previous post, I used the control character \x1F as a temporary character, while executing the TextFX Line up option.

                      Of course, this is not a mandatory step ! You may, as well, use any symbol, which is NOT part of your block selection, yet ;-)). So, for instance, with your initial block of text :

                      public byte PUSH = 1;
                      private const int STOP = 0;
                      public const double SECS_TO_START = 10;
                      public int SEPARATOR = 21;
                      

                      Any symbol, other than a semicolon and the equal sign, could be appropriate ;-))


                      With a hash symbol, for example, the main actions, with your sample text, would be :

                      • Copy a single #, in the clipboard

                      • Perform a first S/R, below, with Regular expression and In selection options ticked

                        • SEARCH (?-i)(?<!\bconst)\x20+

                        • REPLACE #

                      • Click on TextFX > TextFX Edit > Line up multiple lines by (Clipboard Character)

                      • Perform a second S/R, below, with Regular expression and In selection options ticked

                        • SEARCH #

                        • REPLACE \x20 ( you may, also, use a simple space char, instead ! )


                      Of course, if this temporary char is a control character, other than \r or \n, you’re quasi-certain that it is not used anywhere else, in current text or source code file !

                      Cheers,

                      guy038

                      hoji afzalH 1 Reply Last reply Reply Quote 1
                      • hoji afzalH
                        hoji afzal @guy038
                        last edited by

                        @guy038

                        Got it!
                        Notepad++ keeps a history of your searches, which is handy for this kind of operation.
                        Thanks a lot.
                        Hoji

                        1 Reply Last reply Reply Quote 0
                        • hoji afzalH
                          hoji afzal
                          last edited by

                          Hi all,

                          Just an update: I have been using TextFX in the last 5 months and it does the job pretty well. Was too lazy to try the other methods members graciously provided.

                          Thanks!

                          1 Reply Last reply Reply Quote 1
                          • First post
                            Last post
                          The Community of users of the Notepad++ text editor.
                          Powered by NodeBB | Contributors