How to jump to a bookmark and show the bookmarked line at the top of the screen, not in the middle
-
@Alan-Kilborn said in How to jump to a bookmark and show the bookmarked line at the top of the screen, not in the middle:
r maybe there’s a second script to configure it, and the main script uses the configuration?
Yes I was also thinking along those lines. Not knowing how that’s possible I could only assume each time the next/prev bookmark wanted the options would have to be presented. So I take it that within a “session” of NPP these settings can be saved across successive runs of the script?
I don’t suppose it’s possible to save these within one of NPP’s XML files so in fact the config is saved across consecutive runs of NPP? Or would one just create a new XML file with the settings that ONLY that script looks for?
Terry
-
@Terry-R said in How to jump to a bookmark and show the bookmarked line at the top of the screen, not in the middle:
these settings can be saved across successive runs of the script?
A Python “global” variable can hold the value. Two different scripts can access. Or, the config script could write a disk file and the main script could read it (getting to the stuff below).
I don’t suppose it’s possible to save these within one of NPP’s XML files so in fact the config is saved across consecutive runs of NPP?
No.
Or at least: “I wouldn’t do that”Or would one just create a new XML file with the settings that ONLY that script looks for?
It’s so simple, I wouldn’t bother with XML.
I’d go simpler, like the days when.ini
files ruled the day. :-) -
@Terry-R said in How to jump to a bookmark and show the bookmarked line at the top of the screen, not in the middle:
I’m currently going through a course on Python (just started) as I was interested in some of the workings behind NPP (Scintilla functions) but maybe I need to reconsider and look at NppExec. Where does one learn NppExec?
NppExec is fine, but I would definitely stay the course with the Python!
More of an investment, but a lot of payoff. -
@Alan-Kilborn said in How to jump to a bookmark and show the bookmarked line at the top of the screen, not in the middle:
I’d go simpler, like the days when .ini files ruled the day. :-)
So one final question (possibly), is it possible to have 2 shortcuts (ex Shift-F2 and F2, as they ARE the prev and next bookmark options) BOTH mapped to a new script, and then that script can read what invoked it (so able to read which shortcut was used), then act accordingly?
Just a thought as that would save the interaction window with user. The top or bottom option would be set as unlikely user would want to continually change that. Maybe the script would ask first time invoked each session which option top/bottom and write that away (to your .ini file).
Terry
-
All good ideas and thinking, Terry!
Your future scripts will be as good as your regexes. :-)@Terry-R said in How to jump to a bookmark and show the bookmarked line at the top of the screen, not in the middle:
is it possible to have 2 shortcuts (ex Shift-F2 and F2, as they ARE the prev and next bookmark options) BOTH mapped to a new script, and then that script can read what invoked it (so able to read which shortcut was used), then act accordingly?
PythonScripts don’t have any information about what keys invoked them, AFAIK.
A single script can only be tied to a single shortcut.
So, you’d have to have 2 scripts for what you describe.
Of course, each could call a third script with a bunch of common stuff (the “meat”) in it, the first 2 scripts being very short and just passing in arguments to the third to tell it what to do, but that would be THREE when you wanted ONE! -
@Terry-R said in How to jump to a bookmark and show the bookmarked line at the top of the screen, not in the middle:
So one final question (possibly), is it possible to have 2 shortcuts (ex Shift-F2 and F2, as they ARE the prev and next bookmark options) BOTH mapped to a new script, and then that script can read what invoked it (so able to read which shortcut was used), then act accordingly?
Hi @Terry-R, @Alan-Kilborn, All:
AutoHotkey is quite good for what you asked. This short script doesn’t actually deal with the internals of Notepad++, just plays with the user interface.
#IfWinActive ahk_class Notepad++ ~F2:: ~+F2:: Term := SubStr(A_ThisHotkey,2,1) if (Term = "+") { SendInput, ^{Up 14} } else { SendInput, ^{Down 14} } return #IfWinActive
Press
F2
to place the next bookmarked line at the top of the screen, pressShift+F2
to place the previous bookmarked line at the bottom of the screen. In my current set up14
is the number of lines to send up or down, but you may need to adjust it to your needs.The tilde
~
lets the hotkey sequence get through. If you ever want to use the standard behaviour of the bookmark command —place the bookmarked line at the middle of the screen—, just select theNext
orPreviuos Bookmark
commands from theSearch
menu.Finally, the
#IfWinActive
directive ensures that the hotkeys will not interfere with applications other than Notepad++, that is, they won’t work system wide.Have fun!
-
@astrosofista said
14
A limitation of that approach (OP had previously said “it does happen that I resize the window on different screens”), but interesting.
-
-
-
@Terry-R said in How to jump to a bookmark and show the bookmarked line at the top of the screen, not in the middle:
is it possible to have 2 shortcuts (ex Shift-F2 and F2, as they ARE the prev and next bookmark options) BOTH mapped to a new script, and then that script can read what invoked it (so able to read which shortcut was used), then act accordingly?
PythonScripts don’t have any information about what keys invoked them, AFAIK.
A single script can only be tied to a single shortcut.
So, you’d have to have 2 scripts for what you describe.
Of course, each could call a third script with a bunch of common stuff (the “meat”) in it, the first 2 scripts being very short and just passing in arguments to the third to tell it what to do, but that would be THREE when you wanted ONE!
I have followed all the instructions over there but all in vain. Considering myself dmbest -
@Jaguar-Asad said in How to jump to a bookmark and show the bookmarked line at the top of the screen, not in the middle:
I think your posting got screwed up, but this is what you meant to add to this thread:
I have followed all the instructions over there but all in vain. Considering myself dmbest
I guess you’ll have to be more specific about what is giving you trouble, in order for someone to assist.
-
One option could be to temporarily change the font size or zoom level of the document so that the bookmarked line fits at the top of the screen when you jump to it. You can do this by using the zoom in/out feature or changing the font size. After you have finished reviewing the bookmarked line, you can return the font size or zoom level back to its original setting.
-
-