问题
Does emacs have a hide-show code fold-ability for html? I have it when I'm using org mode, but can't seem to find it on the nXML/html side.
回答1:
I wrote this for mhtml-mode and it works pretty well, it can fold HTML by tag as well as the embedded CSS and JS. Simply add it to your emacs config file and you'll be set to go.
;; 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))
Regex Breakdown:
"{\\|<[^/>]*?"
: Match either{
or any opening HTML tags. It matches up to but doesn't include the closing>
in the opening tag. That allows the<script>
and<style>
tags to be treated as HTML tags instead of JS or CSS."}\\|</[^/>]*[^/]>"
: Match either}
or a closing tag.
来源:https://stackoverflow.com/questions/21342120/does-emacs-offer-hide-show-for-html-mode