Goal
To parse text file in Python, search for string, and insert in current emacs buffer
Purpose
I do my document writing in LaTeX under Emacs and I would like to be able to do quick insertion of Bible verses as I type. I am aware of esv-mode in esv.el, which inserts Bible verses by querying biblegateway.org. However, that only works when I am online, and I want to be able to do insertion offline (I frequently work offline) as well.
I am aware of pymacs, which I have not tried since it looks to be severely outdated (I could not even open the help file under the GitHub repository...so it seems to be dying).
What I have tried
I created a simple test file in Python to read dummy text from dummy file:
def get_verse():
with open('/home/test.txt','r') as tmp:
text = tmp.read()
return text
a = get_verse()
print(a)
I normally use Python for data transfer, analysis, and processing, so the current application is outside my experience. If there is some general improvement I would appreciate the suggestions.
I then define that function under my .emacs file as:
;; testing function
(defun bible-verse ()
(interactive)
; (insert (shell-command "python /home/test.py")))
(insert (shell-command-to-string "python /home/test.py")))
(global-set-key
(kbd "C-c pytest")
'bible-verse
)
As you can see, I have tried both the shell-command and shell-command-to-string commands. Neither of which work (i.e. no text is inserted).
However, I do get the text from the dummy file inserted when I execute the following in Emacs:
C-u M-! python /home/test.py
Right now I have two problems:
How do I get Emacs to execute my Python code and insert the returned text within the current buffer?
How can I pass a variable to the Python code from Emacs (i.e. to pull from specific book, chapter, verse)?
Since this is more of an Emacs issue I am not tagging this as Python (feel free to edit that if you think otherwise).