Skip to content

Instantly share code, notes, and snippets.

@khvorov45
Last active June 16, 2023 13:45
Show Gist options
  • Save khvorov45/c33f0f6f631626f0cda9e2071538e6e0 to your computer and use it in GitHub Desktop.
Save khvorov45/c33f0f6f631626f0cda9e2071538e6e0 to your computer and use it in GitHub Desktop.
10xCustomPython
import N10X
import subprocess
def MoveToPreviousEmptyLineSelect():
curSelection = N10X.Editor.GetCursorSelection()
cursor = N10X.Editor.GetCursorPos()
posBefore = curSelection[0]
if (cursor[1] == curSelection[0][1]):
posBefore = curSelection[1]
N10X.Editor.ExecuteCommand("MoveToPreviousEmptyLine")
posAfter = N10X.Editor.GetCursorPos()
N10X.Editor.SetSelection(posBefore, posAfter)
def MoveToNextEmptyLineSelect():
curSelection = N10X.Editor.GetCursorSelection()
cursor = N10X.Editor.GetCursorPos()
posBefore = curSelection[0]
if (cursor[1] == curSelection[0][1]):
posBefore = curSelection[1]
N10X.Editor.ExecuteCommand("MoveToNextEmptyLine")
posAfter = N10X.Editor.GetCursorPos()
N10X.Editor.SetSelection(posBefore, posAfter)
def RemedySync(filename = None):
if filename is None:
filename = N10X.Editor.GetCurrentFilename()
cursor = N10X.Editor.GetCursorPos()
subprocess.Popen(["remedybg", "open-file", filename, str(cursor[1] + 1)])
def RemedyInstallSync():
N10X.Editor.AddPostFileSaveFunction(RemedySync)
def HalfPageUp():
page = N10X.Editor.GetVisibleLineCount()
current = N10X.Editor.GetScrollLine()
newpos = current - page / 2
clamped = max(round(newpos), 0)
N10X.Editor.SetScrollLine(clamped)
cursor = N10X.Editor.GetCursorPos()
newcursor = (cursor[0], cursor[1] + clamped - current)
N10X.Editor.SetCursorPos(newcursor)
def HalfPageDown():
page = N10X.Editor.GetVisibleLineCount()
current = N10X.Editor.GetScrollLine()
newpos = current + page / 2
clamped = min(round(newpos), N10X.Editor.GetLineCount())
N10X.Editor.SetScrollLine(clamped)
cursor = N10X.Editor.GetCursorPos()
newcursor = (cursor[0], cursor[1] + clamped - current)
N10X.Editor.SetCursorPos(newcursor)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment