From mboxrd@z Thu Jan 1 00:00:00 1970 From: Gez Subject: Re: Idea: insert "current sort order" property Date: Wed, 12 Oct 2011 12:35:21 +0100 Message-ID: References: <4E949D13.6060505@christianmoe.com> Reply-To: suleika@gmail.com Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=0016e6d7e1007df86e04af186c3b Return-path: Received: from eggs.gnu.org ([140.186.70.92]:40248) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RDx6A-0005WE-Ul for emacs-orgmode@gnu.org; Wed, 12 Oct 2011 07:35:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RDx66-0003AQ-Mc for emacs-orgmode@gnu.org; Wed, 12 Oct 2011 07:35:46 -0400 Received: from mail-ww0-f49.google.com ([74.125.82.49]:59902) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RDx66-0003A0-EX for emacs-orgmode@gnu.org; Wed, 12 Oct 2011 07:35:42 -0400 Received: by wwp14 with SMTP id 14so647153wwp.30 for ; Wed, 12 Oct 2011 04:35:41 -0700 (PDT) In-Reply-To: <4E949D13.6060505@christianmoe.com> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: mail@christianmoe.com Cc: emacs-orgmode@gnu.org --0016e6d7e1007df86e04af186c3b Content-Type: text/plain; charset=ISO-8859-1 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 On 11 October 2011 20:46, Christian Moe 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. Yours, > Christian > > #+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-map-entries > '(progn > (org-set-property prop > (format fstr counter)) > (setq counter (1+ counter))) > match 'tree) > (message "")))) > #+end_src > --0016e6d7e1007df86e04af186c3b Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Thanks, Christian.=A0 Please forgive my ignorance but what should I do with= the code?=A0 I've not done anything more advanced than org-customize b= efore.=A0

Gez

On 11 October 2011 = 20:46, Christian Moe <mail@christianmoe.com> 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" =A0etc.

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 wo= rks for you (and please *don't* test it on anything valuable without ba= cking up first!).

<snip>

Code follows.
Yours,
Christian

#+begin_src emacs-lisp
=A0(defun cm/org-store-outline-order (arg prop)
=A0 =A0"Store the outline of the subtree of the entry at point by
=A0setting the property PROP of each direct child entry to its
=A0current position in the tree. With prefix ARG, store the position
=A0of the whole subtree. The tree can be restored to the stored
=A0outline by sorting on the property with `C-c ^ r'. Note that this =A0will only work properly on the order of each subtree; if headings
=A0are demoted, promoted, or moved into different subtrees, the
=A0result may or may not be nonsense, but it will be impossible to
=A0restore the original order by sorting."
=A0 =A0(interactive "P\nsProperty key (default OutlineIndex): ")=
=A0 =A0(if (string=3D prop "") (setq prop "OutlineIndex&quo= t;))
=A0 =A0(if (or (not (org-map-entries t (concat prop "=3D{.}") &#= 39;tree))
=A0 =A0 =A0 =A0 =A0 =A0(y-or-n-p "Property exists; overwrite? ")= )
=A0 =A0 =A0 =A0(let* ((match (format "LEVEL%s%s"
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(if arg "&= gt;=3D" "=3D")
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(1+ (org-curren= t-level))))
=A0 =A0 =A0 =A0 =A0 =A0 =A0 (counter 1)
=A0 =A0 =A0 =A0 =A0 =A0 =A0 (width (1+ (floor (log10 (length (org-map-entr= ies t match 'tree))))))
=A0 =A0 =A0 =A0 =A0 =A0 =A0 (fstr (concat "%0" (number-to-string= width) "d")))
=A0 =A0 =A0 =A0 =A0(org-map-entries
=A0 =A0 =A0 =A0 =A0 '(progn
=A0 =A0 =A0 =A0 =A0 =A0 =A0(org-set-property prop
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(format fst= r counter))
=A0 =A0 =A0 =A0 =A0 =A0 =A0(setq counter (1+ counter)))
=A0 =A0 =A0 =A0 =A0 match 'tree)
=A0 =A0 =A0 =A0 =A0(message ""))))
#+end_src

--0016e6d7e1007df86e04af186c3b--