"""
Emacs_Next_Line.py - A Jython macro for jEdit that implements
`Emacs-like` scrolling. If the cursor is at the bottom of the
text area (or electric-scroll boundary), instead of just moving
to the next line, the text area will first be scrolled so the
cursor is in the middle of the screen. This may be used as a
replacement for the built-in 'Go To Next Line' command.

Copyright (C) 2002, Ollie Rutherfurd <oliver@rutherfurd.net>

$Id: Emacs_Next_Line.py 28 2003-03-25 22:40:28Z oliver $
"""

__version__ = '$Revision: 1.4 $'[11:-2]
__author__ = 'Ollie Rutherfurd'

from org.gjt.sp.jedit import Macros


def Emacs_Next_Line(view):
	textArea = view.getTextArea()

	if not getattr(textArea, 'physicalToVirtual', None):
		textArea.goToNextLine(0)
		Macros.error(view, "If you're using jEdit 4.2 pre1 or greater, this macro is redundant.")
		return

	first = textArea.getFirstLine()
	current = textArea.getCaretLine()
	virtual = textArea.physicalToVirtual(current)
	visible = textArea.getVisibleLines()
	pad = textArea.getElectricScroll()

	# move current line to center of screen, if at bottom edge
	if virtual + 1 >= ((first + visible) - pad):
		newFirst = first + ((visible - pad) / 2)
		textArea.setFirstLine(newFirst)

	textArea.goToNextLine(0)


if __name__ in ('__main__','main'):
	Emacs_Next_Line(init.view)

# :indentSize=4:lineSeparator=\n:noTabs=false:tabSize=4:

