From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Newsgroups: gmane.emacs.help Subject: Re: Iterating over buffer lines Date: Sat, 17 Jun 2023 06:48:24 +0200 Message-ID: References: Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="Sx2qJyKZa2Qo2jCk" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="14758"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Platon Pronko , help-gnu-emacs@gnu.org To: Joshua Lambert Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Sat Jun 17 06:50:13 2023 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1qANt7-0003ZN-HG for geh-help-gnu-emacs@m.gmane-mx.org; Sat, 17 Jun 2023 06:50:13 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qANrf-0002i8-4H; Sat, 17 Jun 2023 00:48:43 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qANrd-0002hg-Av for help-gnu-emacs@gnu.org; Sat, 17 Jun 2023 00:48:41 -0400 Original-Received: from mail.tuxteam.de ([5.199.139.25]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qANrZ-0007mf-Iq for help-gnu-emacs@gnu.org; Sat, 17 Jun 2023 00:48:41 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tuxteam.de; s=mail; h=From:In-Reply-To:Content-Type:MIME-Version:References:Message-ID: Subject:Cc:To:Date:Sender:Reply-To:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=Ue32KWQdN9QhbfMWetpm4RbCGzsclyscOVex0I2bcGI=; b=b/d4O0XrA5m6Yds5X+uutSGTcx 708djKACoWOMFymwE+Tv4WOt3gx5Y/dVRTmhyl/BNDlbzCPtseCOLBgDmbGxus9ZkZ9Tzjfg79/xH ZWHjnObcAAVc4lmgloLQKfX8ivvf5jN8/eDmVymsgDF+FKEL5shEScoft8n0Be5/bJ0AQCIOMShx5 zBnaomWgyDebkE1OTAHnNczZvr4iIG7xbtCZWqejYWdY+WRVBX1VCahilCHf7YemAiL81jzQ3cA4J IZicn7rC2gPeN5oP09W4WewnsFkqOK7jSKl0OlF/16YXd8p2k85YhGAsXYTel8Xr/5/Qvl0V+ZVP8 Swp8+l1g==; Original-Received: from tomas by mail.tuxteam.de with local (Exim 4.94.2) (envelope-from ) id 1qANrM-0005Wj-NO; Sat, 17 Jun 2023 06:48:24 +0200 Content-Disposition: inline In-Reply-To: Received-SPF: pass client-ip=5.199.139.25; envelope-from=tomas@tuxteam.de; helo=mail.tuxteam.de X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.29 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-mx.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.help:143966 Archived-At: --Sx2qJyKZa2Qo2jCk Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Jun 16, 2023 at 10:28:45PM -0500, Joshua Lambert wrote: > OK. See below. I'm trying to avoid reusing most of the code in > function my-act-on-region-by-line. There are multiple functions that > correct data errors in a csv file and I want to be able to > interactively run one of those corrections at a time. The resulting > string will be inserted at the beginning of each line. That all works, > I'm just trying not to have so much code repetition. >=20 > (defun my-act-on-region-by-line (some-function &optional beg end) > "Perform a function on the current line or each line of the region. > Each SOME-FUNCTION must return a string." > (let ((beg2 (if (region-active-p) > beg > (line-beginning-position))) > (end2 (if (region-active-p) > end > (line-end-position)))) > (save-excursion > (save-restriction > (narrow-to-region beg2 end2) > (goto-char (point-min)) > (while (not (eobp)) > (goto-char (line-beginning-position)) > (insert some-chosen-function) ;; Inserts text after a > function transforms it. > (insert my-separator) The above means that you are inserting stuff at the beginning of the current line, right? > (forward-line))))) =2E.. and this assumes that your `some-chosen-function' doesn't mess "too much" with point. >=20 > (defun my-paste-corrected-spacing (&optional field-num beg end) > "Correct spacing in a string and paste it at the beginning of a line. > Interactively, BEG and END are the region." > (interactive "*p\nr") > (my-act-on-region-by-line (some-function-to-correct-spacing field-num) > beg > end)) >=20 > (defun some-function-to-correct-spacing (field-num) > "Function that creates a correctly spaced string." > ........ I can't /see/ it, but I have a hunch that this function expects to /replace/ the line by something else. The was it is called above, its result is /inserted/ in front of the line in question, right? Perhaps it's clear to you, but if yes, it doesn't come across: what is the exact interface between your outer function and the one called by it? I.e.: do you need to (save-excursion ...) around `some-chosen-function'? What do you do with its result? That kind of things. Cheers --=20 t --Sx2qJyKZa2Qo2jCk Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iF0EABECAB0WIQRp53liolZD6iXhAoIFyCz1etHaRgUCZI07EgAKCRAFyCz1etHa Ri32AJ9GVKjMd2S8coKVP02+uAsISN7UsACaAlEMC/UxhD6y5euFiKAWc3qPI/E= =jZeq -----END PGP SIGNATURE----- --Sx2qJyKZa2Qo2jCk--