It kind of depends on how you want to set things up. Definitely the portion of the manual on processes is worth reading. Reading the code for 'comint package is a good place to start.
You've listed a pretty limited set of functionality you'd like to expose, which could be solved by a direct connection. You can find helpful utility functions by looking at what is provided in 'net-utils (M-x find-library net-utils RET).
If the application you're trying to connect to has an interpreted language, I'd connect to that, as opposed to writing a custom parser on the app side.
Launching Emacs From App
Since you're launching Emacs from the app (as opposed to the other way (which might have made this job easier)), this is what I'd probably do:
- write little perl script to open a socket and read/write to it
- set up '(read (eval (print))) loop in the interpreter (or write a custom one) and connect it to a socket/port
- launch Emacs with function call (--eval or --execute) specifying the socket
- start the perl script as a subprocess and the port (see how inferior-lisp or inferior-tcl do it)
At that point, anything from Emacs could be sent to the perl subprocess ('comint-send-string), and be passed on to your REPL and have the desired effect there. Likewise, you can send commands back to emacs by just sending over strings, and have them parsed by functions you've stuck in 'comint-output-filter-functions.
You'd then write two little libraries, one in your APP interpreted language, and one in Emacs, to do whatever functionality makes sense. The emacs library should probably be packaged as a major (or minor) mode depending on what the files are like. If they're solely to be used with the app, a major mode, if they're (for example) C++ files, a minor mode would be better given that you'd probably want to leverage the c++-mode.
I'd write the little perl script in perl, as opposed to elisp, simply b/c I know how to interact with 'comint. If the little perl script could be replaced with a chunk of elisp, and still have the benefit using comint, that'd be an added bonus.
I've got pretty much the same setup for Tcl/Tk, only the connection stuff is handled by Tk's send command. It works really well.
Launching App From Emacs
Now, if you could, instead, launch the app from Emacs, the above still applies, only you can get rid of the little perl script and just interact through the 'comint interface. No sockets needed.
- You'd still need the 'repl loop (if the app can't leave stdin/stdout tied to the interpreter
- The libraries would remain the same
That'd be much easier, but only works if the user flow enables you to go that direction. (I've a hunch you're writing this for more than just your use.)
That being said, it might be easier to develop/test this way (launching from Emacs). You could add on the socket communication later as an enhancement. Whichever is more motivating...