From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.bugs Subject: bug#61549: 30.0.50; [PATCH] New keyboard macro counter functions Date: Sat, 11 Mar 2023 10:49:27 +0200 Message-ID: <835yb7y8o8.fsf@gnu.org> References: <83sff41zgm.fsf@gnu.org> <83fsb2xhzp.fsf@gnu.org> Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="38286"; mail-complaints-to="usenet@ciao.gmane.io" Cc: larsi@gnus.org, monnier@iro.umontreal.ca, 61549@debbugs.gnu.org To: Alex Bochannek Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Mar 11 09:50:21 2023 Return-path: Envelope-to: geb-bug-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 1pauvl-0009jk-1l for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 11 Mar 2023 09:50:21 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pauvT-0006Ox-FE; Sat, 11 Mar 2023 03:50:03 -0500 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 1pauvS-0006On-4J for bug-gnu-emacs@gnu.org; Sat, 11 Mar 2023 03:50:02 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pauvR-0005Ks-RZ for bug-gnu-emacs@gnu.org; Sat, 11 Mar 2023 03:50:01 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1pauvR-0006Zr-O5 for bug-gnu-emacs@gnu.org; Sat, 11 Mar 2023 03:50:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 11 Mar 2023 08:50:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 61549 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 61549-submit@debbugs.gnu.org id=B61549.167852459325263 (code B ref 61549); Sat, 11 Mar 2023 08:50:01 +0000 Original-Received: (at 61549) by debbugs.gnu.org; 11 Mar 2023 08:49:53 +0000 Original-Received: from localhost ([127.0.0.1]:56514 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pauvI-0006ZM-D7 for submit@debbugs.gnu.org; Sat, 11 Mar 2023 03:49:52 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:48704) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pauvF-0006Z9-Td for 61549@debbugs.gnu.org; Sat, 11 Mar 2023 03:49:50 -0500 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pauv9-0005K0-Qw; Sat, 11 Mar 2023 03:49:43 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=356889eT8IXMLwUMkGT87udLLQRRjdz6FX8Z0KzZDV8=; b=n4oSl+yPQhTw VuWQMTmbNQXbzIbE74ez49h/TZQBUaXwQUOYOcFIFvUOvGgX3M+g9vacOzTfiQ6Po1gVc8rkIiYPP GW5laZmos2GwWQQx1XtnJplZwvU2VAFoJ7rb/NYBRFb4FqXWFFanpkr9ys8P+zIHvtLwn/5wK6+qz V4cCU69aInupoLMWlFNUfeHnUF9VvTRByDx171vE0a4IKglvZGpZ1ohFtettIXwy/kGnV2nceSEC5 rFW2lKkQk2Dz9nOUt369CiWsOtKWL9A/dRHFFw/p8smMPUYVLby+pH6O4kTaSQtcMNcmXgof/vtFr 8DK/3BCr2i19x4evZK7gLQ==; Original-Received: from [87.69.77.57] (helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pauv8-0006dZ-Rv; Sat, 11 Mar 2023 03:49:43 -0500 In-Reply-To: (message from Alex Bochannek on Sun, 05 Mar 2023 19:37:21 -0800) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:257764 Archived-At: > From: Alex Bochannek > Cc: monnier@iro.umontreal.ca, larsi@gnus.org, 61549@debbugs.gnu.org > Date: Sun, 05 Mar 2023 19:37:21 -0800 > > Took me a little bit longer to find time to do this and I now have > incorporated your feedback in the below patch. Thank you for your > perspective on prefix, that made a lot of sense and I reworked that part > of the code to be consistent with how it usually works. I was not aware > that the interactive code `p' defaults to 1 in the absence of a prefix. > I couldn't find a place where this is documented and it simplified the > code. > > I updated the docstrings as you suggested and even though checkdoc > complained about the lack of a period on the first line, I figured it's > better to keep below the line length limits. Thanks, a few more comments below. > Let me know if you would like to see any other changes, I always > appreciate constructive feedback! > > I am attaching the changes to: > kmacro.texi > kmacro.el > kmacro-tests.el > > The changelog as well as NEWS and emacs.texi remain the same from my > original message. Stefan and Lars didn't respond, and I tend to think there's no need to describe these functions in the Emacs user manual. So for the next iteration (which hopefully will be the last), please submit the patch without the changes in the manual. Also, please post all of the other changes, including NEWS and the commit log message (and mention the bug number in the latter). > +(defun kmacro-reg-add-counter-equal (&optional arg) > + "Increment `kmacro-counter' by ARG if the counter is equal to a > +register's value. The first line of a doc string must be a complete sentence. > +(defun kmacro-reg-add-counter-less (&optional arg) > + "Increment `kmacro-counter' by ARG if the counter is less than a > +register's value. Likewise here (and elsewhere in the patch). > +ARG is the numeric prefix argument that defaults to one." > + (interactive "p") > + (let > + ((register (register-read-with-preview "Compare counter to register: "))) > + (kmacro-reg-add-counter '< register arg))) > + > + > +(defun kmacro-reg-add-counter-greater (&optional arg) I noticed that you always leave 2 empty lines between functions. Is that intentional? We generally leave just one empty line. > +(defun kmacro-reg-add-counter (pred register arg) > + "Increment `kmacro-counter' by ARG if predicate PRED returns > +non-nil. > +PRED is called with two arguments: `kmacro-counter' and REGISTER." > + (let ((register-val (get-register register))) > + (when (apply pred (list kmacro-counter register-val)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ To avoid consing a list here, would it be better to use funcall instead of apply here? > +(defun kmacro-quit-counter (pred &optional arg) > + "Quit the keyboard macro if predicate PRED returns non-nil. > +PRED is called with two arguments: `kmacro-counter' and ARG." > + (when kmacro-initial-counter-value > + (setq kmacro-counter kmacro-initial-counter-value > + kmacro-initial-counter-value nil)) > + (let ((arg > + (cond ((null arg) 0) > + (t (prefix-numeric-value arg))))) > + (when (apply pred (list kmacro-counter arg)) > + (keyboard-quit)))) Likewise here.