Emacs Org-babel 执行 GForth 代码冻结 Emacs

问题描述 投票:0回答:1

我正在尝试在组织模式下执行 GForth 源代码块。但是当我尝试执行 Forth 代码块时,Emacs 就停止响应。

我正在尝试做的事情: 我在我的组织块中写道:

#+begin_src forth
1 2 .s
#+end_src

然后按 C-c C-c,然后显示“正在位置 407 处执行 Forth 代码块...”。然后 Emacs 就‘冻结’了。它只是停止响应任何命令。

预期输出: 1 2 好的 2

我做了什么配置: 我目前正在使用:

  • WSL Ubuntu 22.04
  • gforth 0.7.9_20240215 amd64
  • Emacs 30.0.50,从源代码构建
  • 组织模式9.6.1

我主要遵循以下说明: https://gforth.org/manual/Installing-gforth_002eel.html .

(declare-function forth-proc "ext:gforth" ())
  • 我将 'ext:gforth.el' 放在 ~/emacs.d/lisp/ 目录中,该目录包含在我的加载路径中。

  • 我测试了“ext:gforth.el”中提供的第四模式。我事先跑了 M-x run-out。当我尝试在激活第四模式的情况下在 scratch 缓冲区中执行代码时,一切正常,结果显示在迷你缓冲区中。

我的init.el:

(org-babel-do-load-languages
 'org-babel-load-languages
 '((forth . t)))

(require 'ob-forth)
(load-file "~/.emacs.d/lisp/ext:gforth.el")
(autoload 'forth-mode "ext:gforth.el")
(setq auto-mode-alist (cons '("\\.fs\\'" . forth-mode) 
                auto-mode-alist))
(autoload 'forth-block-mode "ext:gforth.el")
(setq auto-mode-alist (cons '("\\.fb\\'" . forth-block-mode) 
                auto-mode-alist))
(add-hook 'forth-mode-hook (function (lambda ()
   ;; customize variables here:
   (setq forth-indent-level 4)
   (setq forth-minor-indent-level 2)
   (setq forth-hilight-level 3)
   ;;; ...
)))

如有任何建议,我们将不胜感激!

emacs org-mode gforth
1个回答
0
投票

原来问题出在

org-babel-forth-session-execute
ob-forth.el.gz

(defun org-babel-forth-session-execute (body params)
  (require 'forth-mode)
  (let ((proc (forth-proc))
    (rx " \\(\n:\\|compiled\n\\|ok\n\\)")
    (result-start))
    (with-current-buffer (process-buffer (forth-proc))
      (mapcar (lambda (line)
        (setq result-start (progn (goto-char (process-mark proc))
                      (point)))
        (comint-send-string proc (concat line "\n"))
        ;; wait for forth to say "ok"
        (while (not (progn (goto-char result-start)
                   (re-search-forward rx nil t)))
          (accept-process-output proc 0.01))
        (let ((case (match-string 1)))
          (cond
           ((string= "ok\n" case)
            ;; Collect intermediate output.
            (buffer-substring (+ result-start 1 (length line))
                      (match-beginning 0)))
           ((string= "compiled\n" case))
           ;; Ignore partial compilation.
           ((string= "\n:" case)
            ;; Report errors.
            (org-babel-eval-error-notify 1
                                         (buffer-substring
                                          (+ (match-beginning 0) 1) (point-max)))
            nil))))
          (split-string (org-trim
                 (org-babel-expand-body:generic body params))
                "\n"
                'omit-nulls)))))

正则表达式捕获“ok ”,但不是“ok”。如果你评估

1 2 .s
,gforth 将打印“<2> 1 2 ok 2”,并且正则表达式搜索将失败,因此整个过程停止。

我重新定义了

org-babel-forth-session-execute
以在我的
init.el
中捕获“ok”:

;;...
(rx " \\(\n:\\|compiled\n\\|ok\\)")
;;...
((string= "ok" case)

现在一切正常。

© www.soinside.com 2019 - 2024. All rights reserved.