File Specific word wrap (vs. global enable)
-
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 -
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 runnotepad.clearCallbacks([NOTIFICATION.BUFFERACTIVATED])
from python script console or restart npp. ;-)
Cheers
Claudia -
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 !
-
-
@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 )
-
Scott,
don’t dig to deep to find my all of my youthful follies. ;-)
Cheers
Claudia -
Yea, I can tell that is earlier code from you, but it works!
-
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 VIOLATIONI 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. -
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:
BR
-
The Pythonscript is great and all, but this surely feels like something that should be offered as a feature in stock Notepad++. My 2c.
-
I think so. I also think that the regex indicators —not shown in my picture— are a nice and helpfull add-on.
-
@astrosofista said in File Specific word wrap (vs. global enable):
regex indicators
What “regex indicators” are you referring to? Did I miss something?
-
@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:
-
-
-
I revisit the original topic of this thread HERE.
-