【问题标题】:How do you have a process in emacs return value as a function?您如何在 emacs 中将进程作为函数返回值?
【发布时间】:2011-07-16 23:23:41
【问题描述】:

我正在尝试编写需要将数据发送到外部进程的 emacs 工具,我的示例是 REPL 作为低级 lisp 的一部分。

如何让进程的输出像 emacs 函数一样被返回?

我想要类似的东西:

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

我尝试过使用 process-send-string 和 accept-process-output-proc,但输出总是被发送到 suber-lisp。我想要一些东西将数据返回给被调用的函数,以便我可以操作数据。另外,如果可能的话,我不想将输出复制到劣质lisp缓冲区。

【问题讨论】:

    标签: emacs


    【解决方案1】:

    一般来说,你想了解一下运行EMACS subprocesses.getting information from a subprocess有几个有用的功能。

    这是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
    

    要试试这个,在 scratch 中输入 elisp 代码并使用 C-j 运行。

    【讨论】:

      【解决方案2】:

      我可以让它工作的唯一方法是将结果存储在全局中,然后将其传递回函数中。

       (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))
      

      【讨论】:

        猜你喜欢
        • 2021-02-02
        • 2012-05-31
        • 2015-03-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-07-21
        • 1970-01-01
        • 2015-05-20
        相关资源
        最近更新 更多