gpt4 book ai didi

用于 Markdown 和 Python 的 Emacs 多模式

转载 作者:行者123 更新时间:2023-12-01 17:27:01 24 4
gpt4 key购买 nike

我使用 python3 pweave 库 ( http://mpastell.com/pweave/usage.html ) 进行文学编程

pweave 使用文本模式 ma​​rkdown,代码模式 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.

我做错了什么?如何让所需的多模式运行?

最佳答案

这是如何指定ma​​rkdown-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,她帮助我解决了这个问题!有关详细讨论,请查看 polymode issue 180 at github .

或者 我在 emacs stack exchange 上找到了这篇文章:https://emacs.stackexchange.com/questions/20136/pythontex-and-auctex因此,在这篇文章之后,这是进入 ma​​rkdown-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,他在帖子中的详细解释使我的案例运行起来轻而易举!

关于用于 Markdown 和 Python 的 Emacs 多模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52489905/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com