Michael Brock - 2011-05-09

From my last editor, I missed the ability to assign numbers to bookmarks to permit quickly  moving around the document.   I wrote these small scripts (with help from the Help forum) that provide that functionality.   I use a pair of scripts for each numbered book mark.  Bookmarks are indicated by setting margin text corresponding to that bookmark.  One script sets the bookmark (I have that assigned to alt-1, alt-2, alt-3 etc.) by saving the current line to a uniquely named text file and clearing any previous bookmark margin text..  The other (assigned to ctrl-1, ctrl-2, ctrl-3, etc.)  reads the line number from the text file and moves the caret to that line.

The script to set:

import os
editor.setMarginWidthN(3, 10)
editor.setMarginTypeN(3, MARGINTYPE.TEXT)
thisPath = os.path.basename(notepad.getCurrentFilename())
thisName = os.path.splitext(thisPath)
filePath = "C:\\dev_miva\\compile2\\bm_" + thisName[0] + "_1.txt"
if os.path.exists( filePath ):
  FILE = open(filePath,'r')
  lastLine = FILE.readline()
  console.write(lastLine)
  editor.marginSetText(int(lastLine) - 1, "") 
  FILE.close()
currentLine = editor.lineFromPosition(editor.getCurrentPos())
FILE = open(filePath,'w')
editor.marginSetText(currentLine, "1") 
FILE.write(str(currentLine + 1))
FILE.close()
[/quote]
and the script which reads the text file and moves the caret:
[quote]
import os
thisPath = os.path.basename(notepad.getCurrentFilename())
thisName = os.path.splitext(thisPath)
filePath = "C:\\dev_miva\\compile2\\bm_" + thisName[0] + "_1.txt"
FILE = open(filePath,'r')
gotoLine = FILE.readline()
editor.gotoLine(int(gotoLine) - 1)
FILE.close()
[/quote]