[-- Attachment #1: Type: text/plain, Size: 1255 bytes --] 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. Thanks as always, Matt [-- Attachment #2: Type: text/html, Size: 1558 bytes --]
Matt Price <moptop99@gmail.com> 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?