* Determining existence of text following point @ 2021-05-17 21:46 michael-franzese 2021-05-17 22:02 ` Skip Montanaro 0 siblings, 1 reply; 37+ messages in thread From: michael-franzese @ 2021-05-17 21:46 UTC (permalink / raw) To: Help Gnu Emacs Is there a way to figure out whether there exist any characters on line after point. ^ permalink raw reply [flat|nested] 37+ messages in thread
* Re: Determining existence of text following point 2021-05-17 21:46 Determining existence of text following point michael-franzese @ 2021-05-17 22:02 ` Skip Montanaro 2021-05-17 22:31 ` michael-franzese 0 siblings, 1 reply; 37+ messages in thread From: Skip Montanaro @ 2021-05-17 22:02 UTC (permalink / raw) To: michael-franzese; +Cc: Help Gnu Emacs > Is there a way to figure out whether > there exist any characters on line > after point. Maybe (looking-at-p ".") ? Full details on regular expressions searching here https://www.gnu.org/software/emacs/manual/html_node/elisp/Regexp-Search.html Skip ^ permalink raw reply [flat|nested] 37+ messages in thread
* Re: Determining existence of text following point 2021-05-17 22:02 ` Skip Montanaro @ 2021-05-17 22:31 ` michael-franzese 2021-05-17 23:05 ` Eric Abrahamsen 2021-05-18 8:47 ` Jean Louis 0 siblings, 2 replies; 37+ messages in thread From: michael-franzese @ 2021-05-17 22:31 UTC (permalink / raw) To: Skip Montanaro; +Cc: Help Gnu Emacs Would like to delete and insert a string "s" only if there is no text folloming point. (delete-region (point) (line-end-position)) (save-excursion (insert s)) Sent: Tuesday, May 18, 2021 at 10:02 AM From: "Skip Montanaro" <skip.montanaro@gmail.com> To: michael-franzese@gmx.com Cc: "Help Gnu Emacs" <help-gnu-emacs@gnu.org> Subject: Re: Determining existence of text following point > Is there a way to figure out whether > there exist any characters on line > after point. Maybe (looking-at-p ".") ? Full details on regular expressions searching here [1]https://www.gnu.org/software/emacs/manual/html_node/elisp/Regexp-Sea rch.html Skip References 1. https://www.gnu.org/software/emacs/manual/html_node/elisp/Regexp-Search.html ^ permalink raw reply [flat|nested] 37+ messages in thread
* Re: Determining existence of text following point 2021-05-17 22:31 ` michael-franzese @ 2021-05-17 23:05 ` Eric Abrahamsen 2021-05-17 23:15 ` michael-franzese 2021-05-17 23:53 ` michael-franzese 2021-05-18 8:47 ` Jean Louis 1 sibling, 2 replies; 37+ messages in thread From: Eric Abrahamsen @ 2021-05-17 23:05 UTC (permalink / raw) To: michael-franzese; +Cc: Skip Montanaro, Help Gnu Emacs michael-franzese@gmx.com writes: > Would like to delete and insert a string "s" only if there is no text > folloming point. > > (delete-region (point) (line-end-position)) > (save-excursion (insert s)) There's a function for this: `eolp' Return t if point is at the end of a line. ‘End of a line’ includes point being at the end of the buffer. ^ permalink raw reply [flat|nested] 37+ messages in thread
* Re: Determining existence of text following point 2021-05-17 23:05 ` Eric Abrahamsen @ 2021-05-17 23:15 ` michael-franzese 2021-05-17 23:36 ` Skip Montanaro 2021-05-18 0:09 ` Eric Abrahamsen 2021-05-17 23:53 ` michael-franzese 1 sibling, 2 replies; 37+ messages in thread From: michael-franzese @ 2021-05-17 23:15 UTC (permalink / raw) To: Eric Abrahamsen; +Cc: Skip Montanaro, Help Gnu Emacs But if there are only empty spaces it is ok too. > Sent: Tuesday, May 18, 2021 at 11:05 AM > From: "Eric Abrahamsen" <eric@ericabrahamsen.net> > To: michael-franzese@gmx.com > Cc: "Skip Montanaro" <skip.montanaro@gmail.com>, "Help Gnu Emacs" <help-gnu-emacs@gnu.org> > Subject: Re: Determining existence of text following point > > michael-franzese@gmx.com writes: > > > Would like to delete and insert a string "s" only if there is no text > > folloming point. > > > > (delete-region (point) (line-end-position)) > > (save-excursion (insert s)) > > There's a function for this: `eolp' > > Return t if point is at the end of a line. > ‘End of a line’ includes point being at the end of the buffer. > ^ permalink raw reply [flat|nested] 37+ messages in thread
* Re: Determining existence of text following point 2021-05-17 23:15 ` michael-franzese @ 2021-05-17 23:36 ` Skip Montanaro 2021-05-18 0:09 ` Eric Abrahamsen 1 sibling, 0 replies; 37+ messages in thread From: Skip Montanaro @ 2021-05-17 23:36 UTC (permalink / raw) To: michael-franzese; +Cc: Eric Abrahamsen, Help Gnu Emacs > But if there are only empty spaces it is ok too. > Yes. Spaces between point and the end of the line means point is not at eol. (Thank you to Eric for the better solution than (looking-at). Been a while since I actually wrote any significant elisp.) Skip > ^ permalink raw reply [flat|nested] 37+ messages in thread
* Re: Determining existence of text following point 2021-05-17 23:15 ` michael-franzese 2021-05-17 23:36 ` Skip Montanaro @ 2021-05-18 0:09 ` Eric Abrahamsen 2021-05-18 0:37 ` michael-franzese ` (2 more replies) 1 sibling, 3 replies; 37+ messages in thread From: Eric Abrahamsen @ 2021-05-18 0:09 UTC (permalink / raw) To: michael-franzese; +Cc: Skip Montanaro, Help Gnu Emacs michael-franzese@gmx.com writes: > But if there are only empty spaces it is ok too. Ah, then Skip's looking-at is a fine solution: (looking-at-p "\\([[:blank:]]+\\)?\\(\n\\|\\'\\)") That's as a test. Or you could use a single `replace-regexp' invocation, to detect and replace the whitespace in one go. ^ permalink raw reply [flat|nested] 37+ messages in thread
* Re: Determining existence of text following point 2021-05-18 0:09 ` Eric Abrahamsen @ 2021-05-18 0:37 ` michael-franzese 2021-05-18 8:24 ` michael-franzese 2021-05-18 8:56 ` Jean Louis 2 siblings, 0 replies; 37+ messages in thread From: michael-franzese @ 2021-05-18 0:37 UTC (permalink / raw) To: Eric Abrahamsen; +Cc: Skip Montanaro, Help Gnu Emacs > Sent: Tuesday, May 18, 2021 at 12:09 PM > From: "Eric Abrahamsen" <eric@ericabrahamsen.net> > To: michael-franzese@gmx.com > Cc: "Skip Montanaro" <skip.montanaro@gmail.com>, "Help Gnu Emacs" <help-gnu-emacs@gnu.org> > Subject: Re: Determining existence of text following point > > michael-franzese@gmx.com writes: > > > But if there are only empty spaces it is ok too. > > Ah, then Skip's looking-at is a fine solution: > > (looking-at-p "\\([[:blank:]]+\\)?\\(\n\\|\\'\\)") So this is a condition where I can write my string, because there are only spaces or a newline after point. > That's as a test. Or you could use a single `replace-regexp' invocation, > to detect and replace the whitespace in one go. > ^ permalink raw reply [flat|nested] 37+ messages in thread
* Re: Determining existence of text following point 2021-05-18 0:09 ` Eric Abrahamsen 2021-05-18 0:37 ` michael-franzese @ 2021-05-18 8:24 ` michael-franzese 2021-05-18 8:56 ` Jean Louis 2 siblings, 0 replies; 37+ messages in thread From: michael-franzese @ 2021-05-18 8:24 UTC (permalink / raw) To: Eric Abrahamsen; +Cc: Skip Montanaro, Help Gnu Emacs Would like to set a function which I could then use with an if statement Have constructed something as follows. But naturally the name of the function is the reverse of having no text (including empty spaces) (defun looking-at-text () "todo" (looking-at-p "\\([[:blank:]]+\\)?\\(\n\\|\\'\\)") ) Then my condition for inserting my string would be (unless (looking-at-text) (delete-region (point) (line-end-position)) (save-excursion (insert s)) ) > Sent: Tuesday, May 18, 2021 at 12:09 PM > From: "Eric Abrahamsen" <eric@ericabrahamsen.net> > To: michael-franzese@gmx.com > Cc: "Skip Montanaro" <skip.montanaro@gmail.com>, "Help Gnu Emacs" <help-gnu-emacs@gnu.org> > Subject: Re: Determining existence of text following point > > michael-franzese@gmx.com writes: > > > But if there are only empty spaces it is ok too. > > Ah, then Skip's looking-at is a fine solution: > > (looking-at-p "\\([[:blank:]]+\\)?\\(\n\\|\\'\\)") > > That's as a test. Or you could use a single `replace-regexp' invocation, > to detect and replace the whitespace in one go. > ^ permalink raw reply [flat|nested] 37+ messages in thread
* Re: Determining existence of text following point 2021-05-18 0:09 ` Eric Abrahamsen 2021-05-18 0:37 ` michael-franzese 2021-05-18 8:24 ` michael-franzese @ 2021-05-18 8:56 ` Jean Louis 2021-05-18 9:31 ` Christopher Dimech 2021-05-18 20:50 ` michael-franzese 2 siblings, 2 replies; 37+ messages in thread From: Jean Louis @ 2021-05-18 8:56 UTC (permalink / raw) To: Eric Abrahamsen; +Cc: Skip Montanaro, Help Gnu Emacs, michael-franzese * Eric Abrahamsen <eric@ericabrahamsen.net> [2021-05-18 03:09]: > michael-franzese@gmx.com writes: > > > But if there are only empty spaces it is ok too. (defun my-insert-on-empty-end-of-line (s) (let ((line-cut (buffer-substring-no-properties (point) (line-end-position)))) (when (or (not (string-match "[^[:blank:]]" line-cut)) (eolp)) (insert s)))) -- Jean Take action in Free Software Foundation campaigns: https://www.fsf.org/campaigns Sign an open letter in support of Richard M. Stallman https://stallmansupport.org/ https://rms-support-letter.github.io/ ^ permalink raw reply [flat|nested] 37+ messages in thread
* Determining existence of text following point 2021-05-18 8:56 ` Jean Louis @ 2021-05-18 9:31 ` Christopher Dimech 2021-05-18 9:42 ` Jean Louis 2021-05-18 9:54 ` Jean Louis 2021-05-18 20:50 ` michael-franzese 1 sibling, 2 replies; 37+ messages in thread From: Christopher Dimech @ 2021-05-18 9:31 UTC (permalink / raw) To: Jean Louis; +Cc: Eric Abrahamsen, Skip Montanaro, Help Gnu Emacs > Sent: Tuesday, May 18, 2021 at 8:56 PM > From: "Jean Louis" <bugs@gnu.support> > To: "Eric Abrahamsen" <eric@ericabrahamsen.net> > Cc: "Skip Montanaro" <skip.montanaro@gmail.com>, "Help Gnu Emacs" <help-gnu-emacs@gnu.org>, michael-franzese@gmx.com > Subject: Re: Determining existence of text following point > > * Eric Abrahamsen <eric@ericabrahamsen.net> [2021-05-18 03:09]: > > michael-franzese@gmx.com writes: > > > > > But if there are only empty spaces it is ok too. > > (defun my-insert-on-empty-end-of-line (s) > (let ((line-cut (buffer-substring-no-properties (point) (line-end-position)))) > (when (or (not (string-match "[^[:blank:]]" line-cut)) (eolp)) > (insert s)))) I understand that "string-match" returns index of start of first blank match. Suppose the cursor is just after the first period. Then because there is still text left on the line, the string "s" is not inserted. The text should only be inserted when the rest of the line is blank. A neutrino is a fermion. Some more text here. ^ > -- > Jean > > Take action in Free Software Foundation campaigns: > https://www.fsf.org/campaigns > > Sign an open letter in support of Richard M. Stallman > https://stallmansupport.org/ > https://rms-support-letter.github.io/ > > > --------------------- Christopher Dimech General Administrator - Naiad Informatics - GNU Project (Geocomputation) - Geophysical Simulation - Geological Subsurface Mapping - Disaster Preparedness and Mitigation - Natural Resource Exploration and Production - Free Software Advocacy ^ permalink raw reply [flat|nested] 37+ messages in thread
* Re: Determining existence of text following point 2021-05-18 9:31 ` Christopher Dimech @ 2021-05-18 9:42 ` Jean Louis 2021-05-18 9:54 ` Jean Louis 1 sibling, 0 replies; 37+ messages in thread From: Jean Louis @ 2021-05-18 9:42 UTC (permalink / raw) To: Christopher Dimech; +Cc: Eric Abrahamsen, Skip Montanaro, Help Gnu Emacs * Christopher Dimech <dimech@gmx.com> [2021-05-18 12:31]: > > Sent: Tuesday, May 18, 2021 at 8:56 PM > > From: "Jean Louis" <bugs@gnu.support> > > To: "Eric Abrahamsen" <eric@ericabrahamsen.net> > > Cc: "Skip Montanaro" <skip.montanaro@gmail.com>, "Help Gnu Emacs" <help-gnu-emacs@gnu.org>, michael-franzese@gmx.com > > Subject: Re: Determining existence of text following point > > > > * Eric Abrahamsen <eric@ericabrahamsen.net> [2021-05-18 03:09]: > > > michael-franzese@gmx.com writes: > > > > > > > But if there are only empty spaces it is ok too. > > > > (defun my-insert-on-empty-end-of-line (s) > > (let ((line-cut (buffer-substring-no-properties (point) (line-end-position)))) > > (when (or (not (string-match "[^[:blank:]]" line-cut)) (eolp)) > > (insert s)))) > > I understand that "string-match" returns index of start of first blank match. > > Suppose the cursor is just after the first period. Then because there is still > text left on the line, the string "s" is not inserted. The text should only be > inserted when the rest of the line is blank. OK, and is it not exactly what that function does? -- Jean Take action in Free Software Foundation campaigns: https://www.fsf.org/campaigns Sign an open letter in support of Richard M. Stallman https://stallmansupport.org/ https://rms-support-letter.github.io/ ^ permalink raw reply [flat|nested] 37+ messages in thread
* Re: Determining existence of text following point 2021-05-18 9:31 ` Christopher Dimech 2021-05-18 9:42 ` Jean Louis @ 2021-05-18 9:54 ` Jean Louis 2021-05-18 10:08 ` Christopher Dimech 1 sibling, 1 reply; 37+ messages in thread From: Jean Louis @ 2021-05-18 9:54 UTC (permalink / raw) To: Christopher Dimech; +Cc: Eric Abrahamsen, Skip Montanaro, Help Gnu Emacs * Christopher Dimech <dimech@gmx.com> [2021-05-18 12:31]: > > Sent: Tuesday, May 18, 2021 at 8:56 PM > > From: "Jean Louis" <bugs@gnu.support> > > To: "Eric Abrahamsen" <eric@ericabrahamsen.net> > > Cc: "Skip Montanaro" <skip.montanaro@gmail.com>, "Help Gnu Emacs" <help-gnu-emacs@gnu.org>, michael-franzese@gmx.com > > Subject: Re: Determining existence of text following point > > > > * Eric Abrahamsen <eric@ericabrahamsen.net> [2021-05-18 03:09]: > > > michael-franzese@gmx.com writes: > > > > > > > But if there are only empty spaces it is ok too. > > > > (defun my-insert-on-empty-end-of-line (s) > > (let ((line-cut (buffer-substring-no-properties (point) (line-end-position)))) > > (when (or (not (string-match "[^[:blank:]]" line-cut)) (eolp)) > > (insert s)))) > > I understand that "string-match" returns index of start of first blank match. > > Suppose the cursor is just after the first period. Then because there is still > text left on the line, the string "s" is not inserted. The text should only be > inserted when the rest of the line is blank. > > A neutrino is a fermion. Some more text here. That (not (string-match "[^[:blank:]]" line-cut)) means it is true if nothing is found that is not blank space. Test it here where is the block (remove block): (string-match "[^[:blank:]]" (buffer-substring-no-properties (point) (line-end-position)))█ ;; something (not (string-match "[^[:blank:]]" (buffer-substring-no-properties (point) (line-end-position))))█ ;; something (not (string-match "[^[:blank:]]" (buffer-substring-no-properties (point) (line-end-position))))█ ⇒ t There is blank space after last parenthesis here, you can test: (not (string-match "[^[:blank:]]" (buffer-substring-no-properties (point) (line-end-position)))) -- Jean Take action in Free Software Foundation campaigns: https://www.fsf.org/campaigns Sign an open letter in support of Richard M. Stallman https://stallmansupport.org/ https://rms-support-letter.github.io/ ^ permalink raw reply [flat|nested] 37+ messages in thread
* Re: Determining existence of text following point 2021-05-18 9:54 ` Jean Louis @ 2021-05-18 10:08 ` Christopher Dimech 2021-05-18 11:07 ` tomas 0 siblings, 1 reply; 37+ messages in thread From: Christopher Dimech @ 2021-05-18 10:08 UTC (permalink / raw) To: Jean Louis; +Cc: Eric Abrahamsen, Skip Montanaro, Help Gnu Emacs How is it that the following returns nil? (setq sa (string-match "[^[:blank:]]" " ")) > Sent: Tuesday, May 18, 2021 at 9:54 PM > From: "Jean Louis" <bugs@gnu.support> > To: "Christopher Dimech" <dimech@gmx.com> > Cc: "Eric Abrahamsen" <eric@ericabrahamsen.net>, "Skip Montanaro" <skip.montanaro@gmail.com>, "Help Gnu Emacs" <help-gnu-emacs@gnu.org> > Subject: Re: Determining existence of text following point > > * Christopher Dimech <dimech@gmx.com> [2021-05-18 12:31]: > > > Sent: Tuesday, May 18, 2021 at 8:56 PM > > > From: "Jean Louis" <bugs@gnu.support> > > > To: "Eric Abrahamsen" <eric@ericabrahamsen.net> > > > Cc: "Skip Montanaro" <skip.montanaro@gmail.com>, "Help Gnu Emacs" <help-gnu-emacs@gnu.org>, michael-franzese@gmx.com > > > Subject: Re: Determining existence of text following point > > > > > > * Eric Abrahamsen <eric@ericabrahamsen.net> [2021-05-18 03:09]: > > > > michael-franzese@gmx.com writes: > > > > > > > > > But if there are only empty spaces it is ok too. > > > > > > (defun my-insert-on-empty-end-of-line (s) > > > (let ((line-cut (buffer-substring-no-properties (point) (line-end-position)))) > > > (when (or (not (string-match "[^[:blank:]]" line-cut)) (eolp)) > > > (insert s)))) > > > > I understand that "string-match" returns index of start of first blank match. > > > > Suppose the cursor is just after the first period. Then because there is still > > text left on the line, the string "s" is not inserted. The text should only be > > inserted when the rest of the line is blank. > > > > A neutrino is a fermion. Some more text here. > > That (not (string-match "[^[:blank:]]" line-cut)) means it is true if > nothing is found that is not blank space. > > Test it here where is the block (remove block): > > (string-match "[^[:blank:]]" > (buffer-substring-no-properties (point) (line-end-position)))█ ;; something > > (not (string-match "[^[:blank:]]" > (buffer-substring-no-properties (point) (line-end-position))))█ ;; something > > (not (string-match "[^[:blank:]]" > (buffer-substring-no-properties (point) (line-end-position))))█ ⇒ t > > There is blank space after last parenthesis here, you can test: > > (not (string-match "[^[:blank:]]" > (buffer-substring-no-properties (point) (line-end-position)))) > > -- > Jean > > Take action in Free Software Foundation campaigns: > https://www.fsf.org/campaigns > > Sign an open letter in support of Richard M. Stallman > https://stallmansupport.org/ > https://rms-support-letter.github.io/ > > ^ permalink raw reply [flat|nested] 37+ messages in thread
* Re: Determining existence of text following point 2021-05-18 10:08 ` Christopher Dimech @ 2021-05-18 11:07 ` tomas 2021-05-18 11:26 ` Christopher Dimech 0 siblings, 1 reply; 37+ messages in thread From: tomas @ 2021-05-18 11:07 UTC (permalink / raw) To: help-gnu-emacs [-- Attachment #1: Type: text/plain, Size: 287 bytes --] On Tue, May 18, 2021 at 12:08:42PM +0200, Christopher Dimech wrote: > How is it that the following returns nil? > > (setq sa (string-match "[^[:blank:]]" " ")) Because you stated to match any non-blank character and there are only blank characters to match. Cheers - t [-- Attachment #2: Digital signature --] [-- Type: application/pgp-signature, Size: 198 bytes --] ^ permalink raw reply [flat|nested] 37+ messages in thread
* Re: Determining existence of text following point 2021-05-18 11:07 ` tomas @ 2021-05-18 11:26 ` Christopher Dimech 2021-05-18 11:56 ` Jean Louis 2021-05-18 12:02 ` tomas 0 siblings, 2 replies; 37+ messages in thread From: Christopher Dimech @ 2021-05-18 11:26 UTC (permalink / raw) To: tomas; +Cc: help-gnu-emacs --------------------- Christopher Dimech General Administrator - Naiad Informatics - GNU Project (Geocomputation) - Geophysical Simulation - Geological Subsurface Mapping - Disaster Preparedness and Mitigation - Natural Resource Exploration and Production - Free Software Advocacy > Sent: Tuesday, May 18, 2021 at 11:07 PM > From: tomas@tuxteam.de > To: help-gnu-emacs@gnu.org > Subject: Re: Determining existence of text following point > > On Tue, May 18, 2021 at 12:08:42PM +0200, Christopher Dimech wrote: > > How is it that the following returns nil? > > > > (setq sa (string-match "[^[:blank:]]" " ")) > > Because you stated to match any non-blank character and there > are only blank characters to match. The docstring for string-match is "Return index of start of first match for REGEXP in STRING, or nil." I find the description different from what string-match actually returns. > Cheers > - t > ^ permalink raw reply [flat|nested] 37+ messages in thread
* Re: Determining existence of text following point 2021-05-18 11:26 ` Christopher Dimech @ 2021-05-18 11:56 ` Jean Louis 2021-05-18 12:23 ` Christopher Dimech 2021-05-18 12:02 ` tomas 1 sibling, 1 reply; 37+ messages in thread From: Jean Louis @ 2021-05-18 11:56 UTC (permalink / raw) To: Christopher Dimech; +Cc: help-gnu-emacs * Christopher Dimech <dimech@gmx.com> [2021-05-18 14:27]: > > > (setq sa (string-match "[^[:blank:]]" " ")) > I find the description different from what string-match actually > returns. The symbol ^ means "not following", and that regular expression means match non-blanks. (string-match "[^[:blank:]]" " ") ⇒ nil (string-match "[[:blank:]]" " ") ⇒ 0 -- Jean Take action in Free Software Foundation campaigns: https://www.fsf.org/campaigns Sign an open letter in support of Richard M. Stallman https://stallmansupport.org/ https://rms-support-letter.github.io/ ^ permalink raw reply [flat|nested] 37+ messages in thread
* Re: Determining existence of text following point 2021-05-18 11:56 ` Jean Louis @ 2021-05-18 12:23 ` Christopher Dimech 2021-05-18 12:35 ` tomas 0 siblings, 1 reply; 37+ messages in thread From: Christopher Dimech @ 2021-05-18 12:23 UTC (permalink / raw) To: Jean Louis; +Cc: help-gnu-emacs > Sent: Tuesday, May 18, 2021 at 11:56 PM > From: "Jean Louis" <bugs@gnu.support> > To: "Christopher Dimech" <dimech@gmx.com> > Cc: tomas@tuxteam.de, help-gnu-emacs@gnu.org > Subject: Re: Determining existence of text following point > > * Christopher Dimech <dimech@gmx.com> [2021-05-18 14:27]: > > > > (setq sa (string-match "[^[:blank:]]" " ")) > > > I find the description different from what string-match actually > > returns. > > The symbol ^ means "not following", and that regular expression means > match non-blanks. > > (string-match "[^[:blank:]]" " ") ⇒ nil > (string-match "[[:blank:]]" " ") ⇒ 0 You are correct. "^" means match everything but the following class. I am quite used on see "^" to mean "beginning of line". So just read it as I usually do. It is unfortunate that there exist so many different syntaxes for writing regular expressions. > -- > Jean > > Take action in Free Software Foundation campaigns: > https://www.fsf.org/campaigns > > Sign an open letter in support of Richard M. Stallman > https://stallmansupport.org/ > https://rms-support-letter.github.io/ > > ^ permalink raw reply [flat|nested] 37+ messages in thread
* Re: Determining existence of text following point 2021-05-18 12:23 ` Christopher Dimech @ 2021-05-18 12:35 ` tomas 2021-05-18 12:50 ` Christopher Dimech 0 siblings, 1 reply; 37+ messages in thread From: tomas @ 2021-05-18 12:35 UTC (permalink / raw) To: Christopher Dimech; +Cc: help-gnu-emacs, Jean Louis [-- Attachment #1: Type: text/plain, Size: 1734 bytes --] On Tue, May 18, 2021 at 02:23:25PM +0200, Christopher Dimech wrote: > > Sent: Tuesday, May 18, 2021 at 11:56 PM > > From: "Jean Louis" <bugs@gnu.support> > > To: "Christopher Dimech" <dimech@gmx.com> > > Cc: tomas@tuxteam.de, help-gnu-emacs@gnu.org > > Subject: Re: Determining existence of text following point > > > > * Christopher Dimech <dimech@gmx.com> [2021-05-18 14:27]: > > > > > (setq sa (string-match "[^[:blank:]]" " ")) > > > > > I find the description different from what string-match actually > > > returns. > > > > The symbol ^ means "not following", and that regular expression means > > match non-blanks. > > > > (string-match "[^[:blank:]]" " ") ⇒ nil > > (string-match "[[:blank:]]" " ") ⇒ 0 > > You are correct. "^" means match everything but the following class. > > I am quite used on see "^" to mean "beginning of line". So just read > it as I usually do. This is outside the context of character classes, i.e. outside [...]. > It is unfortunate that there exist so many different syntaxes for writing > regular expressions. Yet all those syntaxes coincide in that one thing: "^" outside of brackets means "anchor at the beginning" (of line, most of the time, but it could be "of string" or similar), whereas inside of character class brackets (but _only_ right after the opening bracket!) it means complement. This is an unfortunate quirk, but those notations are around since the early 1970s, so that ship has sailed. Go and tell a phisicist to use something else than the "uppercase L" for the Lagrangian. The multitude of regular expression extensions and implementations is an issue, yes, but a completely different one. Cheers - t [-- Attachment #2: Digital signature --] [-- Type: application/pgp-signature, Size: 198 bytes --] ^ permalink raw reply [flat|nested] 37+ messages in thread
* Re: Determining existence of text following point 2021-05-18 12:35 ` tomas @ 2021-05-18 12:50 ` Christopher Dimech 0 siblings, 0 replies; 37+ messages in thread From: Christopher Dimech @ 2021-05-18 12:50 UTC (permalink / raw) To: tomas; +Cc: help-gnu-emacs, Jean Louis > Sent: Wednesday, May 19, 2021 at 12:35 AM > From: tomas@tuxteam.de > To: "Christopher Dimech" <dimech@gmx.com> > Cc: "Jean Louis" <bugs@gnu.support>, help-gnu-emacs@gnu.org > Subject: Re: Determining existence of text following point > > On Tue, May 18, 2021 at 02:23:25PM +0200, Christopher Dimech wrote: > > > Sent: Tuesday, May 18, 2021 at 11:56 PM > > > From: "Jean Louis" <bugs@gnu.support> > > > To: "Christopher Dimech" <dimech@gmx.com> > > > Cc: tomas@tuxteam.de, help-gnu-emacs@gnu.org > > > Subject: Re: Determining existence of text following point > > > > > > * Christopher Dimech <dimech@gmx.com> [2021-05-18 14:27]: > > > > > > (setq sa (string-match "[^[:blank:]]" " ")) > > > > > > > I find the description different from what string-match actually > > > > returns. > > > > > > The symbol ^ means "not following", and that regular expression means > > > match non-blanks. > > > > > > (string-match "[^[:blank:]]" " ") ⇒ nil > > > (string-match "[[:blank:]]" " ") ⇒ 0 > > > > You are correct. "^" means match everything but the following class. > > > > I am quite used on see "^" to mean "beginning of line". So just read > > it as I usually do. > > This is outside the context of character classes, i.e. outside [...]. > > > It is unfortunate that there exist so many different syntaxes for writing > > regular expressions. > > Yet all those syntaxes coincide in that one thing: "^" outside of > brackets means "anchor at the beginning" (of line, most of the time, > but it could be "of string" or similar), whereas inside of character > class brackets (but _only_ right after the opening bracket!) it > means complement. > > This is an unfortunate quirk, but those notations are around since > the early 1970s, so that ship has sailed. Go and tell a phisicist > to use something else than the "uppercase L" for the Lagrangian. Richard Feynman used to come up with very strange notation, and we relied on Freeman Dyson to make sense in a familiar mathematical notation. Einstein had the same problem. > The multitude of regular expression extensions and implementations > is an issue, yes, but a completely different one. > > Cheers > - t > ^ permalink raw reply [flat|nested] 37+ messages in thread
* Re: Determining existence of text following point 2021-05-18 11:26 ` Christopher Dimech 2021-05-18 11:56 ` Jean Louis @ 2021-05-18 12:02 ` tomas 2021-05-18 12:15 ` Christopher Dimech 2021-05-18 12:28 ` Christopher Dimech 1 sibling, 2 replies; 37+ messages in thread From: tomas @ 2021-05-18 12:02 UTC (permalink / raw) To: Christopher Dimech; +Cc: help-gnu-emacs [-- Attachment #1: Type: text/plain, Size: 596 bytes --] On Tue, May 18, 2021 at 01:26:12PM +0200, Christopher Dimech wrote: [...] > > On Tue, May 18, 2021 at 12:08:42PM +0200, Christopher Dimech wrote: > > > How is it that the following returns nil? > > > > > > (setq sa (string-match "[^[:blank:]]" " ")) > > > > Because you stated to match any non-blank character and there > > are only blank characters to match. > > The docstring for string-match is > > "Return index of start of first match for REGEXP in STRING, or nil." > > I find the description different from what string-match actually returns. ? Cheers - t [-- Attachment #2: Digital signature --] [-- Type: application/pgp-signature, Size: 198 bytes --] ^ permalink raw reply [flat|nested] 37+ messages in thread
* Re: Determining existence of text following point 2021-05-18 12:02 ` tomas @ 2021-05-18 12:15 ` Christopher Dimech 2021-05-18 12:27 ` tomas 2021-05-18 12:28 ` Christopher Dimech 1 sibling, 1 reply; 37+ messages in thread From: Christopher Dimech @ 2021-05-18 12:15 UTC (permalink / raw) To: tomas; +Cc: help-gnu-emacs > Sent: Wednesday, May 19, 2021 at 12:02 AM > From: tomas@tuxteam.de > To: "Christopher Dimech" <dimech@gmx.com> > Cc: help-gnu-emacs@gnu.org > Subject: Re: Determining existence of text following point > > On Tue, May 18, 2021 at 01:26:12PM +0200, Christopher Dimech wrote: > > [...] > > > > On Tue, May 18, 2021 at 12:08:42PM +0200, Christopher Dimech wrote: > > > > How is it that the following returns nil? > > > > > > > > (setq sa (string-match "[^[:blank:]]" " ")) > > > > > > Because you stated to match any non-blank character and there > > > are only blank characters to match. > > > > The docstring for string-match is > > > > "Return index of start of first match for REGEXP in STRING, or nil." > > > > I find the description different from what string-match actually returns. > > ? string-match looks as though it returns the index of the last match because (setq sa (string-match "[^[:blank:]]" " A neutrino is a fermion")) (setq sb (not (string-match "[^[:blank:]]" " A neutrino is a fermion"))) gives sa: 2 sb: nil > Cheers > - t > ^ permalink raw reply [flat|nested] 37+ messages in thread
* Re: Determining existence of text following point 2021-05-18 12:15 ` Christopher Dimech @ 2021-05-18 12:27 ` tomas 2021-05-18 12:43 ` Christopher Dimech 2021-05-18 12:44 ` Jean Louis 0 siblings, 2 replies; 37+ messages in thread From: tomas @ 2021-05-18 12:27 UTC (permalink / raw) To: Christopher Dimech; +Cc: help-gnu-emacs [-- Attachment #1: Type: text/plain, Size: 937 bytes --] On Tue, May 18, 2021 at 02:15:27PM +0200, Christopher Dimech wrote: [...] > string-match looks as though it returns the index of the last match because > > (setq sa (string-match "[^[:blank:]]" " A neutrino is a fermion")) > (setq sb (not (string-match "[^[:blank:]]" " A neutrino is a fermion"))) > > gives > > sa: 2 > sb: nil Sorry. I still don't understand. - You send string-match to find a non-blank character It does find one. If you don't specify more, that will be the first one, i.e. the "A". - Thus the value is 2. This is your first result. - You negate that in your second setup (not ...). By convention, in Lisp, 'nil' is the false value, everything else is considered 'true'. Thus, (not (...)) evaluates to (not 2) evaluates to nil. This is your second result. Now what /is/ your problem? Your posts are sometimes... inscrutable (to me, at least). Cheers - t [-- Attachment #2: Digital signature --] [-- Type: application/pgp-signature, Size: 198 bytes --] ^ permalink raw reply [flat|nested] 37+ messages in thread
* Re: Determining existence of text following point 2021-05-18 12:27 ` tomas @ 2021-05-18 12:43 ` Christopher Dimech 2021-05-18 12:44 ` Jean Louis 1 sibling, 0 replies; 37+ messages in thread From: Christopher Dimech @ 2021-05-18 12:43 UTC (permalink / raw) To: tomas; +Cc: help-gnu-emacs > Sent: Wednesday, May 19, 2021 at 12:27 AM > From: tomas@tuxteam.de > To: "Christopher Dimech" <dimech@gmx.com> > Cc: help-gnu-emacs@gnu.org > Subject: Re: Determining existence of text following point > > On Tue, May 18, 2021 at 02:15:27PM +0200, Christopher Dimech wrote: > > [...] > > > string-match looks as though it returns the index of the last match because > > > > (setq sa (string-match "[^[:blank:]]" " A neutrino is a fermion")) > > (setq sb (not (string-match "[^[:blank:]]" " A neutrino is a fermion"))) > > > > gives > > > > sa: 2 > > sb: nil > > Sorry. I still don't understand. > > - You send string-match to find a non-blank character > It does find one. If you don't specify more, that > will be the first one, i.e. the "A". > > - Thus the value is 2. This is your first result. > > - You negate that in your second setup (not ...). By > convention, in Lisp, 'nil' is the false value, everything > else is considered 'true'. Thus, (not (...)) evaluates > to (not 2) evaluates to nil. This is your second result. > > Now what /is/ your problem? Your posts are sometimes... inscrutable > (to me, at least). There is no problem, had misinterpreted "^" to mean beginning of line. Thusly, everything seemed to be the other way round. > Cheers > - t > ^ permalink raw reply [flat|nested] 37+ messages in thread
* Re: Determining existence of text following point 2021-05-18 12:27 ` tomas 2021-05-18 12:43 ` Christopher Dimech @ 2021-05-18 12:44 ` Jean Louis 1 sibling, 0 replies; 37+ messages in thread From: Jean Louis @ 2021-05-18 12:44 UTC (permalink / raw) To: tomas; +Cc: Christopher Dimech, help-gnu-emacs (setq sa (string-match "[^[:blank:]]" " A neutrino is a fermion")) ⇒ 2 The above is because it is matching anywhere anything that is not blank. If there is only blank character alternative it will not match. It will be true if there is anything non-blank. Manual section: (info "(elisp) Regexp Special") ‘[^ ... ]’ ‘[^’ begins a “complemented character alternative”. This matches any character except the ones specified. Thus, ‘[^a-z0-9A-Z]’ matches all characters _except_ ASCII letters and digits. (setq sb (not (string-match "[^[:blank:]]" " A neutrino is a fermion"))) ⇒ nil The `not' will yield TRUE if there is blank only in the string. What I find really good is that blank is not just space as we know it, it will recognize other space types as well. It will work with: EN SPACE (string-match "[^[:blank:]]" " ") ⇒ nil It will work with: EM SPACE (string-match "[^[:blank:]]" " ") ⇒ nil It will work with: THIN SPACE (string-match "[^[:blank:]]" " ") ⇒ nil It will work with: HAIR SPAICE (string-match "[^[:blank:]]" " ") ⇒ nil It will work with: FIGURE SPACE (string-match "[^[:blank:]]" " ") ⇒ nil It will work with: NO BREAK SPACE (string-match "[^[:blank:]]" " ") ⇒ nil It will work with: OGHAM SPACE MARK (string-match "[^[:blank:]]" " ") ⇒ nil And I guess with other possible spaces. -- Jean Take action in Free Software Foundation campaigns: https://www.fsf.org/campaigns Sign an open letter in support of Richard M. Stallman https://stallmansupport.org/ https://rms-support-letter.github.io/ ^ permalink raw reply [flat|nested] 37+ messages in thread
* Re: Determining existence of text following point 2021-05-18 12:02 ` tomas 2021-05-18 12:15 ` Christopher Dimech @ 2021-05-18 12:28 ` Christopher Dimech 2021-05-18 12:47 ` Jean Louis 1 sibling, 1 reply; 37+ messages in thread From: Christopher Dimech @ 2021-05-18 12:28 UTC (permalink / raw) To: tomas; +Cc: help-gnu-emacs Had not realised that "^" meant "not following". Interpreted as meaning "beginning of line". > Sent: Wednesday, May 19, 2021 at 12:02 AM > From: tomas@tuxteam.de > To: "Christopher Dimech" <dimech@gmx.com> > Cc: help-gnu-emacs@gnu.org > Subject: Re: Determining existence of text following point > > On Tue, May 18, 2021 at 01:26:12PM +0200, Christopher Dimech wrote: > > [...] > > > > On Tue, May 18, 2021 at 12:08:42PM +0200, Christopher Dimech wrote: > > > > How is it that the following returns nil? > > > > > > > > (setq sa (string-match "[^[:blank:]]" " ")) > > > > > > Because you stated to match any non-blank character and there > > > are only blank characters to match. > > > > The docstring for string-match is > > > > "Return index of start of first match for REGEXP in STRING, or nil." > > > > I find the description different from what string-match actually returns. > > ? > > Cheers > - t > ^ permalink raw reply [flat|nested] 37+ messages in thread
* Re: Determining existence of text following point 2021-05-18 12:28 ` Christopher Dimech @ 2021-05-18 12:47 ` Jean Louis 0 siblings, 0 replies; 37+ messages in thread From: Jean Louis @ 2021-05-18 12:47 UTC (permalink / raw) To: Christopher Dimech; +Cc: help-gnu-emacs * Christopher Dimech <dimech@gmx.com> [2021-05-18 15:32]: > Had not realised that "^" meant "not following". Interpreted as meaning > "beginning of line". It depends of the context. (info "(elisp) Regexp Special") There can be context where it means beginning of line. -- Jean Take action in Free Software Foundation campaigns: https://www.fsf.org/campaigns Sign an open letter in support of Richard M. Stallman https://stallmansupport.org/ https://rms-support-letter.github.io/ ^ permalink raw reply [flat|nested] 37+ messages in thread
* Re: Determining existence of text following point 2021-05-18 8:56 ` Jean Louis 2021-05-18 9:31 ` Christopher Dimech @ 2021-05-18 20:50 ` michael-franzese 2021-05-18 22:04 ` Jean Louis 2021-05-18 22:17 ` Jean Louis 1 sibling, 2 replies; 37+ messages in thread From: michael-franzese @ 2021-05-18 20:50 UTC (permalink / raw) To: Jean Louis; +Cc: Eric Abrahamsen, Skip Montanaro, Help Gnu Emacs > Sent: Tuesday, May 18, 2021 at 8:56 PM > From: "Jean Louis" <bugs@gnu.support> > To: "Eric Abrahamsen" <eric@ericabrahamsen.net> > Cc: "Skip Montanaro" <skip.montanaro@gmail.com>, "Help Gnu Emacs" <help-gnu-emacs@gnu.org>, michael-franzese@gmx.com > Subject: Re: Determining existence of text following point > > * Eric Abrahamsen <eric@ericabrahamsen.net> [2021-05-18 03:09]: > > michael-franzese@gmx.com writes: > > > > > But if there are only empty spaces it is ok too. > > (defun my-insert-on-empty-end-of-line (s) > (let ((line-cut (buffer-substring-no-properties (point) (line-end-position)))) > (when (or (not (string-match "[^[:blank:]]" line-cut)) (eolp)) > (insert s)))) Found out that I would need to extend this some more because if the text is ";;" followed by space followed by either a series of ";" or "+", or "-", then the insertion is allowed. So not just only blanks. For instance, if the text in a commented string as follows, I will go ahead with the insertion. ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; ++++++++++++++++++++++++++++++++++ ;; ------------------------------- > > -- > Jean > > Take action in Free Software Foundation campaigns: > https://www.fsf.org/campaigns > > Sign an open letter in support of Richard M. Stallman > https://stallmansupport.org/ > https://rms-support-letter.github.io/ > > > ^ permalink raw reply [flat|nested] 37+ messages in thread
* Re: Determining existence of text following point 2021-05-18 20:50 ` michael-franzese @ 2021-05-18 22:04 ` Jean Louis 2021-05-18 22:17 ` Jean Louis 1 sibling, 0 replies; 37+ messages in thread From: Jean Louis @ 2021-05-18 22:04 UTC (permalink / raw) To: michael-franzese; +Cc: Eric Abrahamsen, Skip Montanaro, Help Gnu Emacs * michael-franzese@gmx.com <michael-franzese@gmx.com> [2021-05-18 23:51]: > For instance, if the text in a commented string as follows, I will go ahead with > the insertion. > > ;; ;;;;;;;;;;;;;;█;;;;;;;;;;;;;;;;;;;;;;;; > > ;; +++++++++++++█+++++++++++++++++++++ > > ;; ------------█------------------- You want to be able to insert it there where there are those blocks? -- Jean Take action in Free Software Foundation campaigns: https://www.fsf.org/campaigns Sign an open letter in support of Richard M. Stallman https://stallmansupport.org/ https://rms-support-letter.github.io/ ^ permalink raw reply [flat|nested] 37+ messages in thread
* Re: Determining existence of text following point 2021-05-18 20:50 ` michael-franzese 2021-05-18 22:04 ` Jean Louis @ 2021-05-18 22:17 ` Jean Louis 2021-05-19 7:28 ` michael-franzese 1 sibling, 1 reply; 37+ messages in thread From: Jean Louis @ 2021-05-18 22:17 UTC (permalink / raw) To: michael-franzese; +Cc: Eric Abrahamsen, Skip Montanaro, Help Gnu Emacs * michael-franzese@gmx.com <michael-franzese@gmx.com> [2021-05-18 23:52]: > For instance, if the text in a commented string as follows, I will go ahead with > the insertion. > (defun my-insert-on-empty-end-of-line (s) (let ((line-cut (buffer-substring-no-properties (point) (line-end-position)))) (when (or (not (string-match "[^[:blank:]]" line-cut)) (eolp)) (insert s)))) (defun my-insert-on-empty-end-of-line (s) (let ((line-cut (buffer-substring-no-properties (point) (line-end-position)))) (when (or (not (string-match "[^+[:blank:];-]" line-cut)) (eolp)) (insert s)))) (defun my-insert () (interactive) (my-insert-on-empty-end-of-line "Hello")) (local-set-key (kbd "<f5>") 'my-insert) Line with blanks, works: ;; Hello Line with something else but our series of chars (does not work, expected): ;; █ abc Line with fancy stuff that we wish to include (works): ;; ;;;;;;;;;;;;;;;;Hello;;;;;;;;;;;;;;;;;;;;;; ;; +++++++++++++++++++++Hello+++++++++++++ ;; -------------------------Hello------Hello Weird other lines (it does not work, as it is so expected): ;; 𝓒𝓾𝓻𝓼𝓸𝓻 𝓲𝓼 𝓱𝓮𝓻𝓮: █ 𝓫𝓾𝓽 𝓲𝓼 𝓷𝓸𝓽 𝔀𝓸𝓻𝓴𝓲𝓷𝓰, 𝐄𝐗𝐏𝐄𝐂𝐓𝐄𝐃! -- Jean Take action in Free Software Foundation campaigns: https://www.fsf.org/campaigns Sign an open letter in support of Richard M. Stallman https://stallmansupport.org/ https://rms-support-letter.github.io/ ^ permalink raw reply [flat|nested] 37+ messages in thread
* Re: Determining existence of text following point 2021-05-18 22:17 ` Jean Louis @ 2021-05-19 7:28 ` michael-franzese 2021-05-19 8:05 ` michael-franzese 2021-05-19 10:23 ` Jean Louis 0 siblings, 2 replies; 37+ messages in thread From: michael-franzese @ 2021-05-19 7:28 UTC (permalink / raw) To: Jean Louis; +Cc: Eric Abrahamsen, Skip Montanaro, Help Gnu Emacs Point will always be at the beginning of a comment on a separate line The "^" shows the position of the cursor. ^;; ;;;;;;;;;;;;;;;;;;;;;;;;;; ^;; +++++++++++++++++++++++++++ ^;; ---------------------------- I want to have a keybinding that if I continue to hit will change a comment from ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; to ;; +++++++++++++++++++++++++++++++++++++ Currently I have the following code (defun insert-bifurcation (s n) "todo" (let* ( (a (point)) (b (line-end-position)) (line-cut (buffer-substring-no-properties a b)) ) (when (or (not (string-match "[^[:blank:]]" line-cut)) (eolp)) (pcase n (0 (save-excursion (insert s)) (comment-region a b)) ((or 1 2 3 4 5) (delete-region a b) (save-excursion (insert s)) (comment-region a b)) (_ (delete-region a b))) )) ) (defvar count 1) (defun insert-bifurcating-comment () "Insert bifurcating line at cursor position" (interactive) (let* ( (m 62) (n 69) (lena (- m (current-column))) ; lena = m - (current-column) (lenb (- n (current-column))) ) (pcase count (0 ;; makes s to be line with repeating ";" (setq-local s (make-string lena ?\;)) ; repeats lena times (insert-bifurcation s count) (setq-local count 1)) (1 ;; makes s to be line with repeating ";" (setq-local s (make-string lenb ?\;)) ; string length lenb (insert-bifurcation s count) (setq-local count 2)) (2 ;; makes s to be line with repeating "+" (setq-local s (make-string lena ?+)) (insert-bifurcation s count) (setq-local count 3)) (_ ;; deactivates the bifurcating line (insert-bifurcation s count) (setq-local count 1)) )) ) > Sent: Wednesday, May 19, 2021 at 10:17 AM > From: "Jean Louis" <bugs@gnu.support> > To: michael-franzese@gmx.com > Cc: "Eric Abrahamsen" <eric@ericabrahamsen.net>, "Skip Montanaro" <skip.montanaro@gmail.com>, "Help Gnu Emacs" <help-gnu-emacs@gnu.org> > Subject: Re: Determining existence of text following point > > * michael-franzese@gmx.com <michael-franzese@gmx.com> [2021-05-18 23:52]: > > For instance, if the text in a commented string as follows, I will go ahead with > > the insertion. > > > (defun my-insert-on-empty-end-of-line (s) > (let ((line-cut (buffer-substring-no-properties (point) (line-end-position)))) > (when (or (not (string-match "[^[:blank:]]" line-cut)) (eolp)) > (insert s)))) > > (defun my-insert-on-empty-end-of-line (s) > (let ((line-cut (buffer-substring-no-properties (point) (line-end-position)))) > (when (or (not (string-match "[^+[:blank:];-]" line-cut)) (eolp)) > (insert s)))) > > (defun my-insert () > (interactive) > (my-insert-on-empty-end-of-line "Hello")) > > (local-set-key (kbd "<f5>") 'my-insert) > > Line with blanks, works: > ;; Hello > > Line with something else but our series of chars (does not work, expected): > > ;; █ abc > > Line with fancy stuff that we wish to include (works): > > ;; ;;;;;;;;;;;;;;;;Hello;;;;;;;;;;;;;;;;;;;;;; > ;; +++++++++++++++++++++Hello+++++++++++++ > ;; -------------------------Hello------Hello > > Weird other lines (it does not work, as it is so expected): > > ;; 𝓒𝓾𝓻𝓼𝓸𝓻 𝓲𝓼 𝓱𝓮𝓻𝓮: █ 𝓫𝓾𝓽 𝓲𝓼 𝓷𝓸𝓽 𝔀𝓸𝓻𝓴𝓲𝓷𝓰, 𝐄𝐗𝐏𝐄𝐂𝐓𝐄𝐃! > > > -- > Jean > > Take action in Free Software Foundation campaigns: > https://www.fsf.org/campaigns > > Sign an open letter in support of Richard M. Stallman > https://stallmansupport.org/ > https://rms-support-letter.github.io/ > > > ^ permalink raw reply [flat|nested] 37+ messages in thread
* Re: Determining existence of text following point 2021-05-19 7:28 ` michael-franzese @ 2021-05-19 8:05 ` michael-franzese 2021-05-19 10:23 ` Jean Louis 1 sibling, 0 replies; 37+ messages in thread From: michael-franzese @ 2021-05-19 8:05 UTC (permalink / raw) To: michael-franzese Cc: Eric Abrahamsen, Skip Montanaro, Help Gnu Emacs, Jean Louis Have made some simplifications to the code. I would also like to handle the following case. ;; .......................................... > Sent: Wednesday, May 19, 2021 at 7:28 PM > From: michael-franzese@gmx.com > To: "Jean Louis" <bugs@gnu.support> > Cc: "Eric Abrahamsen" <eric@ericabrahamsen.net>, "Skip Montanaro" <skip.montanaro@gmail.com>, "Help Gnu Emacs" <help-gnu-emacs@gnu.org> > Subject: Re: Determining existence of text following point > > Point will always be at the beginning of a comment on a separate line > > The "^" shows the position of the cursor. > > ^;; ;;;;;;;;;;;;;;;;;;;;;;;;;; > > ^;; +++++++++++++++++++++++++++ > > ^;; ---------------------------- > > I want to have a keybinding that if I continue to hit will change > a comment from > > ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; > > to > > ;; +++++++++++++++++++++++++++++++++++++ > > Currently I have the following code > > > (defun insert-bifurcation (s n) > "todo" > > (let* ( (a (point)) (b (line-end-position)) > (line-cut (buffer-substring-no-properties a b)) ) > > (when (or (not (string-match > "[^[:blank:]]" line-cut)) (eolp)) > (pcase n > > (0 > (save-excursion (insert s)) > (comment-region a b)) > > ((or 1 2 3 4 5) > (delete-region a b) > (save-excursion (insert s)) > (comment-region a b)) > > (_ > (delete-region a b))) )) ) > > (defvar count 1) > > (defun insert-bifurcating-comment () > "Insert bifurcating line at cursor position" > (interactive) > > (let* ( (m 62) (n 69) > (lena (- m (current-column))) ; lena = m - (current-column) > (lenb (- n (current-column))) ) > > (pcase count > (0 > ;; makes s to be line with repeating ";" > (setq-local s (make-string lena ?\;)) ; repeats lena times > (insert-bifurcation s count) > (setq-local count 1)) > (1 > ;; makes s to be line with repeating ";" > (setq-local s (make-string lenb ?\;)) ; string length lenb > (insert-bifurcation s count) > (setq-local count 2)) > (2 > ;; makes s to be line with repeating "+" > (setq-local s (make-string lena ?+)) > (insert-bifurcation s count) > (setq-local count 3)) > (_ > ;; deactivates the bifurcating line > (insert-bifurcation s count) > (setq-local count 1)) )) ) > > > > > > > > Sent: Wednesday, May 19, 2021 at 10:17 AM > > From: "Jean Louis" <bugs@gnu.support> > > To: michael-franzese@gmx.com > > Cc: "Eric Abrahamsen" <eric@ericabrahamsen.net>, "Skip Montanaro" <skip.montanaro@gmail.com>, "Help Gnu Emacs" <help-gnu-emacs@gnu.org> > > Subject: Re: Determining existence of text following point > > > > * michael-franzese@gmx.com <michael-franzese@gmx.com> [2021-05-18 23:52]: > > > For instance, if the text in a commented string as follows, I will go ahead with > > > the insertion. > > > > > (defun my-insert-on-empty-end-of-line (s) > > (let ((line-cut (buffer-substring-no-properties (point) (line-end-position)))) > > (when (or (not (string-match "[^[:blank:]]" line-cut)) (eolp)) > > (insert s)))) > > > > (defun my-insert-on-empty-end-of-line (s) > > (let ((line-cut (buffer-substring-no-properties (point) (line-end-position)))) > > (when (or (not (string-match "[^+[:blank:];-]" line-cut)) (eolp)) > > (insert s)))) > > > > (defun my-insert () > > (interactive) > > (my-insert-on-empty-end-of-line "Hello")) > > > > (local-set-key (kbd "<f5>") 'my-insert) > > > > Line with blanks, works: > > ;; Hello > > > > Line with something else but our series of chars (does not work, expected): > > > > ;; █ abc > > > > Line with fancy stuff that we wish to include (works): > > > > ;; ;;;;;;;;;;;;;;;;Hello;;;;;;;;;;;;;;;;;;;;;; > > ;; +++++++++++++++++++++Hello+++++++++++++ > > ;; -------------------------Hello------Hello > > > > Weird other lines (it does not work, as it is so expected): > > > > ;; 𝓒𝓾𝓻𝓼𝓸𝓻 𝓲𝓼 𝓱𝓮𝓻𝓮: █ 𝓫𝓾𝓽 𝓲𝓼 𝓷𝓸𝓽 𝔀𝓸𝓻𝓴𝓲𝓷𝓰, 𝐄𝐗𝐏𝐄𝐂𝐓𝐄𝐃! > > > > > > -- > > Jean > > > > Take action in Free Software Foundation campaigns: > > https://www.fsf.org/campaigns > > > > Sign an open letter in support of Richard M. Stallman > > https://stallmansupport.org/ > > https://rms-support-letter.github.io/ > > > > > > > > ^ permalink raw reply [flat|nested] 37+ messages in thread
* Re: Determining existence of text following point 2021-05-19 7:28 ` michael-franzese 2021-05-19 8:05 ` michael-franzese @ 2021-05-19 10:23 ` Jean Louis 2021-05-19 10:32 ` michael-franzese 2021-05-19 12:31 ` michael-franzese 1 sibling, 2 replies; 37+ messages in thread From: Jean Louis @ 2021-05-19 10:23 UTC (permalink / raw) To: michael-franzese; +Cc: Eric Abrahamsen, Skip Montanaro, Help Gnu Emacs * michael-franzese@gmx.com <michael-franzese@gmx.com> [2021-05-19 10:29]: > Point will always be at the beginning of a comment on a separate line > > The "^" shows the position of the cursor. > > ^;; ;;;;;;;;;;;;;;;;;;;;;;;;;; > > ^;; +++++++++++++++++++++++++++ > > ^;; ---------------------------- > > I want to have a keybinding that if I continue to hit will change > a comment from > > ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; > > to > > ;; +++++++++++++++++++++++++++++++++++++ > > Currently I have the following code > > > (defun insert-bifurcation (s n) > "todo" > > (let* ( (a (point)) (b (line-end-position)) > (line-cut (buffer-substring-no-properties a b)) ) > > (when (or (not (string-match > "[^[:blank:]]" line-cut)) (eolp)) > (pcase n > > (0 > (save-excursion (insert s)) > (comment-region a b)) > > ((or 1 2 3 4 5) > (delete-region a b) > (save-excursion (insert s)) > (comment-region a b)) > > (_ > (delete-region a b))) )) ) > > (defvar count 1) > > (defun insert-bifurcating-comment () > "Insert bifurcating line at cursor position" > (interactive) > > (let* ( (m 62) (n 69) > (lena (- m (current-column))) ; lena = m - (current-column) > (lenb (- n (current-column))) ) > > (pcase count > (0 > ;; makes s to be line with repeating ";" > (setq-local s (make-string lena ?\;)) ; repeats lena times > (insert-bifurcation s count) > (setq-local count 1)) > (1 > ;; makes s to be line with repeating ";" > (setq-local s (make-string lenb ?\;)) ; string length lenb > (insert-bifurcation s count) > (setq-local count 2)) > (2 > ;; makes s to be line with repeating "+" > (setq-local s (make-string lena ?+)) > (insert-bifurcation s count) > (setq-local count 3)) > (_ > ;; deactivates the bifurcating line > (insert-bifurcation s count) > (setq-local count 1)) )) ) I am done and obfuscated now. ☺ -- Jean Take action in Free Software Foundation campaigns: https://www.fsf.org/campaigns Sign an open letter in support of Richard M. Stallman https://stallmansupport.org/ https://rms-support-letter.github.io/ ^ permalink raw reply [flat|nested] 37+ messages in thread
* Re: Determining existence of text following point 2021-05-19 10:23 ` Jean Louis @ 2021-05-19 10:32 ` michael-franzese 2021-05-19 12:31 ` michael-franzese 1 sibling, 0 replies; 37+ messages in thread From: michael-franzese @ 2021-05-19 10:32 UTC (permalink / raw) To: Jean Louis; +Cc: Eric Abrahamsen, Skip Montanaro, Help Gnu Emacs Currently the code inserts if the region is blank. But I have a keybinding to change from ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; to ;; ++++++++++++++++++++++++++++++++++++ > Sent: Wednesday, May 19, 2021 at 10:23 PM > From: "Jean Louis" <bugs@gnu.support> > To: michael-franzese@gmx.com > Cc: "Eric Abrahamsen" <eric@ericabrahamsen.net>, "Skip Montanaro" <skip.montanaro@gmail.com>, "Help Gnu Emacs" <help-gnu-emacs@gnu.org> > Subject: Re: Determining existence of text following point > > * michael-franzese@gmx.com <michael-franzese@gmx.com> [2021-05-19 10:29]: > > Point will always be at the beginning of a comment on a separate line > > > > The "^" shows the position of the cursor. > > > > ^;; ;;;;;;;;;;;;;;;;;;;;;;;;;; > > > > ^;; +++++++++++++++++++++++++++ > > > > ^;; ---------------------------- > > > > I want to have a keybinding that if I continue to hit will change > > a comment from > > > > ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; > > > > to > > > > ;; +++++++++++++++++++++++++++++++++++++ > > > > Currently I have the following code > > > > > > (defun insert-bifurcation (s n) > > "todo" > > > > (let* ( (a (point)) (b (line-end-position)) > > (line-cut (buffer-substring-no-properties a b)) ) > > > > (when (or (not (string-match > > "[^[:blank:]]" line-cut)) (eolp)) > > (pcase n > > > > (0 > > (save-excursion (insert s)) > > (comment-region a b)) > > > > ((or 1 2 3 4 5) > > (delete-region a b) > > (save-excursion (insert s)) > > (comment-region a b)) > > > > (_ > > (delete-region a b))) )) ) > > > > (defvar count 1) > > > > (defun insert-bifurcating-comment () > > "Insert bifurcating line at cursor position" > > (interactive) > > > > (let* ( (m 62) (n 69) > > (lena (- m (current-column))) ; lena = m - (current-column) > > (lenb (- n (current-column))) ) > > > > (pcase count > > (0 > > ;; makes s to be line with repeating ";" > > (setq-local s (make-string lena ?\;)) ; repeats lena times > > (insert-bifurcation s count) > > (setq-local count 1)) > > (1 > > ;; makes s to be line with repeating ";" > > (setq-local s (make-string lenb ?\;)) ; string length lenb > > (insert-bifurcation s count) > > (setq-local count 2)) > > (2 > > ;; makes s to be line with repeating "+" > > (setq-local s (make-string lena ?+)) > > (insert-bifurcation s count) > > (setq-local count 3)) > > (_ > > ;; deactivates the bifurcating line > > (insert-bifurcation s count) > > (setq-local count 1)) )) ) > > I am done and obfuscated now. ☺ > > > -- > Jean > > Take action in Free Software Foundation campaigns: > https://www.fsf.org/campaigns > > Sign an open letter in support of Richard M. Stallman > https://stallmansupport.org/ > https://rms-support-letter.github.io/ > > > ^ permalink raw reply [flat|nested] 37+ messages in thread
* Re: Determining existence of text following point 2021-05-19 10:23 ` Jean Louis 2021-05-19 10:32 ` michael-franzese @ 2021-05-19 12:31 ` michael-franzese 1 sibling, 0 replies; 37+ messages in thread From: michael-franzese @ 2021-05-19 12:31 UTC (permalink / raw) To: Jean Louis; +Cc: Eric Abrahamsen, Skip Montanaro, Help Gnu Emacs > I am done and obfuscated now. ☺ Will simplify. How can I detect a comment line composed of ";", "+", "-", or "." because I want to insert the string if I find the following lines First one is comment composed of ";", second one is comment composed of "+", and the rest are comments composed of "-" and ".". The comments could also start at any column. ;; ;;;;;;;;;;;;;;;;;;;;;;;;; ;; +++++++++++++++++++++++++++ ;; -------------------------- ;; ........................ > Sent: Wednesday, May 19, 2021 at 10:23 PM > From: "Jean Louis" <bugs@gnu.support> > To: michael-franzese@gmx.com > Cc: "Eric Abrahamsen" <eric@ericabrahamsen.net>, "Skip Montanaro" <skip.montanaro@gmail.com>, "Help Gnu Emacs" <help-gnu-emacs@gnu.org> > Subject: Re: Determining existence of text following point > > * michael-franzese@gmx.com <michael-franzese@gmx.com> [2021-05-19 10:29]: > > Point will always be at the beginning of a comment on a separate line > > > > The "^" shows the position of the cursor. > > > > ^;; ;;;;;;;;;;;;;;;;;;;;;;;;;; > > > > ^;; +++++++++++++++++++++++++++ > > > > ^;; ---------------------------- > > > > I want to have a keybinding that if I continue to hit will change > > a comment from > > > > ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; > > > > to > > > > ;; +++++++++++++++++++++++++++++++++++++ > > > > Currently I have the following code > > > > > > (defun insert-bifurcation (s n) > > "todo" > > > > (let* ( (a (point)) (b (line-end-position)) > > (line-cut (buffer-substring-no-properties a b)) ) > > > > (when (or (not (string-match > > "[^[:blank:]]" line-cut)) (eolp)) > > (pcase n > > > > (0 > > (save-excursion (insert s)) > > (comment-region a b)) > > > > ((or 1 2 3 4 5) > > (delete-region a b) > > (save-excursion (insert s)) > > (comment-region a b)) > > > > (_ > > (delete-region a b))) )) ) > > > > (defvar count 1) > > > > (defun insert-bifurcating-comment () > > "Insert bifurcating line at cursor position" > > (interactive) > > > > (let* ( (m 62) (n 69) > > (lena (- m (current-column))) ; lena = m - (current-column) > > (lenb (- n (current-column))) ) > > > > (pcase count > > (0 > > ;; makes s to be line with repeating ";" > > (setq-local s (make-string lena ?\;)) ; repeats lena times > > (insert-bifurcation s count) > > (setq-local count 1)) > > (1 > > ;; makes s to be line with repeating ";" > > (setq-local s (make-string lenb ?\;)) ; string length lenb > > (insert-bifurcation s count) > > (setq-local count 2)) > > (2 > > ;; makes s to be line with repeating "+" > > (setq-local s (make-string lena ?+)) > > (insert-bifurcation s count) > > (setq-local count 3)) > > (_ > > ;; deactivates the bifurcating line > > (insert-bifurcation s count) > > (setq-local count 1)) )) ) > > I am done and obfuscated now. ☺ > > > -- > Jean > > Take action in Free Software Foundation campaigns: > https://www.fsf.org/campaigns > > Sign an open letter in support of Richard M. Stallman > https://stallmansupport.org/ > https://rms-support-letter.github.io/ > > > ^ permalink raw reply [flat|nested] 37+ messages in thread
* Re: Determining existence of text following point 2021-05-17 23:05 ` Eric Abrahamsen 2021-05-17 23:15 ` michael-franzese @ 2021-05-17 23:53 ` michael-franzese 1 sibling, 0 replies; 37+ messages in thread From: michael-franzese @ 2021-05-17 23:53 UTC (permalink / raw) To: Eric Abrahamsen; +Cc: Skip Montanaro, Help Gnu Emacs I could use something based on the follewing (if (looking-at "[[:alnum:]]+") But I am quite unsure about the regexp. If there exists at least a character, I would not insert any text. > Sent: Tuesday, May 18, 2021 at 11:05 AM > From: "Eric Abrahamsen" <eric@ericabrahamsen.net> > To: michael-franzese@gmx.com > Cc: "Skip Montanaro" <skip.montanaro@gmail.com>, "Help Gnu Emacs" <help-gnu-emacs@gnu.org> > Subject: Re: Determining existence of text following point > > michael-franzese@gmx.com writes: > > > Would like to delete and insert a string "s" only if there is no text > > folloming point. > > > > (delete-region (point) (line-end-position)) > > (save-excursion (insert s)) > > There's a function for this: `eolp' > > Return t if point is at the end of a line. > ‘End of a line’ includes point being at the end of the buffer. > ^ permalink raw reply [flat|nested] 37+ messages in thread
* Re: Determining existence of text following point 2021-05-17 22:31 ` michael-franzese 2021-05-17 23:05 ` Eric Abrahamsen @ 2021-05-18 8:47 ` Jean Louis 1 sibling, 0 replies; 37+ messages in thread From: Jean Louis @ 2021-05-18 8:47 UTC (permalink / raw) To: michael-franzese; +Cc: Skip Montanaro, Help Gnu Emacs * michael-franzese@gmx.com <michael-franzese@gmx.com> [2021-05-18 01:32]: > Would like to delete and insert a string "s" only if there is no text > folloming point. > > (delete-region (point) (line-end-position)) > (save-excursion (insert s)) (defun my-insert-on-eol (s) (when (eolp) (insert s))) -- Jean Take action in Free Software Foundation campaigns: https://www.fsf.org/campaigns Sign an open letter in support of Richard M. Stallman https://stallmansupport.org/ https://rms-support-letter.github.io/ ^ permalink raw reply [flat|nested] 37+ messages in thread
end of thread, other threads:[~2021-05-19 12:31 UTC | newest] Thread overview: 37+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2021-05-17 21:46 Determining existence of text following point michael-franzese 2021-05-17 22:02 ` Skip Montanaro 2021-05-17 22:31 ` michael-franzese 2021-05-17 23:05 ` Eric Abrahamsen 2021-05-17 23:15 ` michael-franzese 2021-05-17 23:36 ` Skip Montanaro 2021-05-18 0:09 ` Eric Abrahamsen 2021-05-18 0:37 ` michael-franzese 2021-05-18 8:24 ` michael-franzese 2021-05-18 8:56 ` Jean Louis 2021-05-18 9:31 ` Christopher Dimech 2021-05-18 9:42 ` Jean Louis 2021-05-18 9:54 ` Jean Louis 2021-05-18 10:08 ` Christopher Dimech 2021-05-18 11:07 ` tomas 2021-05-18 11:26 ` Christopher Dimech 2021-05-18 11:56 ` Jean Louis 2021-05-18 12:23 ` Christopher Dimech 2021-05-18 12:35 ` tomas 2021-05-18 12:50 ` Christopher Dimech 2021-05-18 12:02 ` tomas 2021-05-18 12:15 ` Christopher Dimech 2021-05-18 12:27 ` tomas 2021-05-18 12:43 ` Christopher Dimech 2021-05-18 12:44 ` Jean Louis 2021-05-18 12:28 ` Christopher Dimech 2021-05-18 12:47 ` Jean Louis 2021-05-18 20:50 ` michael-franzese 2021-05-18 22:04 ` Jean Louis 2021-05-18 22:17 ` Jean Louis 2021-05-19 7:28 ` michael-franzese 2021-05-19 8:05 ` michael-franzese 2021-05-19 10:23 ` Jean Louis 2021-05-19 10:32 ` michael-franzese 2021-05-19 12:31 ` michael-franzese 2021-05-17 23:53 ` michael-franzese 2021-05-18 8:47 ` Jean Louis
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.