From mboxrd@z Thu Jan 1 00:00:00 1970 From: Kaushal Modi Subject: Re: Best way to check if a subtree with a property exists? Date: Fri, 01 Dec 2017 15:17:04 +0000 Message-ID: References: Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="001a1142e20624629a055f48dd1c" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:52606) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eKnaA-0003o3-JK for emacs-orgmode@gnu.org; Fri, 01 Dec 2017 10:51:10 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eKnZY-0003k2-RM for emacs-orgmode@gnu.org; Fri, 01 Dec 2017 10:50:30 -0500 Received: from mail-yw0-x233.google.com ([2607:f8b0:4002:c05::233]:36582) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eKnZY-0003jL-Ln for emacs-orgmode@gnu.org; Fri, 01 Dec 2017 10:49:52 -0500 Received: by mail-yw0-x233.google.com with SMTP id r205so4193297ywb.3 for ; Fri, 01 Dec 2017 07:49:52 -0800 (PST) In-Reply-To: List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: "Emacs-orgmode" To: emacs-orgmode@gnu.org --001a1142e20624629a055f48dd1c Content-Type: text/plain; charset="UTF-8" On Fri, Dec 1, 2017 at 9:00 AM Kaushal Modi wrote: > - How can I quit out of org-map-entries as soon as the first matching > entry is found? > I think this is much better: (let ((valid-found (catch 'break (org-map-entries (lambda () (throw 'break t)) ;; Only map through subtrees where ;; EXPORT_FILE_NAME property is not ;; empty. "EXPORT_FILE_NAME<>\"\"")))) (message "valid-found: %S" valid-found)) - What's a better way to do the same? > Comments are welcome :) Thanks. -- Kaushal Modi --001a1142e20624629a055f48dd1c Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
On Fri, Dec 1,= 2017 at 9:00 AM Kaushal Modi <kaushal.modi@gmail.com> wrote:
- How can I quit out of org-map-e= ntries as soon as the first matching entry is found?

I think this is much bet= ter:

(let ((valid-found
=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0 (catch 'break
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0 (org-map-entries
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0 (lambda ()
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0 (throw 'break t))
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0 ;; Only map through subtrees where
=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ;; EXPORT_FILE_NAME property is = not
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 ;; empty.
= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 "EXPORT_FILE_NA= ME<>\"\""))))
=C2=A0 (message "valid-found: %S= " valid-found))

- What's a better way to do the same?

Comments are welcome :)
=
Thanks.
--
<= div class=3D"gmail_signature" data-smartmail=3D"gmail_signature">

Kaushal Modi

--001a1142e20624629a055f48dd1c-- From mboxrd@z Thu Jan 1 00:00:00 1970 From: Kaushal Modi Subject: Best way to check if a subtree with a property exists? Date: Fri, 01 Dec 2017 14:00:43 +0000 Message-ID: Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="001a11c1867a014775055f47cc92" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:35413) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eKngr-0001ev-0Z for emacs-orgmode@gnu.org; Fri, 01 Dec 2017 10:58:10 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eKng9-0003JN-Jl for emacs-orgmode@gnu.org; Fri, 01 Dec 2017 10:57:24 -0500 Received: from mail-yb0-x22e.google.com ([2607:f8b0:4002:c09::22e]:41626) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eKng9-0003IN-Df for emacs-orgmode@gnu.org; Fri, 01 Dec 2017 10:56:41 -0500 Received: by mail-yb0-x22e.google.com with SMTP id s46so4162875ybi.8 for ; Fri, 01 Dec 2017 07:56:41 -0800 (PST) List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: "Emacs-orgmode" To: emacs-orgmode@gnu.org --001a11c1867a014775055f47cc92 Content-Type: text/plain; charset="UTF-8" Hello, I'd like to check if the current Org file has at least one subtree with a specific property (EXPORT_FILE_NAME in my case). What's the most efficient way to do that? Below works.. but I can see that it's not efficient.. it maps through the whole Org file: (let ((total-valid-subtrees (let ((valid-subtrees (org-map-entries (lambda () t) ;Return value does not matter here ;; Only map through subtrees where ;; EXPORT_FILE_NAME property is not ;; empty. "EXPORT_FILE_NAME<>\"\""))) (safe-length valid-subtrees)))) (if (= 0 total-valid-subtrees) (message "invalid") (message "valid"))) So, - How can I quit out of org-map-entries as soon as the first matching entry is found? - What's a better way to do the same? Thanks. -- Kaushal Modi --001a11c1867a014775055f47cc92 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: base64 PGRpdiBkaXI9Imx0ciI+PGRpdj48ZGl2PjxkaXY+PGRpdj48ZGl2PjxkaXY+SGVsbG8sPGJyPjxi cj48L2Rpdj5JJiMzOTtkIGxpa2UgdG8gY2hlY2sgaWYgdGhlIGN1cnJlbnQgT3JnIGZpbGUgaGFz IGF0IGxlYXN0IG9uZSBzdWJ0cmVlIHdpdGggY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