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