* Save-excursion that works with org visibility?
@ 2017-05-14 0:01 Nikolay Kudryavtsev
2017-05-14 1:05 ` Kyle Meyer
2017-05-14 12:16 ` John Kitchin
0 siblings, 2 replies; 5+ messages in thread
From: Nikolay Kudryavtsev @ 2017-05-14 0:01 UTC (permalink / raw)
To: emacs-orgmode
Is there any way to modify node visibility and then revert those
changes? In particular I'm interested in doing and then reverting
(org-content).
What follows is more details at what I'm trying to accomplish in the end.
Let's say we have nodes:
* A
** B
*** TODO С
For task node C I want to see which parent node has tag "project" and
then put it into a prefix in agenda. Here's my code:
===
(defun org-get-task-project ()
(let ((project ""))
(save-excursion
(org-content)
(while
(progn
(ignore-errors (outline-up-heading 1))
(when (and (eq project "")
(member "project" (org-get-tags-at (point) t)))
(setq project (nth 4 (org-heading-components))))
(> (nth 1 (org-heading-components)) 1))))
project))
(with-eval-after-load 'org-agenda
(add-to-list 'org-agenda-prefix-format
'(todo . " %i %?-20(org-get-task-project)")))
===
In the code above we have to make all headings visible first with
org-content because outline-up-heading works only on visible nodes.
--
Best Regards,
Nikolay Kudryavtsev
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Save-excursion that works with org visibility?
2017-05-14 0:01 Save-excursion that works with org visibility? Nikolay Kudryavtsev
@ 2017-05-14 1:05 ` Kyle Meyer
2017-05-14 16:58 ` Nikolay Kudryavtsev
2017-05-14 12:16 ` John Kitchin
1 sibling, 1 reply; 5+ messages in thread
From: Kyle Meyer @ 2017-05-14 1:05 UTC (permalink / raw)
To: Nikolay Kudryavtsev, emacs-orgmode
Nikolay Kudryavtsev <nikolay.kudryavtsev@gmail.com> writes:
> Is there any way to modify node visibility and then revert those
> changes? In particular I'm interested in doing and then reverting
> (org-content).
If you pass a non-nil value for the INVISIBLE-OK argument of
outline-up-heading, I think that your function should work without the
org-content call. Also, it might be worth replacing outline-up-heading
with org-up-heading-safe, which should be faster.
--
Kyle
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Save-excursion that works with org visibility?
2017-05-14 0:01 Save-excursion that works with org visibility? Nikolay Kudryavtsev
2017-05-14 1:05 ` Kyle Meyer
@ 2017-05-14 12:16 ` John Kitchin
2017-05-14 17:03 ` Nikolay Kudryavtsev
1 sibling, 1 reply; 5+ messages in thread
From: John Kitchin @ 2017-05-14 12:16 UTC (permalink / raw)
To: Nikolay Kudryavtsev; +Cc: emacs-orgmode
Is org-save-outline-visibility what you are looking for?
Nikolay Kudryavtsev writes:
> Is there any way to modify node visibility and then revert those
> changes? In particular I'm interested in doing and then reverting
> (org-content).
>
> What follows is more details at what I'm trying to accomplish in the end.
>
> Let's say we have nodes:
> * A
> ** B
> *** TODO С
> For task node C I want to see which parent node has tag "project" and
> then put it into a prefix in agenda. Here's my code:
> ===
> (defun org-get-task-project ()
> (let ((project ""))
> (save-excursion
> (org-content)
> (while
> (progn
> (ignore-errors (outline-up-heading 1))
> (when (and (eq project "")
> (member "project" (org-get-tags-at (point) t)))
> (setq project (nth 4 (org-heading-components))))
> (> (nth 1 (org-heading-components)) 1))))
> project))
>
> (with-eval-after-load 'org-agenda
> (add-to-list 'org-agenda-prefix-format
> '(todo . " %i %?-20(org-get-task-project)")))
> ===
> In the code above we have to make all headings visible first with
> org-content because outline-up-heading works only on visible nodes.
--
Professor John Kitchin
Doherty Hall A207F
Department of Chemical Engineering
Carnegie Mellon University
Pittsburgh, PA 15213
412-268-7803
@johnkitchin
http://kitchingroup.cheme.cmu.edu
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Save-excursion that works with org visibility?
2017-05-14 1:05 ` Kyle Meyer
@ 2017-05-14 16:58 ` Nikolay Kudryavtsev
0 siblings, 0 replies; 5+ messages in thread
From: Nikolay Kudryavtsev @ 2017-05-14 16:58 UTC (permalink / raw)
To: Kyle Meyer, emacs-orgmode
Thanks. This removed the need for (org-content).
--
Best Regards,
Nikolay Kudryavtsev
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Save-excursion that works with org visibility?
2017-05-14 12:16 ` John Kitchin
@ 2017-05-14 17:03 ` Nikolay Kudryavtsev
0 siblings, 0 replies; 5+ messages in thread
From: Nikolay Kudryavtsev @ 2017-05-14 17:03 UTC (permalink / raw)
To: John Kitchin; +Cc: emacs-orgmode
Thanks for the info, this answers the topic question.
--
Best Regards,
Nikolay Kudryavtsev
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2017-05-14 17:03 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-05-14 0:01 Save-excursion that works with org visibility? Nikolay Kudryavtsev
2017-05-14 1:05 ` Kyle Meyer
2017-05-14 16:58 ` Nikolay Kudryavtsev
2017-05-14 12:16 ` John Kitchin
2017-05-14 17:03 ` Nikolay Kudryavtsev
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.