From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Sven Garbade Newsgroups: gmane.emacs.help Subject: Re: replace-regexp in lisp function Date: Mon, 18 Jan 2010 15:06:39 +0100 Message-ID: <14f08d7e1001180606w26581a69u96eb1def8c7f25c7@mail.gmail.com> References: <87aawby3bk.fsf@lola.goethe.zz> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1263833041 7425 80.91.229.12 (18 Jan 2010 16:44:01 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 18 Jan 2010 16:44:01 +0000 (UTC) Cc: help-gnu-emacs@gnu.org To: David Kastrup Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon Jan 18 17:43: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.50) id 1NWuhf-0008Tg-BM for geh-help-gnu-emacs@m.gmane.org; Mon, 18 Jan 2010 17:43:47 +0100 Original-Received: from localhost ([127.0.0.1]:45814 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NWuhg-0007ZM-BE for geh-help-gnu-emacs@m.gmane.org; Mon, 18 Jan 2010 11:43:48 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NWsFl-00037U-NI for help-gnu-emacs@gnu.org; Mon, 18 Jan 2010 09:06:49 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NWsFg-00033G-40 for help-gnu-emacs@gnu.org; Mon, 18 Jan 2010 09:06:48 -0500 Original-Received: from [199.232.76.173] (port=60239 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NWsFf-00032v-N9 for help-gnu-emacs@gnu.org; Mon, 18 Jan 2010 09:06:43 -0500 Original-Received: from mail-ew0-f224.google.com ([209.85.219.224]:57940) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NWsFd-0003iN-K1; Mon, 18 Jan 2010 09:06:41 -0500 Original-Received: by ewy24 with SMTP id 24so3539086ewy.26 for ; Mon, 18 Jan 2010 06:06:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=6VcMQwRv2u65DdEOACJjWngH6kR9ApJpvU9eJ1hAoW4=; b=vv0tb0TSJ/i+nybYBUyQpvCeS67vbATM8v2xdp0GCzgCEVsN8S1v+PLLuSQ5nvmDLT oaiPRuzgfl4Y1ki5vvrWdfeh+zLLm5rWkeaT1fWxPQrMIkizU37ohmXqP1336aPOce+E Hbj5O+mgy5poTzcSaXsUy1gA6MOva/oDaXB9M= DomainKey-Signature: a=rsa-sha1; c=nofws; d=googlemail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; b=WpE1PGJtaFxAbQTwmP3J0YG3inqY1FgNAziYry2ud7b11ZGGhaOds5qmt0BNYUa3II wFWXJYizXArdHF16blWYDSr5kFPSUXNkhMeae9SzUWL2U/FC0CkHX0ar1bUvbP+qiEXa MP6F9FYvjcz6+4ezibdG5idZoD/AaUJNS+U/g= Original-Received: by 10.216.167.196 with SMTP id i46mr2005775wel.130.1263823599494; Mon, 18 Jan 2010 06:06:39 -0800 (PST) In-Reply-To: <87aawby3bk.fsf@lola.goethe.zz> X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 2) X-Mailman-Approved-At: Mon, 18 Jan 2010 11:42:31 -0500 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:71299 Archived-At: Hi, many thanks. C-x Esc Esc gave me: (query-replace-regexp "\\(<<\\)" (quote (replace-eval-replacement concat "\\1cn" (replace-quote (+ (line-number-at-pos) replace-count)) ",")) nil (if (and transient-mark-mode mark-active) (region-beginning)) (if (and transient-mark-mode mark-active) (region-end))) which works inside my function. Looks quite complicate for me... Are there any recommended documents / books for an elisp newbie? Thanks, Sven 2010/1/18 David Kastrup : > Sven Garbade writes: > >> Hallo List, >> >> I frequently use the following regular-regexp: >> >> M-x replace-regexp \(<<\) \1cn\,(+ (line-number-at-pos) \#) >> >> to replace "<<" with "<> >> ;; add chunk number >> (defun add-chunk-number () >> =C2=A0 (interactive) >> =C2=A0 (query-replace-regexp "\(<<\)" "\1cn\,(+ (line-number-at-pos) \#)= ") >> =C2=A0 ) >> >> to save typing, but this does not work. What did I wrong? > > Lisp string syntax needs additional quoting for regexps, and things like > \, and \# are not supported outside of interactive use. > > I recommend that you first give your command interactively, then use C-x > Esc Esc to get at the corresponding Lisp verbiage. > > -- > David Kastrup >