diff options
author | Jose Antonio Ortega Ruiz <jao@gnu.org> | 2009-02-17 00:44:11 +0100 |
---|---|---|
committer | Jose Antonio Ortega Ruiz <jao@gnu.org> | 2009-02-17 00:44:11 +0100 |
commit | 6e89d965f1b0a8329ddc012feb36fd43c591acbf (patch) | |
tree | fe01c5fd6bc286dc3f360ec5a90338619a5f6c1d | |
parent | 41d54012368ca33461fe3e8668c2b0e3052af3b8 (diff) | |
download | geiser-guile-6e89d965f1b0a8329ddc012feb36fd43c591acbf.tar.gz geiser-guile-6e89d965f1b0a8329ddc012feb36fd43c591acbf.tar.bz2 |
Separate commands for evaluation and compilation.
-rw-r--r-- | elisp/geiser-autodoc.el | 7 | ||||
-rw-r--r-- | elisp/geiser-compile.el | 2 | ||||
-rw-r--r-- | elisp/geiser-completion.el | 6 | ||||
-rw-r--r-- | elisp/geiser-doc.el | 4 | ||||
-rw-r--r-- | elisp/geiser-edit.el | 6 | ||||
-rw-r--r-- | elisp/geiser-eval.el | 28 | ||||
-rw-r--r-- | elisp/geiser-mode.el | 77 | ||||
-rw-r--r-- | elisp/geiser-syntax.el | 4 | ||||
-rw-r--r-- | scheme/guile/geiser/eval.scm | 33 |
9 files changed, 111 insertions, 56 deletions
diff --git a/elisp/geiser-autodoc.el b/elisp/geiser-autodoc.el index 7a63ef4..3c23b32 100644 --- a/elisp/geiser-autodoc.el +++ b/elisp/geiser-autodoc.el @@ -74,9 +74,10 @@ when `geiser-autodoc-display-module-p' is on." (cdr geiser-autodoc--last) (cdr pr)) (setq geiser-autodoc--last-funs funs) - (geiser-eval--send `(:gs ((:ge arguments) ,@(mapcar (lambda (f) (list 'quote (car f))) - funs))) - 'geiser-autodoc--function-args-cont) + (geiser-eval--send + `(:eval ((:ge arguments) + ,@(mapcar (lambda (f) (list 'quote (car f))) funs))) + 'geiser-autodoc--function-args-cont) "")))) (defun geiser-autodoc--function-args-cont (ret) diff --git a/elisp/geiser-compile.el b/elisp/geiser-compile.el index bb85637..2c51425 100644 --- a/elisp/geiser-compile.el +++ b/elisp/geiser-compile.el @@ -76,7 +76,7 @@ (msg (format "%s %s ..." msg path))) (message msg) (geiser-compile--display-result - msg (geiser-eval--send/wait `(:gs ((:ge ,op) ,path) (geiser eval)))))) + msg (geiser-eval--send/wait `(:eval ((:ge ,op) ,path) (geiser eval)))))) ;;; User commands: diff --git a/elisp/geiser-completion.el b/elisp/geiser-completion.el index 22b36a1..fd22044 100644 --- a/elisp/geiser-completion.el +++ b/elisp/geiser-completion.el @@ -145,10 +145,10 @@ terminates a current completion." ;;; Completion functionality: (defsubst geiser-completion--symbol-list (prefix) - (geiser-eval--send/result `(:gs ((:ge completions) ,prefix)))) + (geiser-eval--send/result `(:eval ((:ge completions) ,prefix)))) (defsubst geiser-completion--module-list () - (geiser-eval--send/result '(:gs ((:ge all-modules))))) + (geiser-eval--send/result '(:eval ((:ge all-modules))))) (defvar geiser-completion--symbol-list-func (completion-table-dynamic 'geiser-completion--symbol-list)) @@ -178,7 +178,7 @@ terminates a current completion." (completing-read (or prompt "Module name: ") (geiser-completion--module-list) nil nil - (or default (geiser-syntax--buffer-module)) + (or default (format "%s" (or (geiser-syntax--buffer-module) "("))) (or history geiser-completion--module-history)))) (defun geiser--respecting-message (format &rest format-args) diff --git a/elisp/geiser-doc.el b/elisp/geiser-doc.el index 6bb1d10..3a1759c 100644 --- a/elisp/geiser-doc.el +++ b/elisp/geiser-doc.el @@ -53,10 +53,10 @@ ;;; Docstrings: (defun geiser-doc--get-docstring (symbol) - (geiser-eval--send/result `(:gs ((:ge docstring) ',symbol)))) + (geiser-eval--send/result `(:eval ((:ge docstring) ',symbol)))) (defun geiser-doc--get-module-children (module) - (geiser-eval--send/result `(:gs ((:ge module-children) (quote (:scm ,module)))))) + (geiser-eval--send/result `(:eval ((:ge module-children) (quote (:scm ,module)))))) ;;; Auxiliary functions: diff --git a/elisp/geiser-edit.el b/elisp/geiser-edit.el index 5d6ca46..fad08b6 100644 --- a/elisp/geiser-edit.el +++ b/elisp/geiser-edit.el @@ -95,7 +95,7 @@ (let* ((symbol (geiser-completion--read-symbol "Edit symbol: " nil geiser-edit--symbol-history)) - (cmd `(:gs ((:ge symbol-location) ',symbol)))) + (cmd `(:eval ((:ge symbol-location) ',symbol)))) (geiser-edit--try-edit symbol (geiser-eval--send/wait cmd)))) (defun geiser-edit-symbol-at-point (&optional arg) @@ -104,7 +104,7 @@ With prefix, asks for the symbol to edit." (interactive "P") (let* ((symbol (or (and (not arg) (symbol-at-point)) (geiser-completion--read-symbol "Edit symbol: "))) - (cmd `(:gs ((:ge symbol-location) ',symbol))) + (cmd `(:eval ((:ge symbol-location) ',symbol))) (marker (point-marker))) (geiser-edit--try-edit symbol (geiser-eval--send/wait cmd)) (when marker (ring-insert find-tag-marker-ring marker)))) @@ -119,7 +119,7 @@ With prefix, asks for the symbol to edit." (defun geiser-edit-module (module) "Asks for a module and opens it in a new buffer." (interactive (list (geiser-completion--read-module))) - (let ((cmd `(:gs ((:ge module-location) (quote (:scm ,module)))))) + (let ((cmd `(:eval ((:ge module-location) (quote (:scm ,module)))))) (geiser-edit--try-edit module (geiser-eval--send/wait cmd)))) diff --git a/elisp/geiser-eval.el b/elisp/geiser-eval.el index b1bd83b..4566d0b 100644 --- a/elisp/geiser-eval.el +++ b/elisp/geiser-eval.el @@ -38,22 +38,30 @@ ((eq code :f) "#f") ((eq code :t) "#t") ((listp code) - (cond ((eq (car code) :gs) (geiser-eval--gs (cdr code))) + (cond ((eq (car code) :eval) (geiser-eval--eval (cdr code))) + ((eq (car code) :comp) (geiser-eval--comp (cdr code))) + ((eq (car code) :module) (geiser-eval--module (cadr code))) ((eq (car code) :ge) (geiser-eval--ge (cadr code))) ((eq (car code) :scm) (cadr code)) (t (concat "(" (mapconcat 'geiser-eval--scheme-str code " ") ")")))) ((symbolp code) (format "%s" code)) (t (format "%S" code)))) -(defsubst geiser-eval--gs (code) - (concat "((@ (geiser eval) eval-in) (quote " - (geiser-eval--scheme-str (nth 0 code)) - ") (quote " - (or (and (nth 1 code) - (geiser-eval--scheme-str (nth 1 code))) - (geiser-syntax--buffer-module) - "#f") - "))")) +(defsubst geiser-eval--eval (code) + (geiser-eval--scheme-str + `((@ (geiser eval) eval-in) (quote ,(nth 0 code)) (:module ,(nth 1 code))))) + +(defsubst geiser-eval--comp (code) + (geiser-eval--scheme-str + `((@ (geiser eval) compile-in) (quote ,(nth 0 code)) (:module ,(nth 1 code))))) + +(defsubst geiser-eval--module (code) + (geiser-eval--scheme-str + (cond ((or (eq code '(())) (null code)) + `(quote ,(or (geiser-syntax--buffer-module) :f))) + ((listp code) `(quote ,code)) + ((stringp code) (:scm code)) + (t (error "Invalid module spec: %S" code))))) (defsubst geiser-eval--ge (proc) (format "(@ (geiser emacs) ge:%s)" proc)) diff --git a/elisp/geiser-mode.el b/elisp/geiser-mode.el index cd7a5a6..3c2f1a9 100644 --- a/elisp/geiser-mode.el +++ b/elisp/geiser-mode.el @@ -70,16 +70,9 @@ (newline)) (geiser-mode--pop-to-buffer))) - -;;; Evaluation commands: - -(defun geiser-send-region (start end &optional and-go) - "Send the current region to the Geiser REPL. -With prefix, goes to the REPL buffer afterwards (as -`geiser-send-region-and-go')" - (interactive "rP") +(defun geiser-eval--send-region (compile start end and-go) (let* ((str (buffer-substring-no-properties start end)) - (code `(:gs (:scm ,str))) + (code `(,(if compile :comp :eval) (:scm ,str))) (ret (geiser-eval--send/wait code)) (err (geiser-eval--retort-error ret))) (when and-go @@ -90,31 +83,57 @@ With prefix, goes to the REPL buffer afterwards (as (message (format "=> %s" (geiser-eval--retort-result ret))) (geiser-eval--display-error err (geiser-eval--retort-output ret))))) -(defun geiser-send-region-and-go (start end) - "Send the current region to the Geiser REPL and visit it afterwads." + +;;; Evaluation commands: + +(defun geiser-eval-region (start end &optional and-go) + "Eval the current region in the Geiser REPL. +With prefix, goes to the REPL buffer afterwards (as +`geiser-eval-region-and-go')" + (interactive "rP") + (geiser-eval--send-region nil start end and-go)) + +(defun geiser-eval-region-and-go (start end) + "Eval the current region in the Geiser REPL and visit it afterwads." (interactive "r") - (geiser-send-region start end t)) + (geiser-eval-region start end t)) -(defun geiser-send-definition (&optional and-go) - "Send the current definition to the Geiser REPL. +(defun geiser-eval-definition (&optional and-go) + "Eval the current definition in the Geiser REPL. With prefix, goes to the REPL buffer afterwards (as -`geiser-send-definition-and-go')" +`geiser-eval-definition-and-go')" (interactive "P") (save-excursion (end-of-defun) (let ((end (point))) (beginning-of-defun) - (geiser-send-region (point) end and-go)))) + (geiser-eval-region (point) end and-go)))) + +(defun geiser-eval-definition-and-go () + "Eval the current definition in the Geiser REPL and visit it afterwads." + (interactive) + (geiser-eval-definition t)) -(defun geiser-send-definition-and-go () - "Send the current definition to the Geiser REPL and visit it afterwads." +(defun geiser-eval-last-sexp () + "Eval the previous sexp in the Geiser REPL." (interactive) - (geiser-send-definition t)) + (geiser-eval-region (save-excursion (backward-sexp) (point)) (point))) + +(defun geiser-compile-definition (&optional and-go) + "Compile the current definition in the Geiser REPL. +With prefix, goes to the REPL buffer afterwards (as +`geiser-eval-definition-and-go')" + (interactive "P") + (save-excursion + (end-of-defun) + (let ((end (point))) + (beginning-of-defun) + (geiser-eval--send-region t (point) end and-go)))) -(defun geiser-send-last-sexp () - "Send the previous sexp to the Geiser REPL." +(defun geiser-compile-definition-and-go () + "Compile the current definition in the Geiser REPL and visit it afterwads." (interactive) - (geiser-send-region (save-excursion (backward-sexp) (point)) (point))) + (geiser-compile-definition t)) ;;; Geiser mode: @@ -159,11 +178,13 @@ interacting with the Geiser REPL is at your disposal. (define-key geiser-mode-map "\M-." 'geiser-edit-symbol-at-point) (define-key geiser-mode-map "\M-," 'geiser-edit-pop-edit-symbol-stack) -(define-key geiser-mode-map "\M-\C-x" 'geiser-send-definition) -(define-key geiser-mode-map "\C-x\C-e" 'geiser-send-last-sexp) -(define-key geiser-mode-map "\C-c\M-e" 'geiser-send-definition-and-go) -(define-key geiser-mode-map "\C-c\C-r" 'geiser-send-region) -(define-key geiser-mode-map "\C-c\M-r" 'geiser-send-region-and-go) +(define-key geiser-mode-map "\M-\C-x" 'geiser-eval-definition) +(define-key geiser-mode-map "\C-x\C-e" 'geiser-eval-last-sexp) +(define-key geiser-mode-map "\C-c\M-e" 'geiser-eval-definition-and-go) +(define-key geiser-mode-map "\C-c\C-r" 'geiser-eval-region) +(define-key geiser-mode-map "\C-c\M-r" 'geiser-eval-region-and-go) +(define-key geiser-mode-map "\C-c\M-c" 'geiser-compile-definition) +(define-key geiser-mode-map "\C-c\C-c" 'geiser-compile-definition-and-go) (geiser-mode--triple-chord ?d ?a 'geiser-autodoc-mode) (geiser-mode--triple-chord ?d ?d 'geiser-doc-symbol-at-point) @@ -171,8 +192,6 @@ interacting with the Geiser REPL is at your disposal. (geiser-mode--triple-chord ?e ?m 'geiser-edit-module) -(define-key geiser-mode-map "\C-c\M-c" 'geiser-compile-definition) -(define-key geiser-mode-map "\C-c\C-c" 'geiser-compile-definition-and-go) (define-key geiser-mode-map "\C-c\C-t" 'geiser-trace-procedure) (define-key geiser-mode-map "\C-c\C-x" 'geiser-expand-current-form) diff --git a/elisp/geiser-syntax.el b/elisp/geiser-syntax.el index 6577152..2c69a5c 100644 --- a/elisp/geiser-syntax.el +++ b/elisp/geiser-syntax.el @@ -40,7 +40,7 @@ (save-excursion (goto-char (point-min)) (when (re-search-forward geiser-syntax--module-definition-re nil t) - (match-string-no-properties 1)))))) + (car (read-from-string (match-string-no-properties 1)))))))) ;;; Indentation: @@ -48,6 +48,8 @@ (let ((defuns '(catch))) (mapc (lambda (d) (put d 'scheme-indent-function 'defun)) defuns))) +(geiser-syntax--setup-scheme-indent) + ;;; Code parsing: diff --git a/scheme/guile/geiser/eval.scm b/scheme/guile/geiser/eval.scm index a74bf29..fc5d7bd 100644 --- a/scheme/guile/geiser/eval.scm +++ b/scheme/guile/geiser/eval.scm @@ -25,7 +25,7 @@ ;;; Code: (define-module (geiser eval) - #:export (eval-in comp-file load-file) + #:export (eval-in compile-in comp-file load-file) #:use-module (srfi srfi-1) #:no-backtrace) @@ -45,13 +45,38 @@ SUBR, MSG and REST." (output (with-output-to-string (lambda () + (set! result (eval form module)))))) + (make-result result output))) + error-handler))) + +(define (compile-in form module-name) + "Compiles @var{form} in the module designated by @var{module-name}. +If @var{module-name} is @var{#f} or resolution fails, the current module is used instead. +The result is a list of the form ((RESULT . <form-value>) (OUTPUT . <string>)) +if no evaluation error happens, or ((ERROR (KEY . <error-key>) <error-arg>...)) +in case of errors. Each error arg is a cons (NAME . VALUE), where NAME includes +SUBR, MSG and REST." + (let ((module (or (and (list? module-name) + (resolve-module module-name)) + (current-module)))) + (catch #t + (lambda () + (let* ((result #f) + (output + (with-output-to-string + (lambda () (save-module-excursion (lambda () (set-current-module module) (set! result (compile form)))))))) - (list (cons 'result result) (cons 'output output)))) - (lambda (key . args) - (list (cons 'error (apply parse-error (cons key args)))))))) + (make-result result output))) + error-handler))) + +(define (make-result result output) + (list (cons 'result result) (cons 'output output))) + +(define (error-handler key . args) + (list (cons 'error (apply parse-error (cons key args))))) (define (parse-error key . args) (let* ((len (length args)) |