all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Juri Linkov <juri@linkov.net>
To: "Bozhidar Batsov" <bozhidar@batsov.dev>
Cc: "Emacs Devel" <emacs-devel@gnu.org>
Subject: Re: [PATCH] add outline regexp to ruby-mode
Date: Wed, 06 Jul 2022 11:06:18 +0300	[thread overview]
Message-ID: <867d4qvep9.fsf@mail.linkov.net> (raw)
In-Reply-To: <ebe273b1-6f91-499d-9a0d-db08411550b7@www.fastmail.com> (Bozhidar Batsov's message of "Wed, 06 Jul 2022 10:04:49 +0300")

>> 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) ruby-indent-level))))
              (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	other threads:[~2022-07-06  8:06 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-05 23:28 [PATCH] add outline regexp to ruby-mode Yilkal Argaw
2022-07-05 23:48 ` Yilkal Argaw
2022-07-06  7:04   ` Bozhidar Batsov
2022-07-06  8:06     ` Juri Linkov [this message]
2022-07-08  1:12       ` Dmitry Gutov
2022-07-08  5:38         ` Bozhidar Batsov
2022-07-08  8:27           ` Yilkal Argaw
2022-07-08 17:18             ` Juri Linkov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=867d4qvep9.fsf@mail.linkov.net \
    --to=juri@linkov.net \
    --cc=bozhidar@batsov.dev \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.