ob-ref: Small refactoring

* lisp/ob-ref.el (org-babel-ref-goto-headline-id):
(org-babel-ref-headline-body): Small refactoring.
This commit is contained in:
Nicolas Goaziou 2015-03-31 21:50:43 +02:00
parent 33e2e375df
commit b3e3f901b1
1 changed files with 14 additions and 17 deletions

View File

@ -53,6 +53,8 @@
(eval-when-compile
(require 'cl))
(declare-function org-end-of-meta-data "org" (&optional full))
(declare-function org-find-property "org" (property &optional value))
(declare-function org-remove-if-not "org" (predicate seq))
(declare-function org-at-table-p "org" (&optional table-type))
(declare-function org-count "org" (CL-ITEM CL-SEQ))
@ -98,29 +100,24 @@ the variable."
out))))))
(defun org-babel-ref-goto-headline-id (id)
(goto-char (point-min))
(let ((rx (regexp-quote id)))
(or (re-search-forward
(concat "^[ \t]*:CUSTOM_ID:[ \t]+" rx "[ \t]*$") nil t)
(let* ((file (org-id-find-id-file id))
(m (when file (org-id-find-id-in-file id file 'marker))))
(when (and file m)
(message "file:%S" file)
(org-pop-to-buffer-same-window (marker-buffer m))
(goto-char m)
(move-marker m nil)
(org-show-context)
t)))))
(or (let ((h (org-find-property "CUSTOM_ID" id)))
(when h (goto-char h)))
(let* ((file (org-id-find-id-file id))
(m (when file (org-id-find-id-in-file id file 'marker))))
(when (and file m)
(message "file:%S" file)
(org-pop-to-buffer-same-window (marker-buffer m))
(goto-char m)
(move-marker m nil)
(org-show-context)
t))))
(defun org-babel-ref-headline-body ()
(save-restriction
(org-narrow-to-subtree)
(buffer-substring
(save-excursion (goto-char (point-min))
(forward-line 1)
(when (looking-at "[ \t]*:PROPERTIES:")
(re-search-forward ":END:" nil)
(forward-char))
(org-end-of-meta-data)
(point))
(point-max))))