[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: get subtree contents as string
From: |
Eric Abrahamsen |
Subject: |
Re: get subtree contents as string |
Date: |
Wed, 26 Feb 2020 16:13:52 -0500 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) |
Matt Price <address@hidden> 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?