Community
    • Login

    File Specific word wrap (vs. global enable)

    Scheduled Pinned Locked Moved General Discussion
    feature requestword wrap
    22 Posts 7 Posters 14.6k 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.
    • Claudia FrankC
      Claudia Frank @guy038
      last edited by

      Hi guy038,

      thanks for the hint to the updated encoding thread. Hard work done ;-)

      Regarding the line number, book mark, folding columns I did some test
      and discovered a slight inconsistency here.
      Assuming you have checked

      • display line number
      • display bookmark
      • display folding (doesn’t exist, I know you are aware, it’s just for completeness and should mean is visible)

      you can hide bookmark and folding columns for different documents
      but you cannot hide line number column.
      There is a flickering so I assumed that either npp or a plugin
      checked the visibility state of that column.
      I started notepad with only python script plugin
      and issue still existed, so, I guess it’s npp itself.

      OK, this means we need to revert the conditions and
      assume nothing has been checked and the script
      makes it visibile on demand.
      This works - no problem, as long as you do
      not switch between tabs to fast.

      I will see what else can be made and will come back on this.

      Cheers
      Claudia

      1 Reply Last reply Reply Quote 0
      • Claudia FrankC
        Claudia Frank
        last edited by

        Hi guy038,

        here are some methods you were thinking about.

        Show Symbols

        • editor.setViewWS(1) # 0 to hide
        • editor.setViewEOL(1) # 0 to hide

        Margins (scintilla supports up to 5, npp uses only three 0, 1, 2)

        • line numbers
          editor.setMarginWidthN(0, 38) # standard value

        • bookmark margin
          editor.setMarginWidthN(1, 14) # standard value

        • folding margin
          editor.setMarginWidthN(2, 14) # standard value

        First parameter is the margin id (0,1,2) and second parameter means width in pixel.
        A second parameter being 0 hides the margin

        • line numbers
          editor.setMarginWidthN(0, 0)

        • bookmark margin
          editor.setMarginWidthN(1, 0)

        • folding margin
          editor.setMarginWidthN(2, 0)

        • Show Vertical edge line
          notepad.menuCommand(MENUCOMMAND.VIEW_EDGELINE) # MENUCOMMAND.VIEW_EDGENONE to hide

        • Zoom level
          editor.setZoom(+5)
          A positive number to increase font size, a negativ to decrease or 0 to reset to standard

        • Text direction
          notepad.menuCommand(MENUCOMMAND.RTL) # or MENUCOMMAND.LTR (left-to-right)

        • Indentation Guides
          editor.setIndentationGuides(1) # 0 to hide

        I didn’t found a MENUCOMMAND equivalent for smart highlighting, maybe this hasn’t been ported.

        A more generic version of the script.

        def func2call(i):
            if i == 1:
                editor.setWrapMode(0)
                editor.setMarginWidthN(0,0)
                editor.setMarginWidthN(1,0)
                editor.setMarginWidthN(2,0)
                editor.setViewWS(0)
                editor.setViewEOL(0)
                editor.setIndentationGuides(0)
                editor.setZoom(0)
                notepad.menuCommand(MENUCOMMAND.VIEW_EDGENONE)
                notepad.menuCommand(MENUCOMMAND.EDIT_LTR)
                
            else:
                editor.setWrapMode(1)                               # activate word wrap
                editor.setMarginWidthN(0,38)                        # show line number column
                editor.setMarginWidthN(1,14)                        # show bookmark column
                editor.setMarginWidthN(2,14)                        # show folding column
                # editor.setMarginWidthN(3,0)                         # not used or usage not found yet
                # editor.setMarginWidthN(4,0)                         # not used or usage not found yet
                editor.setViewWS(1)                                 # show whitespaces
                editor.setViewEOL(1)                                # show end of line chars
                editor.setIndentationGuides(1)                      # show indention guides
                editor.setZoom(+5)                                 # ZOOM
                notepad.menuCommand(MENUCOMMAND.VIEW_EDGELINE)      # show edge line
                notepad.menuCommand(MENUCOMMAND.EDIT_RTL)           # text right to left
                
                        
                
        def npp_callback_BUFFERACTIVATED(args):
            if editor.getProperty(args['bufferID']) == '1':
                func2call(0)
            else:
                func2call(1)
                
        if editor.getProperty('callback_already_set') != '1':
            notepad.callback(npp_callback_BUFFERACTIVATED, [NOTIFICATION.BUFFERACTIVATED ])
            editor.setProperty('callback_already_set', '1')
        else:
            notepad.clearCallbacks([NOTIFICATION.BUFFERACTIVATED])
            editor.setProperty('callback_already_set', '0')
            
        current_bufferID = str(notepad.getCurrentBufferID())
        if editor.getProperty(current_bufferID) != '1':
            editor.setProperty(current_bufferID, '1')
            func2call(0)
        else:
            editor.setProperty(current_bufferID, '0')
            func2call(1)
        

        The margin columns seem to be special cases.
        One issue I had when trying to hide the line column
        even when setting to display has been enabled
        and another one is the folding column.
        It reapears if pixel width is set to 0 by
        switching to different document. Hmm … ???
        Assume that both are handled by npp and/or lexer as well.
        Will see if I can work around.

        Cheers
        Claudia

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

          Hi Claudia,

          I’ve just installed the Python Script plugin, on the last v6.8.8 version and I tested your script, choosing successively a particular property : It worked nice !

          Of course, we get, from time to time, some weird effects. One example :

          I previously changed your script, in order to ONLY use the Word Wrap feature ( I put the other lines in comments )

          I suppose that the Word wrap is UNSET, on starting N++, and that it contains four opened tabs

          • Select tab #2 and run your script, then select tab #4 and run your script again. Well, if you select from tab #1 to #4, tabs #2 and #4 have the property Word wrap ENABLED and tabs #1 and #3 DON’T. Logical !

          • Then, click again on tab #2 and run your script => all the tabs seem to have the Word Wrap DISABLED ?

          • Finally, click, a last time, on tab #2 and run your script => Again the tab #2 ( as well as tab #4 !! ) have, again, the property Word Wrap ENABLED :-))

          There are some other cases like that. However, Claudia, it doesn’t matter. The main fact is that a displaying property, which is managed, on the whole, by N++, for all the opened files, can be set, with a Python script, individually, for 1 or few files ONLY :-))

          This valuable script may be useful, from time to time. Many thanks, for your “Python” work !

          Cheers,

          guy038

          Claudia FrankC 2 Replies Last reply Reply Quote 0
          • Claudia FrankC
            Claudia Frank @guy038
            last edited by

            Hi guy038,

            your welcome but you are right, strange, need to dig deeper to see what happens there.
            Let’s see if we find the bug ;-)

            Cheers
            Claudia

            1 Reply Last reply Reply Quote 0
            • Claudia FrankC
              Claudia Frank @guy038
              last edited by Claudia Frank

              Hello guy038,

              I guess I found the problem and a work around because
              I’m not 100% convinced of this solution.

              I did some additional console.write statement wihtin the code and found out,
              that the notepad callback needs to be set once only. Indeed it was the source of the
              problem as it seems that it has confused the python script plugin.

              So what needs to be done is to comment (or delete) the following lines

              # if editor.getProperty('callback_already_set') != '1':
                  # editor.setProperty('callback_already_set', '1')
                  # notepad.callback (npp_callback_BUFFERACTIVATED, [NOTIFICATION.BUFFERACTIVATED ])
                  # console.write('{0}\n'.format('callback registered'))
              # else:
                  # notepad.clearCallbacks([NOTIFICATION.BUFFERACTIVATED])
                  # editor.setProperty('callback_already_set', '0')
                  # console.write('{0}\n'.format('callback deleted'))
              

              and add the line before or afterwards the commented block.

              notepad.callback (npp_callback_BUFFERACTIVATED, [NOTIFICATION.BUFFERACTIVATED ])
              

              The changes do have a drawback so, it means that the script doesn’t do the clearcallback anymore.
              Not sure if this is an issue but if so, you can always run

              notepad.clearCallbacks([NOTIFICATION.BUFFERACTIVATED])
              

              from python script console or restart npp. ;-)

              Cheers
              Claudia

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

                Hi Claudia,

                I tested your changed script. It woks great, indeed ! Referring to my last try, each time I ran this new version of your script, the state of the word wrap option, for the current file was changed into the opposite state, even, when using two simultaneous views !

                And, when running the command, below :

                notepad.clearCallbacks([NOTIFICATION.BUFFERACTIVATED])
                

                In the Python console, I noticed that it sets the Word wrap state of the current document of each view, to all the opened documents of that associated view !

                Of course, after using the Python script, you can’t, seriously, rely on the visual appearance, of the Word Wrap button and/or the v indication, in menu View - Word wrap, as well as a click action, on this button/option !

                Just remember to use the Claudia script, exclusively, to get the right state of the Word Wrap ( or an other property ! ) that you want, for the current document !

                Thanks again, Claudia, for that nice Notepad++'s improvement !

                Cheers,

                guy038

                P.S :

                However, there’s, still, a limitation. For instance, if your create two ( almost ) identical scripts :

                • The first one, to modify a displaying property of the current document

                • The second one, to modify an OTHER property, of the current document

                The python script get confused and the properties can’t be set, simultaneously. Rather normal, however. We just have to be aware about this fact !

                1 Reply Last reply Reply Quote 0
                • Scott SumnerS
                  Scott Sumner
                  last edited by

                  @Claudia-Frank 's FIRST Pythonscript in this thread really shines if the Wrap status is added to the status bar using the technique shown in the following thread: https://notepad-plus-plus.org/community/topic/13134/set-read-only-edit-function-feature-request. In that thread, the read-only status of the current file is shown (based upon a script in yet-another thread…sorry), but that can be modified to show the wrap status as follows:

                  Change

                  line_col_sel_info_for_sb = 'Ln : {user_line}     Col : {user_col}     Sel : {sel}     {ro}r'.format(
                      user_line=curr_line+1,
                      user_col=curr_col+1,
                      sel=sel_part,
                      ro='+' if editor.getReadOnly() else '-'
                      )
                  

                  to

                  line_col_sel_info_for_sb = 'Ln : {user_line}     Col : {user_col}     Sel : {sel}     {w}'.format(
                      user_line=curr_line+1,
                      user_col=curr_col+1,
                      sel=sel_part,
                      w='W' if editor.getWrapMode() == 1 else ''  # show 'W' in status bar if wrap mode is on for this file
                      )
                  
                  Claudia FrankC 1 Reply Last reply Reply Quote 0
                  • Claudia FrankC
                    Claudia Frank @Scott Sumner
                    last edited by

                    Scott,

                    don’t dig to deep to find my all of my youthful follies. ;-)

                    Cheers
                    Claudia

                    Scott SumnerS 1 Reply Last reply Reply Quote 1
                    • Scott SumnerS
                      Scott Sumner @Claudia Frank
                      last edited by

                      @Claudia-Frank

                      Yea, I can tell that is earlier code from you, but it works!

                      1 Reply Last reply Reply Quote 0
                      • Clyfton InC
                        Clyfton In
                        last edited by

                        I know this topic old but I tried the referenced solution and could not get it to work.
                        I went to PLUGINS > PYTHON SCRIPT > NEW SCRIPT and saved the example code as file_word_wrap.
                        When I go to PLUGINS > PYTHON SCRIPT > SCRIPTS and click on file_word_wrap I get error: AN EXCEPTION OCCURRED DUE TO PLUGIN: PYTHONSCRIPT.DLL EXCEPTION REASON: ACCESS VIOLATION

                        I also added …
                        <Item PluginEntryName=“Python Script” PluginCommandItemName=“file_word_wrap” />
                        … at the bottom of contextMenu.xml as instructed but did not see it as a right-click option.

                        astrosofistaA 1 Reply Last reply Reply Quote 0
                        • astrosofistaA
                          astrosofista @Clyfton In
                          last edited by

                          Hi @Clyfton-In , All:

                          I also know that this topic is old, but tried today the python script and it worked fine for me.

                          The following picture includes the relevant code and highlights the status bar zone that shows the requested info:

                          684b9764-8455-4a33-9904-674d5957fc55-imagen.png

                          BR

                          Alan KilbornA 1 Reply Last reply Reply Quote 3
                          • Alan KilbornA
                            Alan Kilborn @astrosofista
                            last edited by

                            The Pythonscript is great and all, but this surely feels like something that should be offered as a feature in stock Notepad++. My 2c.

                            astrosofistaA 1 Reply Last reply Reply Quote 2
                            • astrosofistaA
                              astrosofista @Alan Kilborn
                              last edited by

                              @Alan-Kilborn

                              I think so. I also think that the regex indicators —not shown in my picture— are a nice and helpfull add-on.

                              Alan KilbornA 1 Reply Last reply Reply Quote 0
                              • Alan KilbornA
                                Alan Kilborn @astrosofista
                                last edited by

                                @astrosofista said in File Specific word wrap (vs. global enable):

                                regex indicators

                                What “regex indicators” are you referring to? Did I miss something?

                                astrosofistaA 1 Reply Last reply Reply Quote 0
                                • astrosofistaA
                                  astrosofista @Alan Kilborn
                                  last edited by

                                  @Alan-Kilborn said in File Specific word wrap (vs. global enable):

                                  @astrosofista said in File Specific word wrap (vs. global enable):

                                  regex indicators

                                  What “regex indicators” are you referring to? Did I miss something?

                                  Sorry, my wording wasn’t clear enough. I was referring to the regex metacharacters that Scott Sumner used to enrich the info about the selected characters and lines. They are listed here:

                                  link text

                                  Alan KilbornA 1 Reply Last reply Reply Quote 2
                                  • Alan KilbornA Alan Kilborn referenced this topic on
                                  • Alan KilbornA Alan Kilborn referenced this topic on
                                  • Alan KilbornA
                                    Alan Kilborn @astrosofista
                                    last edited by

                                    I revisit the original topic of this thread HERE.

                                    1 Reply Last reply Reply Quote 0
                                    • Alan KilbornA Alan Kilborn referenced this topic on
                                    • First post
                                      Last post
                                    The Community of users of the Notepad++ text editor.
                                    Powered by NodeBB | Contributors