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: Robert D. Crawford
Subject: Re: elisp beginner's parens question ??
Date: Thu, 26 Apr 2007 21:58:31 -0500
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.98 (gnu/linux)

William Case <billlinux@rogers.com> writes:

> However, the "mental tips or tricks" was really a 'by the way' or an
> after thought question.  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.  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) ?

This might provide your answer.  If you do C-h f and supply a function
name, the resulting buffer, in X anyway, will have a link to the
function's definition.

(defun check-parens ()                  ; lame name?
  "Check for unbalanced parentheses in the current buffer.
More accurately, check the narrowed part of the buffer for unbalanced
expressions (\"sexps\") in general.  This is done according to the
current syntax table and will find unbalanced brackets or quotes as
appropriate.  (See Info node `(emacs)Parentheses'.)  If imbalance is
found, an error is signaled and point is left at the first unbalanced
character."
  (interactive)
  (condition-case data
      ;; Buffer can't have more than (point-max) sexps.
      (scan-sexps (point-min) (point-max))
    (scan-error (goto-char (nth 2 data))
                ;; Could print (nth 1 data), which is either
                ;; "Containing expression ends prematurely" or
                ;; "Unbalanced parentheses", but those may not be so
                ;; accurate/helpful, e.g. quotes may actually be
                ;; mismatched.
                (error "Unmatched bracket or quote"))
    (error (cond ((eq 'scan-error (car data))
                  (goto-char (nth 2 data))
                  (error "Unmatched bracket or quote"))
                 (t (signal (car data) (cdr data)))))))


-- 
Robert D. Crawford                                      rdc1x@comcast.net

If ignorance is bliss, why aren't there more happy people?


reply via email to

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