这是一个关于MuMaMo的问题。如果将以下代码添加到nxhtml/util/mumamo-fun.el的末尾:
(defun rst-bk-latex-directive-chunk (pos min max)
"Find math chunks. Return range and 'latex-mode.
See `mumamo-find-possible-chunk' for POS, MIN and MAX."
(mumamo-quick-static-chunk pos min max ".. math::\n\n" ".." nil 'latex-mode t))
;;;###autoload
(define-mumamo-multi-major-mode rst-bk-mumamo-mode
"Turn on multiple major modes for Python with RestructuredText docstrings."
("ReST" rst-mode
(
rst-bk-latex-directive-chunk
)))
(add-to-list 'auto-mode-alist '("\\.rst\\'" . rst-bk-mumamo-mode))而且还
(load "~/.emacs.d/site-lisp/nxhtml/autostart.el")
(require 'mumamo)
(require 'mumamo-fun)转到~/.emacs
一个在字符串.. math::\n\n和.. be之间获取块,它们是乳胶模式的。
我的问题是-如何在给定模式的两个给定的regexp之间形成块?
编辑
我在mumamo-fun.el的末尾加上了折叠式
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;; ReST + math + bash + python + cl
;; LaTeX:
(defun rst-bk-mumamo-math-regexp-chunk-start (pos max)
(let ((where (mumamo-chunk-start-fw-re pos max
"\\.\\. math::\\(.?\\|\n\\)*?\n\n"
)))
(when where
(list where 'latex-mode))))
(defun rst-bk-mumamo-math-regexp-chunk-end (pos max)
(save-match-data
(mumamo-chunk-end-fw-re pos max
"\\(^[[:blank:]]+$\\|\n\\)+[^[:blank:]\n]"
)))
(defun rst-bk-mumamo-math-quick-regexp-chunk (pos
min
max)
(save-match-data
(mumamo-possible-chunk-forward pos max 'rst-bk-mumamo-math-regexp-chunk-start
'rst-bk-mumamo-math-regexp-chunk-end)))
(defun rst-bk-mumamo-math-directive (pos min max)
"Find math chunks. Return range and 'math-mode.
See `mumamo-find-possible-chunk' for POS, MIN and MAX."
(rst-bk-mumamo-math-quick-regexp-chunk pos min max))
(defun rst-bk-mumamo-math-inline-chunk (pos min max)
"Find math chunks. Return range and 'math-mode.
See `mumamo-find-possible-chunk' for POS, MIN and MAX."
(mumamo-quick-static-chunk pos min max ":math:`" "`" nil 'math-mode t))
;; bash:
(defun rst-bk-mumamo-sh-regexp-chunk-start (pos max)
(let ((where (mumamo-chunk-start-fw-re pos max "\\.\\. code-block:: bash\\(.\\|\n\\)*?\n\n")))
(when where
(list where 'sh-mode))))
(defun rst-bk-mumamo-sh-regexp-chunk-end (pos max)
(save-match-data
(mumamo-chunk-end-fw-re pos max
"\\(^[[:blank:]]+$\\|\n\\)+[^[:blank:]\n]"
)))
(defun rst-bk-mumamo-sh-quick-regexp-chunk (pos
min
max)
(save-match-data
(mumamo-possible-chunk-forward pos max 'rst-bk-mumamo-sh-regexp-chunk-start
'rst-bk-mumamo-sh-regexp-chunk-end)))
(defun rst-bk-mumamo-sh-directive (pos min max)
"Find math chunks. Return range and 'sh-mode.
See `mumamo-find-possible-chunk' for POS, MIN and MAX."
(rst-bk-mumamo-sh-quick-regexp-chunk pos min max))
;; python:
(defun rst-bk-mumamo-py-regexp-chunk-start (pos max)
(let ((where (mumamo-chunk-start-fw-re pos max "\\.\\. code-block:: py\\(thon\\)?\\(.\\|\n\\)*?\n\n")))
(when where
(list where 'python-mode))))
(defun rst-bk-mumamo-py-regexp-chunk-end (pos max)
(save-match-data
(mumamo-chunk-end-fw-re pos max "\\(^[[:blank:]]+$\\|\n\\)+[^[:blank:]\n]")))
(defun rst-bk-mumamo-py-quick-regexp-chunk (pos
min
max)
(save-match-data
(mumamo-possible-chunk-forward pos max 'rst-bk-mumamo-py-regexp-chunk-start
'rst-bk-mumamo-py-regexp-chunk-end)))
(defun rst-bk-mumamo-py-directive (pos min max)
"Find math chunks. Return range and 'py-mode.
See `mumamo-find-possible-chunk' for POS, MIN and MAX."
(rst-bk-mumamo-py-quick-regexp-chunk pos min max))
;; cl:
(defun rst-bk-mumamo-cl-regexp-chunk-start (pos max)
(let ((where (mumamo-chunk-start-fw-re pos max "\\.\\. code-block:: cl\\(.\\|\n\\)*?\n\n")))
(when where
(list where 'emacs-lisp-mode))))
(defun rst-bk-mumamo-cl-regexp-chunk-end (pos max)
(save-match-data
(mumamo-chunk-end-fw-re pos max "\\(^[[:blank:]]+$\\|\n\\)+[^[:blank:]\n]")))
(defun rst-bk-mumamo-cl-quick-regexp-chunk (pos
min
max)
(save-match-data
(mumamo-possible-chunk-forward pos max 'rst-bk-mumamo-cl-regexp-chunk-start
'rst-bk-mumamo-cl-regexp-chunk-end)))
(defun rst-bk-mumamo-cl-directive (pos min max)
"Find math chunks. Return range and 'cl-mode.
See `mumamo-find-possible-chunk' for POS, MIN and MAX."
(rst-bk-mumamo-cl-quick-regexp-chunk pos min max))
;;;###autoload
(define-mumamo-multi-major-mode rst-bk-mumamo-mode
"Turn on multiple major modes for Python with RestructuredText docstrings."
("ReST" rst-mode (
rst-bk-mumamo-math-directive
rst-bk-mumamo-math-inline-chunk
rst-bk-mumamo-sh-directive
rst-bk-mumamo-py-directive
)))就在(provide 'mumamo-fun)之前。
然后在.emacs
(load "~/.emacs.d/site-lisp/nxhtml/autostart.el")
;; Mumamo is making emacs 23.3 freak out:
(when (and (equal emacs-major-version 23)
(equal emacs-minor-version 3))
(eval-after-load "bytecomp"
'(add-to-list 'byte-compile-not-obsolete-vars
'font-lock-beginning-of-syntax-function))
;; tramp-compat.el clobbers this variable!
(eval-after-load "tramp-compat"
'(add-to-list 'byte-compile-not-obsolete-vars
'font-lock-beginning-of-syntax-function)))
(require 'mumamo)
(load "mumamo-fun")
(add-to-list 'auto-mode-alist '("\\.rst\\'" . rst-bk-mumamo-mode))现在,当我打开ReST文件时,我拥有:
math:`TEXT`
LaTeX模式
.. math:
TEXTLaTeX模式
.. code-block: bash
TEXT在sh模式下,以及
.. code-block: py
TEXT巨蟒模式。
编辑2
如果一个人加上
("^ \\(.+\\)" 1 'font-latex-math-face)之后
(dolist (item
'(("\\(^\\|[^\\]\\)\\(&+\\)" 2 'font-latex-warning-face)
("\\$\\$\\([^$]+\\)\\$\\$" 1 'font-latex-math-face)
;; HERE
...在font-latex-make-user-keywords in font-latex.el of AUCTeX中,人们会得到.. math::下的数学模式.
发布于 2013-07-20 10:16:08
关键函数是mumamo-possible-chunk-forward与mumamo-chunk-start-fw-re和mumamo-chunk-end-fw-re相结合,后两者进行regexp匹配。
以下是其中的诀窍:
(defun regexp-chunk-start (pos max)
(let ((where (mumamo-chunk-start-fw-re pos max "math:\n\n")))
(when where
(list where 'latex-mode))))
(defun regexp-chunk-end (pos max)
(save-match-data
(mumamo-chunk-end-fw-re pos max "\\.\\.")))
(defun mumamo-quick-regexp-chunk (pos
min
max)
(save-match-data
(mumamo-possible-chunk-forward pos max 'regexp-chunk-start
'regexp-chunk-end)))
(defun rst-bk-latex-directive (pos min max)
"Find math chunks. Return range and 'latex-mode.
See `mumamo-find-possible-chunk' for POS, MIN and MAX."
(mumamo-quick-regexp-chunk pos min max))
;;;###autoload
(define-mumamo-multi-major-mode rst-bk-mumamo-mode
"Turn on multiple major modes for Python with RestructuredText docstrings."
("ReST" rst-mode (rst-bk-latex-directive)))
(add-to-list 'auto-mode-alist '("\\.rst\\'" . rst-bk-mumamo-mode))我抄袭了你提供的自传。坦率地说,我不明白如何加载MuMaMo主要模式。但是,我能够通过在mumamo-alias-rst-bk-latex-directive文件中手动调用ReST来测试这个特性。
MuMaMo的API有点不幸。匹配缓冲区区域的功能分散在三个不同的函数上,这使得重用变得困难。我希望一旦您有了模式匹配工作,您可能希望定义许多regexp。
下面是另一个版本,它封装了马可define-quick-regexp-chunk中的所有内容
(defmacro define-quick-regexp-chunk (regexp-chunk-fun begin-mark end-mark mode)
(let ((regexp-chunk-start-fun (gensym))
(regexp-chunk-end-fun (gensym)))
`(progn
(defun ,regexp-chunk-start-fun (pos max)
(let ((where (mumamo-chunk-start-fw-re pos max ,begin-mark)))
(when where
(list where ,mode))))
(defun ,regexp-chunk-end-fun (pos max)
(save-match-data
(mumamo-chunk-end-fw-re pos max ,end-mark)))
(defun ,regexp-chunk-fun (pos
min
max)
(save-match-data
(mumamo-possible-chunk-forward pos max ',regexp-chunk-start-fun
',regexp-chunk-end-fun))))))
;; switch to latex-mode in between "math:\n\n" ".."
;; defines a function named "rst-bk-latex-directive" which should be called by MuMaMo
(define-quick-regexp-chunk rst-bk-latex-directive "math:\n\n" "\\.\\." 'latex-mode)
;;;###autoload
(define-mumamo-multi-major-mode rst-bk-mumamo-mode
"Turn on multiple major modes for Python with RestructuredText docstrings."
("ReST" rst-mode (rst-bk-latex-directive)))
(add-to-list 'auto-mode-alist '("\\.rst\\'" . rst-bk-mumamo-mode))它做的事情完全一样,但是现在我可以使用define-quick-regexp-chunk轻松地定义许多正则表达式分隔的区域。请注意,您必须使用)。
查看noweb2块在nxHtml源(in /util/mumamo-fun.el)中的定义,了解如何使用MuMaMo的regexp函数的更高级示例。
https://stackoverflow.com/questions/17614522
复制相似问题