how do I import functions from a file in the same directory as the file that is the source of the current text buffer?
You can add the text file's folder to the system path, which will enable you to import from that path.

I'd also suggest to extract the folder path via os.path.dirname.

Short example to clarify:

import sys
from os.path import dirname
textFilePath = "/home/me/somewhere/textfiles/text1"
textFileFolder = dirname( textFilePath ) # = "/home/me/somewhere/textfiles"

sys.path.append(textFileFolder)

import someFileThatExistsInTextFolder