Skip to main content
 首页 » 编程设计

python之在 emacs 的 ipython 模式下,有没有办法执行当前行

2025年05月04日14zdz8207

我可以执行突出显示的区域,但是有执行单行的命令吗?没有 C 空格来突出显示它。

有什么想法吗?

请您参考如下方法:

我假设您使用的是 Emacs 附带的 python.el。据我所知,该模式没有定义执行单行的命令。但是我们可以很容易地定义一个命令来这样做。下面是我尝试定义这样一个命令

(defun python-send-line () 
  (interactive) 
  (save-excursion  
    (back-to-indentation) 
    (python-shell-send-string (concat (buffer-substring-no-properties (point) 
                                                                      (line-end-position))  
                                      "\n")))) 

如果您正在使用 python-mode.el,它确实有一个名为 py-execute-line 的命令,根据 docstring

Send current line from beginning of indent to Python interpreter.