Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

cperl-mode - outline minor mode - subroutines

19 views
Skip to first unread message

Terrence Brannon

unread,
Apr 19, 2010, 11:12:34 AM4/19/10
to
Hello, I'm using GNU Emacs 23. There is a huge subroutine that I want
to outline the various parts of.

I would like to know how to give hints to outline minor mode, so that
the subroutine can be broken down into
sections and subsections.

LanX

unread,
Apr 19, 2010, 12:16:07 PM4/19/10
to

> I would like to know how to give hints to outline minor mode, so that
> the subroutine can be broken down into
> sections and subsections.

I presume we are talking about cperl-mode?

Thats defined in a list of regex in the variable outline-regexp which
is derived from cperl-outline-regexp


"^\\(\\([ ]*package\\(\\([ \n]\\|#[^\n]*\n\\)+\\([a-zA-Z_0-9:']+\\)\
\)?\\)\\|[ ]*sub\\(\\([ \n]\\|#[^\n]*\n\\)+\\(::[a-zA-Z_0-9:']+\\|[a-
zA-Z_'][a-zA-Z_0-9:']*\\)\\)\\([ \n]*\\(#[^\n]*\n[ \n]*\\)*\\
(([^()]*)\\)\\)?\\([ \n]*\\(#[^\n]*\n[ \n]*\\)*\\(:[^:]\\)\\)?[ \n]*
\\(#[^\n]*\n[ \n]*\\)*\\|=head\\([1-4]\\)[ ]+\\([^\n]+\\)$\\)\\|\\`"

all of this derived as concat from


--------------------
;;; Details of groups in this are used in `cperl-imenu--create-perl-
index'
;;; and `cperl-outline-level'.
;;;; Was: 2=sub|package; now 2=package-group, 5=package-name 8=sub-
name (+3)
(defvar cperl-imenu--function-name-regexp-perl
(concat
"^\\(" ; 1 = all
"\\([ \t]*package" ; 2 = package-group
"\\(" ; 3 = package-name-group
cperl-white-and-comment-rex ; 4 = pre-package-name
"\\([a-zA-Z_0-9:']+\\)\\)?\\)" ; 5 = package-name
"\\|"
"[ \t]*sub"
(cperl-after-sub-regexp 'named nil) ; 8=name 11=proto 14=attr-start
cperl-maybe-white-and-comment-rex ; 15=pre-block
"\\|"
"=head\\([1-4]\\)[ \t]+" ; 16=level
"\\([^\n]+\\)$" ; 17=text
"\\)"))

(defvar cperl-outline-regexp
(concat cperl-imenu--function-name-regexp-perl "\\|" "\\`"))

--------------------------------

HTH please give a note if you are succesful! :)

Cheers
rolf

Terrence Brannon

unread,
Apr 19, 2010, 12:39:28 PM4/19/10
to
On Apr 19, 12:16 pm, LanX <lanx.p...@googlemail.com> wrote:
> > I would like to know how to give hints to outline minor mode, so that
> > the subroutine can be broken down into
> > sections and subsections.
>
> I presume we are talking about cperl-mode?

yes, sorry I must've forgotten to mention that

> HTH please give a note if you are succesful! :)
>

well, what I still dont know is how to outline a subroutine... how to
decompose it into sections and subsections:

sub somesub {

# A - do something

# A1 - do something within do something
# A2 - do something else within do something

# B - next step

# B1 - do something within next step
# B2 - do something else within next step

}

LanX

unread,
Apr 19, 2010, 12:41:32 PM4/19/10
to
i Terrance

changing the ending of outline-regexp to "\\|.*#---\\|\\`" helped
folding on comments starting with 3 minus.

Cheers
rolf

LanX

unread,
Apr 19, 2010, 12:49:30 PM4/19/10
to
There is multiple possibilities to fold, eg. by indentation level!

http://www.emacswiki.org/emacs/CategoryHideStuff

Terrence Brannon

unread,
Apr 19, 2010, 2:02:57 PM4/19/10
to
On Apr 19, 12:41 pm, LanX <lanx.p...@googlemail.com> wrote:
> i Terrance

Hi, outline-regexp's value is

"^\\(\\([ ]*package\\(\\([ \n]\\|#[^\n]*\n\\)+\\([a-zA-Z_0-9:']+\\)\
\)?\\)\\|[ ]*sub\\(\\([ \n]\\|#[^\n]*\n\\)+\\(::[a-zA-Z_0-9:']+\\|[a-
zA-Z_'][a-zA-Z_0-9:']*\\)\\)\\([ \n]*\\(#[^\n]*\n[ \n]*\\)*\\
(([^()]*)\\)\\)?\\([ \n]*\\(#[^\n]*\n[ \n]*\\)*\\(:[^:]\\)\\)?[ \n]*
\\(#[^\n]*\n[ \n]*\\)*\\|=head\\([1-4]\\)[ ]+\\([^\n]+\\)$\\)\\|\\`"

>


> changing the ending of outline-regexp to "\\|.*#---\\|\\`" helped
> folding on comments starting with 3 minus.

Programmatically:

(let ( (some-string "some-extension-of-regexp"))
(setq outline-regexp (concat some-string outline-regexp)) )

What would you set some-string to for changing the ending as you
suggest?

And how would the code look? Could you create sections and subsections
and subsubsections?

LanX

unread,
Apr 20, 2010, 4:22:32 AM4/20/10
to
Hi Terrence

On 19 Apr., 20:02, Terrence Brannon <metap...@gmail.com> wrote:
> What would you set some-string to for changing the ending as you
> suggest?

It's a regex to discover the headings of sections, "\\|" is the same
"or" like in perl-regex only with "slasheritis".

Only _you_ can know which headings precede the subsections in _your_
perl code.

> And how would the code look?

I did it manually with M-x set-variable.

> Could you create sections and subsections
> and subsubsections?

No idea how nesting is defined for "outline" ...

I think you want to fold by indentation, did you read the emacswiki
page I linked???

Cheers
rolf

Terrence Brannon

unread,
Apr 20, 2010, 3:10:30 PM4/20/10
to
On Apr 20, 4:22 am, LanX <lanx.p...@googlemail.com> wrote:

>
> I think you want to fold by indentation, did you read the emacswiki
> page I linked???

I looked at it. I think I will just settle for vanilla cperl and
outline-mode.

That is fine under normal circumstances. I'm just dealing with some
horrible unfactored legacy code.

That's why I need so much breaking down.


LanX

unread,
Apr 21, 2010, 9:52:28 AM4/21/10
to
There plenty of questions you didn't answer.

Once again "outline-minor-mode" works on headlines like "sub {" and
"package" so if you wanna fold chunks you have to mark them by a
leading headline like " #- Chunk to be folded\n".

But only appending ".*#- " to "cperl-outline-regexp" which is matching
these headlines isn't enough!

You have also to change the function "cperl-outline-level" such that
the folding levels don't get confused.

I have no big idea or time to fiddle out how to do this without
hacking into Ilya's code

Maybe he is reading a willing to update his mode to allow a variable
"cperl-outline-chunk-regexp"

Anyway if can't add extra heading-comment to the code in questions all
these efforts are useless!

Hope its clear now...

Terrence Brannon

unread,
Apr 21, 2010, 2:28:02 PM4/21/10
to
On Apr 19, 12:49 pm, LanX <lanx.p...@googlemail.com> wrote:
> There is multiple possibilities to fold, eg. by indentation level!
>
> http://www.emacswiki.org/emacs/CategoryHideStuff

Actually I looked closer. I think the hs-mode that comes with Emacs 23
in combination with hideshowvis ( http://www.emacswiki.org/emacs/hideshowvis.el
)

will work naturally well for me.

thank you for your help :)

David Rogoff

unread,
Apr 21, 2010, 2:36:25 PM4/21/10
to
Anyone know if any of these methods work well with Verilog code / verilog-mode?

Thanks,

David

LanX

unread,
Apr 21, 2010, 9:25:44 PM4/21/10
to
> Actually I looked closer. I think the hs-mode that comes with Emacs 23
> in combination with hideshowvis (http://www.emacswiki.org/emacs/hideshowvis.el

> )
>
> will work naturally well for me.

good luck, I had to deactivate hideshowvis.el because my emacs was
hanging at startup.

Ilya Zakharevich

unread,
Apr 23, 2010, 4:49:18 PM4/23/10
to
On 2010-04-21, LanX <rolf.la...@googlemail.com> wrote:
> There plenty of questions you didn't answer.
>
> Once again "outline-minor-mode" works on headlines like "sub {" and
> "package" so if you wanna fold chunks you have to mark them by a
> leading headline like " #- Chunk to be folded\n".
>
> But only appending ".*#- " to "cperl-outline-regexp" which is matching
> these headlines isn't enough!
>
> You have also to change the function "cperl-outline-level" such that
> the folding levels don't get confused.
>
> I have no big idea or time to fiddle out how to do this without
> hacking into Ilya's code

Myself, I have not used outline mode more than a time or two.

So all I can suggest is for you people giving me suggestions how the
USERS may want/need to add their own "extra" outline levels. Given this
information, I might be able to incorporate something into the CPerl's
puny outline support...

> Maybe he is reading a willing to update his mode to allow a variable
> "cperl-outline-chunk-regexp"

... only if I know some examples of what people like to do.

Yours,
Ilya

LanX

unread,
Apr 23, 2010, 7:09:32 PM4/23/10
to
Hi Ilya

> So all I can suggest is for you people giving me suggestions how the
> USERS may want/need to add their own "extra" outline levels.  Given this
> information, I might be able to incorporate something into the CPerl's
> puny outline support...
>
> > Maybe he is reading a willing to update his mode to allow a variable
> > "cperl-outline-chunk-regexp"
>
> ... only if I know some examples of what people like to do.

I can only tell how I'm doing it, I'm not "the USERS" and I'm still
confused about the whishes of Terrence/Metaperl (hs-minor-mode simply
folds at all blocks "{"blocks"}" )

Chunks of code line - normally but not necessarily paragraphs - get a
leading comment line like

---------------------------
sub do_data {

#- fetching data
open my $fh,"<","txt";
$data=slurp $fh;

#- processing data ...

#- returning data ...
}
--------------------------

to be able to fold these with outline minor mode I add an extra hyphen
to distinguish these line comments from others.

(I don't think it's possible to design a regex that only folds single
comment lines on tops of code chunks.)


more folding on =pods would be nice, too.

But I'm not sure if outline or hide-show is the better choice.


If you want a more representative answer you should maybe ask at
perlmonks.org

Cheers
Rolf

Ilya Zakharevich

unread,
Apr 24, 2010, 10:07:58 PM4/24/10
to
On 2010-04-23, LanX <lanx...@googlemail.com> wrote:
> more folding on =pods would be nice, too.

Right now I have no idea what this might mean: essentially, we have an
"interleaved" file with two different "channels": code, and POD. Each
one of them has its notion of "outline level", so if they were
separate, one could outline them without much problem.

Now how would these two different outline semantics be reflected on
the "interleaved" file? Would one want to have two different "active"
levels, one for POD, another for code?

Puzzled,
Ilya

LanX

unread,
Apr 25, 2010, 6:15:10 AM4/25/10
to
Hi

> Now how would these two different outline semantics be reflected on
> the "interleaved" file?  Would one want to have two different "active"
> levels, one for POD, another for code?

I think the problem is how to map these two channels onto linear
outline levels...

I just sometimes want to fold all embedded pod - like function headers
- away... so maybe just a switch is enough?

hs-minor-mode has a flag to "hide all comments when hiding all"

> Puzzled,
> Ilya

me too, outline-minor-mode is not very intuitive to handle ... mabe
hideshow is better.

IMHO a brainstorm at perlmonks is the best strategy...

Cheers
Rolf

LanX

unread,
Apr 25, 2010, 7:36:57 AM4/25/10
to
from perlpod:

-----------------------
=pod
=cut

The ``=pod'' directive does nothing beyond telling the compiler to
lay off parsing code through the next ``=cut''. It's useful for adding
another paragraph to the doc if you're mixing up code and pod a lot.
-----------------------

maybe just assigning a high outline level to lines starting with
"=pod" might be sufficient.

BTW: did you see http://debbugs.gnu.org/cgi/bugreport.cgi?bug=6013

Ilya Zakharevich

unread,
Apr 27, 2010, 12:13:57 AM4/27/10
to
On 2010-04-25, LanX <lanx...@googlemail.com> wrote:
> from perlpod:
>
> -----------------------
>=pod
>=cut
>
> The ``=pod'' directive does nothing beyond telling the compiler to
> lay off parsing code through the next ``=cut''. It's useful for adding
> another paragraph to the doc if you're mixing up code and pod a lot.
> -----------------------
>
> maybe just assigning a high outline level to lines starting with
> "=pod" might be sufficient.

Unclear: do you say that the handling of =headN, =item etc is already
satisfactory, and only the =pod is mishandled, or what?

Yes. [This is a contributed code, so I might be very slow in
touching it...]

Ilya

LanX

unread,
May 4, 2010, 10:59:41 AM5/4/10
to
Hi

> Unclear: do you say that the handling of =headN, =item etc is already
> satisfactory, and only the =pod is mishandled, or what?

I'm not sure about the best approach to mix POD with code, after long
meditation I started a thread at perlmonks:

http://perlmonks.org/index.pl?node_id=838289

maybe the best approach would be allowing to generally hide all pod...

Cheers
rolf

Ted Zlatanov

unread,
Jul 1, 2010, 12:16:29 PM7/1/10
to
On Sun, 25 Apr 2010 02:07:58 +0000 (UTC) Ilya Zakharevich <nospam...@ilyaz.org> wrote:

IZ> On 2010-04-23, LanX <lanx...@googlemail.com> wrote:
>> more folding on =pods would be nice, too.

IZ> Right now I have no idea what this might mean: essentially, we have an
IZ> "interleaved" file with two different "channels": code, and POD. Each
IZ> one of them has its notion of "outline level", so if they were
IZ> separate, one could outline them without much problem.

IZ> Now how would these two different outline semantics be reflected on
IZ> the "interleaved" file? Would one want to have two different "active"
IZ> levels, one for POD, another for code?

I would do outline levels on POD and also set up the next-error
framework to move back and forth between functions.

I used to use folding-mode in Perl but it's really dangerous to hide
code in my experience. So I would only ever hide POD.

Ted

0 new messages