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

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

Re: looking-at function behaviour


From: Pascal J. Bourguignon
Subject: Re: looking-at function behaviour
Date: Wed, 08 Dec 2010 15:12:06 -0000
User-agent: Gnus/5.101 (Gnus v5.10.10) Emacs/23.1 (gnu/linux)

Andrea Crotti <andrea.crotti.0@gmail.com> writes:

> I don't understand how I should use the looking-at function, from what I
> see in the doc is not what I see happening.
>
> --8<---------------cut here---------------start------------->8---
>  (when (not (looking-at closing-char))
>    (insert closing-char))
>  (newline-force))))
> --8<---------------cut here---------------end--------------->8---
>
> With this code I would like to
> - see if a char is before the end of line
> - insert it if not
>
> Is quite simple but it doesn't work.
> And even trying now on the fly
>
> (looking-at "a") ;; "a"
>
> Is anyway always nil,

You are lying!

(with-temp-buffer 
  (insert "cbacba")
  (goto-char (point-min))
  (let ((result '()))
    (while (< (point) (point-max))
     (push (looking-at "a") result)
     (forward-char 1))
    (reverse result)))

--> (nil nil t nil nil t)


To test it on the fly, you would have to move the cursor on a
character (a or b), and type:

M-: (looking-at "a") RET

and watch the result in the minibuffer.


>  how then am I supposed to do it given that this is
> the function which reading at the info page should be used?

Just do it.


-- 
__Pascal Bourguignon__                     http://www.informatimago.com/


reply via email to

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