Problem with Margins in PythonScript Plugin and Margins in Distraction Free mode
-
Hi, I have stumbled upon PeterJones’ replies in these two posts:
First
SecondThat indeed solved my issue back then, but since then I have had a few problems and wondered if the same feature is able to work in “Distraction Free mode”?
So first - the problem. As PeterJones have nicely explained I’ve installed PythonScript plugin and Plugins > Python Script > Scripts and upon Ctrl+Click startup(user) I have set these values:
editor1.setMarginLeft(325) editor2.setMarginLeft(325) editor1.setMarginRight(325) editor2.setMarginRight(325)
Since I’ve wanted to have 80 characters on the line.
I don’t know if this would work universally, but for my ancient 5:4 Monitor 1280x1024 it works. 79 characters are available on a single line, while 80th character is a CRLF(I guess that’s two in a way, but visually it’s the same since I only see 79 characters on the line).Anyway, what is the problem? The problem is that I’ve set this Plugin to ATSTARTUP and while it definitely works when I open a file in Notepad++ it breaks immediately as soon as I make any change inside of it.
By change I don’t mean insertion and deletion of characters in the opened file, but on any external thing I do in Notepad++ such as: Opening a new Tab, Closing a Tab, Pressing Alt key(for Menu bar to appear since I have both Menu bar and Toolbar hidden by default), getting back from Distraction Free Mode, etc. etc.
Is there a way to make this Plugin more embedded in the Notepad++ so it doesn’t break on everything I do?
Also is it possible that I can edit Margin values inside of Distraction Free mode? Currently the default is quite a bit “wider” than my 80 characters centered.
Distraction Free mode with centered 80 characters would be a dream.
Is it possible to do such thing inside of Notepad++?
Thanks.
-
@Neko-Nekokovic said in Problem with Margins in PythonScript Plugin and Margins in Distraction Free mode:
Anyway, what is the problem? The problem is that I’ve set this Plugin to ATSTARTUP and while it definitely works when I open a file in Notepad++ it breaks immediately as soon as I make any change inside of it.
By change I don’t mean insertion and deletion of characters in the opened file, but on any external thing I do in Notepad++ such as: Opening a new Tab, Closing a TabWhen you switch tabs in Notepad++, as an example, Notepad++ does a mini-reinitialization of Scintilla, because there’s truly only one (or possibly two, if you have both views open) Scintilla documents open at a time, no matter how many tabs you have open. Some of the things N++ does during this can trounce on something you’ve set via a scripting plugin, as it re-inits for the active tab/document.
Notepad++ and PythonScript don’t always act entirely “in concert” with one another, and apparently you’ve hit on one of those cases. Truly, Notepad++ doesn’t care (or know) at all what PS does; PS for its part, as the “follow-on” plugin, mostly compensates for however N++ wants to do things–it has to.
Is there a way to make this Plugin more embedded in the Notepad++ so it doesn’t break on everything I do?
Well, not really. And it shouldn’t break everything you want to do; it’s probably just that the thing you want to do is prone to such “breakage”.
Often you can compensate by redoing your stuff in a buffer-activated callback function. Sure, it seems redundant, but it often works just fine. I don’t know if yours would be one of those cases, because I’ve never tried what you’re doing.
I know you really really like the idea of what you’re attempting to do. However, such stuff is problematic at its core.
-
@Alan-Kilborn First of all - Thanks for such a thorough response. I really appreciate that.
Often you can compensate by redoing your stuff in a buffer-activated callback function. Sure, it seems redundant, but it often works just fine. I don’t know if yours would be one of those cases, because I’ve never tried what you’re doing.
I’m not sure I’ve understood this. What is it that I can do to compensate? What is it that I would need to redo in a “Buffer-activated callback function” (don’t know what that means)
The thing that would’ve solved my problem completely would be to manually change the margins of Distraction Free mode. Is such thing possible even with extreme hackery? I’m down for such adventures. I would really make an effort to accomplish such behavior.
I guess that “the problem” part of my Post isn’t possible and such breakage is inevitable since N++ has no “awareness” of PS. But the second part of my Post remained unanswered.
Is it possible to change Margins or whatever to make Distraction Free mode center 80 characters on the line?
Currently Distraction Free Mode displays 141 character on a single line, which is way to wide for me.
80 characters would’ve been ideal, but if that isn’t possible, is it possble to reduce it at all? 141 is way too much for a Distraction Free mode as far as I’m concerned.Thank you for your time.
-
@Neko-Nekokovic said in Problem with Margins in PythonScript Plugin and Margins in Distraction Free mode:
What is it that I can do to compensate? What is it that I would need to redo in a “Buffer-activated callback function”
Well, if you’ve tried
setMarginLeft()
where you’re currently doing it, and it hasn’t “stuck”, then that would be something I’d try doing in every buffer-activated callback.“Buffer-activated callback function” (don’t know what that means)
PS provides some notification capability to your code in the form of “callbacks”. One such is a “buffer activated” callback which fires each time you switch the active tab in N++.
A recent example of setting one up comes to mind from THIS THREAD’S SCRIPT script, which doesn’t use buffer-activated but rather update-ui, but the concept is the same.
The thing that would’ve solved my problem completely would be to manually change the margins of Distraction Free mode. Is such thing possible even with extreme hackery?
I don’t know; maybe someone else will comment.
I’m down for such adventures. I would really make an effort to accomplish such behavior.
Let the adventure begin!
If you get anywhere with it, I’m sure it will be interesting, so posting back here to let others know how it went would be good. -
@Alan-Kilborn
I’ve just read your "thread script’ that you’ve linked here. And have jumped on PythonScript basics by Peter Jones again.What I’ve found is that I’ve set Margins in Machine script “startup.py” instead of User Script. It seems I cannot make it appear as a User script. Maybe that is the problem?
Plugins > Python Script > Scripts > (Samples | startup)
Also Plugins > Python Script > Configuration > User Scripts is empty.
I don’t have any User sripts shown.
I’ve also seen this article where one guy suggested this script:
import ctypes from ctypes.wintypes import RECT FindWindow = ctypes.windll.user32.FindWindowW GetWindowRect = ctypes.windll.user32.GetWindowRect Rect = RECT() nppHandle = FindWindow(u'Notepad++', None) notepad.runMenuCommand("View", "Post-It") if GetWindowRect(nppHandle, ctypes.byref(Rect)) != 0: w = Rect.right editor.setMarginLeft(w/3) editor.setMarginRight(w/3)
Again I’ve Plugins > Python Script > New Script and pasted it there, named it and saved it in:
C:\ProgramFiles\Notepad++\plugins\Config\PythonScript\scripts folder. But again - nothing changed.I’ve again tried to access it through Plugins > Python Script > Configuration but under “User scrips” I’ve again found an empty list.
While Plugins > Python Script > Scripts > (Samples | startup) is show again. I don’t have any (user) scripts shown in there as an option. Not even grayed out.
What am I missing?
Let the adventure begin!
If you get anywhere with it, I’m sure it will be interesting, so posting back here to let others know how it went would be goodOh I will definitely post it here if I make it.
Also, is “update-ui” the only difference I’d need to change in given script or is this just a more general example to illustrate how I go about achieving desired behavior in “buffer-activated” environment ? Or whatever it is called.
-
…startup.py…
You don’t want to change any “machine” scripts (e.g. its startup.py) at all.
There’s info about getting user
startup.py
going HERE.Really, though, you don’t want to do a lot of coding in user
startup.py
, you want to keep that fairly clean and call out to separately named scripts.I’ve also seen this article where one guy suggested this script
I don’t see the relevance of that, other than it calls the margin functions you want to call…
Also, is “update-ui” the only difference I’d need to change in given script or is this just a more general example to illustrate how I go about achieving desired behavior in “buffer-activated” environment ? Or whatever it is called.
The pointer to the other script was just for showing how to do a callback function in general; nothing else about that script is relevant.
-
@Alan-Kilborn I’ve read that post from Peter Jones but, as mentioned in my last comment - nothing shows up and/or changes.
I cannot make any User script to appear in Plugins > Python Script > Scripts
I’ve read your “thread script” post and at the end of it the same thing was linked. So I’ve read it and tried to have User scripts work, but it just doesn’t appear anywhere.
The pointer to the other script was just for showing how to do a callback function in general; nothing else about that script is relevant.
Oh okay. Thanks.
-
@Neko-Nekokovic said in Problem with Margins in PythonScript Plugin and Margins in Distraction Free mode:
I cannot make any User script to appear in Plugins > Python Script > Scripts
Even if you manually create a file in the correct place?
For me, sometimes the New Script wants to save my intended new file in a weird directory, i.e., not the Scripts directory. :-(
So if it happened to do that to you, then you went to the Scripts menu, that script wouldn’t appear.So by “manually create” I mean, make a .py file without using the New Script command…
If you suspect the same kind of weird thing is happening to you, try opening one of the “Samples” scripts by holding Ctrl while clicking on it in the menus, then when it opens do a SaveAs but when saving move up one folder level, i.e., don’t save it in the “Samples” folder, but the parent of samples. And give it a new base name, e.g. “testme.py”.
Then see iftestme
appears in the Scripts menu. -
Even if you manually create a file in the correct place?
Yes. Well, this is a bit different. I’m unable to create a new text file in C:\ProgramFiles\Notepad++\plugins\Config\PythonScript\scripts
The only option I have is this
So to overcome this what I’ve managed to do is - I’ve created a text file on Desktop. Pasted python scirpt there. Saved it as a .py file. And then successfully moved it over in:
C:\ProgramFiles\Notepad++\plugins\Config\PythonScript\scriptsThat’s how “proba.py” and “startup.py” are there. Upon moving, it asked me to “Continue” with Admin rights which I have clicked.
If you suspect the same kind of weird thing is happening to you, try opening one of the “Samples” scripts by holding Ctrl while clicking on it in the menus, then when it opens do a SaveAs but when saving move up one folder level, i.e., don’t save it in the “Samples” folder, but the parent of samples. And give it a new base name, e.g. “testme.py”.
Then see if testme appears in the Scripts menu.
That worked indeed! Now I see “proba.py” listed.
But if I go Plugins > Python Script > Configuration every script that I see is under “Machine scripts” and none in “User scripts”.
-
@Alan-Kilborn The thing that I’ve found in one of the above linked posts is this. This is exactly what I’ve want and it seems that someone managed to make it that way.
Although I’d exclude numbers as well, but that is trivial.
But the thing that I don’t understand in this picture, or in that post is - A guy below said that it was a feature that was going to be available after v7.9.6 release. Do you know anything about it?
-
Oh, wait, it appears I gave bad advice. The “Samples” are considered “machine scripts”. :-(
Sorry, but I honestly don’t think about this much, because I don’t have such troubles…OK, so user scripts are under
...\Config\PythonScript\scripts
(note the important part of that is “Config”).Machine scripts are NOT under
Config
.The only option I have is this
So if “this” is a link to a screenshot, don’t do that, just Ctrl+v paste an image directly. Nobody is clicking links that aren’t immediately recognizable.
But if I go Plugins > Python Script > Configuration every script that I see is under “Machine scripts” and none in “User scripts”.
You have clicked on this, right?:
-
@Neko-Nekokovic said in Problem with Margins in PythonScript Plugin and Margins in Distraction Free mode:
The thing that I’ve found in one of the above linked posts is this. This is exactly what I’ve want and it seems that someone managed to make it that way.
Again, nobody is clicking on such a “this” link.
Paste a screenshot right into your posting.But the thing that I don’t understand in this picture, or in that post is - A guy below said that it was a feature that was going to be available after v7.9.6 release. Do you know anything about it?
I can’t answer questions deriving from links I’m not clicking on. :-)
-
So if “this” is a link to a screenshot, don’t do that, just Ctrl+v paste an image directly. Nobody is clicking links that aren’t immediately recognizable.
Ah, okay.
And that was from a post named “Is there a distraction-free writing mode like Vimroom(a plugin of Vim)?” on this website. So if you don’t want to click a link of it, you can go there and find this part.
-
You have clicked on this, right?
Yes. That’s what I meant when I said “User Scripts” is empty.
-
@Neko-Nekokovic said in Problem with Margins in PythonScript Plugin and Margins in Distraction Free mode:
And that was from a post named “Is there a distraction-free writing mode like Vimroom(a plugin of Vim)?” on this website. So if you don’t want to click a link of it, you can go there and find this part.
Or YOU could have just provided this link.
-
@Alan-Kilborn said in Problem with Margins in PythonScript Plugin and Margins in Distraction Free mode:
A guy below said that it was a feature that was going to be available after v7.9.6
That “guy” is the author of Notepad++. :-)
Turns out after reviewing that other thread that he meant “Distraction free mode” would be available…and that made it into v8.0 (there was no v7.9.6). -
Or YOU could have just provided this link.
I guess there is a misunderstanding here.
You’ve said earlier:
Again, nobody is clicking on such a “this” link.
And in the last comment you’ve said:
Or YOU could have just provided this link.
I understand that pictures should have been pasted as images, but either way you cannot know what is on the “link” no matter how I name it. You don’t know if it’s a link to a post or a link to an image. If you’re not clicking “this link” then why would I provide a link in the first place?
I guess you can have a preview when you hover over a link, but https://ibb.co/… is a popular domain as far as I know. I’ve seen it many times since many people link images from imgBB website and that is their domain. It’s quite popular so I don’t understand what was the problem.
I guess we don’t understand each other here.
That “guy” is the author of Notepad++. :-)
Ah cool.
Oh only Distraction Free mode. :/But in that post, the picture shows exactly what I want to achieve. I guess it is possible, I just don’t know how.
-
@Neko-Nekokovic said in Problem with Margins in PythonScript Plugin and Margins in Distraction Free mode:
I guess we don’t understand each other here.
I think we do…
I guess you can have a preview when you hover over a link
Yep, which is exactly how I know where links lead, no matter what they say, e.g. a blue/purple this.
but https://ibb.co/… is a popular domain as far as I know
And it is blocked by my I.T. department since it is so popular.
And since I do all of my Notepad++ work on my work PC, in my spare time at work, I can’t click on those links. Well, I can, but they won’t lead anywhere.But in that post, the picture shows exactly what I want to achieve
I think first things first…you need to get beyond problems with putting script files in user scripts folder and having them appear in the Notepad++ menus…are you beyond that?
-
@Alan-Kilborn said in Problem with Margins in PythonScript Plugin and Margins in Distraction Free mode:
I think we do…
Well we haven’t on this very issue then.And it is blocked by my I.T. department since it is so popular.
What does that mean? Which I.T. department? I don’t understand what that means. Why would a link from imgBB be banned or blocked?
Is there any other “imageToLink” website that isn’t blocked by anyone and that you would happily open even if it’s a picture in the link? What about Imgur? I’m curious now. I’ve never heard that someone blocks that website. Is there any specific reason? (Well I am sure there is, the question is rather - what is the reason behind the block?)
I think first things first…you need to get beyond problems with putting script files in user scripts folder and having them appear in the Notepad++ menus…are you beyond that?
Yeah I agree. Well, no. I’ve managed to make them appear only if I put them in “Machine Scripts”. If I save them in Config/PythonScript/scripts nothing seems to show up.
I should fix that first definitely. I hope I’ll find a way. Currently I have no idea how to overcome that.
-
@Neko-Nekokovic said in Problem with Margins in PythonScript Plugin and Margins in Distraction Free mode:
Which I.T. department?
Umm, the one where I am employed?
Why would a link from imgBB be banned or blocked?
To keep people from going there.
Is there any other “imageToLink” website that isn’t blocked by anyone and that you would happily open even if it’s a picture in the link? What about Imgur?
Imgur was used here before the forum software got the ability to directly paste images. So, yes, I could access that one.
But it is all kind of pointless, because we CAN paste here directly and there is no reason at all to user external sites for such things.