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.
    • guy038G
      guy038
      last edited by guy038

      Hi Dan , and Claudia,

      Up to now, the individual properties, memorized by Notepad++, in the Session.xml configuration file, for each file and each view, are the following :

      • File firstVisibleLine
      • xOffset
      • scrollWidth
      • startPos
      • endPos
      • selMode
      • lang
      • encoding
      • filename
      • backupFilePath
      • originalFileLastModifTimestamp

      So, Claudia, your Python script, seems valuable, to customize N++, for some other properties, than Word Wrap, which can, only, be set for all the opened files. I thinking of :

      • The show symbols

      • The line numbers margin

      • The bookmark margin

      • The vertical edge line

      • The smart highlighting

      • The zoom level

      • The text direction

      • …


      So, I’m wondering, if these properties could be set, as the Word Wrap one, individually, for few opened files, only ?

      For instance, the Python script command, for displaying the line numbers margin, should be :

      Notepad.menuCommand(MENUCOMMAND.VIEW_LINENUMBER)
      

      Not sure, Claudia, that is the exact syntax, anyway !!

      Best Regards,

      guy038

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

        Hi guy038,

        I disagree, the script is a global word wrap hack, correct, but it does what it was asking for. If you run this script on the opened document, only this document
        has the word wrap done. The other documents stay without having the word
        wrap done. It cannot be saved, not in the current state of it version, to survive
        a restart of npp but I can think of possible solutions to overcome this as well.
        Something like

        • create a file and store the status of the files which should have the word wrap
        • in startup.py, run code to load that file on npp startup.

        Just out of my mind, nothing tested but I strongly believe that it could be done.

        Cheers
        Claudia

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

          Hi guy038,

          I missed this one

          So, I’m wondering, if these properties could be set, as the Word Wrap one, individually, for few opened files, only ?

          Yes, I assume this can be done. Let me check it and do some tests.

          and in regards to

          Notepad.menuCommand(MENUCOMMAND.VIEW_LINENUMBER)
          

          yes, only change first letter to be lowercase.

          notepad.menuCommand(MENUCOMMAND.VIEW_LINENUMBER)
          

          then it will work. ;-)

          Cheers
          Claudia

          Btw. don’t know if you celebrate christmas, if so merry christmas ;-)

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

            Hi Claudia,

            I’ve already understood, as you clearly explained, that your script :

            • allows to set the Word Wrap feature, for the current file A

            • allows to reset the Word Wrap feature for the same current file A, by running file_word_Wrap, a second time

            So, in my previous post, I shouldn’t have spoken about the Session.xml file, which stores some parameters, for each file of a session, for the next sessions to come. This behaviour is quite different from your script’s behaviour, of course and my post was a bit confusing :-(

            However, I do think that your script could be useful for other properties than the Word Wrap one !

            For instance, before sending a new post, I, generally, write it, first, in a text file, with N++. For these different text files, I usually don’t need the Line Numbers margin. So, it would be interesting, from time to time, to display the line numbers for one/two specific file(s), only :-)

            Cheers,

            guy038

            P.S. :

            I think that we replied to each other, simultaneously ! Thanks for your correction. And I’m rather glad for getting my first right command, in the Python Script help file !

            Have a look, again, at my post below. I added, in post-scriptum, the main differences between an Encoding and a Converting N++ action :

            https://notepad-plus-plus.org/community/topic/10981/np-6-8-8-file-encode-type-does-not-stay-as-utf8/7

            Claudia FrankC 1 Reply Last reply Reply Quote 0
            • 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