From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0 ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id RBpKFQfam2AADAAAgWs5BA (envelope-from ) for ; Wed, 12 May 2021 15:37:11 +0200 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0 with LMTPS id oF9jEAfam2CkKgAA1q6Kng (envelope-from ) for ; Wed, 12 May 2021 13:37:11 +0000 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 78B90140B9 for ; Wed, 12 May 2021 15:37:10 +0200 (CEST) Received: from localhost ([::1]:57696 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lgp2z-0000uR-M8 for larch@yhetil.org; Wed, 12 May 2021 09:37:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50364) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lgp2R-0000uA-R9 for emacs-orgmode@gnu.org; Wed, 12 May 2021 09:36:35 -0400 Received: from mail-wm1-x331.google.com ([2a00:1450:4864:20::331]:46074) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lgp2P-0004SW-F3 for emacs-orgmode@gnu.org; Wed, 12 May 2021 09:36:35 -0400 Received: by mail-wm1-x331.google.com with SMTP id s5-20020a7bc0c50000b0290147d0c21c51so3067421wmh.4 for ; Wed, 12 May 2021 06:36:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=EewTogwtUZxqwODmY8EQU5R19WjKqyxs5M0hEIj+eDE=; b=RDTn56ANWJxzDEKiAb7q9V8Iqw1EyiVyzn2YnEcSx82RIzpj1C5XESDGXFqc3gtlMt NBPVW1NAWA/auAf+k+TP2rpSRwFprWy0ORM+kG+3feLVUTLyivT23yRa3FxN8/cjP1+V 3lMp23D6bhmat97SfaSi5cl6ZGGkdKEKl0Ya/ySba4lL8vz6qvO1m21TI8zVhd3+HbYL +Q6Acc84eXuPEM6yGTebLxZyjSKD95WP0Jm4ztE22g7ae5WpHF69kLmyWtKKTQ6o1qqK zhcJkRse/VqutVRZr9Qk6TnGP8U87csIUtVQvxlPEmCwyW6GtU3E4fhceEz0S7O8GJQm 90Fg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=EewTogwtUZxqwODmY8EQU5R19WjKqyxs5M0hEIj+eDE=; b=ItxEQ2Hqm0sFrdsMF3hce28RTnSFyDpcUUSKcx9/DWlfA0meZg35yg/E8y4pL/IyIy GVyz5MmKHzV/dv9uCQP2p0aVTJeR31r/8WoqMfeZJrRs4Z8HlxzshJrlz1zVATJdFmqk PYIYIO1J0nzdJzQ+x2VhEH2LtoZZ1GE3aQwalfYknTfSSLizf6QiObxbJ5l0qdAjePI7 t43NnSk65K1lUXPtVRRCMCktUhmm1byCaOydPffd7BU2Za+me8X+yFvAmO7Dvyb7KcYg Que1NqHtlAjbVV2z3H27mGbrtXeOY9tk8DfyRJ2q8N+el6uI9dTlOozDw4dNcsAOJggj VhLQ== X-Gm-Message-State: AOAM531aU+3XBPO5h5jH+OeylSROnouFTuHDuKVwmWOrpjIK4h0cpAKo F9zCHcXzMagmvHfmChnAlrF4b4y/xYDbz9DRnkjgtsApZxpeYQ== X-Google-Smtp-Source: ABdhPJwwEdQRo0shTVRc6J/gJNBmJBlUh1gQZeUU55nirIQ5CeHj10nlhHGBaZLIjMlDnJFp8L6JFbAm7+/ywoK2uOc= X-Received: by 2002:a7b:c34a:: with SMTP id l10mr39342345wmj.46.1620826590805; Wed, 12 May 2021 06:36:30 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Tim Visher Date: Wed, 12 May 2021 09:35:54 -0400 Message-ID: Subject: Re: Refiling All 'Terminal TODO State' Entries to a Particular Heading To: Emacs Org Mode mailing list Content-Type: multipart/alternative; boundary="00000000000030025505c2221966" Received-SPF: pass client-ip=2a00:1450:4864:20::331; envelope-from=tim.visher@gmail.com; helo=mail-wm1-x331.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, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.23 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 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1620826630; 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:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=EewTogwtUZxqwODmY8EQU5R19WjKqyxs5M0hEIj+eDE=; b=gUhwDcyLVQzrkY/iChhKgIf71pJGC/yEwOo51qKCts8bDlwxethHntJu78Hz291amzsfTL bAIyKaZdK4pDlwcvAF6efEaUMtYlUKJGHARI/hiXLn07GtvaaQQFOmF5wcU/3iosOHAiiW tUhTDFK/q83dMiJa8rLCeVovtm+1ti9rO6gQgp+XwbBNBWhuolDhz33/CxmSudQRJSttSp qKmWNJAnyUqWW2dSOKc+T7pQm26Rn/XnHMg9oJYhvC+4YHfQLfqGccljGBrGvYQfXx55Ys briGAhsYpuNcokPoe1Nk7WWs1v0kCNyEH3O5gP4c/37FEvrltwocwQUiwYz07A== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1620826630; a=rsa-sha256; cv=none; b=UGgnSCQzppGz1/zfBSKsfLe0Qt1uNCTdPNbMda8wdGb3FVXJjBN9JYhdRTcyHQpRWHXpwI bC2+spGE2OBR3fhV4jqNXD/F9YePKnOY16yB/kHlNoqoDhngb8rnQmRV43avrBJDZMjbX9 ek5UKHh4LSvjw+gKlfi0oOjfZD9Sj4pPoPqUrP+1U9ZYWgnztxJLSbksEcZ/iihOvkEFMl +8mgfZuUmNaRbqy46sZQbcj/YFo/kvKo5OGUAhgMJfL3PFMGuZjXL4Zik+De0x2v7Mqens OjmM9wiTrvFqjbBq4Ulpjz3m49UzrXh48KiRiPIxviPcsGp8MLXi0cYsXhn4nw== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20161025 header.b=RDTn56AN; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (aspmx1.migadu.com: domain of emacs-orgmode-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=emacs-orgmode-bounces@gnu.org X-Migadu-Spam-Score: -3.15 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20161025 header.b=RDTn56AN; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (aspmx1.migadu.com: domain of emacs-orgmode-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=emacs-orgmode-bounces@gnu.org X-Migadu-Queue-Id: 78B90140B9 X-Spam-Score: -3.15 X-Migadu-Scanner: scn0.migadu.com X-TUID: aFQFxeml70rK --00000000000030025505c2221966 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi Everyone, I found that my timvisher-org-refile-done-entries had a bug where it could skip entries if the org buffer had consecutive DONE/CANCELLED entries. I believe this is because of this quote from the manual: After evaluation, Org moves point to the end of the line that was just processed. Search continues from that point forward. This may not always work as expected under some conditions, such as if the current sub-tree was removed by a previous archiving operation. In such rare circumstances, Org skips the next entry entirely when it should not. To stop Org from such skips, make FUNC set the variable =E2=80=98org-map-continue-from=E2=80=99 t= o a specific buffer position. I've been doing some experimentation around how to fix this: Attempt 1 This feels like the simplest and most naive approach: (defun timvisher-org-refile-done-entry-position () (save-excursion (goto-char (point-min)) (- (re-search-forward "^\\* Done") 6))) (defun timvisher-org-refile-done-entry () (org-refile nil (current-buffer) (list "* Done" (buffer-file-name) nil (timvisher-org-refile-done-entry-position)))) (defun timvisher-org-refile-done-entries () (interactive) (while (< 0 (length (org-map-entries #'timvisher-org-refile-done-entry "LEVEL=3D2/+DONE|+CANCELLED" nil 'archive))))) Here we're literally just doing the org-map-entries operation forever until the operation finds nothing to operate on. I worry about infinite loops and all that here though. It also just seems, well, a little brute force. Attempt 2 (defun timvisher-org-refile-done-entry (point) (let ((done-entry-position (timvisher-org-refile-done-entry-position))) (when (< done-entry-position point) (error (concat "Refile target at %d is located after the Done " "entry at %d. Move the Done entry to the bottom " "of the file.") point done-entry-position)) (goto-char point) (org-refile nil (current-buffer) (list "* Done" (buffer-file-name) nil (timvisher-org-refile-done-entry-position))))) (defun timvisher-org-refile-done-entries () (interactive) (seq-map #'timvisher-org-refile-done-entry (reverse (org-map-entries #'point "LEVEL=3D2/+DONE|+CANCELLED" nil 'archive)))) Here we're recognizing that if we could process the entries in reverse then we'd never have to worry about an entry moving from underneath us as we refile. This also seems silly: 1. I'm sure there's a function already that just returns me the matching entries for a given match search. Using the mapping API for seems incorr= ect. 2. It requires that the Done entry be below all possible targets which I'd rather not require. My Done entry is typically above my deferred entries and I want to be able to mark deferred entries as cancelled or d= one and have this work properly. Overall I actually like this attempt less than the first one. Attempt 3 I'm convinced that there must be something I can do with the org-map-continue-from var but I'm having a lot of trouble grokking how to use it properly. My initial attempt looks like this: (defun timvisher-org-refile-done-entry () (let ((entry-begin-point (point))) (org-refile nil (current-buffer) (list "* Done" (buffer-file-name) nil (timvisher-org-refile-done-entry-position))) (setq org-map-continue-from entry-begin-point))) (defun timvisher-org-refile-done-entries () (interactive) (org-map-entries #'timvisher-org-refile-done-entry "LEVEL=3D2/+DONE|+CANCELLED" nil 'archive)) The idea being that if I do in fact refile an entry I'd actually like the 'search to continue' from where it just was. This 'works' in that it successfully refiles all the entries even if they're consecutive but it also manages to get into an infinite loop because, AFAICT, it ignores the 'archive skipping somehow. I've spent some time in the debugger and I can't figure out yet why it does that. Any tips on how I might use this variable to achieve my goals? Thanks in advance! -- In Christ, Timmy V. https://blog.twonegatives.com http://five.sentenc.es --00000000000030025505c2221966 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Hi Everyone,

I= found that my=C2=A0timvisher-org-refile-done-entries=C2=A0had= a bug where it could skip entries if the org buffer had consecutive=C2=A0<= code>DONE/CANCELLED=C2=A0entries. I believe this is because of this = quote from the manual:

After evaluation, Org moves point to the end of the line th= at was just processed. Search continues from that point forward. This may n= ot always work as expected under some conditions, such as if the current su= b-tree was removed by a previous archiving operation. In such rare circumst= ances, Org skips the next entry entirely when it should not. To stop Org fr= om such skips, make FUNC set the variable =E2=80=98org-map-continue-from=E2= =80=99 to a specific buffer position.

I've been doing some experimentation ar= ound how to fix this:

Attempt 1

This feels like the simplest and most naiv= e approach:

(defun timvisher-org-refile-done=
-entry-position
    ()
  (save-excursion
    (goto-char (point-min))
    (- (re-search-forward "^\\* D=
one") 6)))

(defun timvisher-org-refile-done-entry
    ()
  (org-refile nil
              (current-buffer)
              (list "* Done"=

                    (buffer-file-name)
                    nil
                    (timvisher-org-refile-done-entry-position))))

(defun timvisher-org-refile-done-entries
    ()
  (interactive)
  (while (< 0 (length (org-=
map-entries #'timvisher-org-refile-done-entry
                                       "LEVEL=3D2/+DONE|+CANCELLED"
                                       nil
                                       'archive)))))

Here we're literally just doing the=C2=A0org-map-e= ntries=C2=A0operation forever until the operation finds nothing to o= perate on.

I worry about infinite loops and all that here though. It = also just seems, well, a little brute force.

Attempt 2

=
(defun timvisher-org-refile-done-entry
    (point)
  (let ((done-entry-position (=
timvisher-org-refile-done-entry-position)))
    (when (< done-entry-pos=
ition point)
      (error (co=
ncat "Refile target at %d is loca=
ted after the Done "
                     "entry at %d=
. Move the Done entry to the bottom "
                     "of the file=
.")
             point
             done-entry-position))
    (goto-char point)
    (org-refile nil
                (current-buffer)
                (list "* Done&quo=
t;
                      (buffer-file-name)
                      nil
                      (timvisher-org-refile-done-entry-position)))))

(defun timvisher-org-refile-done-entries
    ()
  (interactive)
  (seq-map #'timvisher-org-refile-done-entry
           (reverse (org-map-entries #'point
                                     &=
quot;LEVEL=3D2/+DONE|+CANCELLED"
                                     nil
                                     'archive))))

Here we're recognizing that if we could process the entr= ies in reverse then we'd never have to worry about an entry moving from= underneath us as we refile.

This also seems silly:

  1. I'm sure there's a function already that just retu= rns me the matching entries for a given match search. Using the mapping API= for seems incorrect.
  2. It requires that the=C2=A0Done= =C2=A0entry be below all possible targets which I'd rather not require.= My Done entry is typically above my deferred entries and I want to be able= to mark deferred entries as cancelled or done and have this work properly.=

Overall I actually like this attempt less than the first one.<= /p>

Attempt 3

I'm convinced that there must be something I can= do with the=C2=A0org-map-continue-from=C2=A0var but I'm h= aving a lot of trouble grokking how to use it properly.

My initial at= tempt looks like this:

(defun timvisher-org-=
refile-done-entry
    ()
  (let ((entry-begin-point (po=
int)))
    (org-refile nil
                (current-buffer)
                (list "* Done&quo=
t;
                      (buffer-file-name)
                      nil
                      (timvisher-org-refile-done-entry-position)))
    (setq org-map-continue-fro=
m entry-begin-point)))

(defun timvisher-org-refile-done-entries
    ()
  (interactive)
  (org-map-entries #'timvisher-org-refile-done-entry
                   "LEVEL=3D2/+DO=
NE|+CANCELLED"
                   nil
                   'archive))

The idea being that if I do in fact refile an entry I'd = actually like the 'search to continue' from where it just was. This= 'works' in that it successfully refiles all the entries even if th= ey're consecutive but it also manages to get into an infinite loop beca= use, AFAICT, it ignores the=C2=A0'archive=C2=A0skipping so= mehow. I've spent some time in the debugger and I can't figure out = yet why it does that.

Any tips on how I might use this variable to ac= hieve my goals?

Thanks in advance!

--

In Christ,

= Timmy V.

https://blog.twon= egatives.com
http://five.sentenc.= es

--00000000000030025505c2221966--