3

我使用 python3 pweave库 ( http://mpatell.com/pweave/usage.html ) 进行识字编程

pweave 使用作为文本模式markdown,作为代码模式python3,并且可以使用noweb ( https://en.wikipedia.org/wiki/Noweb ) 识字编程语法。

为了在emacs中正确突出显示语法,我打算使用polymode库(https://polymode.github.io/https://github.com/polymode)。

我使用emacs version26.1。而且我能够从 melpa 安装 polymode。

不幸的是,主机模式没有预先存在的多模式:markdown,内部模式:python3,语法:noweb 所以我尝试根据文档和现有代码编写我的一个 poly-pweave-mode,方法是:lisp代码到我的.emacs文件中。

(require 'polymode-classes)

(defcustom pm-host/pweave-text
  (pm-host-chunkmode :name "pweave-text"
                     :mode 'markdown-mode)
  "markdown host chunkmode"
  :group 'poly-hostmodes
  :type 'object)

(defcustom  pm-inner/pweave-code
  (pm-inner-chunkmode :name "pweave-code"
                      :head-matcher "^[ \t]*<<\\(.*\\)>>="
                      :tail-matcher "^[ \t]*@.*$"
                      :mode 'python-mode)
  "noweb static python3 inner chunkmode."
  :group 'poly-innermodes
  :type 'object)

(define-polymode poly-pweave-mode
  :hostmode 'pm-host/pweave-text
  :innermode 'pm-inner/pweave-code)

(add-to-list 'auto-mode-alist '("\\.pymd" . poly-pweave-mode))

但不知何故,emacs 不吃这个。当我打开 emacs 时,出现以下错误:

Warning (initialization): An error occurred while loading `/Users/abc/.emacs':

Symbol's function definition is void: pm-host-chunkmode

To ensure normal operation, you should investigate and remove the
cause of the error in your initialization file.  Start Emacs with
the `--debug-init' option to view a complete error backtrace.

我错了什么?我怎样才能让所需的多模运行?

4

1 回答 1

2

这是如何指定markdown-python3-noweb polymode的解决方案

;; define pwn polymode
(require 'poly-noweb)
(require 'poly-markdown)

(defcustom pm-inner/noweb-python
  (clone pm-inner/noweb
         :name "noweb-python"
         :mode 'python-mode)
  "Noweb for Python"
  :group 'poly-innermodes
  :type 'object)

(define-polymode poly-pweave-mode poly-markdown-mode
  :innermodes '(pm-inner/noweb-python :inherit))

(add-to-list 'auto-mode-alist '("\\.pymd" . poly-pweave-mode))

我要感谢polymode包的作者 Vitalie Spinu 帮助我解决了这个问题!有关详细讨论,请查看github 上的 polymode 问题 180

或者,我在 emacs 堆栈交换中找到了这篇文章:https ://emacs.stackexchange.com/questions/20136/pythontex-and-auctex所以,在这篇文章之后,这是获得markdown-python3-noweb mmm-的解决方案模式

;; define pwn multi major modes mode
(require 'mmm-auto)

(mmm-add-classes
 '((noweb-python
    :submode python-mode
    :face mmm-default-submode-face
    :front "^<<.*>>=\n"
    :back "^@$")))

(setq mmm-global-mode 'maybe)
(mmm-add-mode-ext-class 'markdown-mode nil 'noweb-python)

(add-to-list 'auto-mode-alist '("\\.pymd" . markdown-mode))

我要感谢Jean Pierre,他在帖子中的详细解释让我的案子运行起来轻而易举!

于 2018-11-05T04:43:56.693 回答