0

Session file entry for one of the files to be opened by Notepad++ 7.4.2:

<File firstVisibleLine="36070" xOffset="0" scrollWidth="1232" startPos="1677659" endPos="1677659" selMode="0" lang="Normal Text" encoding="-1" filename="<pathToFile>" backupFilePath="" originalFileLastModifTimestamp="1547671177" mapFirstVisibleDisplayLine="39239" mapFirstVisibleDocLine="36070" mapLastVisibleDocLine="36102" mapNbLine="56" mapHigherPos="1677659" mapWidth="326" mapHeight="224" mapKByteInDoc="1639" mapWrapIndentMode="1" mapIsWrap="yes" />

(1) After the file (length changes daily) has been loaded, I want to see the 16 last lines of the document at the top of the window.

If impossible: (2) How can I see always the last x lines of the document? (x = number of lines of the window)

Option "Settings | Preferences | Editing | Enable scrolling beyond last line" is checked.

0

I don't know how to scroll beyond the end automatically for option (1), but for option (2): If you have PythonScript, you can use editor.documentEnd() to scroll to the end of the active document. To automatically scroll to end on open, run the following script:

# encoding=utf-8
"""in response to https://superuser.com/questions/1395356/open-a-session-file-and-show-the-last-document-lines-at-the-top-of-the-window"""
from Npp import *

def su1395356_ScrollToEnd_Callback(args):
    """this will scroll to the end of the current file"""
    b = args['bufferID']
    notepad.activateBufferID(b)
    editor.documentEnd()

def su1395356_EndCallback():
    """This deactivates (clears) the scroll-to-end callback"""
    notepad.clearCallbacks(su1395356_ScrollToEnd_Callback)

if __name__ == '__main__':
    """This registers (activates) the scroll-to-end callback"""
    su1395356_EndCallback()
    notepad.callback(su1395356_ScrollToEnd_Callback, [NOTIFICATION.FILEOPENED])

Every file you open after running this script should scroll to the end of the buffer when you open it.

To stop this callback, Plugins > PythonScript > Show Console, then run su1395356_EndCallback() from the immediate-line. Or, the end-callback could be placed in a separate script, which imports this first, and then calls the su1395356_EndCallback() function.

If you restart NPP, the callback won't be active any more, so you'll need to run the script again. Or, you might want to import this script from your startup.py, with Plugins > Python Script > Configuration... setting "Initialisation" to "ATSTARTUP", which will make it automatically start

If you don't have it in startup.py, you might want to use the Configuration... dialog to add it to the Menu Items list; once that's done and NPP is restarted, you can use Settings > Shortcut Mapper to assign a keyboard shortcut.


edit: Figured out for (1): edit the first function and add another function, as below. Set n=16 to however many lines you want it, or make it a parameter, as desired. This is just a starting point.

def su1395356_ScrollToEnd_Callback(args):
    """this will scroll to the end of the current file"""
    b = args['bufferID']
    notepad.activateBufferID(b)
    su1395356_AlternateScrollToLastNLines()

def su1395356_AlternateScrollToLastNLines():
    """will scroll the last n, assuming **Settings | Preferences | Editing | Enable scrolling beyond last line** enabled"""
    n = 16
    editor.scrollToEnd()
    for i in range(n-1):        # use n-1 because one row is already visible
        editor.lineScrollUp()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.