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 21:51:16 +0200 Message-ID: <4E95EFB4.8000104@christianmoe.com> References: <4E949D13.6060505@christianmoe.com> <4E958523.60909@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]:36378) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RE4nT-000327-H7 for emacs-orgmode@gnu.org; Wed, 12 Oct 2011 15:49:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RE4nS-0005O0-6r for emacs-orgmode@gnu.org; Wed, 12 Oct 2011 15:48:59 -0400 Received: from mars.hitrost.net ([91.185.211.18]:59633) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RE4nR-0005KL-Pm for emacs-orgmode@gnu.org; Wed, 12 Oct 2011 15:48:58 -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 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 >> >