emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH] Allow property retrieval before first heading?
@ 2011-02-12 16:26 Dan Davison
  2011-02-12 16:42 ` Dan Davison
  2011-02-12 18:03 ` [Accepted] " Bastien Guerry
  0 siblings, 2 replies; 4+ messages in thread
From: Dan Davison @ 2011-02-12 16:26 UTC (permalink / raw)
  To: emacs-orgmode

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.

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] Allow property retrieval before first heading?
  2011-02-12 16:26 [PATCH] Allow property retrieval before first heading? Dan Davison
@ 2011-02-12 16:42 ` Dan Davison
  2011-02-12 18:04   ` Bastien
  2011-02-12 18:03 ` [Accepted] " Bastien Guerry
  1 sibling, 1 reply; 4+ messages in thread
From: Dan Davison @ 2011-02-12 16:42 UTC (permalink / raw)
  To: emacs-orgmode

Dan Davison <dandavison7@gmail.com> writes:

> 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). 

Hmm, for the record I was confused on that point; Eric already has a
workaround for the error to the effect that babel will take header args
from a #+PROPERTY line in a buffer with no headings. But my question
stands, as this error is a gotcha, requiring code like this

  (or (condition-case nil
	  (org-entry-get (point) header-arg t)
	(error nil))
      (cdr (assoc header-arg org-file-properties))))

Dan


> 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.
>
>
> _______________________________________________
> Emacs-orgmode mailing list
> Please use `Reply All' to send replies to the list.
> Emacs-orgmode@gnu.org
> http://lists.gnu.org/mailman/listinfo/emacs-orgmode

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Accepted] Allow property retrieval before first heading?
  2011-02-12 16:26 [PATCH] Allow property retrieval before first heading? Dan Davison
  2011-02-12 16:42 ` Dan Davison
@ 2011-02-12 18:03 ` Bastien Guerry
  1 sibling, 0 replies; 4+ messages in thread
From: Bastien Guerry @ 2011-02-12 18:03 UTC (permalink / raw)
  To: emacs-orgmode

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 <dandavison7@gmail.com>
> X-Patchwork-Id: 595
> Message-Id: <m1tyg9qkwg.fsf@94.197.159.103.threembb.co.uk>
> 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.
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Re: [PATCH] Allow property retrieval before first heading?
  2011-02-12 16:42 ` Dan Davison
@ 2011-02-12 18:04   ` Bastien
  0 siblings, 0 replies; 4+ messages in thread
From: Bastien @ 2011-02-12 18:04 UTC (permalink / raw)
  To: Dan Davison; +Cc: emacs-orgmode

Hi Dan,

Dan Davison <dandavison7@gmail.com> writes:

> Dan Davison <dandavison7@gmail.com> writes:
>
>> 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!

Thanks for the patch -- makes sense, I applied it.

>> 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). 
>
> Hmm, for the record I was confused on that point; Eric already has a
> workaround for the error to the effect that babel will take header args
> from a #+PROPERTY line in a buffer with no headings. But my question
> stands, as this error is a gotcha, requiring code like this
>
>   (or (condition-case nil
> 	  (org-entry-get (point) header-arg t)
> 	(error nil))
>       (cdr (assoc header-arg org-file-properties))))

Yes - I removed a few useless condition-case wrapping since your patch.

Please report any problem.

Thanks,

-- 
 Bastien

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2011-02-12 18:04 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-02-12 16:26 [PATCH] Allow property retrieval before first heading? Dan Davison
2011-02-12 16:42 ` Dan Davison
2011-02-12 18:04   ` Bastien
2011-02-12 18:03 ` [Accepted] " Bastien Guerry

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).