Browse Source

Allow storing and following ID links before first heading

* lisp/org.el (org-find-property): Make org-find-property work
  correctly also before first heading.

* lisp/org-id.el (org-id-store-link): Make it possible to store ID
  links also before first heading.
Gustav Wikström 5 years ago
parent
commit
8e3b73d4dc
2 changed files with 7 additions and 3 deletions
  1. 5 2
      lisp/org-id.el
  2. 2 1
      lisp/org.el

+ 5 - 2
lisp/org-id.el

@@ -665,8 +665,11 @@ optional argument MARKERP, return the position as a new marker."
     (let* ((link (concat "id:" (org-id-get-create)))
     (let* ((link (concat "id:" (org-id-get-create)))
 	   (case-fold-search nil)
 	   (case-fold-search nil)
 	   (desc (save-excursion
 	   (desc (save-excursion
-		   (org-back-to-heading t)
-		   (or (and (looking-at org-complex-heading-regexp)
+		   (org-back-to-heading-or-point-min t)
+		   (or (and (org-before-first-heading-p)
+			    (file-name-nondirectory
+			     (buffer-file-name (buffer-base-buffer))))
+		       (and (looking-at org-complex-heading-regexp)
 			    (if (match-end 4)
 			    (if (match-end 4)
 				(match-string 4)
 				(match-string 4)
 			      (match-string 0)))
 			      (match-string 0)))

+ 2 - 1
lisp/org.el

@@ -13140,7 +13140,8 @@ part of the buffer."
 	(while (re-search-forward re nil t)
 	(while (re-search-forward re nil t)
 	  (when (if value (org-at-property-p)
 	  (when (if value (org-at-property-p)
 		  (org-entry-get (point) property nil t))
 		  (org-entry-get (point) property nil t))
-	    (throw 'exit (progn (org-back-to-heading t) (point)))))))))
+	    (throw 'exit (progn (org-back-to-heading-or-point-min t)
+				(point)))))))))
 
 
 (defun org-delete-property (property)
 (defun org-delete-property (property)
   "In the current entry, delete PROPERTY."
   "In the current entry, delete PROPERTY."