【问题标题】:Emacs C-c C-c for python codeEmacs C-c C-c 用于 python 代码
【发布时间】:2014-01-17 15:51:35
【问题描述】:

我刚开始使用 emacs 作为 python 的 IDE。我激活了 pymode 和 Ropemacs。我的理解是我应该能够突出显示一个区域,然后使用 C-c C-c 将其发送到交互式终端。我需要其他软件包来完成此操作吗?

我得到的 C-c C-c 错误是:

Wrong type argument: integer-or-marker-p, nil

我还看到 this link 对此发表了声明,但这看起来不像是我的错误。

更新回答扎克

为了设置该变量,我进入了 emacs scratch 并这样做了:

(setq debug-on-error t)

然后M-x eval-region

(这是将其设置为 true 的正确方法吗?)

那么这就是我的调试器中出现的内容:

Debugger entered--Lisp error: (wrong-type-argument integer-or-marker-p nil)
  count-lines(1 nil)
  (save-restriction (widen) (count-lines (point-min) (or (and (eq start (line-beginning-position)) (not (eobp)) (1+ start)) start)))
  (let* ((windows-config (window-configuration-to-register 313465889)) (origline (save-restriction (widen) (count-lines (point-min) (or (and (eq start ...) (not ...) (1+ start)) start)))) (py-shell-name (or shell (py-choose-shell))) (py-exception-buffer (current-buffer)) (execute-directory (cond ((condition-case nil (progn (file-name-directory ...)) (error nil))) ((and py-use-current-dir-when-execute-p (buffer-file-name)) (file-name-directory (buffer-file-name))) ((and py-use-current-dir-when-execute-p py-fileless-buffer-use-default-directory-p) (expand-file-name default-directory)) ((stringp py-execute-directory) py-execute-directory) ((getenv "VIRTUAL_ENV")) (t (getenv "HOME")))) (py-buffer-name (or py-buffer-name (py-buffer-name-prepare))) (filename (and filename (expand-file-name filename))) (py-orig-buffer-or-file (or filename (current-buffer))) (proc (or proc (if py-dedicated-process-p (get-buffer-process (py-shell nil py-dedicated-process-p py-shell-name py-buffer-name t)) (or (and (boundp ...) (get-buffer-process py-buffer-name)) (get-buffer-process (py-shell nil py-dedicated-process-p py-shell-name ... t)))))) err-p) (set-buffer py-exception-buffer) (py-update-execute-directory proc py-buffer-name execute-directory) (cond (python-mode-v5-behavior-p (py-execute-python-mode-v5 start end)) (py-execute-no-temp-p (py-execute-ge24\.3 start end filename execute-directory)) ((or file (and (not (buffer-modified-p)) filename)) (py-execute-file-base proc filename nil py-buffer-name filename execute-directory)) (t (py-execute-buffer-finally start end execute-directory))))
  py-execute-base(nil nil nil "/home/mittenchops/gh/myscript.py" nil "/home/mittenchops/gh/myscript.py")
  (setq erg (py-execute-base nil nil nil file nil (or (and (boundp (quote py-orig-buffer-or-file)) py-orig-buffer-or-file) file)))
  (if (file-readable-p file) (setq erg (py-execute-base nil nil nil file nil (or (and (boundp (quote py-orig-buffer-or-file)) py-orig-buffer-or-file) file))) (message "%s not readable. %s" file "Do you have write permissions?"))
  (let (erg) (if (file-readable-p file) (setq erg (py-execute-base nil nil nil file nil (or (and (boundp (quote py-orig-buffer-or-file)) py-orig-buffer-or-file) file))) (message "%s not readable. %s" file "Do you have write permissions?")) erg)
  py-execute-file("/home/mittenchops/gh/myscript.py")
  (let* ((py-master-file (or py-master-file (py-fetch-py-master-file))) (file (if py-master-file (expand-file-name py-master-file) (buffer-file-name)))) (py-execute-file file))
  py-execute-buffer-base()
  (progn (write-file (buffer-file-name)) (py-execute-buffer-base))
  (if (y-or-n-p "Buffer changed, save first? ") (progn (write-file (buffer-file-name)) (py-execute-buffer-base)) (py-execute-region (point-min) (point-max)))
  (if (and py-prompt-on-changed-p (buffer-file-name) (interactive-p) (buffer-modified-p)) (if (y-or-n-p "Buffer changed, save first? ") (progn (write-file (buffer-file-name)) (py-execute-buffer-base)) (py-execute-region (point-min) (point-max))) (if (buffer-file-name) (py-execute-buffer-base) (py-execute-region (point-min) (point-max))))
  py-execute-buffer()
  call-interactively(py-execute-buffer nil nil)

【问题讨论】:

  • debug-on-error 设置为t,重复测试,并在**Debug** 窗口中发布您获得的回溯。 (然后使用M-x top-level 退出调试器。Emacs 调试器太可怕了,您绝对不想尝试使用它,但我们确实需要这种回溯。)
  • 为了以后参考,Lisp 变量可以用M-x set-variable 设置,这可能比拉起暂存缓冲区更方便。选项卡完成和一切。

标签: python emacs


【解决方案1】:

显示的错误是由 python-mode.el 中的错误导致的,该错误已在主干中修复。 AFAIK 该错误仅在执行未保存的缓冲区时发生,因此首先保存缓冲区会使 C-c C-c 工作。

BTW py-execute-region RET 是 C-c |,而 C-c C-c 将始终发送整个缓冲区,无论现有区域如何。如果 C-c C-c 应该尊重一个区域,那可能值得一个功能请求。如果有兴趣,请在此处提交:

https://bugs.launchpad.net/python-mode

仍然是个人观点:将区域标记为这样的成本很高 - 例如。一件费力的事情,因为它需要一些注意力来定义边界权,而这在所涉及的问题本身上会花费更多。 Python 模式将通过提供几个执行什么命令来完成大量的工作。也许看看菜单“Python”,参见“执行...”部分和“更多...”按钮。以类似的方式,其他几个编辑应该会更容易。

【讨论】:

  • 我已经更新到 6.1.3 并且似乎仍然有这个错误。我正在使用保存的缓冲区。
  • @Mittenchops 目前无法重现。请在bugs.launchpad.net/python-mode 开票。需要一些示例代码、M-x report-emacs-bug RET 的输出和最近的回溯(如果有)。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2023-03-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-12-18
相关资源
最近更新 更多