[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [O] Idea: insert "current sort order" property

From: Gez
Subject: Re: [O] Idea: insert "current sort order" property
Date: Wed, 12 Oct 2011 12:35:21 +0100

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. 


On 11 October 2011 20:46, Christian Moe <address@hidden> wrote:
Hi, Gez,

On 10/7/11 5:02 PM, Gez wrote:
What I'm imagining is a command executed on a headline to insert a
property into each of its children "fixing" the current order;
something like ":sorted:01", ":sorted:02"  etc.

I think this is a neat idea, and can see some uses for it for my own stuff. I've made a first pass below. Please test it and let me know how it works for you (and please *don't* test it on anything valuable without backing up first!).


Code follows.

#+begin_src emacs-lisp
 (defun cm/org-store-outline-order (arg prop)
   "Store the outline 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. The tree can be restored to the stored
 outline by sorting on the 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\nsProperty key (default OutlineIndex): ")
   (if (string= prop "") (setq prop "OutlineIndex"))
   (if (or (not (org-map-entries t (concat prop "={.}") 'tree))
           (y-or-n-p "Property exists; overwrite? "))
       (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")))
             (org-set-property prop
                               (format fstr counter))
             (setq counter (1+ counter)))
          match 'tree)
         (message ""))))

reply via email to

[Prev in Thread] Current Thread [Next in Thread]