From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Kendall Shaw Newsgroups: gmane.emacs.help Subject: Re: help with regexp function Date: Wed, 22 Nov 2017 09:05:53 -0800 Message-ID: <640a2442-163b-2b1d-8fe9-a5a81501cb68@kendallshaw.com> References: NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: quoted-printable X-Trace: blaine.gmane.org 1511370425 31898 195.159.176.226 (22 Nov 2017 17:07:05 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Wed, 22 Nov 2017 17:07:05 +0000 (UTC) User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed Nov 22 18:06:56 2017 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eHYUA-0007bw-Pl for geh-help-gnu-emacs@m.gmane.org; Wed, 22 Nov 2017 18:06:54 +0100 Original-Received: from localhost ([::1]:40564 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eHYUI-0004nG-2A for geh-help-gnu-emacs@m.gmane.org; Wed, 22 Nov 2017 12:07:02 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:58611) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eHYTP-0004kp-M9 for help-gnu-emacs@gnu.org; Wed, 22 Nov 2017 12:06:11 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eHYTK-0002sj-2S for help-gnu-emacs@gnu.org; Wed, 22 Nov 2017 12:06:07 -0500 Original-Received: from c.mail.sonic.net ([64.142.111.80]:56854) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eHYTJ-0002pT-Pn for help-gnu-emacs@gnu.org; Wed, 22 Nov 2017 12:06:02 -0500 Original-Received: from [192.168.1.73] (108-64-77-57.lightspeed.sntcca.sbcglobal.net [108.64.77.57]) (authenticated bits=0) by c.mail.sonic.net (8.15.1/8.15.1) with ESMTPSA id vAMH5rxF003382 (version=TLSv1.2 cipher=DHE-RSA-AES128-SHA bits=128 verify=NOT) for ; Wed, 22 Nov 2017 09:05:53 -0800 In-Reply-To: Content-Language: en-US X-Sonic-CAuth: UmFuZG9tSVZL8w54WvjEPBvE1iR9fDSQsIOoj6wCMUxFqnkFsuHS0U5FJDycdH+7+R9AmyXP6PnX/pw6C75HrUc3zA1Yjois X-Sonic-ID: C;+KX6ZafP5xGG8esnWtmBlw== M;YrAmZqfP5xGG8esnWtmBlw== X-Sonic-Spam-Details: 0.0/5.0 by cerberusd X-MIME-Autoconverted: from 8bit to quoted-printable by c.mail.sonic.net id vAMH5rxF003382 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 64.142.111.80 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.org gmane.emacs.help:115053 Archived-At: On 11/21/2017 03:30 PM, B. T. Raven wrote: > Dear Emacs gurus: > > I can perform this inteactive substitution > CM-%: \(^[0-9]+ \)\(.+\) -> \2 \1) > in order to change a buffer line prefixed with a number into one=20 > post-fixed with the same number but I can't figue out how to do the=20 > same programatically to a whole region. I started with this code: > > (defun verse-num-move-beg-to-end (beg end) > "Move int-string and following space from beginning of line to end of=20 > line throughout region." > (interactive "r") > (goto-char beg) > (while (<=3D (point) end) > =C2=A0=C2=A0 (re-search-forward "^[0-9]+ ") > =C2=A0=C2=A0 (setq num (substring (match-string 0) 0 -1)) ;; should be = a string=20 > of ;;digits without trailing space > =C2=A0=C2=A0 (print num) > > ;; here the value generates a wrong argument error: > setq: Wrong type argument: listp, #("234" 0 3 (fontified t)) > (type-of=C2=A0 #("234" 0 3 (fontified t))) > > ;; I have a function which is a black box to to me but it works in the=20 > larger context I have it in. Does match-string do something like this=20 > implicitly (casting a list as a string?) > ... > (substring (match-string 0) 0 -1) > (replace-match "" nil t) > > > 234 asentuhasneothu ;; example buffer-line=20 re-search-forward signals an error if the search string isn't matched. I=20 don't know if that could explain the error you are seeing, but this=20 would prevent a non-local exit: (cond =C2=A0 ((re-search-forward "^[0-9]+ " nil t) =C2=A0=C2=A0 (setq num ...) =C2=A0=C2=A0 (print num)) =C2=A0 (t =C2=A0=C2=A0 (goto-char end))) Kendall