【问题标题】:Emacs polymode for Markdown and Python用于 Markdown 和 Python 的 Emacs 多模式
【发布时间】:2019-02-28 14:08:43
【问题描述】:

我使用 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 版本 26.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.

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

【问题讨论】:

  • 我无法提供解决方案,但我希望看到它能够正常工作,因为我越来越多地使用 Python,而不是我传统上使用 Rmarkdown 的 R。如果您还没有,可能值得在Emacs Stackexchange 上发帖。
  • 完成了一些挖掘,它有点过时但也许this thread 可能有用。
  • @slackline :对不起,我的慢动作回复。我联系了 Vspinu——polymode 包的作者——我们打开了一个关于这个主题的问题:github.com/polymode/polymode/issues/180。该问题尚未完全解决(20181031),但您应该能够在您的 emacs 上运行“用于 markdown 和 python 的 polymode”版本,按照我们在那里的讨论。
  • 感谢您的提醒,即使没有完全解决,看起来也很有用。干杯
  • 另外我发现了这篇文章:

标签: emacs literate-programming noweb pweave


【解决方案1】:

这是如何指定 ma​​rkdown-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))

我要感谢 polymode 包的作者 Vitalie Spinu,他帮助我解决了这个问题! 如需详细讨论,请查看polymode issue 180 at github。

另外我在 emacs 堆栈交换中找到了这篇文章: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,他在帖子中的详细解释让我的案子运行起来轻而易举!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-04-16
    • 2013-03-18
    • 1970-01-01
    • 2010-10-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多