From mboxrd@z Thu Jan 1 00:00:00 1970 From: Eric Abrahamsen Subject: Re: get subtree contents as string Date: Wed, 26 Feb 2020 16:13:52 -0500 Message-ID: <87zhd5vypb.fsf@ericabrahamsen.net> References: Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:470:142:3::10]:52734) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j740M-0005mg-RM for emacs-orgmode@gnu.org; Wed, 26 Feb 2020 16:14:08 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j740K-0004T3-LC for emacs-orgmode@gnu.org; Wed, 26 Feb 2020 16:14:06 -0500 Received: from ciao.gmane.io ([159.69.161.202]:42082) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j740K-0004KA-E2 for emacs-orgmode@gnu.org; Wed, 26 Feb 2020 16:14:04 -0500 Received: from list by ciao.gmane.io with local (Exim 4.92) (envelope-from ) id 1j740I-0005bn-0X for emacs-orgmode@gnu.org; Wed, 26 Feb 2020 22:14:02 +0100 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-mx.org@gnu.org Sender: "Emacs-orgmode" To: emacs-orgmode@gnu.org Matt Price writes: > I have the following convenience function that scans contents of a subtree > and then sets a property, adds an overlay, and changes the TODO status: > (defun org-lms-set-grade () > "set grade property for all headings on basis of \"- Grade :: \" line > Use with caution." > (interactive) > (save-restriction > (org-narrow-to-subtree) > (save-excursion > (org-back-to-heading) > (while (re-search-forward ol-grade-regex nil t ) > (org-set-property "GRADE" (or (match-string 2) 0)) > (org-todo "READY")))) > (org-lms-overlay-headings) ) > > It works, but there's a short (<1sec) non-responsive period when it runs. > I'm wondering if it has to do with ~org-narrow-to-subtree~, so I thought > I'd just copy the contents of the subtree as a string and replace > re-search-forward with string-match. However, I'm not finding a > super-obvious way to copy the subtree as a string. Am I missing something? > And am I likely to be right that that's the source of the delay (as I write > this, I'mwondering if hte overlay drawing might be the real problem? The > whole project this is part of (https://github.com/titaniumbones/org-lms) > suffers from delays while the buffer redraws, so I'm keen to figure out > Better Ways To Do Things. If it's just a matter of getting the subtree text, you could use buffer-substring with org-end-of-subtree to find the end of the string. Does that do it?