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
1 changed files with 40 additions and 14 deletions

View File

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