I would like to configure my Emacs fringe to show code folding sections.

For example, BBEdit on the Mac would show the following when editing a JSON file:

BBEdit code folding marks

The marks themselves are actionable: clicking on a mark would expand or collapse the corresponding code section. When the document does not have a mode that supports code folding, the fringe is not shown.

Is it possible to expand the Emacs fringe functionality in such a way?


Hideshowvis adds clickable icons to the fringe, but for some strange reason it's not included in elpa or melpa. By default it shows a - in the fringe for code that can be folded, and then elides the content with a .... By also enabling hideshowvis-symbols it adds a + and makes the hinting for folded content a little louder.

Hideshow itself also allows mouse clicks on the line to toggle display using S-mouse-2 (or shift middle click). That is built in and can be enabled with hs-minor-mode.

  • 1
    Nice, hideshowvis.el uses a hack similar to the one I'm suggesting, but without the ugliness of having to double-click (by reading the raw event). Thanks for the pointer. – Sigma Sep 24 '14 at 4:24
  • 3
    Hideshowvis.el works great, thanks! I had some issues getting it to work on JSON files with js3-mode; to work around these issues I had to make sure that hideshowvis only is enabled after all actions in the queue, e.g.: (dolist (hook '(emacs-lisp-mode-hook c++-mode-hook)) (add-hook hook 'hideshowvis-enable)) (defun hideshowvis-enable-immediately () (run-at-time "0 seconds" nil 'hideshowvis-enable)) (add-hook 'js3-mode-hook 'hideshowvis-enable-immediately) – Mathieu Legrand Sep 25 '14 at 1:54
  • It's on melpa now. – dshepherd Feb 2 '17 at 22:10

While I don't think the fringe items can directly receive clicks (I might be wrong though), a possible hack would be to bind (kbd "<left-fringe> <double-mouse-1>")

Since the first click would move the point to the beginning of the line that corresponds to the fringe icon, testing the value of (point) in your hypothetical (un)folding function would allow you to identify which portion of code to (un)fold, or if you need to do anything at all (in case no fringe icon is present for this line)

example with an org-mode buffer:

(define-key org-mode-map (kbd "<left-fringe> <double-mouse-1>") 'org-cycle)

Double-clicking on the fringe cycles the corresponding subtree.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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