From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id 6FprC8oipWC1SQEAgWs5BA (envelope-from ) for ; Wed, 19 May 2021 16:38:02 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id qOcTB8oipWAAaAAAbx9fmQ (envelope-from ) for ; Wed, 19 May 2021 14:38:02 +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 50F108CC7 for ; Wed, 19 May 2021 16:38:01 +0200 (CEST) Received: from localhost ([::1]:59726 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ljNKi-0004x9-7N for larch@yhetil.org; Wed, 19 May 2021 10:38:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59798) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ljNJg-0004aw-Lr for emacs-orgmode@gnu.org; Wed, 19 May 2021 10:36:56 -0400 Received: from mail-wr1-x429.google.com ([2a00:1450:4864:20::429]:33342) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ljNJe-0004dk-JL for emacs-orgmode@gnu.org; Wed, 19 May 2021 10:36:56 -0400 Received: by mail-wr1-x429.google.com with SMTP id n2so14359031wrm.0 for ; Wed, 19 May 2021 07:36:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=andrew-cmu-edu.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=zlo1UMzxkbzfiUMBiKlzJA26MMkO2lmBkTpMzzwxb8Q=; b=YVeFIUUYo3Kp3/uDxjAQjwY7hkAEwdr6SqriO78HBC/PNwBW6EpRvxqGdQgtvv6Oye g+zxq8rwaguGU7zcmHpSjISGtZ2hENiu3jTiAGBkwjXQqfVsRxwM8lXln4KE4xL3FjL1 tmGGr7mGkCWceoUP+wtl1UZtwiewgs6gGEav+x5BBHItNSU68c8hGOjRlKxEP+1QWcgV +WcMbnTlq5yVhj9R0Y7ziazK5ER1IbVayd4IGD3YYoIvjXu7/huyWtBPrN+x7cjxRze6 +432kjKGyVkJEKUn+uJKpTVTyzDZU4Yr7xiiLoIpXnnxl80+L93xW7ORdqdWeWg0SQLT 7Sew== 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:cc; bh=zlo1UMzxkbzfiUMBiKlzJA26MMkO2lmBkTpMzzwxb8Q=; b=l76fTCCiYQn42X081UgLDlsdRW3FtyEiHquV/vWvZj1xp2nhVdOSxhisxfTriVqcbk BJXugisGFPnJaO4PhB4dSiDyPFw/TdkNhBDPsrWaK2ACEyj5AXqpOydVVnAaISP6Whk/ DkWa21jakt01DM0VeR7uc0FBEVTqs+hLZwA+2ytBX3g9PTMQTOi7jVicD1FN0mgtxyfi P2HAtz6u3K9K7Ojf/CW8cFuQfO5aMYdQ1Sg+JsLe+SvS+PwEQyWKsKyVYaHG43WhdAkf BH35PpYzWtuARedOrtHrqTJ+S/TMF12cgsDww4XCgMaj6f4MQSqwZFX62EmmDDkuEYRu Q2ng== X-Gm-Message-State: AOAM533BNCTVTEg64Z4uM/OlL5s7sZ5ufV/SriuPWyco2dmTTLkp2qNL 2nbHJll2aS8kgLAA52hLOcHc1glL6C5VkIC2bLg= X-Google-Smtp-Source: ABdhPJxYwiuSUeXpZHqwQti9QhjCjnte3YTKTLKsd0GEz0arXtegSzhawJrcJaFwpH6vxjquUsui6xlOL2zzRNiIvtc= X-Received: by 2002:adf:f3cb:: with SMTP id g11mr14858078wrp.75.1621435012729; Wed, 19 May 2021 07:36:52 -0700 (PDT) MIME-Version: 1.0 References: <41-60a4c380-5-7d67d100@4304905> <871ra2g65q.fsf@autistici.org> In-Reply-To: <871ra2g65q.fsf@autistici.org> From: John Kitchin Date: Wed, 19 May 2021 10:36:41 -0400 Message-ID: Subject: Re: Get list of top-level headings To: Jonathan Gregory Content-Type: multipart/alternative; boundary="000000000000f5d16805c2afc109" Received-SPF: pass client-ip=2a00:1450:4864:20::429; envelope-from=johnrkitchin@gmail.com; helo=mail-wr1-x429.google.com X-Spam_score_int: -13 X-Spam_score: -1.4 X-Spam_bar: - X-Spam_report: (-1.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.25, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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: , Cc: org-mode-email 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=1621435081; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc: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=zlo1UMzxkbzfiUMBiKlzJA26MMkO2lmBkTpMzzwxb8Q=; b=WrC76cfM3viOxLSnKGALdLPz4G9ZtiinPCR5bTWTO5Lrgfg1830J1tv52NjoKr1wJeKAFc WLDtcXd311g6pPqlU1r1qV4oUCgimi8c2A26m0vO+z/IB12BXl1KfOcR3yFBEqcaoSR+52 bnabRPpAPSn+rclc7ee1MOBhnZuIFQoA6xEg993LO9l9cV1sKW5lVkmSVOoc1zdeTXeSao nLQeaHC+Rv1gF+TWS59m/yhQKLnAE7AwQ4zP4fD6VSCKCgFyFwnRRi+SNPCZfQrboUnobv Z6wVrAOOF5H7q7hygHVNFKQqJisaWvlK1DT1J2oPEF1eE5KyjZKpLaUpo/58/w== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1621435081; a=rsa-sha256; cv=none; b=Bs5tQj1/S61lIzLPzh4/gCb4zfDum16itni2r7YFJr5+p3st+v7TX5hnDd7U2DEHE/lKv4 NtGU7n7t0cGsOV1xQIg/L+qcKPmI4ZsYdRKAxkpgp2UQJ5h12lL+OH5x534/YfgHdXSnAm F/CYwXr+xKGx9LS4gEQ7pnqim9Eosf65VthR8IIYfqDVFhvy36VAHgu4m9tDnhlscBZ3Wh 6+xAKu6MheKie/iPab9p5h43yRVWrrPZpFxo+3MwYp37B654MTvT7v9XF2LDlYgrKtLmXT /OG23NDyyY9knR0SEB1ovNX2EyXfbJMrtIhYm6WCk5JO79IonAcV+nu9bSog1g== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=andrew-cmu-edu.20150623.gappssmtp.com header.s=20150623 header.b=YVeFIUUY; 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: -2.54 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=andrew-cmu-edu.20150623.gappssmtp.com header.s=20150623 header.b=YVeFIUUY; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=andrew.cmu.edu (policy=none); 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: 50F108CC7 X-Spam-Score: -2.54 X-Migadu-Scanner: scn0.migadu.com X-TUID: H/auinkRyKH5 --000000000000f5d16805c2afc109 Content-Type: text/plain; charset="UTF-8" that is often true, especially with large buffers, but you have to add a bunch of code to go to point-max, and check the level with this. #+BEGIN_SRC emacs-lisp (save-excursion (goto-char (point-max)) (let (components (headings '())) (while (re-search-backward org-complex-heading-regexp nil t) (setq components (org-heading-components)) (when (= (first components) 1) (push (fifth components) headings))) headings)) #+END_SRC This takes about 0.04 ms on a small example. The org-map-entries approach takes 0.6ms on the same example. In a big buffer that might be noticeable! John ----------------------------------- Professor John Kitchin (he/him/his) Doherty Hall A207F Department of Chemical Engineering Carnegie Mellon University Pittsburgh, PA 15213 412-268-7803 @johnkitchin http://kitchingroup.cheme.cmu.edu On Wed, May 19, 2021 at 10:19 AM Jonathan Gregory wrote: > Hi > > On 19 May 2021, John Kitchin wrote: > > > I think this is all you need to get a list of titles of level 1 > > headings as strings > > > > (org-map-entries (lambda () (fifth (org-heading-components))) > > "LEVEL=1") > > > > this also works for me: > > > > #+BEGIN_SRC emacs-lisp > > (org-map-entries (lambda () (org-element-property :title > > (org-element-at-point)) ) "LEVEL=1") > > #+END_SRC > > This is a better approach indeed. No need to create a new list, > although I get faster results using: > > (while (re-search-backward org-complex-heading-regexp nil t) > > > -- > Jonathan > > --000000000000f5d16805c2afc109 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
that is often true, especially with large buffers, but you= have to add a bunch of code to go to point-max, and check the level with t= his.=C2=A0

#+BEGIN_SRC emacs-lisp
(save-excursion=C2=A0 (goto-char (point-max))
=C2=A0 (let (components
(headings &#= 39;()))
=C2=A0 =C2=A0 (while (re-search-backward org-complex-heading-reg= exp nil t)
=C2=A0 =C2=A0 =C2=A0 (setq components (org-heading-components= ))
=C2=A0 =C2=A0 =C2=A0 (when (=3D (first components) 1)
(push (fift= h components) headings)))
=C2=A0 =C2=A0 headings))
#+END_SRC
=
This takes about 0.04 ms on a small example. The org-map-ent= ries approach takes 0.6ms on the same example. In a big buffer that might b= e noticeable!

John

-----------------------------------
Professor = John Kitchin (he/him/his)
Doherty Hall A207F
Department of Chemical E= ngineering
Carnegie Mellon University
Pittsburgh, PA 15213
412-268= -7803


On Wed, May 19, 2021 at 10= :19 AM Jonathan Gregory <jgrg@auti= stici.org> wrote:
Hi

On 19 May 2021, John Kitchin wrote:

> I think this is all you need to get a list of titles of level 1
> headings as strings
>
> (org-map-entries (lambda () (fifth (org-heading-components)))
> "LEVEL=3D1")
>
> this also works for me:
>
> #+BEGIN_SRC emacs-lisp
> (org-map-entries (lambda () (org-element-property :title
> (org-element-at-point)) ) "LEVEL=3D1")
> #+END_SRC

This is a better approach indeed. No need to create a new list,
although I get faster results using:

=C2=A0(while (re-search-backward org-complex-heading-regexp nil t)


--
Jonathan

--000000000000f5d16805c2afc109--