Limit line length



  • Is there a way to limit line length? I use this program to read and create military message that have a line length limitation of 69 characters. I would like to be able to have the line wrap at that point so my text is the proper format. Can this be accomplished currently?

    L Bryan



  • @Larry-Bryan Yes, it can. But you’re not going to like it.

    1. Open Notepad++ as Administrator.
    2. Go to Plugins > Plugin Manager > Show Plugin Manager.
    3. Under Available, locate “TextFX Characters”, check its little checkbox, and click [Install].
    4. Upon completion, a Dialog should append asking to restart: click [Yes].

    Ok. Now, you got the tool. Now, here’s how to format it to the 69 character limit.

    1. Hit Cntrl+n, type 69 into the new file, hit Cntrl+a then Cntrl+x, close the new file.
    2. Select (highlight) your message.
    3. Click TextFX on Notepad++ (it should be on menu-bar/top), then hover over “TextFX Editor”, and finally click “ReWrap…Clipboard or 72…” (it should be the second from the bottom).

    The tool wil now format your big long message into lines of 69 characters. The tool knew you copied 69 onto your clipboard so it read 69 and used 69 instead of 72.



  • @Larry-Bryan

    Another solution would involve python script plugin and this script.

    WRAP_CHAR_COL = 69                                                                  # wrap lines after position WRAP_CHAR_COL
    EOL_CHARS = ['\r\n','\r','\n']                                                      # used to insert correct eol char
    
    _g = globals()                                                                      # global variable used to check status
    if not _g.get('CUSTOM_WRAP_IS_RUNNING'):                                            # if variable not defined yet,
        CUSTOM_WRAP_IS_RUNNING = False                                                  # set it to False (=NOT RUNNING)
                                                                                        
    # -----------------------------------------------------------------------------     
                                                                                        
    def callback_CHARADDED(args):                                                       # get called when char has been added
        current_position = editor.getCurrentPos()                                       # get current caret position
        if editor.getColumn(current_position) > WRAP_CHAR_COL:                          # if position is greater then WRAP_CHAR_COL
            word_position = editor.wordStartPosition(current_position, True)            # calculate start position of current word and
            eol_char = EOL_CHARS[editor.getEOLMode()]                                   # get eol char currently used.
            editor.insertText(word_position, eol_char)                                  # insert the eol char at the word start position
            editor.gotoPos(current_position + len(eol_char))                            # and move caret to new position
                                                                                        
    # -----------------------------------------------------------------------------     
                                                                                         
    def main():                                                                         # main function to handle start/stop behavior
        global CUSTOM_WRAP_IS_RUNNING                                                   # assining to global variable
        if CUSTOM_WRAP_IS_RUNNING:                                                      # if script is currently running
            editor.clearCallbacks([SCINTILLANOTIFICATION.CHARADDED])                    # clear registered callback,
            editor.setEdgeMode(False)                                                   # hide edge line and
            CUSTOM_WRAP_IS_RUNNING = False                                              # set flag to False
        else:                                                                           # else
            CUSTOM_WRAP_IS_RUNNING = True                                               # set the flag to true and
            editor.setEdgeColumn(WRAP_CHAR_COL)                                         # edge line position.
            editor.setEdgeMode(True)                                                    # show edge line and
            editor.callback(callback_CHARADDED, [SCINTILLANOTIFICATION.CHARADDED])      # register needed callback
                                                                                         
    # ----------------------------------------------------------------------------- 
            
    main()
    

    Comments describe what the script does. I assumed that you would break the whole word and not only by char.

    What needs to be done first is described here

    Just in case that you haven’t installed python script plugin yet, I would propose to use the MSI package instead of using the plugin manager.

    Cheers
    Claudia



  • Hello Larry,

    You could, also, have a look to my method, using regular expressions, at the address, below :

    https://notepad-plus-plus.org/community/topic/10642/how-do-i-get-the-file-to-wrap-the-line-at-78-characters/5

    Best Regards,

    guy038


Log in to reply