From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: filebat Mark Newsgroups: gmane.emacs.help Subject: Re: Retrieve a web page into buffer and insert some text into it. Date: Sat, 31 Jul 2010 10:05:22 +0800 Message-ID: References: <4C504E73.6050207@mousecar.com> <4C50C15D.6000808@mousecar.com> <4C51DE14.2060102@mousecar.com> <4C52B62E.9060405@mousecar.com> <87sk30sxlg.fsf@mithlond.arda> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=000e0cd31284703b6e048ca5667f X-Trace: dough.gmane.org 1280541954 16461 80.91.229.12 (31 Jul 2010 02:05:54 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sat, 31 Jul 2010 02:05:54 +0000 (UTC) Cc: GNU Emacs List To: Teemu Likonen Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sat Jul 31 04:05:53 2010 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 1Of1ST-0006wT-16 for geh-help-gnu-emacs@m.gmane.org; Sat, 31 Jul 2010 04:05:53 +0200 Original-Received: from localhost ([127.0.0.1]:56731 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Of1SS-0000fd-9F for geh-help-gnu-emacs@m.gmane.org; Fri, 30 Jul 2010 22:05:52 -0400 Original-Received: from [140.186.70.92] (port=40618 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Of1S1-0000fY-Qz for help-gnu-emacs@gnu.org; Fri, 30 Jul 2010 22:05:26 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1Of1S0-0004XW-CM for help-gnu-emacs@gnu.org; Fri, 30 Jul 2010 22:05:25 -0400 Original-Received: from mail-pz0-f41.google.com ([209.85.210.41]:34391) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Of1S0-0004XJ-3d for help-gnu-emacs@gnu.org; Fri, 30 Jul 2010 22:05:24 -0400 Original-Received: by pzk33 with SMTP id 33so1487706pzk.0 for ; Fri, 30 Jul 2010 19:05:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:received:in-reply-to :references:date:message-id:subject:from:to:cc:content-type; bh=kuU8bbUuCl5M2hQFxnxLdsYUy0X9u2fq+OwEPUQ8dJg=; b=rbniH+BaWkeQIDUDnTfldx+9HeBIM9k9MN5FnR19ABtm4NEtM1nWVze6gqpp5VY6Uo gKR17OroO0JmzQU0t//W4sNHnQiF93hk9OIu8gJHA1prpzkqWkSMBOvrEO5BqzFe3wev 2lAOTuVf909572olR3FSzfwh64IJ3/5cgIBss= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; b=JyEV3U0ratKGD5ZtbbY6ipeGX7SqvUxkRhb2EbTskwi1r9X9d02uYFpQl+UrO8YK+j GNFiKIDiol7Pa8CBr7IAp/8rEThZBtTdtXhcNr29dhUzRJT7tp1QZlX0Yqr/6c3x9hv6 Zgx8M5NX5EmXjvMdDsxBIRYGOJPQZfPa7iKEY= Original-Received: by 10.142.143.8 with SMTP id q8mr727560wfd.153.1280541922965; Fri, 30 Jul 2010 19:05:22 -0700 (PDT) Original-Received: by 10.142.209.12 with HTTP; Fri, 30 Jul 2010 19:05:22 -0700 (PDT) In-Reply-To: <87sk30sxlg.fsf@mithlond.arda> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) 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:74363 Archived-At: --000e0cd31284703b6e048ca5667f Content-Type: text/plain; charset=ISO-8859-1 Thanks a lot, likonen for your suggestion. Agree, (let ((case-fold-search t)) is much safer than override global variable. I need to do more homework for lisp programming. ^-^ Regards, Denny On 7/31/10, Teemu Likonen wrote: > > * 2010-07-31 00:51 (+0800), filebat Mark wrote: > > > Does the below solve your problem? > > > I don't know but I'll comment your code in general. > > > > (defun match-web-body() > > (interactive) > > (setq case-fold-search t);;Make searches case insensitive > > (goto-char 0) > > (re-search-forward "\\(< *\n* *body\n* +fgcolor=\".*\" *\n*>\\)" nil t > 1) > > (setq match_str (match-string 1)) > > (message match_str) > > ) > > > If you want to set case-fold-search or other state-changing variable for > certain operation create a local binding for the variable, do not assign > new value to the existing binding. In other words, do not do this: > > > (setq case-fold-search t) > > (re-search-forward ...) > > Do this instead: > > (let ((case-fold-search t)) > (re-search-forward ...)) > > Also, do not introduce new global variables in functions like you did > here: > > > > (setq match_str (match-string 1)) > > (message match_str) > > > In that case there is no need for the variable at all. It could be > written like this: > > (message "%s" (match-string 1)) > > But even if you needed a variable you shouldn't introduce it with SETQ > but create a local binding with LET: > > (let ((match-str (match-string 1))) > (message "%s" match-str) > ;; Plus other uses of the variable > ) > > In short, keep things local. > -- Thanks & Regards Denny Zhang --000e0cd31284703b6e048ca5667f Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Thanks a lot, likonen for your suggestion.

Agree,=A0 (let ((case-fol= d-search t)) is much safer than override global variable.
I need to do m= ore homework for lisp programming. ^-^

Regards,
Denny

On 7/31/10, Teemu= Likonen <tlikonen@iki.fi>= wrote:
* 2010-07-31 00:51 (+0800), filebat Mark wrote:

> Does the belo= w solve your problem?


I don't know but I'll comment yo= ur code in general.


> (defun match-web-body()
>=A0= =A0 (interactive)
>=A0=A0=A0=A0(setq case-fold-search t);;Make searches case insensitive<= br> >=A0=A0=A0=A0(goto-char 0)
>=A0=A0=A0=A0(re-search-forward &q= uot;\\(< *\n* *body\n* +fgcolor=3D\".*\" *\n*>\\)" nil= t 1)
>=A0=A0=A0=A0(setq match_str (match-string 1))
>=A0=A0=A0=A0(message match_str)
> )


If you want to= set case-fold-search or other state-changing variable for
certain oper= ation create a local binding for the variable, do not assign
new value = to the existing binding. In other words, do not do this:


=A0=A0=A0=A0(setq case-fold-search t)

=A0=A0=A0=A0(re-sear= ch-forward ...)

Do this instead:

=A0=A0=A0=A0(let ((case-f= old-search t))
=A0=A0=A0=A0=A0=A0(re-search-forward ...))

Also,= do not introduce new global variables in functions like you did
here:


>=A0=A0=A0=A0(setq match_str (match-string 1))
&= gt;=A0=A0=A0=A0(message match_str)


In that case there is no ne= ed for the variable at all. It could be
written like this:

=A0= =A0=A0=A0(message "%s" (match-string 1))

But even if you needed a variable you shouldn't introduce it with= SETQ
but create a local binding with LET:

=A0=A0=A0=A0(let ((m= atch-str (match-string 1)))
=A0=A0=A0=A0=A0=A0(message "%s" ma= tch-str)
=A0=A0=A0=A0=A0=A0;; Plus other uses of the variable
=A0=A0=A0=A0=A0=A0)

In short, keep things local.
=


--
Thanks & Regards

Denny Zh= ang
--000e0cd31284703b6e048ca5667f--