我将python3 pweave 库(http://mpastell.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版本26.1。 而且我能够从melpa安装polymode。
不幸的是,没有用于 主机模式:markdown,内部模式:python3,语法:noweb 所以我尝试根据文档和现有代码编写自己的 通过将以下 lisp 代码放入我的 .emacs 文件中,以 poly-pweave-mode 。
(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.
我怎么了? 如何使所需的多模运行?
答案 0 :(得分:2)
这是解决方案,如何指定 markdown-python3-noweb多模式
;; 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))
我要感谢多模式软件包的作者 Vitalie Spinu ,他帮助我解决了这个问题! 有关详细讨论,请查看polymode issue 180 at github。
或者我在emacs堆栈交换中找到了这篇文章:https://emacs.stackexchange.com/questions/20136/pythontex-and-auctex因此,在这篇文章之后,这是获得 markdown-python3-noweb mmm-mode的解决方案
;; 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 ,他在帖子中的详细解释使这件事变得轻而易举,可以为我的案子运行!