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?


  • 1
    What have you already tired?
    – PythonNut
    Jan 12, 2016 at 6:36
  • Vim and Sublime and they both work :) Just sayin'
    – Cezar
    Jan 13, 2016 at 17:48
  • Well, for example, vimish-fold should be language agnostic. origami may also work with its indentation based parser.
    – PythonNut
    Jan 13, 2016 at 17:54

2 Answers 2


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
  (add-to-list 'hs-special-modes-alist

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.

  • Seems I spoke somewhat too soon – the error is not, per se, with Web Mode itself (assuming that not initializing particular variables were not a deliberate choice) but with the variables comment-start and comment-end being nil. With those not having a string value of some sort, starting hs-minor-mode will fail.
    – Jaft
    Jan 12, 2016 at 6:50
  • As far as I can tell 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.
    – Cezar
    Jan 13, 2016 at 17:49
  • @Cezar perhaps js2-jsx-mode?
    – PythonNut
    Jan 13, 2016 at 17:58
  • @Cezar Agreed; plus, Web Mode is super helpful when dealing with anything web related, I find. Take a look at the comment I left right above yours – the problem actually isn't with Web Mode but the variables 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
    – Jaft
    Jan 15, 2016 at 8:35
  • @Cezar (ignoring the beginning of the code in that last comment:) (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.
    – Jaft
    Jan 15, 2016 at 8:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.