[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] add outline regexp to ruby-mode

From: Juri Linkov
Subject: Re: [PATCH] add outline regexp to ruby-mode
Date: Wed, 06 Jul 2022 11:06:18 +0300
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (x86_64-pc-linux-gnu)

>> Some programming modes built into emacs provide outline-regexp to
>> allow for code folding and an example of this is python-mode.
>> "ruby-mode" on the other hand does does not have this feature. Since
>> it is a very handy feature to have it might be worth adding with the
>> following simple patch.
>> -  (setq-local syntax-propertize-function #'ruby-syntax-propertize))
>> +  (setq-local syntax-propertize-function #'ruby-syntax-propertize)
>> +  (setq-local outline-regexp ruby-indent-beg-re))
> I like this suggestion, although I don't think that's the right regexp to
> use for an outline. Shouldn't it be limited to definitions only (similar to
> what imenu typically does)?

I have been successfully using outlines in ruby-mode for a long time
with such simple customization because I didn't want to make outlines
on if/unless/case/..., only on definitions class/module/def.

  (add-hook 'ruby-mode-hook
            (lambda ()
              ;; Copied some keywords from ‘ruby-block-beg-keywords’ and
              ;; ‘ruby-imenu-create-index-in-block’
              (setq-local outline-regexp (concat "^\\s *" (regexp-opt '("class" 
"module" "def")) "\\s +"))
              (setq-local outline-level (lambda () (1+ (/ (current-indentation) 
              (outline-minor-mode +1)))

But now I noticed that actually if/unless/case/... in
ruby-indent-beg-re has no effect on outlines, because
they are on a separate regexp group.  So using it for
outline-regexp would be fine.  Then I only suggest
to add outline-level as well.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]