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

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

Re: use of "match-string"


From: PJ Weisberg
Subject: Re: use of "match-string"
Date: Tue, 8 Mar 2011 11:06:45 -0800

On Tue, Mar 8, 2011 at 9:31 AM, ken <gebser@mousecar.com> wrote:
>
> Part of this function doesn't make sense--
>
> (defun html-toc-find-max ()
>  (goto-char (point-min))
>  (let ((max-toc 0))
>    (while (search-forward-regexp html-toc-tocref nil t)
>      (if (> (string-to-int (match-string 1)) max-toc)
>          (setq max-toc (string-to-int (match-string 1)))))
>    (1+ max-toc)))
>
> -- specifically, where match-string is first called and turned into a
> number.  The docs say that match-string returns a string....  Yes, this
> can be done I suppose, but to what end?  Moreover, depending upon its
> value, this "number" may then be assigned to a variable, and that value
> then compared with subsequent strings.
>
> Perhaps I'm missing some nuance here.  The entirety of the code is
> below.  Does anyone understand what's going on here?

Maybe it would help if you looked at the value of the regexp that's
being matched.  The function html-toc-find-max does (almost) exactly
what it says it does: it finds the highest numbered section in the
table of contents, then returns that number plus one.

It's converting the strings to numbers because if it just compared the
strings alphabetically "25" would come before "3", etc.

-PJ



reply via email to

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