Browse Source

thinking about and stubbing out functions for referencing external resources

Eric Schulte 16 years ago
parent
commit
74498d6055
4 changed files with 36 additions and 4 deletions
  1. 2 1
      litorgy/litorgy-lisp.el
  2. 27 1
      litorgy/litorgy-reference.el
  3. 2 2
      litorgy/litorgy.el
  4. 5 0
      rorg.org

+ 2 - 1
litorgy/litorgy-lisp.el

@@ -37,7 +37,8 @@
   "Execute a block of emacs-lisp code with litorgy.  This
   "Execute a block of emacs-lisp code with litorgy.  This
 function is called by `litorgy-execute-src-block'."
 function is called by `litorgy-execute-src-block'."
   (save-window-excursion
   (save-window-excursion
-    (let ((print-level nil) (print-length nil) results)
+    (let ((vars (litorgy-reference-variables params))
+          (print-level nil) (print-length nil) results)
       (message "executing emacs-lisp code block...")
       (message "executing emacs-lisp code block...")
       (format "%S" (eval (read body))))))
       (format "%S" (eval (read body))))))
 
 

+ 27 - 1
litorgy/litorgy-reference.el

@@ -29,7 +29,7 @@
 ;; Functions for referencing data from the header arguments of a
 ;; Functions for referencing data from the header arguments of a
 ;; litorgical block.  The syntax of such a reference should be
 ;; litorgical block.  The syntax of such a reference should be
 ;;
 ;;
-;;   #+VAR: variable-name file resource-id:name
+;;   #+VAR: variable-name=file:resource-id
 ;;
 ;;
 ;; - variable-name :: the name of the variable to which the value
 ;; - variable-name :: the name of the variable to which the value
 ;;                    will be assigned
 ;;                    will be assigned
@@ -53,5 +53,31 @@
 ;;; Code:
 ;;; Code:
 (require 'litorgy)
 (require 'litorgy)
 
 
+(defun litorgy-reference-variables (params)
+  "Takes a parameter alist, and return an alist of variable
+names, and the string representation of the related value."
+  (mapcar #'litorgy-reference-parse
+   (delq nil (mapcar (lambda (pair) (if (= (car pair) :var) (cdr pair))) params))))
+
+(defun litorgy-reference-parse (reference)
+  "Parse a reference to an external resource returning a list
+with two elements.  The first element of the list will be the
+name of the variable, and the second will be an emacs-lisp
+representation of the value of the variable."
+  (save-excursion
+    (if (string-match "(.+)=(.+)" reference)
+      (let ((var (match-string 1 reference))
+            (ref (match-string 2 reference)))
+        (when (string-match "(.+):(.+)" reference)
+          (find-file (match-string 1 reference))
+          (setf ref (match-string 2 reference)))
+        ;; follow the reference in the current file
+        (case ref
+          ("previous"
+           )
+          ("next")
+          (t ))
+        ))))
+
 (provide 'litorgy-reference)
 (provide 'litorgy-reference)
 ;;; litorgy-reference.el ends here
 ;;; litorgy-reference.el ends here

+ 2 - 2
litorgy/litorgy.el

@@ -32,8 +32,8 @@
 (require 'org)
 (require 'org)
 
 
 (defun litorgy-execute-src-block-maybe ()
 (defun litorgy-execute-src-block-maybe ()
-  "Detect if this is context for a litorgical src-block and run if
-so then run `litorgy-execute-src-block'."
+  "Detect if this is context for a litorgical src-block and if so
+then run `litorgy-execute-src-block'."
   (let ((case-fold-search t))
   (let ((case-fold-search t))
     (if (save-excursion
     (if (save-excursion
           (beginning-of-line 1)
           (beginning-of-line 1)

+ 5 - 0
rorg.org

@@ -238,6 +238,11 @@ internal to the source-code evaluation process?
     need to look more closely at that and we should try to come up with a
     need to look more closely at that and we should try to come up with a
     formats for referencing data from source-code in such a way that it
     formats for referencing data from source-code in such a way that it
     will be as source-code-language independent as possible.
     will be as source-code-language independent as possible.
+    
+    Org tables already have a sophisticated reference system in place
+    that allows referencing table ranges in other files, as well as
+    specifying constants in the header arguments of a table.  This is
+    described in [[info:org:References]].
 
 
 **** Dan: thinking aloud re: referencing data from R
 **** Dan: thinking aloud re: referencing data from R
      Suppose in some R code, we want to reference data in an org
      Suppose in some R code, we want to reference data in an org