How to jump to a bookmark and show the bookmarked line at the top of the screen, not in the middle
-
@Sebastian-Freeh said in How to jump to a bookmark and show the bookmarked line at the top of the screen, not in the middle:
using SHIFT+F2 and the bookmarked line appears in the middle of the screen. However, I would like it to appear at the top.
It’s quite likely someone else may want it at the bottom of the screen, then others who want 1 line to show before the bookmarked line, the options are almost endless. I’m going to suggest the developers possibly knew of all the situations such as yours and made the compromise that in the middle suited MOST people the best.
However all is not lost. I just tested a theory and it seems to work well enough. Make yourself a macro by recording the step of:
Shift-F2
Ctrl-Shift-Down Arrow (approximately 10-15 times)
Ctrl-Shift-Up Arrow (same number of times)Then save this recording. You could possibly reassign the default Shift-F2 (prev bookmark) as something else so you could then use the Shift-F2 shortcut as being assigned to this new macro.
For me when used it shifted the bookmark off the top of the screen, and then brought it back down so it was the second line on the screen. Your mileage may vary and this will only work with a set height on the NPP window. If you ever re-size the NPP window then the macro won’t function as well.
Terry
-
@Terry-R Thanks for your suggestion! That’s surely a way to do it. I was hoping for something a bit more straightforward, since it does happen that I resize the window on different screens.
I will give it a go though!Releated to my question above: Is it perhaps possible to put the current line at the top of the screen by using a shortcut or possibly create one?
-
@Terry-R Using CTRL+SHIFT-UP/DOWN moves the current line up/down for me. Did you mean CTRL+UP/DOWN? That works for me
-
@Sebastian-Freeh said in How to jump to a bookmark and show the bookmarked line at the top of the screen, not in the middle:
Did you mean CTRL+UP/DOWN? That works for me
That suggests you have already started with customising your shortcuts. For me it’s
That is unless there is some language setting which changes the shortcuts, doubtful?
And as you resize your NPP window that will make my macro somewhat ineffective.
I understand the other idea you have of getting what is the current line to the top question, nice idea, but although I’m not completely conversant with NPP functions a quick check did not show up anything I think will work like that.
Possibly PythonScript which can access a lot of the extra functions which don’t show on the NPP windows might have that ability. But as I don’t use that I couldn’t say for sure if that might be possible.
Currently I doubt the developers will consider your request, as to do so means that’d have to consider ALL other similar requests. I think that my macro does a passable job, and until/unless you or someone else can look at the PythonScript method (or other supported program language/plugin) it might the best you will get.
Terry
-
@Sebastian-Freeh said in How to jump to a bookmark and show the bookmarked line at the top of the screen, not in the middle:
Did you mean CTRL+UP/DOWN? That works for me
Actually that does work if you don’t have long lines that “word wrap”. In my case my lines are wrapping so a single line can actually show as 2 (or more) lines on the screen because they are so long.
Terry
-
@Sebastian-Freeh said in How to jump to a bookmark and show the bookmarked line at the top of the screen, not in the middle:
I was hoping for something a bit more straightforward, since it does happen that I resize the window on different screens.
I just thought of another method of getting close to your need. It won’t be perfect but it is something that you can easily set up “on the fly”. Using “Clone to another View” (Under View, Move/Clone the current document). Then you would offset the view of the “cloned” version to half a page behind (so the line numbers would be off by approx half the number that show on screen). Then set the “vertical synchronise scrolling” under the View menu.
So the “primary screen” would be where you do all the editing. The cloned copy will show additional code but you wouldn’t need to actually do any work in it, it’s purely to give you the “extra lookahead” option. Actually thinking further on, you could set the offset to a full page of lines behind, that way you’d get even further “lookahead”.
Terry
-
@Terry-R Interesting. I think I haven’t changed anything, at least I’m not aware of anything. I’m still farily new to Notepad++. I haven’t used PythonScript so far, thanks for pointing that out
-
@Terry-R Nice idea! Just tried it out and works pretty well actually. Could be helpful in some situations. I’ll probably go for the macro, though.
-
@Sebastian-Freeh 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 I haven’t changed anything
My fault. I initially thought you’d changed the shortcuts I referred to in the image of “my” shortcuts. But actually you were just using a different shortcut. If you look in the shortcut mapper for the items I was referring to you should see the keys I used will likely be what you have also.
Well at least you have 2 ideas that should work reasonably well. It’s a bit of a leap to get on the Python train. Considering you are already programming though, it might not be too much of a job to learn “yet” another language.
Just as a bit of a background, NPP is built on top of a couple of other products out there, “Boost C++ libraries” and “Scintilla”. You can read more about these (links are under the FAQ section) elsewhere. Boost has the “regular expression” language (if you wish to call it that) that NPP uses, and Scintilla is the editor. Scintilla has lots of functions, more than NPP presents and it may be possible one of those could do EXACTLY what you want. PythonScript is one method of linking to those functions. There are lots of references made to these in other posts here, which you can search on.
Terry
-
@Sebastian-Freeh
@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:PythonScript is one method of linking to those functions. There are lots of references made to these in other posts here, which you can search on.
One other such language is NppExec and the simplest form would be:
SCI_SENDMSG SCI_GETCURRENTPOS SET LOCAL POS = $(MSG_RESULT) SET LOCAL MASK ~ 1<<24 :LISTNEXT SCI_SENDMSG SCI_MARKERNEXT $(POS) $(MASK) SET LOCAL $(LINE) = $(MSG_RESULT) IF $(LINE)==-1 THEN SET LOCAL POS = 0 GOTO LISTNEXT ENDIF IF $(LINE)==$(POS) THEN SET LOCAL POS ~ $(POS) + 1 GOTO LISTNEXT ENDIF SCI_SENDMSG SCI_SETFIRSTVISIBLELINE $(LINE) SCI_SENDMSG SCI_GOTOLINE $(LINE) :END
You’d associate that script with some shortcut key and basically it finds your current position and sets the marker to find as the Notepad++ bookmark (24, bit-shifted to form the proper mask) and then finds the next mark from your current position. If the return value is -1, there is no next mark so start at the top of the document and search again. If the next mark is the same line you’re on, then go to the next line and search again.
Note you could make the script more robust by using
SCI_MARKERPREVIOUS
and some logic to search both up and / or down direction with wrap-around.The Scintilla docs for marker searching (again, 24 is the Notepad++ bookmark and you need to bit shift it to get the mask value they speak of).
Cheers.
-
Another NppExec variant without using loops:
npp_console keep sci_sendmsg SCI_HOMEDISPLAY npp_sendmsg WM_COMMAND IDM_SEARCH_PREV_BOOKMARK sci_sendmsg SCI_GETCURRENTPOS sci_sendmsg SCI_LINEFROMPOSITION $(MSG_RESULT) sci_sendmsg SCI_SETFIRSTVISIBLELINE $(MSG_RESULT)
-
Thanks for all your suggestions so far!
-
npp_sendmsg WM_COMMAND IDM_SEARCH_PREV_BOOKMARK
I think your
IDM_SEARCH_PREV_BOOKMARK
should really beIDM_SEARCH_NEXT_BOOKMARK
, i.e., just a typo?Anyway, for another take on that specific solution, here’s a PythonScript equivalent:
from Npp import editor, notepad, MENUCOMMAND editor.homeDisplay() notepad.menuCommand(MENUCOMMAND.SEARCH_NEXT_BOOKMARK) curr_pos = editor.getCurrentPos() curr_line = editor.lineFromPosition(curr_pos) editor.setFirstVisibleLine(curr_line)
-
I’m curious, though, how one might adapt these solutions to put the bookmarked line at the very bottom of the user’s display window.
I didn’t see the obvious solution to this one, in the available Scintilla functions as there is no “SCI_SETLASTVISIBLELINE”.
I thought maybe SCI_GETLINEVISIBLE would help, but no, it returns “true” for lines that are not currently on-screen (as long as those lines aren’t part of a “fold”, or “hidden” lines).
-
@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’m curious, though, how one might adapt these solutions to put the bookmarked line at the very bottom of the user’s display window.
SCI_SENDMSG SCI_GETFIRSTVISIBLELINE SET LOCAL FIRST = $(MSG_RESULT) SCI_SENDMSG SCI_LINESONSCREEN SET LOCAL LINES = $(MSG_RESULT) SET LOCAL LINE ~ $(FIRST) + $(LINES) SCI_SENDMSG SCI_GOTOLINE $(LINE)
Cheers.
-
@Michael-Vincent said in How to jump to a bookmark and show the bookmarked line at the top of the screen, not in the middle:
SCI_LINESONSCREEN
In light of that info, thanks @Michael-Vincent , I’ll offer up this script, which can do either behavior, by a simple change (of one character) from
1
to0
(your choice!) in the first line:from Npp import editor, notepad, MENUCOMMAND align_bookmark_to_bottom_of_window_not_top = True if 1 else False editor.homeDisplay() notepad.menuCommand(MENUCOMMAND.SEARCH_NEXT_BOOKMARK) line_of_bookmark = editor.lineFromPosition(editor.getCurrentPos()) lines_on_screen = editor.linesOnScreen() if align_bookmark_to_bottom_of_window_not_top else 1 editor.setFirstVisibleLine(line_of_bookmark - lines_on_screen + 1)
-
@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’ll offer up this script, which can do either behavior
@Michael-Vincent @dinkumoil also, actually the OP stated
Shift-F2
which is previous bookmark. I see through all the iterations of solutions that seems to have changed tonext
bookmark.Maybe someone might want to offer up a solution for a choice of forward or backwards and bookmarked line at top or at bottom. So in effect 4 options. How can this be achieved within the 1 solution. Is it possible to have NppExec do a quick question on screen before enacting the request. So asking whether next or previous and top or bottom.
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?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:
actually the OP stated Shift-F2 which is previous bookmark
Ah, okay, so that is why @dinkumoil did what he did, and makes my typing of:
I think your IDM_SEARCH_PREV_BOOKMARK should really be IDM_SEARCH_NEXT_BOOKMARK, i.e., just a typo?
nicely invalid.
:-) -
@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:
a solution for a choice of forward or backwards and bookmarked line at top or at bottom
So the problem here is that nobody would want to answer such questions each time they want to jump to a bookmark. :-)
So it becomes a “configuration” issue, that you’d answer once, perhaps the first time you run the script in a N++ session?
Or maybe there’s a second script to configure it, and the main script uses the configuration? To change the configuration mid-session, you’d run the config script again.
Lots of things are possible… :-)
Config with Pythonscript could be two message-boxes based questions:
and
-
@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