From mboxrd@z Thu Jan 1 00:00:00 1970 From: Bastien Guerry Subject: [Accepted] Allow property retrieval before first heading? Date: Sat, 12 Feb 2011 19:03:15 +0100 (CET) Message-ID: <20110212180315.40C738860@myhost.localdomain> References: Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from [140.186.70.92] (port=46195 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PoJoO-0003V4-HI for emacs-orgmode@gnu.org; Sat, 12 Feb 2011 13:03:16 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PoJoM-0003aJ-0N for emacs-orgmode@gnu.org; Sat, 12 Feb 2011 13:03:12 -0500 Received: from mail-fx0-f41.google.com ([209.85.161.41]:49844) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PoJoL-0003a9-K7 for emacs-orgmode@gnu.org; Sat, 12 Feb 2011 13:03:09 -0500 Received: by fxm12 with SMTP id 12so4025460fxm.0 for ; Sat, 12 Feb 2011 10:03:08 -0800 (PST) List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org Patch 595 (http://patchwork.newartisans.com/patch/595/) is now "Accepted". Maintainer comment: none This relates to the following submission: http://mid.gmane.org/%3Cm1tyg9qkwg.fsf%4094.197.159.103.threembb.co.uk%3E Here is the original message containing the patch: > Content-Type: text/plain; charset="utf-8" > MIME-Version: 1.0 > Content-Transfer-Encoding: 7bit > Subject: [Orgmode] Allow property retrieval before first heading? > Date: Sat, 12 Feb 2011 21:26:23 -0000 > From: Dan Davison > X-Patchwork-Id: 595 > Message-Id: > To: emacs-orgmode@gnu.org > > Currently (org-entry-get) throws an error if point is before the first > heading. Is there a reason that this must be so? Org is too essential > for headings to be obligatory! > > An example of when it would be useful to get properties is in a buffer > containing src blocks but no headings (babel takes header args from Org > properties). I make heavy use of such buffers as a scratch pad. > > I'm not sure to what extent speed is essential in these functions, and > therefore unsure whether the calls to `org-before-first-heading-p' are > acceptable. > > Dan > > Allow properties to be retrieved before first heading in file. > > * lisp/org.el (org-entry-get): Don't look for a property drawer if we > are before the first heading in the file. > (org-entry-get-with-inheritance): Don't attempt to move up the tree if > we are before the first heading in the file. Also, enclose less of the > function in the save-excursion. > > > diff --git a/lisp/org.el b/lisp/org.el > index 0104007..a676ec4 100644 > --- a/lisp/org.el > +++ b/lisp/org.el > @@ -13567,7 +13567,8 @@ when a \"nil\" value can supersede a non-nil value higher up the hierarchy." > ;; We need a special property. Use `org-entry-properties' to > ;; retrieve it, but specify the wanted property > (cdr (assoc property (org-entry-properties nil 'special property))) > - (let ((range (org-get-property-block))) > + (let ((range (unless (org-before-first-heading-p) > + (org-get-property-block)))) > (if (and range > (goto-char (car range)) > (re-search-forward > @@ -13680,6 +13681,7 @@ should be considered as undefined (this is the meaning of nil here). > However, if LITERAL-NIL is set, return the string value \"nil\" instead." > (move-marker org-entry-property-inherited-from nil) > (let (tmp) > + (unless (org-before-first-heading-p) > (save-excursion > (save-restriction > (widen) > @@ -13690,11 +13692,12 @@ However, if LITERAL-NIL is set, return the string value \"nil\" instead." > (move-marker org-entry-property-inherited-from (point)) > (throw 'ex tmp)) > (or (org-up-heading-safe) (throw 'ex nil))))) > + )) > (setq tmp (or tmp > (cdr (assoc property org-file-properties)) > (cdr (assoc property org-global-properties)) > (cdr (assoc property org-global-properties-fixed)))) > - (if literal-nil tmp (org-not-nil tmp))))) > + (if literal-nil tmp (org-not-nil tmp)))) > > (defvar org-property-changed-functions nil > "Hook called when the value of a property has changed. >