多个隐藏的正则表达式

时间:2009-05-24 23:21:19

标签: emacs

在emacs中,有没有办法让hideshow模式识别多个正则表达式以便隐藏?

2 个答案:

答案 0 :(得分:4)

取自EmacsWiki。如果我理解你的问题,你可能会失去运气,但“没有简单的方法”可能意味着有一个复杂的方法可以找到。

祝你好运

  

没有简单的指定方法   单个的多个正则表达式对   语言,例如,

* Open: {, close: }
* Open: #ifdef, close: #else or #elif or … etc.

答案 1 :(得分:0)

我假设您的意思是相同的模式。可以这样做,但是需要一些省略号和一些小的正则表达式。您将需要拥有或创建一种方法来检测您所处的子模式。

让我们以mhtml-mode(HTML / CSS / JS)为例:

;;; .emacs

;; When called this automatically detects the submode at the current location.
;; It will then either forward to end of tag(HTML) or end of code block(JS/CSS).
;; This will be passed to hs-minor-mode to properly navigate and fold the code.
(defun mhtml-forward (arg)
  (interactive "P")
  (pcase (get-text-property (point) `mhtml-submode)
    (`nil (sgml-skip-tag-forward 1))
    (submode (forward-sexp))))

;; Adds the tag and curly-brace detection to hs-minor-mode for mhtml.
(add-to-list 'hs-special-modes-alist
             '(mhtml-mode
               "{\\|<[^/>]*?"
               "}\\|</[^/>]*[^/]>"
               "<!--"
               mhtml-forward
               nil))

函数mhtml-forward检测应使用哪种类型的转发语句。

然后将

Hideshow设置为识别开始表达式{<tag>,以及结束表达式}</tag>。它将始终与正确的匹配,因为自定义转发功能可让您找到该特定实例的正确关闭表达式。

相关问题