开发者

How do you have a process in emacs return value as a function?

I'm trying to write emacs tools that require sending data to an external process, my example is a REPL as part of an inferior-lisp.

How do you get the output of the process to be returned as if it were an emacs function?

I would like something like:

(defun get-data () 
  (process-send-string (get-process) "foo command")
  (get-data-output-from-process (get-process)))

I've tried using process-send-string and accept-process-output-proc but the output always gets sent to the inferior-lisp. I would like something to return data to the function that was called so I can manipulate the data. Also if possible I would like to not copy th开发者_JS百科e output to the inferior-lisp buffer.


Generally, you want to read up on running EMACS subprocesses. There are several useful functions for getting information from a subprocess.

Here's an example with call-process:

;; results go into current buffer
(call-process "pwd" nil t)
/nishome/crmartin  ; there's the results
0                  ; return value is value from exit
(call-process "false" nil t)
1                  ; false(1) always returns non-0
;; results go into a buffer named "bletch", creating it if needed.
(call-process "pwd" nil "bletch" t)
0

To try this, type the elisp code into scratch and run with C-j.


The only way I could get this to work was to store the results in a global, then pass it back in the function.

 (defvar ac-dj-toolkit-current-doc nil "Holds dj-toolkit docstring for current symbol")

 (defun dj-toolkit-parse (proc text)
   (setq ac-dj-toolkit-current-doc text)
   text)

 (defun dj-toolkit-doc (s)
   (let ((proc (inferior-lisp-proc)))
     (process-send-string (inferior-lisp-proc)
             (format "(clojure.repl/doc %s)\n"
                 s))
     (set-process-filter proc 'dj-toolkit-parse)
     (accept-process-output proc 1)
     (set-process-filter proc nil)
     ac-dj-toolkit-current-doc))
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜