這是一個關於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
和..
是乳膠模式。
我的問題是 - 如何在給定模式的兩個給定正則表達式之間做一個塊?
編輯:在(provide 'mumamo-fun)
之前就
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;; 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
)))
:
我已經添加了follosing到mumamo-fun.el
結束。
然後在.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))
,現在當我打開其餘的文件,我有:
math:`TEXT`
.. math:
TEXT
乳膠模式
.. code-block: bash
TEXT
的SH-模式
,和
.. code-block: py
TEXT
的蟒模式
。
編輯2:
此外,如果一個後
(dolist (item
'(("\\(^\\|[^\\]\\)\\(&+\\)" 2 'font-latex-warning-face)
("\\$\\$\\([^$]+\\)\\$\\$" 1 'font-latex-math-face)
;; HERE
...
到font-latex-make-user-keywords
在AUCTeX的font-latex.el
增加
("^ \\(.+\\)" 1 'font-latex-math-face)
,一會又.. math::
下獲得數學模式。
你可以看看小說'define-mumamo-multi-major-mode'的定義,看看它如何以及何時調用函數'rst-bk-latex-directive-chunk'。 – Malabarba