From: Christian Moe <mail@christianmoe.com>
To: suleika@gmail.com
Cc: emacs-orgmode@gnu.org
Subject: Re: Idea: insert "current sort order" property
Date: Wed, 12 Oct 2011 21:51:16 +0200 [thread overview]
Message-ID: <4E95EFB4.8000104@christianmoe.com> (raw)
In-Reply-To: <CAPQe_UpwfwDpcWtmngVmXw1vMA9dQJm665i0f+Y5u6qZDTiB+g@mail.gmail.com>
On 10/12/11 5:59 PM, Gez wrote:
> I do use revisioning, but Is there a protocol I should use for testing
> code snippets before using them on my original data or can they be
> considered safe after being run once?
Save often; backup/commit often; be ready to hit 'undo'...? Do the
first test run on mock data in a test.org file?
> One thing that might be useful to add to the code please ... If when
> prompting for the property key, TAB brought up the list of
> auto-complete keys (like when using C-c C-x p) that would make for
> easier maintenance and consistency; e.g. when I deliberately want to
> overwrite a previous outline index it would avoid a second set of
> properties being written accidentally if I made a typo.
Then we need a way to keep track of what property keys are used to
store outlines in, so we can offer those and only those for
completion. (We don't want to offer all the property keys used in the
buffer -- that's an invitation to overwrite data.)
So in my second pass (below), when you use a :foo: property to store
the outline index, `foo' gets added to a list of keys in the
:Stored_outlines: property of the parent. When you store an outline,
the prompt for a property key offers completion on all the keys stored
in :Stored_outlines:. See how this works for you.
Yours,
Christian
#+BEGIN_SRC emacs-lisp
(defun cm/org-store-outline-order (arg prop)
"Store the heading order of the subtree of the entry at point
by setting the property PROP of each direct child entry to its
current position in the tree. With prefix ARG, store the position
of the whole subtree.
You can store different heading orders in the same subtree by
using different keys as PROP; these will be listed in the
Stored_Outlines property of the parent entry. The tree can be
restored to a given stored outline by sorting on the appropriate
property with `C-c ^ r'.
Note that this will only work properly on the order of each
subtree; if headings are demoted, promoted, or moved into
different subtrees, the result may or may not be nonsense, but it
will be impossible to restore the original order by sorting."
(interactive "P\ni")
(let* ((match (format "LEVEL%s%s"
(if arg ">=" "=")
(1+ (org-current-level))))
(counter 1)
(width (1+
(floor
(log10
(length (org-map-entries t match 'tree))))))
(fstr (concat "%0" (number-to-string width) "d"))
(defaultprop "OutlineIndex")
(keychain "Stored_Outlines")
(keys (org-entry-get-multivalued-property
(point) keychain)))
(unless prop
(setq prop
(org-icompleting-read
(concat "Property to use [" defaultprop "]: ")
(mapcar 'list keys) nil nil nil nil defaultprop)))
(when (or (not (org-map-entries t (concat prop "={.}") 'tree))
(y-or-n-p "Property exists; overwrite? "))
(org-entry-add-to-multivalued-property
(point) "Stored_Outlines" prop)
(org-map-entries
'(progn
(org-set-property prop
(format fstr counter))
(setq counter (1+ counter)))
match 'tree)
(message ""))))
#+END_SRC
> Gez
>
>
>> On 10/12/11 1:35 PM, Gez wrote:
>>>
>>> Thanks, Christian. Please forgive my ignorance but what should I do
>>> with the code? I've not done anything more advanced than
>>> org-customize before.
>>>
>>> Gez
>>
>
next prev parent reply other threads:[~2011-10-12 19:49 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-10-07 15:02 Idea: insert "current sort order" property Gez
2011-10-11 19:46 ` Christian Moe
2011-10-12 11:35 ` Gez
2011-10-12 12:16 ` Christian Moe
2011-10-12 15:59 ` Gez
2011-10-12 19:51 ` Christian Moe [this message]
2011-10-13 11:40 ` Gez
2011-10-13 12:39 ` Christian Moe
2011-10-13 18:34 ` Gez
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.orgmode.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4E95EFB4.8000104@christianmoe.com \
--to=mail@christianmoe.com \
--cc=emacs-orgmode@gnu.org \
--cc=suleika@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).