【求助】 如何为 emacs-lisp-mode 写 hideshow 规则代替 origami 折叠?

想要实现这样的折叠

;; -*- origami-fold-style: triple-braces -*-

;; title
;; {{{
;; text to fold
;; }}}
;; title
;; {{{ ... }}}

官方文档里有九个参数,但默认值里只有六个参数,看不太懂正则表达式怎么写。

 (mhtml-mode "{\\|<[^/>]*?" "}\\|</[^/>]*[^/]>" "<!--" mhtml-forward nil)
Each element has the form
  (MODE START END COMMENT-START FORWARD-SEXP-FUNC ADJUST-BEG-FUNC
   FIND-BLOCK-BEGINNING-FUNC FIND-NEXT-BLOCK-FUNC
   LOOKING-AT-BLOCK-START-P-FUNC).

我感觉这里的 START 是指折叠的“开始位置”的正则匹配,类似。COMMENT-START 是注释的正则匹配?

例如 {\\|<[^/>]*? 去掉转义是 {|<[^/>]*?,也就是 { 或者 <[^/>]*?

主要还要 FORWARD-SEXP-FUNC 这个参数配合使用

这里附上 doom 的配置供参考(你想要的 {{{?)

(setq hs-special-modes-alist
      (append
       '((vimrc-mode "{{{" "}}}" "\"")
         (yaml-mode "\\s-*\\_<\\(?:[^:]+\\)\\_>"
                    ""
                    "#"
                    +fold-hideshow-forward-block-by-indent-fn nil)
         (haml-mode "[#.%]" "\n" "/" +fold-hideshow-haml-forward-sexp-fn nil)
         (ruby-mode "class\\|d\\(?:ef\\|o\\)\\|module\\|[[{]"
                    "end\\|[]}]"
                    "#\\|=begin"
                    ruby-forward-sexp)
         (matlab-mode "if\\|switch\\|case\\|otherwise\\|while\\|for\\|try\\|catch"
                      "end"
                      nil (lambda (_arg) (matlab-forward-sexp)))
         (nxml-mode "<!--\\|<[^/>]*[^/]>"
                    "-->\\|</[^/>]*[^/]>"
                    "<!--" sgml-skip-tag-forward nil)
         (latex-mode
          ;; LaTeX-find-matching-end needs to be inside the env
          ("\\\\begin{[a-zA-Z*]+}\\(\\)" 1)
          "\\\\end{[a-zA-Z*]+}"
          "%"
          (lambda (_arg)
            ;; Don't fold whole document, that's useless
            (unless (save-excursion
                      (search-backward "\\begin{document}"
                                       (line-beginning-position) t))
              (LaTeX-find-matching-end)))
          nil))
       hs-special-modes-alist
       '((t))))
2 个赞

感谢感谢,我稍后研究一下,才用 Emacs 没多久,还不太熟怎么写正则。