From mboxrd@z Thu Jan 1 00:00:00 1970 From: Christian Moe Subject: Re: Idea: insert "current sort order" property Date: Wed, 12 Oct 2011 14:16:35 +0200 Message-ID: <4E958523.60909@christianmoe.com> References: <4E949D13.6060505@christianmoe.com> Reply-To: mail@christianmoe.com Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Return-path: Received: from eggs.gnu.org ([140.186.70.92]:35725) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RDxgx-0001uH-IP for emacs-orgmode@gnu.org; Wed, 12 Oct 2011 08:13:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RDxgw-00041K-BP for emacs-orgmode@gnu.org; Wed, 12 Oct 2011 08:13:47 -0400 Received: from mars.hitrost.net ([91.185.211.18]:42868) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RDxgv-000415-T9 for emacs-orgmode@gnu.org; Wed, 12 Oct 2011 08:13:46 -0400 In-Reply-To: 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: suleika@gmail.com Cc: emacs-orgmode@gnu.org Hi, You can copy the code into a buffer and `evaluate' it, i.e. teach Emacs the new function for this session. You evaluate an elisp expression by placing point right after the last closing parenthesis and pressing `C-x C-e'. When you do, the minibuffer should display the name of the function. After this, Emacs will only remember the function for the rest of the session. If you like it and want it available the next time you start Emacs, just copy it into your .emacs file (only the bit *between* the #+BEGIN_SRC and #+END_SRC lines). This is the basic drill for using little snippets of code that don't merit a file of their own. Since this is an interactive function, you can call it with `M-x'. Place point in the appropriate parent entry in your music outline and try `M-x cm/org-store-outline-order'. Options: - Since the code in this case is surrounded by a #+BEGIN_SRC block, if you copy it into an Org buffer, you can also evaluate it simply by `C-c C-c' with point anywhere on the code block. - You can change the name and drop the `cm/' prefix if you like (I just use it as a reminder this is my hack, not part of Org-mode). Yours, Christian 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 > > 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 > >