unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Allowing spaces in the regexp for outlines
@ 2024-03-20 19:24 Heime
  2024-03-20 19:45 ` Emanuel Berg
  2024-03-21  4:32 ` Stefan Monnier via Users list for the GNU Emacs text editor
  0 siblings, 2 replies; 13+ messages in thread
From: Heime @ 2024-03-20 19:24 UTC (permalink / raw)
  To: Heime via Users list for the GNU Emacs text editor

Have made a regexp for outlines to use ';;;' followed by 'H' and a number.

I would like to allow any number of spaces between the ';;;' and the letter 'H'.
How can I change the regexp to allow such a capability ?

(defvar el-hglevels
  '( (";;; H1" . 1) (";;; H2" . 2) (";;; H3" . 3) (";;; H4" . 4) )
  "Outline levels for elisp major mode.")

(defun outlhg-regexp ()

  (cond

    ((memq major-mode '(emacs-lisp-mode lisp-interaction-mode))
       (let ( (hglevels el-hglevels) )
         (setq outline-regexp
               (concat (regexp-opt (mapcar 'car hglevels)) "\\>"))
         (setq outline-heading-alist hglevels)
         (setq-local outline-level 'outline-level))) ))





^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Allowing spaces in the regexp for outlines
  2024-03-20 19:24 Allowing spaces in the regexp for outlines Heime
@ 2024-03-20 19:45 ` Emanuel Berg
  2024-03-21  4:44   ` Heime
  2024-03-21  5:08   ` Heime
  2024-03-21  4:32 ` Stefan Monnier via Users list for the GNU Emacs text editor
  1 sibling, 2 replies; 13+ messages in thread
From: Emanuel Berg @ 2024-03-20 19:45 UTC (permalink / raw)
  To: help-gnu-emacs

Heime wrote:

> (defvar el-hglevels
>   '( (";;; H1" . 1) (";;; H2" . 2) (";;; H3" . 3) (";;; H4" . 4) )
>   "Outline levels for elisp major mode.")

You can also use `comment-start' instead of hardcoding ';',
and use explicit repitition instead of hardcoding 3 - see

  (info "(elisp) Regexp Backslash")

- and then also not hardcode the 1s, 2s, 3s, and 4s in pairs
but inserting them as integers into the string.

So yes, you can improve a lot! And spend all weekend on it.

-- 
underground experts united
https://dataswamp.org/~incal




^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Allowing spaces in the regexp for outlines
  2024-03-20 19:24 Allowing spaces in the regexp for outlines Heime
  2024-03-20 19:45 ` Emanuel Berg
@ 2024-03-21  4:32 ` Stefan Monnier via Users list for the GNU Emacs text editor
  2024-03-21  4:49   ` Emanuel Berg
  2024-03-27 19:12   ` Christopher Dimech
  1 sibling, 2 replies; 13+ messages in thread
From: Stefan Monnier via Users list for the GNU Emacs text editor @ 2024-03-21  4:32 UTC (permalink / raw)
  To: help-gnu-emacs

> Have made a regexp for outlines to use ';;;' followed by 'H' and a number.
>
> I would like to allow any number of spaces between the ';;;' and the letter 'H'.
> How can I change the regexp to allow such a capability ?

Why?

ELisp already has a set convention for outlining, where `;;;` is
a top-level heading, then `;;;;` is a subheading, `;;;;;` is
a subsubheading, etc...


        Stefan




^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Allowing spaces in the regexp for outlines
  2024-03-20 19:45 ` Emanuel Berg
@ 2024-03-21  4:44   ` Heime
  2024-03-21  4:59     ` Emanuel Berg
  2024-03-21  5:08   ` Heime
  1 sibling, 1 reply; 13+ messages in thread
From: Heime @ 2024-03-21  4:44 UTC (permalink / raw)
  To: Emanuel Berg; +Cc: help-gnu-emacs






Sent with Proton Mail secure email.

On Thursday, March 21st, 2024 at 7:45 AM, Emanuel Berg <incal@dataswamp.org> wrote:

> Heime wrote:
> 
> > (defvar el-hglevels
> > '( (";;; H1" . 1) (";;; H2" . 2) (";;; H3" . 3) (";;; H4" . 4) )
> > "Outline levels for elisp major mode.")
> 
> 
> You can also use `comment-start' instead of hardcoding ';',
> and use explicit repitition instead of hardcoding 3 - see
> 
> (info "(elisp) Regexp Backslash")
> 
> - and then also not hardcode the 1s, 2s, 3s, and 4s in pairs
> but inserting them as integers into the string.
> 
> So yes, you can improve a lot! And spend all weekend on it.
 
This is not about improving existing functionality, bet allowing
aty number of spaces between ;;; and H.



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Allowing spaces in the regexp for outlines
  2024-03-21  4:32 ` Stefan Monnier via Users list for the GNU Emacs text editor
@ 2024-03-21  4:49   ` Emanuel Berg
  2024-03-22 12:56     ` Arash Esbati
  2024-03-27 19:12   ` Christopher Dimech
  1 sibling, 1 reply; 13+ messages in thread
From: Emanuel Berg @ 2024-03-21  4:49 UTC (permalink / raw)
  To: help-gnu-emacs

Stefan Monnier via Users list for the GNU Emacs text editor wrote:

>> Have made a regexp for outlines to use ';;;' followed by
>> 'H' and a number.
>>
>> I would like to allow any number of spaces between the
>> ';;;' and the letter 'H'. How can I change the regexp to
>> allow such a capability ?
>
> Why?

Right, but isn't the question never "why", but "how"?

> ELisp already has a set convention for outlining, where
> `;;;` is a top-level heading, then `;;;;` is a subheading,
> `;;;;;` is a subsubheading, etc...

I remember from LaTeX they had came to the conclusion that
three levels were enough. So when I wanted four levels I had
to bring in some stuff or solve that in some other way for it
to happen.

Maybe they are right that more than three levels is a sign of
poor disposition, but I still like the Lisp way more where it
is up to whoever to just use the same syntax to get as many
sublevels as desired.

And for tech documents like manuals one can easily think of
huge catalogs where individual items (e.g. function names in
programming) end up at the forth floor, basement level.

-- 
underground experts united
https://dataswamp.org/~incal




^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Allowing spaces in the regexp for outlines
  2024-03-21  4:44   ` Heime
@ 2024-03-21  4:59     ` Emanuel Berg
  0 siblings, 0 replies; 13+ messages in thread
From: Emanuel Berg @ 2024-03-21  4:59 UTC (permalink / raw)
  To: help-gnu-emacs

Heime wrote:

>> You can also use `comment-start' instead of hardcoding ';',
>> and use explicit repitition instead of hardcoding 3 - see
>> 
>> (info "(elisp) Regexp Backslash")
>> 
>> - and then also not hardcode the 1s, 2s, 3s, and 4s in pairs
>> but inserting them as integers into the string.
>> 
>> So yes, you can improve a lot! And spend all weekend on it.
>
> This is not about improving existing functionality

It is about improving your skills?

> bet allowing aty number of spaces between ;;; and H.

I already wrote, but it didn't appear,

  For oh to arbitrary repetition, see * described here

    (info "(elisp) Regexp Special")

  For whitespace, see [:blank:] here.

    (info "(elisp) Char Classes")

  Or just use it the way you have it, hardcoded whitespace,
  which is also fine.

-- 
underground experts united
https://dataswamp.org/~incal




^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Allowing spaces in the regexp for outlines
  2024-03-20 19:45 ` Emanuel Berg
  2024-03-21  4:44   ` Heime
@ 2024-03-21  5:08   ` Heime
  2024-03-21  6:40     ` Heime
  1 sibling, 1 reply; 13+ messages in thread
From: Heime @ 2024-03-21  5:08 UTC (permalink / raw)
  To: Emanuel Berg; +Cc: help-gnu-emacs






Sent with Proton Mail secure email.

On Thursday, March 21st, 2024 at 7:45 AM, Emanuel Berg <incal@dataswamp.org> wrote:

> Heime wrote:
> 
> > (defvar el-hglevels
> > '( (";;; H1" . 1) (";;; H2" . 2) (";;; H3" . 3) (";;; H4" . 4) )
> > "Outline levels for elisp major mode.")
> 
> 
> You can also use `comment-start' instead of hardcoding ';',
> and use explicit repitition instead of hardcoding 3 - see
> 
> (info "(elisp) Regexp Backslash")
> 
> - and then also not hardcode the 1s, 2s, 3s, and 4s in pairs
> but inserting them as integers into the string.
> 
> So yes, you can improve a lot! And spend all weekend on it.
 
Have attempted the following without success

 (";;;\\[[:space:]]+H1" . 1) 

 (";;;\[[:space:]]+H1" . 1) 

 (";;;[[:space:]]+H1" . 1) 




^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Allowing spaces in the regexp for outlines
  2024-03-21  5:08   ` Heime
@ 2024-03-21  6:40     ` Heime
  2024-03-21 19:52       ` Emanuel Berg
  0 siblings, 1 reply; 13+ messages in thread
From: Heime @ 2024-03-21  6:40 UTC (permalink / raw)
  To: Heime; +Cc: Emanuel Berg, help-gnu-emacs


On Thursday, March 21st, 2024 at 5:08 PM, Heime <heimeborgia@protonmail.com> wrote:

> On Thursday, March 21st, 2024 at 7:45 AM, Emanuel Berg incal@dataswamp.org wrote:
> 
> > Heime wrote:
> > 
> > > (defvar el-hglevels
> > > '( (";;; H1" . 1) (";;; H2" . 2) (";;; H3" . 3) (";;; H4" . 4) )
> > > "Outline levels for elisp major mode.")
> > 
> > You can also use `comment-start' instead of hardcoding ';',
> > and use explicit repitition instead of hardcoding 3 - see
> > 
> > (info "(elisp) Regexp Backslash")
> > 
> > - and then also not hardcode the 1s, 2s, 3s, and 4s in pairs
> > but inserting them as integers into the string.
> > 
> > So yes, you can improve a lot! And spend all weekend on it.
> 
> 
> Have attempted the following without success
> 
> (";;;\\[[:space:]]+H1" . 1)
> 
> (";;;\[[:space:]]+H1" . 1)
> 
> (";;;[[:space:]]+H1" . 1)

And now as well with

(";;;\\([[:space:]]+\\)H1" . 1)




^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Allowing spaces in the regexp for outlines
  2024-03-21  6:40     ` Heime
@ 2024-03-21 19:52       ` Emanuel Berg
  0 siblings, 0 replies; 13+ messages in thread
From: Emanuel Berg @ 2024-03-21 19:52 UTC (permalink / raw)
  To: help-gnu-emacs

Heime wrote:

>> Have attempted the following without success
>> 
>> (";;;\\[[:space:]]+H1" . 1)
>> 
>> (";;;\[[:space:]]+H1" . 1)
>> 
>> (";;;[[:space:]]+H1" . 1)
>
> And now as well with
>
> (";;;\\([[:space:]]+\\)H1" . 1)

Try `eval'ing the REs like below to confirm they work or not.

Because if and when they do, and it still doesn't work,
something else is up.

(re-search-forward (format "%s\\{3\\}[[:blank:]]*H1" comment-start))

(re-search-forward ";;; *H1")

;;; H1

-- 
underground experts united
https://dataswamp.org/~incal




^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Allowing spaces in the regexp for outlines
  2024-03-21  4:49   ` Emanuel Berg
@ 2024-03-22 12:56     ` Arash Esbati
  2024-03-22 15:39       ` Heime
  0 siblings, 1 reply; 13+ messages in thread
From: Arash Esbati @ 2024-03-22 12:56 UTC (permalink / raw)
  To: help-gnu-emacs

Emanuel Berg <incal@dataswamp.org> writes:

> Stefan Monnier via Users list for the GNU Emacs text editor wrote:
>
>> ELisp already has a set convention for outlining, where
>> `;;;` is a top-level heading, then `;;;;` is a subheading,
>> `;;;;;` is a subsubheading, etc...
>
> I remember from LaTeX they had came to the conclusion that
> three levels were enough. So when I wanted four levels I had
> to bring in some stuff or solve that in some other way for it
> to happen.

You mean these three levels?

\part{part}
\chapter{chapter} % available with report/book
\section{section}
\subsection{subsection}
\subsubsection{subsubsection}
\paragraph{paragraph}
\subparagraph{subparagraph}

Best, Arash




^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Allowing spaces in the regexp for outlines
  2024-03-22 12:56     ` Arash Esbati
@ 2024-03-22 15:39       ` Heime
  0 siblings, 0 replies; 13+ messages in thread
From: Heime @ 2024-03-22 15:39 UTC (permalink / raw)
  To: Arash Esbati; +Cc: help-gnu-emacs

On Saturday, March 23rd, 2024 at 12:56 AM, Arash Esbati <arash@gnu.org> wrote:

> Emanuel Berg incal@dataswamp.org writes:
> 
> > Stefan Monnier via Users list for the GNU Emacs text editor wrote:
> > 
> > > ELisp already has a set convention for outlining, where
> > > `;;;` is a top-level heading, then `;;;;` is a subheading,
> > > `;;;;;` is a subsubheading, etc...

Nevertheless, elisp provide the capability of changing the search pattern
to other than the set convention.



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Allowing spaces in the regexp for outlines
  2024-03-21  4:32 ` Stefan Monnier via Users list for the GNU Emacs text editor
  2024-03-21  4:49   ` Emanuel Berg
@ 2024-03-27 19:12   ` Christopher Dimech
  2024-03-27 19:32     ` Heime
  1 sibling, 1 reply; 13+ messages in thread
From: Christopher Dimech @ 2024-03-27 19:12 UTC (permalink / raw)
  To: monnier; +Cc: help-gnu-emacs


> Sent: Thursday, March 21, 2024 at 4:32 PM
> From: "Stefan Monnier via Users list for the GNU Emacs text editor" <help-gnu-emacs@gnu.org>
> To: help-gnu-emacs@gnu.org
> Subject: Re: Allowing spaces in the regexp for outlines
>
> > Have made a regexp for outlines to use ';;;' followed by 'H' and a number.
> >
> > I would like to allow any number of spaces between the ';;;' and the letter 'H'.
> > How can I change the regexp to allow such a capability ?
>
> Why?

There is already the functionality for changing the font-lock for outline-minor-mode.
So why not !  It is not so easy to do though.  Because managing outlines in a buffer
is valuable for almost everybody, it would help for there to me clear explanation
of what has to be done with actual examples.  Good for this would be in the Introduction
to Emacs Lisp Programming.

> ELisp already has a set convention for outlining, where `;;;` is
> a top-level heading, then `;;;;` is a subheading, `;;;;;` is
> a subsubheading, etc...
>
>
>         Stefan
>
>
>



^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: Allowing spaces in the regexp for outlines
  2024-03-27 19:12   ` Christopher Dimech
@ 2024-03-27 19:32     ` Heime
  0 siblings, 0 replies; 13+ messages in thread
From: Heime @ 2024-03-27 19:32 UTC (permalink / raw)
  To: Christopher Dimech; +Cc: monnier, help-gnu-emacs

On Thursday, March 28th, 2024 at 7:12 AM, Christopher Dimech <dimech@gmx.com> wrote:

> > Sent: Thursday, March 21, 2024 at 4:32 PM
> > From: "Stefan Monnier via Users list for the GNU Emacs text editor" help-gnu-emacs@gnu.org
> > To: help-gnu-emacs@gnu.org
> > Subject: Re: Allowing spaces in the regexp for outlines
> > 
> > > Have made a regexp for outlines to use ';;;' followed by 'H' and a number.
> > > 
> > > I would like to allow any number of spaces between the ';;;' and the letter 'H'.
> > > How can I change the regexp to allow such a capability ?
> > 
> > Why?
> 
> 
> There is already the functionality for changing the font-lock for outline-minor-mode.
> So why not ! It is not so easy to do though. Because managing outlines in a buffer
> is valuable for almost everybody, it would help for there to me clear explanation
> of what has to be done with actual examples. Good for this would be in the Introduction
> to Emacs Lisp Programming.

That would help a lot. How can one set general patterns for each outline level precisely ?

Is the way to do it like this

(defvar el-hglevels '( (";;; H1" . 1) (";;; H2" . 2) (";;; H3" . 3) ))
 
(setq outline-regexp (concat (regexp-opt (mapcar 'car el-hglevels)) "\\>"))
(setq outline-heading-alist el-hglevels)
(setq-local outline-level 'outline-level)

> > ELisp already has a set convention for outlining, where `;;;` is
> > a top-level heading, then `;;;;` is a subheading, `;;;;;` is
> > a subsubheading, etc...
> > 
> > Stefan



^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2024-03-27 19:32 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-20 19:24 Allowing spaces in the regexp for outlines Heime
2024-03-20 19:45 ` Emanuel Berg
2024-03-21  4:44   ` Heime
2024-03-21  4:59     ` Emanuel Berg
2024-03-21  5:08   ` Heime
2024-03-21  6:40     ` Heime
2024-03-21 19:52       ` Emanuel Berg
2024-03-21  4:32 ` Stefan Monnier via Users list for the GNU Emacs text editor
2024-03-21  4:49   ` Emanuel Berg
2024-03-22 12:56     ` Arash Esbati
2024-03-22 15:39       ` Heime
2024-03-27 19:12   ` Christopher Dimech
2024-03-27 19:32     ` Heime

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).