From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp12.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id mPRdFXJuAGL+TAAAgWs5BA (envelope-from ) for ; Mon, 07 Feb 2022 01:57:22 +0100 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp12.migadu.com with LMTPS id 2G7PEXJuAGJLiQAAauVa8A (envelope-from ) for ; Mon, 07 Feb 2022 01:57:22 +0100 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id DB44F3B976 for ; Mon, 7 Feb 2022 01:57:21 +0100 (CET) Received: from localhost ([::1]:59662 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nGsLI-0002Ka-Hd for larch@yhetil.org; Sun, 06 Feb 2022 19:57:20 -0500 Received: from eggs.gnu.org ([209.51.188.92]:52770) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nGsCg-0002Jt-RL for emacs-orgmode@gnu.org; Sun, 06 Feb 2022 19:48:30 -0500 Received: from ciao.gmane.io ([116.202.254.214]:38088) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nGsCd-0005wp-U5 for emacs-orgmode@gnu.org; Sun, 06 Feb 2022 19:48:26 -0500 Received: from list by ciao.gmane.io with local (Exim 4.92) (envelope-from ) id 1nGsCb-0007y3-CQ for emacs-orgmode@gnu.org; Mon, 07 Feb 2022 01:48:21 +0100 X-Injected-Via-Gmane: http://gmane.org/ To: emacs-orgmode@gnu.org From: Sacha Chua Subject: Re: [PATCH] org-list-send-item: allow dest to be a buffer position Date: Sun, 06 Feb 2022 19:48:13 -0500 Message-ID: <87k0e7a4du.fsf@sachachua.com> References: <87o83kaf3m.fsf@sachachua.com> <87o83kuxk3.fsf@localhost> Mime-Version: 1.0 Content-Type: text/plain User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux) Cancel-Lock: sha1:Su1rQvC6wxw5ax4CRyiMw95ZCBU= Received-SPF: pass client-ip=116.202.254.214; envelope-from=geo-emacs-orgmode@m.gmane-mx.org; helo=ciao.gmane.io X-Spam_score_int: -16 X-Spam_score: -1.7 X-Spam_bar: - X-Spam_report: (-1.7 / 5.0 requ) BAYES_00=-1.9, HEADER_FROM_DIFFERENT_DOMAINS=0.249, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Migadu-Flow: FLOW_IN X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1644195441; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=yVHUDjkkKlfBTuxReYh7hLzMMeueOYwkN9NmafmL2i8=; b=r+MHpR1kPRyCss5WQqlzdtwaKO5WLSentY4UwAzmB/V+1Y2XGHwj6HyW0wCccBMpa73ti/ TxU1cwjrh/SMvSwKKIrkObWZDrzBYaA0DHFg9QvSZ3k34LcJ2LeQ4TTx0FcCWEjQJ85RXU c4Nal5+XH25jRMR3HnME28Rqm4gayuROZjKrPEPnm4mmL2zeaaGbpja6BP9subugLjGkIf r4EtX/KXwjn7JMgVv8I7XeYCWZbeft5Jptl+69f3yAoQ+DQoFr/vSjWHYEV3iLqRY6gq4r +ETWlb+Z6FLB1TTz3HS+bcF8Red+PrZiutmYSjeAWCegMIvZYMZuRxGDrpVYpw== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1644195441; a=rsa-sha256; cv=none; b=pu3hrI5p+Hpl/LXu1svdFQIKycDrce65oiD/Sv4CEit/U/RZygWmpgIYzWBjdL0/pYQjpw PSzn+LefnCgc+HvhwtjZaoLam94CE+s/1Psae+g8NCNAvDh0BHRYZgXA8maO6XTR5g0U9E dksVt3mUsPqhHtJKUynXuBmx+ZIQRGbcgwkC4Mzr1wisz0hoBKBskn0jIDoOt+kdyQNZaM T+yTZbKr5CgnYrgp+L756sLncg7YwD5TojtBrIRd+yzPLTt6+SDUM+lUyyPPHGnzlltCQm l3heKG+ll8aUIJxnE3M4XBxHgTAqRobWiBGYvX/+e2io0z2TpMN6ixfjmBxvuw== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" X-Migadu-Spam-Score: -2.63 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" X-Migadu-Queue-Id: DB44F3B976 X-Spam-Score: -2.63 X-Migadu-Scanner: scn1.migadu.com X-TUID: V6jmMwKhlXqT Ihor Radchenko writes: >> Passing an integer representing a buffer position to org-list-send-item >> was failing because of the string-match-p, so here's something that lets >> integers skip that part. I have copyright assignment papers on file. > LGTM! Would you mind supplying a test for this function? Sure! Here's the new patch that includes the change and tests for the different kinds of input accepted by org-list-send-item. Sacha lisp/org-list.el: org-list-send-item: allow dest to be a buffer position * lisp/org-list.el (org-list-send-item): Check if dest is a string before matching it, to allow dest to be a buffer position. * testing/lisp/test-org-list.el (test-org-list/send-item): Add tests --- lisp/org-list.el | 2 +- testing/lisp/test-org-list.el | 64 +++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+), 1 deletion(-) diff --git a/lisp/org-list.el b/lisp/org-list.el index 3533c8319..f1ab2ca76 100644 --- a/lisp/org-list.el +++ b/lisp/org-list.el @@ -1442,7 +1442,7 @@ (defun org-list-send-item (item dest struct) (save-excursion (goto-char (org-list-get-last-item item struct prevs)) (point-at-eol))) - ((string-match-p "\\`[0-9]+\\'" dest) + ((and (stringp dest) (string-match-p "\\`[0-9]+\\'" dest)) (let* ((all (org-list-get-all-items item struct prevs)) (len (length all)) (index (mod (string-to-number dest) len))) diff --git a/testing/lisp/test-org-list.el b/testing/lisp/test-org-list.el index 3689a172f..e21409ca5 100644 --- a/testing/lisp/test-org-list.el +++ b/testing/lisp/test-org-list.el @@ -900,6 +900,70 @@ (ert-deftest test-org-list/insert-item () (org-insert-item) (buffer-string))))) +(ert-deftest test-org-list/send-item () + "Test `org-list-send-item' specifications." + ;; Move to beginning + (should + (equal "- item3\n- item1\n- item2\n" + (org-test-with-temp-text + "- item1\n- item2\n- item3\n" + (org-list-send-item (caar (last (org-list-struct))) + 'begin (org-list-struct)) + (buffer-string)))) + ;; Move to beginning with child item + (should + (equal "- item3\n - item4\n- item1\n- item2\n" + (org-test-with-temp-text + "- item1\n- item2\n- item3\n - item4\n" + (org-list-send-item (car (nth 2 (org-list-struct))) + 'begin (org-list-struct)) + (buffer-string)))) + ;; Move to end + (should + (equal "- item2\n- item3\n - item4\n- item1\n - item1child\n" + (org-test-with-temp-text + "- item1\n - item1child\n- item2\n- item3\n - item4\n" + (org-list-send-item (car (nth 0 (org-list-struct))) + 'end (org-list-struct)) + (buffer-string)))) + ;; Move to item number by string should move the item before the specified one + (should + (equal "- item2\n- item1\n - item1child\n- item3\n- item4\n- item5\n" + (org-test-with-temp-text + "- item1\n - item1child\n- item2\n- item3\n- item4\n- item5\n" + (org-list-send-item (car (nth 0 (org-list-struct))) + "3" (org-list-struct)) + (buffer-string)))) + ;; Move to item number by position should move the item before the specified one + (should + (equal "- item2\n- item1\n - item1child\n- item3\n- item4\n- item5\n" + (org-test-with-temp-text + "- item1\n - item1child\n- item2\n- item3\n- item4\n- item5\n" + (re-search-forward "item3") + (org-list-send-item (car (nth 0 (org-list-struct))) + (point-at-bol) (org-list-struct)) + (buffer-string)))) + ;; Delete + (should + (equal "- item1\n - item1child\n- item2\n- item4\n- item5\n" + (org-test-with-temp-text + "- item1\n - item1child\n- item2\n- item3\n- item4\n- item5\n" + (re-search-forward "item3") + (org-list-send-item (point-at-bol) + 'delete (org-list-struct)) + (buffer-string)))) + ;; Kill + (let ((kill-ring nil)) + (org-test-with-temp-text + "- item1\n - item1child\n- item2\n- item3\n - item3child\n- item4\n- item5\n" + (re-search-forward "item3") + (org-list-send-item (point-at-bol) + 'kill (org-list-struct)) + (should (equal "- item1\n - item1child\n- item2\n- item4\n- item5\n" + (buffer-string))) + (should (equal "item3\n - item3child" + (current-kill 0 t)))))) + (ert-deftest test-org-list/repair () "Test `org-list-repair' specifications." ;; Repair indentation. -- 2.25.1