fixed error w/simple ruby arrays, and added litorgy-chomp function
This commit is contained in:
parent
6940577d8e
commit
b6f2fc7e0d
|
@ -1,4 +1,4 @@
|
|||
;;; litorgy-script.el --- litorgy functions for script execution
|
||||
;;; litorgy-script.el --- litorgy functions for scripting languages
|
||||
|
||||
;; Copyright (C) 2009 Eric Schulte
|
||||
|
||||
|
@ -92,7 +92,7 @@ executed through litorgy."
|
|||
(format "\treturn %s\n" (car (last body-lines)))))))
|
||||
;; (message (buffer-substring (point-min) (point-max))) ;; debug script
|
||||
(shell-command-on-region (point-min) (point-max) cmd nil 'replace)
|
||||
;; (message (buffer-string)) ;; debug results
|
||||
;; (message (format "shell output = %s" (buffer-string))) ;; debug results
|
||||
(litorgy-script-table-or-results (buffer-string))))))
|
||||
|
||||
(defun litorgy-script-var-to-ruby/python (var)
|
||||
|
@ -105,21 +105,18 @@ code specifying a var of the same value."
|
|||
(defun litorgy-script-table-or-results (results)
|
||||
"If the results look like a table, then convert them into an
|
||||
Emacs-lisp table, otherwise return the results as a string."
|
||||
(setq results (litorgy-chomp results))
|
||||
(litorgy-read
|
||||
(if (string-match "^\\[.+\\]$" results)
|
||||
;; somewhat hacky, but thanks to similarities between languages
|
||||
;; it seems to work
|
||||
(litorgy-read
|
||||
(replace-regexp-in-string
|
||||
"\\[" "(" (replace-regexp-in-string
|
||||
"\\]" ")" (replace-regexp-in-string
|
||||
", " " " (replace-regexp-in-string
|
||||
"'" "\"" results)))))
|
||||
;; strip trailing endline
|
||||
(progn
|
||||
(while (string= "\n" (substring results -1))
|
||||
(setq results (substring results 0 -1)))
|
||||
results))))
|
||||
"\\[" "(" (replace-regexp-in-string
|
||||
"\\]" ")" (replace-regexp-in-string
|
||||
", " " " (replace-regexp-in-string
|
||||
"'" "\"" results)))))
|
||||
(litorgy-chomp results))))
|
||||
|
||||
(provide 'litorgy-script)
|
||||
;;; litorgy-script.el ends here
|
||||
|
|
|
@ -277,5 +277,13 @@ This is taken almost directly from `org-read-prop'."
|
|||
"Return t if STRING represents a number"
|
||||
(string-match "^[[:digit:]]*\\.?[[:digit:]]*$" string))
|
||||
|
||||
(defun litorgy-chomp (string &optional regexp)
|
||||
"Remove any trailing space or carriage returns characters from
|
||||
STRING. Default regexp used is \"[ \f\t\n\r\v]\" but can be
|
||||
overwritten by specifying a regexp as a second argument."
|
||||
(while (string-match "[ \f\t\n\r\v]" (substring results -1))
|
||||
(setq results (substring results 0 -1)))
|
||||
results)
|
||||
|
||||
(provide 'litorgy)
|
||||
;;; litorgy.el ends here
|
||||
|
|
27
rorg.org
27
rorg.org
|
@ -312,11 +312,11 @@ This is currently working only with emacs lisp as in the following
|
|||
example in the [[* emacs lisp source reference][emacs lisp source reference]].
|
||||
|
||||
|
||||
* Bugs [3/4]
|
||||
* Bugs [4/5]
|
||||
|
||||
** TODO extra quotes for nested string
|
||||
when string are 2 deep in org-mode tables their quotes aren't being
|
||||
stripped
|
||||
when string are nested 2 deep in org-mode tables their quotes aren't
|
||||
being stripped
|
||||
|
||||
these should not be quoted
|
||||
#+srcname: ls
|
||||
|
@ -342,8 +342,23 @@ ls
|
|||
|
||||
#+srcname: ruby-quote-test
|
||||
#+begin_src ruby
|
||||
puts %w(eric michael schulte)
|
||||
[3, 4, 5]
|
||||
#+end_src
|
||||
|
||||
** RESOLVED simple ruby arrays not working
|
||||
|
||||
As an example eval the following. Adding a line to test
|
||||
|
||||
#+srcname: simple-ruby-array
|
||||
#+begin_src ruby
|
||||
[3, 4, 5]
|
||||
#+end_src
|
||||
|
||||
#+srcname: ruby-array-test
|
||||
#+begin_src ruby :var ar = simple-ruby-array
|
||||
ar.first
|
||||
#+end_src
|
||||
|
||||
** RESOLVED space trailing language name
|
||||
fix regexp so it works when there's a space trailing the language name
|
||||
|
||||
|
@ -430,6 +445,10 @@ litorgy functionality.
|
|||
| of | Fibonacci | 3 | 3 | 3 | pass |
|
||||
| different | Fibonacci | 4 | 5 | 5 | pass |
|
||||
| arguments | Fibonacci | 5 | 8 | 8 | pass |
|
||||
|-------------------------+------------------+-----+-------------+-------------+------|
|
||||
| bug fixing | | | | | pass |
|
||||
|-------------------------+------------------+-----+-------------+-------------+------|
|
||||
| simple ruby arrays | ruby-array-test | | 3 | 3 | pass |
|
||||
#+TBLFM: $5='(if (= (length $3) 1) (progn (message (format "running %S" '(sbe $2 (n $3)))) (sbe $2 (n $3))) (sbe $2))::$6='(if (string= $4 $5) "pass" (format "expected %S but was %S" $4 $5))
|
||||
|
||||
** basic tests
|
||||
|
|
Loading…
Reference in New Issue