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

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

Re: elisp beginner's parens question ??


From: William Case
Subject: Re: elisp beginner's parens question ??
Date: Fri, 27 Apr 2007 09:58:10 -0400

Thanks Thi;

Just to finish off and share the answer with anyone else who is
interested ....

On Fri, 2007-04-27 at 11:59 +0200, Thien-Thi Nguyen wrote:
> () William Case <billlinux@rogers.com>
> () Thu, 26 Apr 2007 22:38:24 -0400
> 
>    What I was really asking was how the interpreter or emacs uses
>    parenthesis or how parenthesis are nested.  Put another way, I was
>    trying to develop for myself a minds eye view of how check-parens
>    works.
> 
> i share this desire, and did this to get a quick (10sec) overview:
> C-h f check-parens RET         ; what do you do?
> C-x o TAB                      ; where do you do it?
> RET                            ; how do you do it?
> [ogle ogle]
> 
> from this i see that one of the funcs called is `scan-sexps' and there
> is also some kind of error handling.
> 
>    Does check-parens just count left parens and compare that to the
>    number of right parens to find an error, or does it actually examine
>    nested parens pairs and work inword (or outward) ?
> 
> it uses `scan-sexps' and handles errors that `scan-sexps' throws.  
I chased down scan-sexps and this is what I got:

"scan-sexps is a built-in function.
(scan-sexps FROM COUNT)

Scan from character number FROM by COUNT balanced expressions.
If COUNT is negative, scan backwards.
Returns the character number of the position thus found.

Comments are ignored if `parse-sexp-ignore-comments' is non-nil.

If the beginning or end of (the accessible part of) the buffer is
reached
in the middle of a parenthetical grouping, an error is signaled.
If the beginning or end is reached between groupings
but before count is used up, nil is returned."

It seems that a given expression is scanned by'check-parens'.
'check-parens uses 'scan-sexps' (a builtin function) to couunt the
parens ( " " ()) established in the syntax table for a given mode.  If
the number of parens is even then scan-sexps returns nil, if the number
of parens is odd 'scan-exps' scans backwards checking for unbalanced
expressions.

Because 'scan-exps' is builtin, I don't have, or know how to look at,
its source code.  Therefore, I am unable to say how it goes about
checking for the position of the error on the backward scan.  It seems
to me, that that is the final piece needed for a full understanding.  I
have searched in info and googled the web looking for the source code
for 'scan-exps' and found nothing.  (That could just be a beginners lack
of correct search criteria.)


> these
> are things i didn't know before starting this message, and will probably
> forget a few moments after C-c C-c, but the method for re-knowing is
> what is important.  perhaps that is the mental tip you seek.

That is why I spend so much time chasing down how things work.  I find
that instead of just memorizing something (which for me is easily
forgettable) that if I can create a sensible mental image of what is
happening, I can then move a new fact from "memorized" to "known" and
its there in my head pretty much for good.

The mental tip I was looking for was perhaps there is a way to block out
all but one ))))) as I chase something down or a quick mental trick to
keep track of the parens for each sub expression as I check them one by
one.  The best answer I have come up with was hinted at by Robert D.
Crawford's response to this thread.  I have bound 'show-paren-mode' to
S-F4 to toggle 'show-paren-mode' on and off.  It helps me to visually
check each expression and sub-expression for balanced parens.

I have appreciated your help.

-- 
Regards Bill





reply via email to

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