help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Determining existence of text following point


From: Christopher Dimech
Subject: Re: Determining existence of text following point
Date: Tue, 18 May 2021 12:08:42 +0200

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/
> 
>



reply via email to

[Prev in Thread] Current Thread [Next in Thread]