这是一个关于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
并且..
是乳胶模式。
我的问题是——如何在给定模式的两个给定正则表达式之间创建一个块?
编辑:
我已将以下内容添加到末尾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:
TEXT
LaTeX 模式
.. 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
...
到AUCTeX 中,然后一个人会font-latex-make-user-keywords
在.font-latex.el
.. math::