* get subtree contents as string
@ 2020-02-26 18:35 Matt Price
2020-02-26 21:13 ` Eric Abrahamsen
0 siblings, 1 reply; 2+ messages in thread
From: Matt Price @ 2020-02-26 18:35 UTC (permalink / raw)
To: Org Mode
[-- 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 --]
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: get subtree contents as string
2020-02-26 18:35 get subtree contents as string Matt Price
@ 2020-02-26 21:13 ` Eric Abrahamsen
0 siblings, 0 replies; 2+ messages in thread
From: Eric Abrahamsen @ 2020-02-26 21:13 UTC (permalink / raw)
To: emacs-orgmode
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?
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2020-02-26 21:14 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-26 18:35 get subtree contents as string Matt Price
2020-02-26 21:13 ` Eric Abrahamsen
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).