【问题标题】:Is there a function like eval-print-last-sexp for Comint-Mode?Comint-Mode 是否有类似 eval-print-last-sexp 的功能?
【发布时间】:2017-08-19 08:53:40
【问题描述】:

对于 emacs 中的 comint 派生模式,是否有与 eval-print-last-sexp 等效的函数?

具体来说,我正在使用 python-mode(使用 elpy)并且正在寻找一种方法将区域的内容发送到 Python 进程,然后在我正在工作的 python 脚本的下一行打印结果在。

将结果打印到 Messages 缓冲区也是可以接受的,但是最好使用 eval-print-last-sexp 的行为。

我正在运行 Emacs 25.1.1 和 elpy 1.13.0。

【问题讨论】:

    标签: python emacs eval elpy


    【解决方案1】:

    这取决于 comint 派生模式,因为您需要重定向进程输出。不同的模式有不同的方法与劣质进程交互。 Python 模式已经有一个函数可以做到这一点,python-shell-send-string-no-output(其他模式也有类似的函数,但你需要搜索它们)。

    我不确定你想如何为 python 定义一个 sexp,但这里有一个发送当前行的示例,输出类似于 eval-print-last-sexp

    (defun python-eval-print-last-sexp ()
      "Print result of evaluating current line into current buffer."
      (interactive)
      (let ((res (python-shell-send-string-no-output
                  ;; modify to get a different sexp
                  (buffer-substring (line-beginning-position)
                                    (line-end-position))))
            (standard-output (current-buffer)))
        (when res
          (terpri)
          (princ res)
          (terpri))))
    

    【讨论】:

    • 太棒了! python-shell-send-string-no-output 正是我所需要的,你的功能完美无缺。
    【解决方案2】:

    elpy-shell-send-statement 来自Emacs Python Development Environment

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-11-21
      • 2012-08-01
      • 2012-04-04
      • 2023-04-07
      • 1970-01-01
      相关资源
      最近更新 更多