Community

    • Login
    • Search
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

    How to jump to a bookmark and show the bookmarked line at the top of the screen, not in the middle

    Help wanted · · · – – – · · ·
    bookmark bookmarks navigation
    8
    30
    5437
    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.
    • Sebastian Freeh
      Sebastian Freeh @Terry R last edited by Sebastian Freeh

      @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 1 Reply Last reply Reply Quote 0
      • Sebastian Freeh
        Sebastian Freeh @Terry R last edited by Sebastian Freeh

        @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

        Terry R 1 Reply Last reply Reply Quote 0
        • Terry R
          Terry R last edited by Terry R

          @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

          e31d0461-e8d3-4bc4-b6a6-9902e8c3e8da-image.png

          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 1 Reply Last reply Reply Quote 1
          • Terry R
            Terry R @Sebastian Freeh last edited by Terry R

            @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

            1 Reply Last reply Reply Quote 1
            • Terry R
              Terry R @Sebastian Freeh last edited by

              @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

              Sebastian Freeh 1 Reply Last reply Reply Quote 1
              • Sebastian Freeh
                Sebastian Freeh @Terry R last edited by

                @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

                1 Reply Last reply Reply Quote 0
                • Sebastian Freeh
                  Sebastian Freeh @Terry R last edited by

                  @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.

                  1 Reply Last reply Reply Quote 2
                  • Terry R
                    Terry R last edited by Terry R

                    @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

                    Michael Vincent 1 Reply Last reply Reply Quote 5
                    • Michael Vincent
                      Michael Vincent @Terry R last edited by

                      @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.

                      1 Reply Last reply Reply Quote 5
                      • dinkumoil
                        dinkumoil @Sebastian Freeh last edited by dinkumoil

                        @Sebastian-Freeh

                        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)
                        
                        Alan Kilborn 1 Reply Last reply Reply Quote 4
                        • Sebastian Freeh
                          Sebastian Freeh last edited by

                          Thanks for all your suggestions so far!

                          1 Reply Last reply Reply Quote 0
                          • Alan Kilborn
                            Alan Kilborn @dinkumoil last edited by

                            @dinkumoil

                            npp_sendmsg WM_COMMAND IDM_SEARCH_PREV_BOOKMARK

                            I think your IDM_SEARCH_PREV_BOOKMARK should really be IDM_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)
                            
                            1 Reply Last reply Reply Quote 2
                            • Alan Kilborn
                              Alan Kilborn last edited by

                              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).

                              Michael Vincent 1 Reply Last reply Reply Quote 0
                              • Michael Vincent
                                Michael Vincent @Alan Kilborn last edited by

                                @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)
                                

                                SCI_LINESONSCREEN

                                Cheers.

                                Alan Kilborn 1 Reply Last reply Reply Quote 3
                                • Alan Kilborn
                                  Alan Kilborn @Michael Vincent last edited by Alan Kilborn

                                  @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 to 0 (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)
                                  
                                  1 Reply Last reply Reply Quote 2
                                  • Terry R
                                    Terry R last edited by

                                    @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 to next 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

                                    Alan Kilborn 2 Replies Last reply Reply Quote 3
                                    • Alan Kilborn
                                      Alan Kilborn @Terry R last edited by

                                      @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.
                                      :-)

                                      1 Reply Last reply Reply Quote 2
                                      • Alan Kilborn
                                        Alan Kilborn @Terry R last edited by

                                        @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:

                                        Imgur

                                        and

                                        Imgur

                                        1 Reply Last reply Reply Quote 4
                                        • Terry R
                                          Terry R last edited by

                                          @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

                                          Alan Kilborn 1 Reply Last reply Reply Quote 3
                                          • Alan Kilborn
                                            Alan Kilborn @Terry R last edited by Alan Kilborn

                                            @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. :-)

                                            1 Reply Last reply Reply Quote 3
                                            • First post
                                              Last post
                                            Copyright © 2014 NodeBB Forums | Contributors