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: ken
Subject: Re: use of "match-string"
Date: Tue, 08 Mar 2011 14:32:20 -0500
User-agent: Thunderbird 2.0.0.24 (X11/20101213)

Thanks, PJ.  You're right.  The parens are pulling out just the numbers
and so the comparison isn't looking at the whole string searched for.
Totally clear now.


On 03/08/2011 02:06 PM PJ Weisberg wrote:
> On Tue, Mar 8, 2011 at 9:31 AM, ken <address@hidden> 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]