* Regexp with comment character of buffer
@ 2024-08-12 10:08 Heime
2024-08-12 11:03 ` Yuri Khan
0 siblings, 1 reply; 10+ messages in thread
From: Heime @ 2024-08-12 10:08 UTC (permalink / raw)
To: Heime via Users list for the GNU Emacs text editor
How can I change the regexp so that instead of the beginning ;;;
I use the comment character of the current buffer, replicated three
times ?
(let ( (heading-regexp "^;;;\\s-+\\([HM][[:digit:]]\\)\\s-")
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Regexp with comment character of buffer
2024-08-12 10:08 Regexp with comment character of buffer Heime
@ 2024-08-12 11:03 ` Yuri Khan
2024-08-12 11:41 ` Heime
0 siblings, 1 reply; 10+ messages in thread
From: Yuri Khan @ 2024-08-12 11:03 UTC (permalink / raw)
To: Heime; +Cc: Heime via Users list for the GNU Emacs text editor
On Mon, 12 Aug 2024 at 17:09, Heime <heimeborgia@protonmail.com> wrote:
>
> How can I change the regexp so that instead of the beginning ;;;
> I use the comment character of the current buffer, replicated three
> times ?
>
> (let ( (heading-regexp "^;;;\\s-+\\([HM][[:digit:]]\\)\\s-")
You’re asking a homework question so here are hints that I would give
someone who is struggling with homework.
Do you already know how to get the comment character of the current buffer?
Do you already know how to escape an arbitrary character for safe use
in a regexp?
Do you already know which part of the regexp you have is responsible
for matching three semicolons?
Do you already know how to concatenate strings?
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Regexp with comment character of buffer
2024-08-12 11:03 ` Yuri Khan
@ 2024-08-12 11:41 ` Heime
2024-08-12 12:26 ` Yuri Khan
0 siblings, 1 reply; 10+ messages in thread
From: Heime @ 2024-08-12 11:41 UTC (permalink / raw)
To: Yuri Khan; +Cc: Heime via Users list for the GNU Emacs text editor
Sent with Proton Mail secure email.
On Monday, August 12th, 2024 at 11:03 PM, Yuri Khan <yuri.v.khan@gmail.com> wrote:
> On Mon, 12 Aug 2024 at 17:09, Heime heimeborgia@protonmail.com wrote:
>
> > How can I change the regexp so that instead of the beginning ;;;
> > I use the comment character of the current buffer, replicated three
> > times ?
> >
> > (let ( (heading-regexp "^;;;\\s-+\\([HM][[:digit:]]\\)\\s-")
>
>
> You’re asking a homework question so here are hints that I would give
> someone who is struggling with homework.
>
> Do you already know how to get the comment character of the current buffer?
Have done the following. Do I really need all this or are there better ways ?
(let* ((comment-char (regexp-quote (string-trim comment-start)))
(three-comment-chars (make-string 3 (string-to-char comment-char)))
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Regexp with comment character of buffer
2024-08-12 11:41 ` Heime
@ 2024-08-12 12:26 ` Yuri Khan
2024-08-12 12:36 ` Heime
0 siblings, 1 reply; 10+ messages in thread
From: Yuri Khan @ 2024-08-12 12:26 UTC (permalink / raw)
To: Heime; +Cc: Heime via Users list for the GNU Emacs text editor
On Mon, 12 Aug 2024 at 18:41, Heime <heimeborgia@protonmail.com> wrote:
> > > How can I change the regexp so that instead of the beginning ;;;
> > > I use the comment character of the current buffer, replicated three
> > > times ?
> > >
> > > (let ( (heading-regexp "^;;;\\s-+\\([HM][[:digit:]]\\)\\s-")
> Have done the following. Do I really need all this or are there better ways ?
>
> (let* ((comment-char (regexp-quote (string-trim comment-start)))
> (three-comment-chars (make-string 3 (string-to-char comment-char)))
Does that work for you? (If not, go back to solving the problem.)
Does that work in all scenarios that are important to you? (If not, go
back to solving the problem in a more general way.)
What aspects of the working solution seem unsatisfactory to you?
What hypothetical capabilities would you require in order to improve
those aspects?
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Regexp with comment character of buffer
2024-08-12 12:26 ` Yuri Khan
@ 2024-08-12 12:36 ` Heime
2024-08-12 17:11 ` Yuri Khan
0 siblings, 1 reply; 10+ messages in thread
From: Heime @ 2024-08-12 12:36 UTC (permalink / raw)
To: Yuri Khan; +Cc: Heime via Users list for the GNU Emacs text editor
On Tuesday, August 13th, 2024 at 12:26 AM, Yuri Khan <yuri.v.khan@gmail.com> wrote:
> On Mon, 12 Aug 2024 at 18:41, Heime heimeborgia@protonmail.com wrote:
>
> > > > How can I change the regexp so that instead of the beginning ;;;
> > > > I use the comment character of the current buffer, replicated three
> > > > times ?
> > > >
> > > > (let ( (heading-regexp "^;;;\\s-+\\([HM][[:digit:]]\\)\\s-")
>
> > Have done the following. Do I really need all this or are there better ways ?
> >
> > (let* ((comment-char (regexp-quote (string-trim comment-start)))
> > (three-comment-chars (make-string 3 (string-to-char comment-char)))
>
>
> Does that work for you? (If not, go back to solving the problem.)
>
> Does that work in all scenarios that are important to you? (If not, go
> back to solving the problem in a more general way.)
>
> What aspects of the working solution seem unsatisfactory to you?
>
> What hypothetical capabilities would you require in order to improve
> those aspects?
Is a string-trim required for comment-start ?
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Regexp with comment character of buffer
2024-08-12 12:36 ` Heime
@ 2024-08-12 17:11 ` Yuri Khan
2024-08-12 17:50 ` Heime
0 siblings, 1 reply; 10+ messages in thread
From: Yuri Khan @ 2024-08-12 17:11 UTC (permalink / raw)
To: Heime; +Cc: Heime via Users list for the GNU Emacs text editor
On Mon, 12 Aug 2024 at 19:36, Heime <heimeborgia@protonmail.com> wrote:
> > > (let* ((comment-char (regexp-quote (string-trim comment-start)))
> > > (three-comment-chars (make-string 3 (string-to-char comment-char)))
> Is a string-trim required for comment-start ?
Required *for comment-start*? No. What does the docstring for
comment-start tell you?
String to insert to start a new comment, or[…]
The space is there so that when the string is inserted, the user will
be able to start typing the comment text and it will be separated from
the delimiter.
# comment in shell or Python
; comment in Elisp
// comment in C++
/* comment in C */
<!-- comment in HTML -->
Required for *your use* of comment-start? Maybe.
Anyway, what’s your plan for modes whose comment-start is longer than
a single character after trimming the space?
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Regexp with comment character of buffer
2024-08-12 17:11 ` Yuri Khan
@ 2024-08-12 17:50 ` Heime
2024-08-12 19:13 ` Yuri Khan
0 siblings, 1 reply; 10+ messages in thread
From: Heime @ 2024-08-12 17:50 UTC (permalink / raw)
To: Yuri Khan; +Cc: Heime via Users list for the GNU Emacs text editor
On Tuesday, August 13th, 2024 at 5:11 AM, Yuri Khan <yuri.v.khan@gmail.com> wrote:
> On Mon, 12 Aug 2024 at 19:36, Heime heimeborgia@protonmail.com wrote:
>
> > > > (let* ((comment-char (regexp-quote (string-trim comment-start)))
> > > > (three-comment-chars (make-string 3 (string-to-char comment-char)))
>
> > Is a string-trim required for comment-start ?
>
>
> Required for comment-start? No. What does the docstring for
> comment-start tell you?
>
> String to insert to start a new comment, or[…]
>
> The space is there so that when the string is inserted, the user will
> be able to start typing the comment text and it will be separated from
> the delimiter.
Is the space part of 'comment-start'. It is difficult to say from the code.
Can I just use `comment-start` without trimming it ?
> # comment in shell or Python
> ; comment in Elisp
> // comment in C++
> /* comment in C */
> <!-- comment in HTML -->
>
>
>
> Required for your use of comment-start? Maybe.
>
> Anyway, what’s your plan for modes whose comment-start is longer than
> a single character after trimming the space?
Currently I support modes with single character comments.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Regexp with comment character of buffer
2024-08-12 17:50 ` Heime
@ 2024-08-12 19:13 ` Yuri Khan
2024-08-12 19:19 ` Heime
0 siblings, 1 reply; 10+ messages in thread
From: Yuri Khan @ 2024-08-12 19:13 UTC (permalink / raw)
To: Heime; +Cc: Heime via Users list for the GNU Emacs text editor
On Tue, 13 Aug 2024 at 00:50, Heime <heimeborgia@protonmail.com> wrote:
> Is the space part of 'comment-start'. It is difficult to say from the code.
You do not have to say that from code. You activate a buffer and do an
M-: comment-start RET, and look at the result in the echo area. Repeat
with a different mode.
Alternatively, you read Emacs sources, see that many but not all modes
set comment-start with a trailing space.
> Can I just use `comment-start` without trimming it ?
Since you’re using string-to-char which is documented to return only
the first character of the input string, it does not matter if you
trim the original string beforehand.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Regexp with comment character of buffer
2024-08-12 19:13 ` Yuri Khan
@ 2024-08-12 19:19 ` Heime
2024-08-12 19:22 ` Heime
0 siblings, 1 reply; 10+ messages in thread
From: Heime @ 2024-08-12 19:19 UTC (permalink / raw)
To: Yuri Khan; +Cc: Heime via Users list for the GNU Emacs text editor
Sent with Proton Mail secure email.
On Tuesday, August 13th, 2024 at 7:13 AM, Yuri Khan <yuri.v.khan@gmail.com> wrote:
> On Tue, 13 Aug 2024 at 00:50, Heime heimeborgia@protonmail.com wrote:
>
> > Is the space part of 'comment-start'. It is difficult to say from the code.
>
>
> You do not have to say that from code. You activate a buffer and do an
> M-: comment-start RET, and look at the result in the echo area. Repeat
> with a different mode.
>
> Alternatively, you read Emacs sources, see that many but not all modes
> set comment-start with a trailing space.
comment-start should not introduce a trailing space for convenience, but added
later, so users can start writing the comment after a space.
> > Can I just use `comment-start` without trimming it ?
>
>
> Since you’re using string-to-char which is documented to return only
> the first character of the input string, it does not matter if you
> trim the original string beforehand.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Regexp with comment character of buffer
2024-08-12 19:19 ` Heime
@ 2024-08-12 19:22 ` Heime
0 siblings, 0 replies; 10+ messages in thread
From: Heime @ 2024-08-12 19:22 UTC (permalink / raw)
To: Yuri Khan; +Cc: Heime via Users list for the GNU Emacs text editor
Sent with Proton Mail secure email.
On Tuesday, August 13th, 2024 at 7:19 AM, Heime <heimeborgia@protonmail.com> wrote:
>
>
>
>
>
> Sent with Proton Mail secure email.
>
>
> On Tuesday, August 13th, 2024 at 7:13 AM, Yuri Khan yuri.v.khan@gmail.com wrote:
>
> > On Tue, 13 Aug 2024 at 00:50, Heime heimeborgia@protonmail.com wrote:
> >
> > > Is the space part of 'comment-start'. It is difficult to say from the code.
> >
> > You do not have to say that from code. You activate a buffer and do an
> > M-: comment-start RET, and look at the result in the echo area. Repeat
> > with a different mode.
> >
> > Alternatively, you read Emacs sources, see that many but not all modes
> > set comment-start with a trailing space.
Users should not be doing that, and figure out additional things are being
added for convenience. It is not a good strategy.
> comment-start should not introduce a trailing space for convenience, but added
> later, so users can start writing the comment after a space.
>
> > > Can I just use `comment-start` without trimming it ?
> >
> > Since you’re using string-to-char which is documented to return only
> > the first character of the input string, it does not matter if you
> > trim the original string beforehand.
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2024-08-12 19:22 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-12 10:08 Regexp with comment character of buffer Heime
2024-08-12 11:03 ` Yuri Khan
2024-08-12 11:41 ` Heime
2024-08-12 12:26 ` Yuri Khan
2024-08-12 12:36 ` Heime
2024-08-12 17:11 ` Yuri Khan
2024-08-12 17:50 ` Heime
2024-08-12 19:13 ` Yuri Khan
2024-08-12 19:19 ` Heime
2024-08-12 19:22 ` Heime
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.