Skip to content

Commit

Permalink
NORMAL added ^ and .^ support, for and forcell with indexing options.
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentToups committed Apr 20, 2012
1 parent 871526a commit 0c1ec4b
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 9 deletions.
20 changes: 17 additions & 3 deletions auxilliary.el
Expand Up @@ -7,25 +7,39 @@

(defun parenlab-do (p)
(interactive "P")
(message "%S" p)

(let* ((code-string
(if p
(read-from-minibuffer "pl: ")
(concat "(" (buffer-substring (point-min) (point-max))
")")))
(code (append (list 'script (intern (replace-string-in-string ".parenlab" "" (buffer-name)))) (car (read-from-string code-string)))))
(message "%S" code)

(pl:transcode code)
(comint-send-strings (get-buffer pla:matlab-buffer)
(pl:mangle (replace-string-in-string ".parenlab" "" (buffer-name))))))

(defun parenlab-do-last-sexp ()
(interactive "")
(save-excursion
(let ((code (get-last-sexp)))
(let* ((code (get-last-sexp))
(code `(emessage (evalc ',code))))
;; Note that the above code uses my personal matlab function
;; emessage which sends a message to emacs from matlab, it is
;; not included with this library.
(comint-send-strings (get-buffer pla:matlab-buffer)
(pl:transcode-to-string code)))))

(defun parenlab-do-region (s e)
(interactive "r")
(let ((string (concat "(block "
(buffer-substring s e)
")")))
(comint-send-strings (get-buffer pla:matlab-buffer)
(pl:transcode-to-string
(car (read-from-string string))))))


(add-to-list 'auto-mode-alist (cons "\\.parenlab"
(lambda ()
(lisp-mode)
Expand Down
2 changes: 2 additions & 0 deletions caret.m
@@ -0,0 +1,2 @@
function r=caret(b,e)
r=b^e;
2 changes: 2 additions & 0 deletions dotcaret.m
@@ -0,0 +1,2 @@
function r = dotcaret(base,exponent)
r = base.^exponent;
43 changes: 37 additions & 6 deletions parenlab.el
Expand Up @@ -33,10 +33,16 @@
(s1 (replace-regexp-in-string "-\\([a-z]\\)"
(lambda (x)
(upcase (substring x 1)))
s)))
s))
(s1 (replace-regexp-in-string (regexp-quote "%")
"modsign"
s1))
(s1 (if (string= "." (substring s1 0 1))
(concat "dot" (substring s1 1))
s1)))
(replace-regexp-in-string
(rx
(| "+" "-" "*" "$" "!" ":" "/" "\\" "#" "@" "?" "="
(| "+" "-" "*" "%" "$" "&" "^" "!" ":" "/" "\\" "#" "@" "?" "="
"<" ">"))
(match-lambda
("+" "plus")
Expand All @@ -46,9 +52,12 @@
(">" "greaterThan")
("$" "cash")
("=" "equal")
("%" "modsign")
("!" "bang")
("?" "who")
(":" ":")
("&" "ampersand")
("^" "caret")
("/" "divide")
("\\" "mdivide")
("#" "hash")
Expand Down Expand Up @@ -143,6 +152,10 @@
the value of the forms."
(pl:transcode (pl:transcode-to-string form)))

(defun-match pl:transcode ((list-rest 'elisp forms))
"Escape and execute lisp FORMS."
(eval `(progn ,@forms)))

(defun-match pl:transcode ((list 'not form))
"Translate the not operator."
(pl:insertf "~(")
Expand Down Expand Up @@ -383,6 +396,23 @@ regular, non-functional if statement."
(pl:insertf "end\n")
(indent-region start (point))))

(defun-match pl:transcode ((list-rest 'forcell
(p #'symbolp v)
expr
body))
(pl:transcode `(for ,v expr
(setq ,v ({} ,v 1))
,@body)))

(defun-match pl:transcode ((list-rest 'forcell
(list (p #'symbolp i)
(p #'symbolp v))
expr
body))
(pl:transcode `(for (,i ,v) ,expr
(setq ,v ({} ,v 1))
,@body)))

(defun-match pl:transcode ((list 'literally string))
"Allows you to insert code directly into the output stream."
(pl:insertf string))
Expand Down Expand Up @@ -511,9 +541,7 @@ regular, non-functional if statement."
when (< i (length arguments))
do
(pl:insertf ", ")
(if (and (> i 3)
(= 0 (mod i 2)))
(pl:insertf "...\n") ))
)
(pl:insertf ")")
(indent-region start (point))))

Expand Down Expand Up @@ -570,9 +598,12 @@ with the transcoded code."
(pl:defun (s) extend-struct (s f val)
(setq (.. s f) val))

(pl:def-pl-macro dont-do (&rest body)
())

(defmacro* pl:pl (&body body)
"Transcode BODY to matlab."
`(pl:transcode ',body))
`(pl:transcode '(block ,@body)))

(provide 'parenlab)

0 comments on commit 0c1ec4b

Please sign in to comment.