I'm using web-mode
to edit jsx
files and I'm wondering what minor-mode can I use to add folding support. Is there anything out there that works?
Thanks
Although it's an old question, I'll share my setup for anyone still looking for ways to do this.
I use built-in hideshow
package with additional configuration for handling HTML tags.
(use-package hideshow
:diminish hs-minor-mode
:config
(add-to-list 'hs-special-modes-alist
'(web-mode
"<!--\\|<[^/>]*[^/]>"
"-->\\|</[^/>]*[^/]>"
"<!--"
web-mode-forward-sexp
nil)))
It's not quite a full answer (unless you're O. K. with ditching web-mode which I would think is less than ideal) but Hideshow Minor Mode will, technically, get the job done for you.
If you enable it (with (hs-minor-mode t)
), running the function hs-hide-block
while the cursor is within a pair of curly braces will fold that block.
The one snag in all of this – from the perspective of web development in Emacs – is that Web Mode won't allow you to enable Hideshow Minor Mode while it (Web Mode) is in use. An ideal answer will allow find someway to enable the feature while keeping Web Mode present and fully functional.
comment-start
and comment-end
being nil
. With those not having a string value of some sort, starting hs-minor-mode
will fail.
web-mode
is the mode to use with jsx. Isn't it? I mean I wouldn't want to loose other features just to get folding.
comment-start
and comment-end
not being set to anything other than nil
. Something I put in my .emacs file was `(defun func-name-of-choice () (let ((ext (file-name-extension (buffer-name)))) (cond
(defun func-name-of-choice () (let ((ext (file-name-extension (buffer-name)))) (cond ((string-equal ext "css") (setq-local comment-start "/* ") (setq-local comment-end " */")) ((string-equal ext "js") (setq-local comment-start "// ") (setq-local comment-end "")) ((or (string-equal ext "html") (string-equal ext "xml")) (setq-local comment-start "<!-- ") (setq-local comment-end " -->")))) (hs-minor-mode t))
That, when entering web mode, determines what the file ext. is and sets comments appropriately and enters HS Minor Mode.
vimish-fold
should be language agnostic.origami
may also work with its indentation based parser.