From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Joshua Lambert Newsgroups: gmane.emacs.help Subject: Re: Iterating over buffer lines Date: Fri, 16 Jun 2023 22:28:45 -0500 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="40420"; mail-complaints-to="usenet@ciao.gmane.io" Cc: help-gnu-emacs@gnu.org To: Platon Pronko Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Sat Jun 17 05:29:41 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 1qAMdB-000AP1-7Z for geh-help-gnu-emacs@m.gmane-mx.org; Sat, 17 Jun 2023 05:29:41 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qAMce-0000W9-94; Fri, 16 Jun 2023 23:29:08 -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 1qAMcZ-0000Vd-Um for help-gnu-emacs@gnu.org; Fri, 16 Jun 2023 23:29:04 -0400 Original-Received: from mail-ed1-x535.google.com ([2a00:1450:4864:20::535]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qAMcU-0004TR-Of for help-gnu-emacs@gnu.org; Fri, 16 Jun 2023 23:29:00 -0400 Original-Received: by mail-ed1-x535.google.com with SMTP id 4fb4d7f45d1cf-51a2661614cso1907837a12.2 for ; Fri, 16 Jun 2023 20:28:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1686972537; x=1689564537; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=n3vY+Vh0yn/XV+4C8uOSMygxHGJ/DyvECiDpOy6CWk8=; b=Eh/Ricmzzbq7cZ0TLtTDv1zhmkpSHBUdL/d3s56MHg1pZs1TVmExa7NdxaA9z1ldpa 0g61BqZZaYYaCWOwlLe6zCtzojWmcsEv5eVutHMvm8MVuaaUvxExW/YGUwZq+VDhsJGt a8QNqRbb2EHhrCh7HiGA9MOTcVP+CKf+vo0LvatPWN4JC+JVzO6lS0qXz7k5MWvPQGQe aWzeHWf+QM8G/+jXMAy4r1At9NN53/8iDXyTtqwSzDWsuLO34b5mw7ijvcICdZ2etlND 0oE/JuJ7usfXDjUJxrZ7BLt5FbvZyvkpef/iQ6MZNHRapn4cBBm4zIwWtXRQTzNa53yi GTwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686972537; x=1689564537; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=n3vY+Vh0yn/XV+4C8uOSMygxHGJ/DyvECiDpOy6CWk8=; b=DHY/AhGMrakXz9ltpxq/cHy4zNYyTLhTMJDDX4k5udtxWahsMurKo5FNhpDH3JNIL7 UdAo0trZT71jOW/o9OyypCeogfNPGhgWKrYrdjyPlU7Ej2LfKdY2SWYcRPQC7WerSywo dEZNrGRy1lwcOnClw1Xg25fTNV0f40dECaq/FWyKikorIJdMZwgxDRLS/8trAzc+63Iu n9JsATnQIVAcW7UjRoluLJe72TpamZdWKzR7CWRDgRT+zx4p14l7HxDeYjcKA6LWprfu tZ74GJPln+isxf2NbpRYAvPNtNkB1ObeblOJhR4dwKfc1HRosbVKc1Az07CWqBi07lGS pZGg== X-Gm-Message-State: AC+VfDwqFTkcMK2fRcXEoWQl4PxytjemQ79Auf2XjdxVjY0X5JW4O2Gu HUw9a3EKUc4WoMSOxcg6mJ4LSPPR+/uHqfkPGTc= X-Google-Smtp-Source: ACHHUZ4zSB1JwKvK+L7UeUb9P1+SeMCCkvVWDxjYCs6Kt67F68C3+qQQIDic3SyVvWpFKlo0bhPzj+y8y9FcaBOn604= X-Received: by 2002:aa7:d304:0:b0:51a:2ea9:a313 with SMTP id p4-20020aa7d304000000b0051a2ea9a313mr2469196edq.26.1686972536425; Fri, 16 Jun 2023 20:28:56 -0700 (PDT) In-Reply-To: Received-SPF: pass client-ip=2a00:1450:4864:20::535; envelope-from=jlambert.lis.tech@gmail.com; helo=mail-ed1-x535.google.com 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, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, 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:143965 Archived-At: 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. (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) (forward-line))))) (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)) (defun some-function-to-correct-spacing (field-num) "Function that creates a correctly spaced string." ........ On Fri, Jun 16, 2023 at 7:10=E2=80=AFPM Platon Pronko wrote: > > On 2023-06-17 06:19, Joshua Lambert wrote: > > I have created some functions that make changes to one buffer line of > > a csv file. Let's call those functions a, b and c. Each of those take > > one or more arguments. I want to create a separate interactive > > function that does what function a, b, and c do, but on every line of > > the region. I successfully created a function (act-on-region-by-line) > > to go through all lines in a region and then call function a, function > > b, or function c. But, It seems redundant to have multiple functions > > that have 9-15 lines similar and one line different, the one that > > specifies function a, b or c. What is the best way to be efficient in > > this situation? > > > > I have attempted to pass function b as a parameter, but I am slow to > > understand how to do that. Is that the best way, or is there another? > > > > Thanks, > > J Lambert > > > > It's a bit difficult to understand what the problem is without seeing the= code. Can you show the code for your latest attempt? > > Yes, passing function as a parameter seems to be the best way. And partia= l function application might be useful here as well. > > -- > Best regards, > Platon Pronko > PGP 2A62D77A7A2CB94E >