1
0
mirror of https://git.savannah.gnu.org/git/emacs/org-mode.git synced 2024-11-28 07:44:49 +00:00

references to #+resname lines are now working

This commit is contained in:
Eric Schulte 2009-06-13 17:07:16 -07:00
parent dd0392a4f2
commit 47810f8e14

View File

@ -89,6 +89,7 @@ return nil."
(defun org-babel-ref-resolve-reference (ref)
"Resolve the reference and return it's value"
(save-excursion
(message "processing ref %S from %d" ref (point))
(let ((case-fold-search t)
type args new-refere new-referent result)
;; assign any arguments to pass to source block
@ -105,7 +106,7 @@ return nil."
(find-file (match-string 1 ref))
(setf ref (match-string 2 ref)))
(goto-char (point-min))
(unless (let ((result_regexp (concat "^#\\+\\(TBL\\|RES\\)NAME:[ \t]*"
(if (let ((result_regexp (concat "^#\\+\\(TBL\\|RES\\)NAME:[ \t]*"
(regexp-quote ref) "[ \t]*$"))
(regexp (concat "^#\\+SRCNAME:[ \t]*"
(regexp-quote ref) "[ \t]*$")))
@ -113,24 +114,23 @@ return nil."
(re-search-forward result_regexp nil t)
(re-search-forward regexp nil t)
(re-search-backward regexp nil t)))
;; ;; TODO: allow searching for names in other buffers
;; (setq id-loc (org-id-find ref 'marker)
;; buffer (marker-buffer id-loc)
;; loc (marker-position id-loc))
;; (move-marker id-loc nil)
(progn (message (format "reference '%s' not found in this buffer" ref))
(error (format "reference '%s' not found in this buffer" ref))))
(goto-char (match-beginning 0))
;; ;; TODO: allow searching for names in other buffers
;; (setq id-loc (org-id-find ref 'marker)
;; buffer (marker-buffer id-loc)
;; loc (marker-position id-loc))
;; (move-marker id-loc nil)
(progn (message (format "reference '%s' not found in this buffer" ref))
(error (format "reference '%s' not found in this buffer" ref))))
(while (not (setq type (org-babel-ref-at-ref-p)))
(forward-line 1)
(beginning-of-line)
(if (or (= (point) (point-min)) (= (point) (point-max)))
(error "reference not found")))
(message "type=%S point=%d" type (point))
(case type
('table
(mapcar (lambda (row)
(if (and (symbolp row) (equal row 'hline)) row
(mapcar #'org-babel-read row)))
(org-table-to-lisp)))
('results-line (org-babel-ref-read-result))
('table (org-babel-ref-read-table))
('source-block
(setq result (org-babel-execute-src-block
t nil (org-combine-plists args nil)))
@ -141,7 +141,33 @@ return nil."
of the supported reference types are found. Supported reference
types are tables and source blocks."
(cond ((org-at-table-p) 'table)
((looking-at "^#\\+BEGIN_SRC") 'source-block)))
((looking-at "^#\\+BEGIN_SRC") 'source-block)
((looking-at "^#\\+RESNAME:") 'results-line)))
(defun org-babel-ref-read-result ()
"Read the result at `point' into emacs-lisp."
(cond
((org-at-table-p) (org-babel-ref-read-table))
((looking-at ": ")
(let ((result-string
(org-babel-trim
(mapconcat (lambda (line) (if (and (> (length line) 1)
(string= ": " (substring line 0 2)))
(substring line 2)
line))
(split-string
(buffer-substring (point) (org-babel-result-end)) "[\r\n]+")
"\n"))))
(or (org-babel-number-p result-string) result-string)))
((looking-at "^#\\+RESNAME:")
(save-excursion (forward-line 1) (org-babel-ref-read-result)))))
(defun org-babel-ref-read-table ()
"Read the table at `point' into emacs-lisp."
(mapcar (lambda (row)
(if (and (symbolp row) (equal row 'hline)) row
(mapcar #'org-babel-read row)))
(org-table-to-lisp)))
(provide 'org-babel-ref)
;;; org-babel-ref.el ends here