Browse Source

Store link: Don't error before the first heading in a file

Matt Lundin writes:

> When I call org-remember or org-store-link above the first headline in
> an org buffer, I receive the following error message:
>
>    Before first headline at position 1 in buffer index.org
>
> It seems that either org-remember or org-store-link (or both) calls
> org-back-to-heading in order to grab the relevant heading for
> annotation. As a result, if I try to store a link above the first
> heading, emacs spits out the error message above because there is no
> heading to return to.
>
> Is this the intended behavior? Sometimes I prefer to create a link to
> the file as a whole rather than to a particular headline. E.g., I might
> want to create a todo to organize notes.org, which is not an agenda
> file. In this instance, it does not matter whether org-remember creates
> a link to a particular headline. In fact, I would prefer a link to the
> file as a whole and thus expect to be able to store a link while on the
> first empty line of the file or on #+TITLE.
Carsten Dominik 15 years ago
parent
commit
206660bc8c
2 changed files with 3 additions and 1 deletions
  1. 1 0
      lisp/ChangeLog
  2. 2 1
      lisp/org.el

+ 1 - 0
lisp/ChangeLog

@@ -6,6 +6,7 @@
 	hidden.
 	(org-iswitchb-completing-read): Bind `switchb-use-virtual-buffers'
 	to nil for special completion.
+	(org-store-link): Don't error before the first heading.
 
 	* org-agenda.el (org-agenda-open-link): Pass the prefix to
 	`org-offer-links-in-entry'.

+ 2 - 1
lisp/org.el

@@ -7269,7 +7269,8 @@ For file links, arg negates `org-context-in-file-links'."
 			  (condition-case nil
 			      (org-make-org-heading-search-string txt)
 			    (error "")))
-		  desc (or (nth 4 (org-heading-components)) "NONE"))))
+		  desc (or (nth 4 (ignore-errors
+				    (org-heading-components))) "NONE"))))
 	(if (string-match "::\\'" cpltxt)
 	    (setq cpltxt (substring cpltxt 0 -2)))
 	(setq link (org-make-link cpltxt)))))