unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: PJ Weisberg <pj@irregularexpressions.net>
To: GNU Emacs List <help-gnu-emacs@gnu.org>
Subject: Re: use of "match-string"
Date: Tue, 8 Mar 2011 11:06:45 -0800	[thread overview]
Message-ID: <AANLkTimFUYoGJyytLvGH0JW7VJUxPgNMPVJrZw03cC7s@mail.gmail.com> (raw)
In-Reply-To: <4D7667E5.4070501@mousecar.com>

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	other threads:[~2011-03-08 19:06 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-03-08 17:31 use of "match-string" ken
2011-03-08 19:06 ` PJ Weisberg [this message]
2011-03-08 19:32   ` ken
     [not found] <mailman.2.1299605488.4046.help-gnu-emacs@gnu.org>
2011-03-08 21:36 ` Tim X
2011-03-08 23:48   ` ken

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=AANLkTimFUYoGJyytLvGH0JW7VJUxPgNMPVJrZw03cC7s@mail.gmail.com \
    --to=pj@irregularexpressions.net \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).