From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: ken Newsgroups: gmane.emacs.help Subject: use of "match-string" Date: Tue, 08 Mar 2011 12:31:17 -0500 Message-ID: <4D7667E5.4070501@mousecar.com> Reply-To: gebser@mousecar.com NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Trace: dough.gmane.org 1299605541 18301 80.91.229.12 (8 Mar 2011 17:32:21 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Tue, 8 Mar 2011 17:32:21 +0000 (UTC) To: GNU Emacs List Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue Mar 08 18:32:17 2011 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Px0lX-0007IP-AG for geh-help-gnu-emacs@m.gmane.org; Tue, 08 Mar 2011 18:32:16 +0100 Original-Received: from localhost ([127.0.0.1]:48602 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Px0lN-0006pz-9F for geh-help-gnu-emacs@m.gmane.org; Tue, 08 Mar 2011 12:32:01 -0500 Original-Received: from [140.186.70.92] (port=42946 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Px0kn-0006oS-IZ for help-gnu-emacs@gnu.org; Tue, 08 Mar 2011 12:31:27 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Px0km-0006D7-1c for help-gnu-emacs@gnu.org; Tue, 08 Mar 2011 12:31:25 -0500 Original-Received: from mout.perfora.net ([74.208.4.194]:49688) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Px0kl-0006Cr-TN for help-gnu-emacs@gnu.org; Tue, 08 Mar 2011 12:31:24 -0500 Original-Received: from dellap.mousecar.net (dsl093-011-016.cle1.dsl.speakeasy.net [66.93.11.16]) by mrelay.perfora.net (node=mrus4) with ESMTP (Nemesis) id 0LrNcy-1Q6wqx30vs-012zve; Tue, 08 Mar 2011 12:31:21 -0500 User-Agent: Thunderbird 2.0.0.24 (X11/20101213) X-Enigmail-Version: 0.96.0 OpenPGP: id=5AD091E7 X-Provags-ID: V02:K0:7Nmy4IZSAnMgzcWhfQjwr6uRajT09XmkQHnK+3F+kdn H96C0OecMwWPXvUN5/UfJPqIujQS5LkEqWy8daKFAWkRSFIfh2 gkhaxZj9/YBkpnonPs7NzFwxwuqMezzSZD7ZT6eDY4nyTMsvmC yRXnaOMvcg6R7hRKkp7INoixAyZ8An39R6jvDzlPPnoClXOCYU 5Xv/8R0PNU2pqtbOCsmiO47Jkny86TZe00pfpIehYc= X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 74.208.4.194 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:79886 Archived-At: 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? tia. ;;; html-toc.el creates a table-of-contents on a html-document ;; Copyright (c) 2001 Rolf Rander N�ss ;; Author: Rolf Rander N�ss ;; Created: 17-Mar-2001 ;; Version: 0.3 ;; Keywords: html ;; X-URL: http://www.pvv.org/~rolfn/html-toc.el ;; This is free software; you can redistribute it and/or modify it ;; under the terms of the GNU General Public License as published by ;; the Free Software Foundation; either version 2, or (at your option) ;; any later version. This is distributed in the hope that it will be ;; useful, but without any warranty; without even the implied warranty ;; of merchantability or fitness for a particular purpose. See the ;; GNU General Public License for more details. You should have ;; received a copy of the GNU General Public License along with GNU ;; Emacs; see the file `COPYING'. If not, write to the Free Software ;; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA ;; 02111-1307, USA. ;; Brief users guide: ;; ;; This package will create a table-of-contents in a HTML-document ;; based on tags. The toc will be placed between the ;; strings defined by *toc-open* and *toc-close*. If these doesn't ;; exist, it will be placed right after . If no -tag ;; exists, it will be put right before the first header. ;; Known bugs: ;; ;; - strange things will happen if your headers aren't valid (lack a ;; close-tag), but in this case your page will also look strange in a ;; browser... (defvar html-toc-head-open "<[ \t\n]*[Hh]\\([1-3]\\)[^>]*>") (defvar html-toc-head-close "<[ \t\n]*/[ \t\n]*[Hh][1-3][ \t\n]*>") (defvar html-toc-a-name "") (defvar html-toc-open "") (defvar html-toc-close "") (defvar html-toc-body-open "<[ \t\n]*[Bb][Oo][Dd][Yy][ \t\n]*>") (defvar html-toc-list-open "
    ") (defvar html-toc-list-close "
") (defvar html-toc-list-item "
  • ") (defvar html-toc-name-pre "tocref") (defvar html-toc-title "Table of Contents") (defvar html-toc-tocref (concat "")) (defun html-toc-find-position () (goto-char (point-min)) (if (search-forward html-toc-open nil t) (let ((toc-start (point))) (if (search-forward html-toc-close nil t) (delete-region toc-start (match-beginning 0)) (insert html-toc-close)) (goto-char toc-start) (insert "\n")) (progn (goto-char (point-min)) (if (not (search-forward-regexp html-toc-body-open nil t)) (progn (goto-char (point-min)) (search-forward-regexp html-toc-head-open nil t) (goto-char (match-beginning 0)))) (insert html-toc-open "\n") (let ((p (point))) (insert html-toc-close "\n\n") (goto-char p))))) (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))) (defun html-toc-build () (let ((toc '()) (toc-cnt (html-toc-find-max))) (goto-char (point-min)) (while (search-forward-regexp html-toc-head-open nil t) (let* ((level (string-to-int (match-string 1))) (name (cond ((looking-at html-toc-a-name) (goto-char (match-end 0)) (match-string 1)) (t (let ((n (concat html-toc-name-pre (int-to-string toc-cnt)))) (insert "") (setq toc-cnt (1+ toc-cnt)) n)))) (head-start (point))) (search-forward-regexp html-toc-head-close nil t) (setq toc (cons (list level name (buffer-substring head-start (match-beginning 0))) toc)))) (nreverse toc))) (defun html-toc-aref (name text) (concat "" text "")) (defun html-toc-write-level (toc cur-level) (if toc (let* ((entry (car toc)) (level (car entry)) (name (cadr entry)) (text (cadr (cdr entry))) (rest (cdr toc))) (cond ((> level cur-level) (insert html-toc-list-open "\n") (setq rest (html-toc-write-level toc (1+ cur-level))) (insert html-toc-list-close "\n") (html-toc-write-level rest cur-level)) ((= level cur-level) (insert html-toc-list-item (html-toc-aref name text) "\n") (html-toc-write-level rest cur-level)) ((< level cur-level) toc))))) (defun html-toc-write (toc) (insert "

    " html-toc-title "

    \n") (html-toc-write-level toc 0)) (defun html-toc () (interactive) (save-excursion (html-toc-find-position) (let* ((toc-pos (point)) (toc (html-toc-build))) (goto-char toc-pos) (html-toc-write toc)))) (provide 'html-toc)