In ruby-mode, using hs-minor-mode (hideshow) you can hide almost any block of code, but heredocs.

I've tried adding "LONG_HEREDOC" to hs-special-modes-alist, but it didn't worked:

(eval-after-load "hideshow"
  '(add-to-list 'hs-special-modes-alist
                   ,(rx (or "def" "class" "module" "{" "[" "do" "<<LONG_HEREDOC")) ; Block start
                   ,(rx (or "}" "]" "end" "LONG_HEREDOC"))                       ; Block end
                   ,(rx (or "#" "=begin"))                        ; Comment start
                   ruby-forward-sexp nil)))

I think it has todo with "ruby-forward-sexp". It doesn't seem to work with heredoc comments.

Does any one knows how to solve this?

(require 'hideshow)

;; Set up hs-mode (HideShow) for Ruby
(add-to-list 'hs-special-modes-alist
           ,(rx (or "def" "class" "module" "do")) ; Block start
               ,(rx (or "end"))                       ; Block end
               ,(rx (or "#" "=begin"))                ; Comment start
               ruby-forward-sexp nil))

(add-hook 'ruby-mode-hook 'hs-minor-mode)

(global-set-key (kbd "<f9>") 'hs-toggle-hiding)
(global-set-key (kbd "C-<f9>") 'hs-hide-all)
(global-set-key (kbd "C-S-<f9>") 'hs-show-all)

Stolen from this gist.

  • 4
    It would be better to provide instructions/code rather than a bare link which will easily go out of date. – Andrew Swann Jun 29 '15 at 8:37
  • I don't think this answer even includes heredocs at all, unless I'm missing something, so I don't know why this answer received any votes. – Ibrahim Aug 9 '16 at 1:27

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.