litorgy-reference.el 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. ;;; litorgy-reference.el --- litorgical functions for referencing external data
  2. ;; Copyright (C) 2009 Eric Schulte, Dan Davison, Austin F. Frank
  3. ;; Author: Eric Schulte, Dan Davison, Austin F. Frank
  4. ;; Keywords: literate programming, reproducible research
  5. ;; Homepage: http://orgmode.org
  6. ;; Version: 0.01
  7. ;;; License:
  8. ;; This program is free software; you can redistribute it and/or modify
  9. ;; it under the terms of the GNU General Public License as published by
  10. ;; the Free Software Foundation; either version 3, or (at your option)
  11. ;; any later version.
  12. ;;
  13. ;; This program is distributed in the hope that it will be useful,
  14. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. ;; GNU General Public License for more details.
  17. ;;
  18. ;; You should have received a copy of the GNU General Public License
  19. ;; along with GNU Emacs; see the file COPYING. If not, write to the
  20. ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  21. ;; Boston, MA 02110-1301, USA.
  22. ;;; Commentary:
  23. ;; Functions for referencing data from the header arguments of a
  24. ;; litorgical block. The syntax of such a reference should be
  25. ;;
  26. ;; #+VAR: variable-name=file:resource-id
  27. ;;
  28. ;; - variable-name :: the name of the variable to which the value
  29. ;; will be assigned
  30. ;;
  31. ;; - file :: path to the file containing the resource, or omitted if
  32. ;; resource is in the current file
  33. ;;
  34. ;; - resource-id :: the id or name of the resource, or 'previous' to
  35. ;; grab the previous table, or 'next' to grab the
  36. ;; next table
  37. ;;
  38. ;; So an example of a simple src block referencing table data in the
  39. ;; same file would be
  40. ;;
  41. ;; #+var: table previous
  42. ;; #+begin_src emacs-lisp
  43. ;; (message table)
  44. ;; #+end_src
  45. ;;
  46. ;;; Code:
  47. (require 'litorgy)
  48. (defun litorgy-reference-variables (params)
  49. "Takes a parameter alist, and return an alist of variable
  50. names, and the string representation of the related value."
  51. (mapcar #'litorgy-reference-parse
  52. (delq nil (mapcar (lambda (pair) (if (= (car pair) :var) (cdr pair))) params))))
  53. (defun litorgy-reference-parse (reference)
  54. "Parse a reference to an external resource returning a list
  55. with two elements. The first element of the list will be the
  56. name of the variable, and the second will be an emacs-lisp
  57. representation of the value of the variable."
  58. (save-excursion
  59. (if (string-match "(.+)=(.+)" reference)
  60. (let ((var (match-string 1 reference))
  61. (ref (match-string 2 reference)))
  62. (when (string-match "(.+):(.+)" reference)
  63. (find-file (match-string 1 reference))
  64. (setf ref (match-string 2 reference)))
  65. ;; follow the reference in the current file
  66. (case ref
  67. ("previous"
  68. )
  69. ("next")
  70. (t ))
  71. ))))
  72. (provide 'litorgy-reference)
  73. ;;; litorgy-reference.el ends here