From 2d30daecad657d692a7f3cb66deb496630362600 Mon Sep 17 00:00:00 2001 From: Jose Antonio Ortega Ruiz Date: Mon, 24 May 2010 00:03:30 +0200 Subject: Racket: PLT implementation renamed to Racket. --- elisp/geiser-impl.el | 2 +- elisp/geiser-plt.el | 208 ---------------------------------- elisp/geiser-racket.el | 209 +++++++++++++++++++++++++++++++++++ elisp/geiser.el | 10 +- scheme/Makefile.am | 20 ++-- scheme/plt/geiser.rkt | 22 ---- scheme/plt/geiser/autodoc.rkt | 189 ------------------------------- scheme/plt/geiser/completions.rkt | 31 ------ scheme/plt/geiser/enter.rkt | 103 ----------------- scheme/plt/geiser/eval.rkt | 81 -------------- scheme/plt/geiser/locations.rkt | 54 --------- scheme/plt/geiser/main.rkt | 47 -------- scheme/plt/geiser/modules.rkt | 150 ------------------------- scheme/plt/geiser/user.rkt | 57 ---------- scheme/plt/geiser/utils.rkt | 27 ----- scheme/racket/geiser.rkt | 22 ++++ scheme/racket/geiser/autodoc.rkt | 189 +++++++++++++++++++++++++++++++ scheme/racket/geiser/completions.rkt | 31 ++++++ scheme/racket/geiser/enter.rkt | 103 +++++++++++++++++ scheme/racket/geiser/eval.rkt | 81 ++++++++++++++ scheme/racket/geiser/locations.rkt | 54 +++++++++ scheme/racket/geiser/main.rkt | 47 ++++++++ scheme/racket/geiser/modules.rkt | 150 +++++++++++++++++++++++++ scheme/racket/geiser/user.rkt | 56 ++++++++++ scheme/racket/geiser/utils.rkt | 27 +++++ 25 files changed, 985 insertions(+), 985 deletions(-) delete mode 100644 elisp/geiser-plt.el create mode 100644 elisp/geiser-racket.el delete mode 100644 scheme/plt/geiser.rkt delete mode 100644 scheme/plt/geiser/autodoc.rkt delete mode 100644 scheme/plt/geiser/completions.rkt delete mode 100644 scheme/plt/geiser/enter.rkt delete mode 100644 scheme/plt/geiser/eval.rkt delete mode 100644 scheme/plt/geiser/locations.rkt delete mode 100644 scheme/plt/geiser/main.rkt delete mode 100644 scheme/plt/geiser/modules.rkt delete mode 100644 scheme/plt/geiser/user.rkt delete mode 100644 scheme/plt/geiser/utils.rkt create mode 100644 scheme/racket/geiser.rkt create mode 100644 scheme/racket/geiser/autodoc.rkt create mode 100644 scheme/racket/geiser/completions.rkt create mode 100644 scheme/racket/geiser/enter.rkt create mode 100644 scheme/racket/geiser/eval.rkt create mode 100644 scheme/racket/geiser/locations.rkt create mode 100644 scheme/racket/geiser/main.rkt create mode 100644 scheme/racket/geiser/modules.rkt create mode 100644 scheme/racket/geiser/user.rkt create mode 100644 scheme/racket/geiser/utils.rkt diff --git a/elisp/geiser-impl.el b/elisp/geiser-impl.el index e5bff0a..1c3347c 100644 --- a/elisp/geiser-impl.el +++ b/elisp/geiser-impl.el @@ -26,7 +26,7 @@ :type 'symbol :group 'geiser-implementation) -(geiser-custom--defcustom geiser-active-implementations '(guile plt) +(geiser-custom--defcustom geiser-active-implementations '(guile racket) "List of active installed Scheme implementations." :type '(repeat symbol) :group 'geiser-implementation) diff --git a/elisp/geiser-plt.el b/elisp/geiser-plt.el deleted file mode 100644 index 64b770d..0000000 --- a/elisp/geiser-plt.el +++ /dev/null @@ -1,208 +0,0 @@ -;; geiser-plt.el -- geiser support for PLT scheme - -;; Copyright (C) 2009, 2010 Jose Antonio Ortega Ruiz - -;; This program is free software; you can redistribute it and/or -;; modify it under the terms of the Modified BSD License. You should -;; have received a copy of the license along with this program. If -;; not, see . - -;; Start date: Sat Apr 25, 2009 21:13 - - - -(require 'geiser-edit) -(require 'geiser-doc) -(require 'geiser-eval) -(require 'geiser-syntax) -(require 'geiser-custom) -(require 'geiser-base) - - -;;; Customization: - -(defgroup geiser-plt nil - "Customization for Geiser's PLT flavour." - :group 'geiser) - -(geiser-custom--defcustom geiser-plt-binary - (cond ((eq system-type 'windows-nt) "Racket.exe") - ((eq system-type 'darwin) "racket") - (t "racket")) - "Name to use to call the mzscheme executable when starting a REPL." - :type '(choice string (repeat string)) - :group 'geiser-plt) - -(geiser-custom--defcustom geiser-plt-collects nil - "A list of paths to be added to mzscheme's collection directories." - :type '(repeat file) - :group 'geiser-plt) - -(geiser-custom--defcustom geiser-plt-init-file "~/.plt-geiser" - "Initialization file with user code for the mzscheme REPL." - :type 'string - :group 'geiser-plt) - - - -;;; REPL support: - -(defun geiser-plt--binary () - (if (listp geiser-plt-binary) (car geiser-plt-binary) geiser-plt-binary)) - -(defun geiser-plt--parameters () - "Return a list with all parameters needed to start mzscheme. -This function uses `geiser-plt-init-file' if it exists." - (let ((init-file (and (stringp geiser-plt-init-file) - (expand-file-name geiser-plt-init-file)))) - `("-i" "-q" - "-S" ,(expand-file-name "plt/" geiser-scheme-dir) - ,@(apply 'append (mapcar (lambda (p) (list "-S" p)) geiser-plt-collects)) - ,@(and (listp geiser-plt-binary) (cdr geiser-plt-binary)) - ,@(and init-file (file-readable-p init-file) (list "-f" init-file)) - "-f" ,(expand-file-name "plt/geiser.rkt" geiser-scheme-dir)))) - -(defconst geiser-plt--prompt-regexp "^=?\\(mzscheme\\|racket\\)@[^ ]*?> ") - - -;;; Evaluation support: - -(defun geiser-plt--language () - (save-excursion - (goto-char (point-min)) - (if (re-search-forward - "^\\(?:#lang\\|(module +[^ ]+?\\) +\\([^ ]+?\\|([^)]+)\\) *$" nil t) - (car (geiser-syntax--read-from-string (match-string-no-properties 1))) - :f))) - -(defun geiser-plt--geiser-procedure (proc) - (if (memq proc '(eval compile)) - `((dynamic-require 'geiser 'geiser:eval) ',(geiser-plt--language)) - `(dynamic-require 'geiser ',(intern (format "geiser:%s" proc))))) - -(defconst geiser-plt--module-re - "^(module +\\([^ ]+\\)") - -(defun geiser-plt--explicit-module () - (save-excursion - (goto-char (point-min)) - (and (re-search-forward geiser-plt--module-re nil t) - (ignore-errors - (car (geiser-syntax--read-from-string - (match-string-no-properties 1))))))) - -(defsubst geiser-plt--implicit-module () - (save-excursion - (goto-char (point-min)) - (if (re-search-forward "^#lang " nil t) - (buffer-file-name) - :f))) - -(defun geiser-plt--get-module (&optional module) - (cond ((and (null module) (buffer-file-name))) - ;; (geiser-plt--explicit-module) - ((null module) (geiser-plt--implicit-module)) - ((symbolp module) module) - ((and (stringp module) (file-name-absolute-p module)) module) - ((stringp module) (intern module)) - (t nil))) - -(defun geiser-plt--symbol-begin (module) - (save-excursion (skip-syntax-backward "^-()>") (point))) - -(defun geiser-plt--enter-command (module) - (and (stringp module) (format "(enter! (file %S))" module))) - -(defconst geiser-plt--binding-forms - '(for for/list for/hash for/hasheq for/and for/or - for/lists for/first for/last for/fold)) - -(defconst geiser-plt--binding-forms* - '(for* for*/list for*/lists for*/hash for*/hasheq for*/and - for*/or for*/first for*/last for*/fold)) - -;;; External help - -(defsubst geiser-plt--get-help (symbol module) - (geiser-eval--send/wait - `(:eval (get-help ',symbol (:module ,module)) geiser/autodoc))) - -(defun geiser-plt--external-help (id module) - (message "Requesting help for '%s'..." id) - (let ((out (geiser-eval--retort-output (geiser-plt--get-help id module)))) - (when (and out (string-match " but provided by:\n +\\(.+\\)\n" out)) - (geiser-plt--get-help symbol (match-string 1 out)))) - (minibuffer-message "%s done" (current-message)) - t) - - -;;; Error display - -(defconst geiser-plt--file-rxs '("^\\([^:\n\"]+\\):\\([0-9]+\\):\\([0-9]+\\)" - "path:\"?\\([^>\"\n]+\\)\"?>" - "module: \"\\([^>\"\n]+\\)\"")) - -(defun geiser-plt--find-files (rx) - (save-excursion - (while (re-search-forward rx nil t) - (geiser-edit--make-link (match-beginning 1) - (match-end 1) - (match-string 1) - (match-string 2) - (match-string 3))))) - -(defun geiser-plt--display-error (module key msg) - (when key - (insert "Error: ") - (geiser-doc--insert-button key nil 'plt) - (newline 2)) - (when msg - (let ((p (point))) - (insert msg) - (when key - (let ((end (point))) - (goto-char p) - (mapc 'geiser-plt--find-files geiser-plt--file-rxs) - (goto-char end) - (newline))))) - t) - - -;;; Trying to ascertain whether a buffer is mzscheme scheme: - -(defun geiser-plt--guess () - (or (save-excursion - (goto-char (point-min)) - (re-search-forward "#lang " nil t)) - (geiser-plt--explicit-module))) - - -;;; Implementation definition: - -(define-geiser-implementation plt - (unsupported-procedures '(callers callees generic-methods)) - (binary geiser-plt--binary) - (arglist geiser-plt--parameters) - (startup) - (prompt-regexp geiser-plt--prompt-regexp) - (marshall-procedure geiser-plt--geiser-procedure) - (find-module geiser-plt--get-module) - (enter-command geiser-plt--enter-command) - (find-symbol-begin geiser-plt--symbol-begin) - (display-error geiser-plt--display-error) - (display-help geiser-plt--external-help) - (check-buffer geiser-plt--guess) - (binding-forms geiser-plt--binding-forms) - (binding-forms* geiser-plt--binding-forms*)) - -(geiser-impl--add-to-alist 'regexp - "\\.\\(mzscheme\\|racket\\)\\.sl?s$" 'plt t) -(geiser-impl--add-to-alist 'regexp "\\.ss$" 'plt t) -(geiser-impl--add-to-alist 'regexp "\\.rkt$" 'plt t) - -(defalias 'run-racket 'run-plt) -(defalias 'switch-to-racket 'switch-to-plt) - - -(provide 'geiser-plt) -;;; geiser-plt.el ends here diff --git a/elisp/geiser-racket.el b/elisp/geiser-racket.el new file mode 100644 index 0000000..dd086a5 --- /dev/null +++ b/elisp/geiser-racket.el @@ -0,0 +1,209 @@ +;; geiser-racket.el -- geiser support for Racket scheme + +;; Copyright (C) 2009, 2010 Jose Antonio Ortega Ruiz + +;; This program is free software; you can redistribute it and/or +;; modify it under the terms of the Modified BSD License. You should +;; have received a copy of the license along with this program. If +;; not, see . + +;; Start date: Sat Apr 25, 2009 21:13 + + + +(require 'geiser-edit) +(require 'geiser-doc) +(require 'geiser-eval) +(require 'geiser-syntax) +(require 'geiser-custom) +(require 'geiser-base) + + +;;; Customization: + +(defgroup geiser-racket nil + "Customization for Geiser's Racket flavour." + :group 'geiser) + +(geiser-custom--defcustom geiser-racket-binary + (cond ((eq system-type 'windows-nt) "Racket.exe") + ((eq system-type 'darwin) "racket") + (t "racket")) + "Name to use to call the mzscheme executable when starting a REPL." + :type '(choice string (repeat string)) + :group 'geiser-racket) + +(geiser-custom--defcustom geiser-racket-collects nil + "A list of paths to be added to mzscheme's collection directories." + :type '(repeat file) + :group 'geiser-racket) + +(geiser-custom--defcustom geiser-racket-init-file "~/.racket-geiser" + "Initialization file with user code for the mzscheme REPL." + :type 'string + :group 'geiser-racket) + + + +;;; REPL support: + +(defun geiser-racket--binary () + (if (listp geiser-racket-binary) + (car geiser-racket-binary) + geiser-racket-binary)) + +(defun geiser-racket--parameters () + "Return a list with all parameters needed to start mzscheme. +This function uses `geiser-racket-init-file' if it exists." + (let ((init-file (and (stringp geiser-racket-init-file) + (expand-file-name geiser-racket-init-file)))) + `("-i" "-q" + "-S" ,(expand-file-name "racket/" geiser-scheme-dir) + ,@(apply 'append (mapcar (lambda (p) (list "-S" p)) geiser-racket-collects)) + ,@(and (listp geiser-racket-binary) (cdr geiser-racket-binary)) + ,@(and init-file (file-readable-p init-file) (list "-f" init-file)) + "-f" ,(expand-file-name "racket/geiser.rkt" geiser-scheme-dir)))) + +(defconst geiser-racket--prompt-regexp "^=?\\(mzscheme\\|racket\\)@[^ ]*?> ") + + +;;; Evaluation support: + +(defun geiser-racket--language () + (save-excursion + (goto-char (point-min)) + (if (re-search-forward + "^\\(?:#lang\\|(module +[^ ]+?\\) +\\([^ ]+?\\|([^)]+)\\) *$" nil t) + (car (geiser-syntax--read-from-string (match-string-no-properties 1))) + :f))) + +(defun geiser-racket--geiser-procedure (proc) + (if (memq proc '(eval compile)) + `((dynamic-require 'geiser 'geiser:eval) ',(geiser-racket--language)) + `(dynamic-require 'geiser ',(intern (format "geiser:%s" proc))))) + +(defconst geiser-racket--module-re + "^(module +\\([^ ]+\\)") + +(defun geiser-racket--explicit-module () + (save-excursion + (goto-char (point-min)) + (and (re-search-forward geiser-racket--module-re nil t) + (ignore-errors + (car (geiser-syntax--read-from-string + (match-string-no-properties 1))))))) + +(defsubst geiser-racket--implicit-module () + (save-excursion + (goto-char (point-min)) + (if (re-search-forward "^#lang " nil t) + (buffer-file-name) + :f))) + +(defun geiser-racket--get-module (&optional module) + (cond ((and (null module) (buffer-file-name))) + ;; (geiser-racket--explicit-module) + ((null module) (geiser-racket--implicit-module)) + ((symbolp module) module) + ((and (stringp module) (file-name-absolute-p module)) module) + ((stringp module) (intern module)) + (t nil))) + +(defun geiser-racket--symbol-begin (module) + (save-excursion (skip-syntax-backward "^-()>") (point))) + +(defun geiser-racket--enter-command (module) + (and (stringp module) (format "(enter! (file %S))" module))) + +(defconst geiser-racket--binding-forms + '(for for/list for/hash for/hasheq for/and for/or + for/lists for/first for/last for/fold)) + +(defconst geiser-racket--binding-forms* + '(for* for*/list for*/lists for*/hash for*/hasheq for*/and + for*/or for*/first for*/last for*/fold)) + +;;; External help + +(defsubst geiser-racket--get-help (symbol module) + (geiser-eval--send/wait + `(:eval (get-help ',symbol (:module ,module)) geiser/autodoc))) + +(defun geiser-racket--external-help (id module) + (message "Requesting help for '%s'..." id) + (let ((out (geiser-eval--retort-output + (geiser-racket--get-help id module)))) + (when (and out (string-match " but provided by:\n +\\(.+\\)\n" out)) + (geiser-racket--get-help symbol (match-string 1 out)))) + (minibuffer-message "%s done" (current-message)) + t) + + +;;; Error display + +(defconst geiser-racket--file-rxs + '("^\\([^:\n\"]+\\):\\([0-9]+\\):\\([0-9]+\\)" + "path:\"?\\([^>\"\n]+\\)\"?>" + "module: \"\\([^>\"\n]+\\)\"")) + +(defun geiser-racket--find-files (rx) + (save-excursion + (while (re-search-forward rx nil t) + (geiser-edit--make-link (match-beginning 1) + (match-end 1) + (match-string 1) + (match-string 2) + (match-string 3))))) + +(defun geiser-racket--display-error (module key msg) + (when key + (insert "Error: ") + (geiser-doc--insert-button key nil 'racket) + (newline 2)) + (when msg + (let ((p (point))) + (insert msg) + (when key + (let ((end (point))) + (goto-char p) + (mapc 'geiser-racket--find-files geiser-racket--file-rxs) + (goto-char end) + (newline))))) + t) + + +;;; Trying to ascertain whether a buffer is mzscheme scheme: + +(defun geiser-racket--guess () + (or (save-excursion + (goto-char (point-min)) + (re-search-forward "#lang " nil t)) + (geiser-racket--explicit-module))) + + +;;; Implementation definition: + +(define-geiser-implementation racket + (unsupported-procedures '(callers callees generic-methods)) + (binary geiser-racket--binary) + (arglist geiser-racket--parameters) + (startup) + (prompt-regexp geiser-racket--prompt-regexp) + (marshall-procedure geiser-racket--geiser-procedure) + (find-module geiser-racket--get-module) + (enter-command geiser-racket--enter-command) + (find-symbol-begin geiser-racket--symbol-begin) + (display-error geiser-racket--display-error) + (display-help geiser-racket--external-help) + (check-buffer geiser-racket--guess) + (binding-forms geiser-racket--binding-forms) + (binding-forms* geiser-racket--binding-forms*)) + +(geiser-impl--add-to-alist 'regexp + "\\.\\(mzscheme\\|racket\\)\\.sl?s$" 'racket t) +(geiser-impl--add-to-alist 'regexp "\\.ss$" 'racket t) +(geiser-impl--add-to-alist 'regexp "\\.rkt$" 'racket t) + + +(provide 'geiser-racket) +;;; geiser-racket.el ends here diff --git a/elisp/geiser.el b/elisp/geiser.el index 4389652..b241b78 100644 --- a/elisp/geiser.el +++ b/elisp/geiser.el @@ -47,11 +47,11 @@ (autoload 'switch-to-guile "geiser-guile.el" "Start a Geiser Guile REPL, or switch to a running one." t) -(autoload 'run-plt "geiser-plt.el" - "Start a Geiser MzScheme REPL, or switch to a running one." t) +(autoload 'run-racket "geiser-racket.el" + "Start a Geiser Racket REPL, or switch to a running one." t) -(autoload 'switch-to-plt "geiser-guile.el" - "Start a Geiser MzScheme REPL, or switch to a running one." t) +(autoload 'switch-to-racket "geiser-guile.el" + "Start a Geiser Racket REPL, or switch to a running one." t) (autoload 'geiser-mode "geiser-mode.el" "Minor mode adding Geiser REPL interaction to Scheme buffers." t) @@ -72,7 +72,7 @@ geiser-faces geiser-mode geiser-guile - geiser-plt + geiser-racket geiser-implementation geiser-xref)) diff --git a/scheme/Makefile.am b/scheme/Makefile.am index adb25f8..d437bb6 100644 --- a/scheme/Makefile.am +++ b/scheme/Makefile.am @@ -7,13 +7,13 @@ nobase_dist_pkgdata_DATA = \ guile/geiser/modules.scm \ guile/geiser/utils.scm \ guile/geiser/xref.scm \ - plt/geiser.ss \ - plt/geiser/autodoc.ss \ - plt/geiser/completions.ss \ - plt/geiser/enter.ss \ - plt/geiser/eval.ss \ - plt/geiser/locations.ss \ - plt/geiser/main.ss \ - plt/geiser/modules.ss \ - plt/geiser/user.ss \ - plt/geiser/utils.ss + racket/geiser.rkt \ + racket/geiser/autodoc.rkt \ + racket/geiser/completions.rkt \ + racket/geiser/enter.rkt \ + racket/geiser/eval.rkt \ + racket/geiser/locations.rkt \ + racket/geiser/main.rkt \ + racket/geiser/modules.rkt \ + racket/geiser/user.rkt \ + racket/geiser/utils.rkt diff --git a/scheme/plt/geiser.rkt b/scheme/plt/geiser.rkt deleted file mode 100644 index 45d1289..0000000 --- a/scheme/plt/geiser.rkt +++ /dev/null @@ -1,22 +0,0 @@ -;;; geiser.rkt -- entry point - -;; Copyright (C) 2009, 2010 Jose Antonio Ortega Ruiz - -;; This program is free software; you can redistribute it and/or -;; modify it under the terms of the Modified BSD License. You should -;; have received a copy of the license along with this program. If -;; not, see . - -;; Start date: Sat Apr 25, 2009 22:36 - -;;; Code: - -(require version/utils) -(unless (version<=? "5.0" (version)) - (error 'geiser - "Racket version 5.0 or better required (found ~a)" - (version))) - -(require geiser/user) - -;;; geiser.rkt ends here diff --git a/scheme/plt/geiser/autodoc.rkt b/scheme/plt/geiser/autodoc.rkt deleted file mode 100644 index d6fffbb..0000000 --- a/scheme/plt/geiser/autodoc.rkt +++ /dev/null @@ -1,189 +0,0 @@ -;;; autodoc.rkt -- suport for autodoc echo - -;; Copyright (C) 2009, 2010 Jose Antonio Ortega Ruiz - -;; This program is free software; you can redistribute it and/or -;; modify it under the terms of the Modified BSD License. You should -;; have received a copy of the license along with this program. If -;; not, see . - -;; Start date: Sun May 03, 2009 14:45 - -#lang scheme - -(provide autodoc update-signature-cache get-help) - -(require geiser/utils geiser/modules geiser/locations scheme/help) - -(define (get-help symbol mod) - (with-handlers ((exn? (lambda (_) - (eval `(help ,symbol))))) - (eval `(help ,symbol #:from ,(ensure-module-spec mod))))) - -(define (autodoc ids) - (if (not (list? ids)) - '() - (map (lambda (id) (or (autodoc* id) (list id))) ids))) - -(define (autodoc* id) - (and - (symbol? id) - (let* ((loc (symbol-location* id)) - (name (car loc)) - (path (cdr loc)) - (sgns (and path (find-signatures path name id))) - (sgns (and sgns (if (list? sgns) sgns '())))) - (and sgns - `(,id - (name . ,name) - (args ,@(map format-signature sgns)) - (module . ,(module-path-name->name path))))))) - -(define (format-signature sign) - (if (signature? sign) - `((required ,@(signature-required sign)) - (optional ,@(signature-optional sign) - ,@(let ((rest (signature-rest sign))) - (if rest (list "...") '()))) - (key ,@(signature-keys sign))) - '())) - -(define signatures (make-hash)) - -(define-struct signature (required optional keys rest)) - -(define (find-signatures path name local-name) - (let ((path (if (path? path) (path->string path) path))) - (hash-ref! (hash-ref! signatures - path - (lambda () (parse-signatures path))) - name - (lambda () (infer-signatures local-name))))) - -(define (parse-signatures path) - (let ((result (make-hasheq))) - (with-handlers ((exn? (lambda (e) result))) - (with-input-from-file path - (lambda () - (parameterize ((read-accept-reader #t)) - (let loop ((stx (read-syntax path))) - (cond ((eof-object? stx) void) - ((syntax->datum stx) => - (lambda (datum) - (parse-datum! datum result) - (loop (read-syntax path)))) - (else void))))))) - result)) - -(define (parse-datum! datum store) - (with-handlers ((exn? (lambda (_) void))) - (match datum - (`(module ,name ,lang (#%module-begin . ,forms)) - (for-each (lambda (f) (parse-datum! f store)) forms)) - (`(module ,name ,lang . ,forms) - (for-each (lambda (f) (parse-datum! f store)) forms)) - (`(define ((,name . ,formals) . ,_) . ,_) - (add-signature! name formals store)) - (`(define (,name . ,formals) . ,_) - (add-signature! name formals store)) - (`(define ,name (lambda ,formals . ,_)) - (add-signature! name formals store)) - (`(define ,name (case-lambda ,clauses ...)) - (for-each (lambda (c) (add-signature! name (car c) store)) - (reverse clauses))) - (`(define-for-syntax (,name . ,formals) . ,_) - (add-signature! name formals store)) - (`(define-for-syntax ,name (lambda ,formals . ,_)) - (add-signature! name formals store)) - (`(define-syntax-rule (,name . ,formals) . ,_) - (add-signature! name formals store)) - (`(define-syntax ,name (syntax-rules ,specials . ,clauses)) - (for-each (lambda (c) (add-signature! name (cdar c) store)) - (reverse clauses))) - (`(define-syntax ,name (lambda ,_ (syntax-case ,_ . ,clauses))) - (for-each (lambda (c) (add-signature! name (cdar c) store)) - (reverse clauses))) - (_ void)))) - -(define (add-signature! name formals store) - (when (symbol? name) - (hash-set! store - name - (cons (parse-formals formals) - (hash-ref store name '()))))) - -(define (parse-formals formals) - (let loop ((formals formals) (req '()) (opt '()) (keys '())) - (cond ((null? formals) - (make-signature (reverse req) (reverse opt) (reverse keys) #f)) - ((symbol? formals) - (make-signature (reverse req) (reverse opt) - (reverse keys) formals)) - ((pair? (car formals)) (loop (cdr formals) - req - (cons (car formals) opt) - keys)) - ((keyword? (car formals)) (let* ((kname - (keyword->symbol (car formals))) - (arg-id (cadr formals)) - (name (if (pair? arg-id) - (list kname - (cadr arg-id)) - kname))) - (loop (cddr formals) - req - opt - (cons name keys)))) - (else (loop (cdr formals) (cons (car formals) req) opt keys))))) - -(define (infer-signatures name) - (define syntax-tag (cons 1 0)) - (define error-tag (cons 1 1)) - (define generic-signature (make-signature '(...) '() '() #f)) - (let ((value (with-handlers ((exn:fail:syntax? (lambda (_) syntax-tag)) - (exn:fail:contract:variable? (lambda (_) - error-tag))) - (namespace-variable-value name)))) - (cond ((procedure? value) (arity->signatures (procedure-arity value))) - ((eq? value syntax-tag) (list generic-signature)) - ((eq? value error-tag) #f) - (else 'variable)))) - -(define (arity->signatures arity) - (define (args fst count) - (let* ((letts (list->vector '(#\x #\y #\z #\u #\v #\w #\r #\s))) - (len (vector-length letts)) - (lett (lambda (n) (vector-ref letts (modulo n len))))) - (map (lambda (n) (string->symbol (format "~a" (lett n)))) - (build-list count (lambda (n) (+ n fst)))))) - (define (arity->signature arity) - (cond ((number? arity) - (make-signature (args 0 arity) '() '() #f)) - ((arity-at-least? arity) - (make-signature (args 0 (arity-at-least-value arity)) - '() '() 'rest)))) - (define (conseq? lst) - (cond ((< (length lst) 2) (number? (car lst))) - ((and (number? (car lst)) - (number? (cadr lst)) - (eqv? (+ 1 (car lst)) (cadr lst))) - (conseq? (cdr lst))) - (else #f))) - (cond ((and (list? arity) (conseq? arity)) - (let ((mi (apply min arity)) - (ma (apply max arity))) - (list (make-signature (args 0 mi) (args mi (- ma mi)) '() #f)))) - ((list? arity) (map arity->signature arity)) - (else (list (arity->signature arity))))) - -(define (update-signature-cache path . form) - (when (and (string? path) - (or (null? form) - (and (list? (car form)) - (not (null? (car form))) - (memq (caar form) - '(define-syntax-rule - define-syntax define set! define-struct))))) - (hash-remove! signatures path))) - -;;; autodoc.rkt ends here diff --git a/scheme/plt/geiser/completions.rkt b/scheme/plt/geiser/completions.rkt deleted file mode 100644 index e0ff239..0000000 --- a/scheme/plt/geiser/completions.rkt +++ /dev/null @@ -1,31 +0,0 @@ -;;; completions.rkt -- completion support - -;; Copyright (C) 2009, 2010 Jose Antonio Ortega Ruiz - -;; This program is free software; you can redistribute it and/or -;; modify it under the terms of the Modified BSD License. You should -;; have received a copy of the license along with this program. If -;; not, see . - -;; Start date: Sun Apr 26, 2009 19:02 - -#lang scheme - -(provide symbol-completions - module-completions) - -(require srfi/13 geiser/utils geiser/modules) - -(define (filter-prefix prefix lst sort?) - (filter (lambda (s) (string-prefix? prefix s)) - (if sort? (sort lst stringstring (namespace-mapped-symbols)) - #t)) - -(define (module-completions prefix) - (filter-prefix prefix (module-list) #f)) - -;;; completions.rkt ends here diff --git a/scheme/plt/geiser/enter.rkt b/scheme/plt/geiser/enter.rkt deleted file mode 100644 index 705482d..0000000 --- a/scheme/plt/geiser/enter.rkt +++ /dev/null @@ -1,103 +0,0 @@ -;;; enter.rkt -- custom module loaders - -;; Copyright (C) 2010 Jose Antonio Ortega Ruiz - -;; This program is free software; you can redistribute it and/or -;; modify it under the terms of the Modified BSD License. You should -;; have received a copy of the license along with this program. If -;; not, see . - -;; Start date: Wed Mar 31, 2010 21:53 - -#lang scheme/base - -(require syntax/modcode - (for-syntax scheme/base)) - -(provide get-namespace enter-module module-loader module-loaded?) - -(define-struct mod (name timestamp depends)) - -(define loaded (make-hash)) - -(define (module-loaded? path) - (with-handlers ((exn? (lambda (_) #f))) - (let ((rp (module-path-index-resolve (module-path-index-join path #f)))) - (hash-has-key? loaded (resolved-module-path-name rp))))) - -(define (enter-module mod) - (dynamic-require mod #f) - (check-latest mod)) - -(define (module-loader orig) - (enter-load/use-compiled orig #f)) - -(define (notify re? path) - (when re? - (fprintf (current-error-port) " [re-loading ~a]\n" path))) - -(define inhibit-eval (make-parameter #f)) - -(define (get-namespace mod) - (parameterize ([inhibit-eval #t]) - (module->namespace mod))) - -(define ((enter-load/use-compiled orig re?) path name) - (when (inhibit-eval) - (raise (make-exn:fail "namespace not found" - (current-continuation-marks)))) - (if name - ;; Module load: - (let ([code (get-module-code path "compiled" compile - (lambda (ext loader?) - (load-extension ext) - #f) - #:notify (lambda (chosen) - (notify re? chosen)))] - [path (normal-case-path - (simplify-path - (path->complete-path path - (or (current-load-relative-directory) - (current-directory)))))]) - ;; Record module timestamp and dependencies: - (let ([mod (make-mod name - (get-timestamp path) - (if code - (apply append - (map cdr (module-compiled-imports code))) - null))]) - (hash-set! loaded path mod)) - ;; Evaluate the module: - (eval code)) - ;; Not a module: - (begin - (notify re? path) - (orig path name)))) - -(define (get-timestamp path) - (file-or-directory-modify-seconds path #f (lambda () -inf.0))) - -(define (check-latest mod) - (let ([mpi (module-path-index-join mod #f)] - [done (make-hash)]) - (let loop ([mpi mpi]) - (let* ([rpath (module-path-index-resolve mpi)] - [path (resolved-module-path-name rpath)]) - (when (path? path) - (let ([path (normal-case-path path)]) - (unless (hash-ref done path #f) - (hash-set! done path #t) - (let ([mod (hash-ref loaded path #f)]) - (when mod - (for-each loop (mod-depends mod)) - (let ([ts (get-timestamp path)]) - (when (ts . > . (mod-timestamp mod)) - (let ([orig (current-load/use-compiled)]) - (parameterize ([current-load/use-compiled - (enter-load/use-compiled orig #f)] - [current-module-declare-name rpath]) - ((enter-load/use-compiled orig #t) - path - (mod-name mod))))))))))))))) - -;;; enter.rkt ends here diff --git a/scheme/plt/geiser/eval.rkt b/scheme/plt/geiser/eval.rkt deleted file mode 100644 index cef6130..0000000 --- a/scheme/plt/geiser/eval.rkt +++ /dev/null @@ -1,81 +0,0 @@ -;;; eval.rkt -- evaluation - -;; Copyright (C) 2009, 2010 Jose Antonio Ortega Ruiz - -;; This program is free software; you can redistribute it and/or -;; modify it under the terms of the Modified BSD License. You should -;; have received a copy of the license along with this program. If -;; not, see . - -;; Start date: Sun Apr 26, 2009 00:44 - -#lang scheme - -(provide eval-in - compile-in - load-file - compile-file - macroexpand - make-repl-reader) - -(require scheme/enter geiser/modules geiser/autodoc) - -(define last-result (void)) - -(define namespace->module-name - (compose module-path-name->name namespace->module-path-name)) - -(define last-namespace (make-parameter (current-namespace))) - -(define (exn-key e) - (vector-ref (struct->vector e) 0)) - -(define (set-last-error e) - (set! last-result `((error (key . ,(exn-key e))))) - (display (exn-message e))) - -(define (write-value v) - (with-output-to-string - (lambda () (write v)))) - -(define (set-last-result . vs) - (set! last-result `((result ,@(map write-value vs))))) - -(define (call-with-result thunk) - (set-last-result (void)) - (let ((output - (with-output-to-string - (lambda () - (with-handlers ((exn? set-last-error)) - (call-with-values thunk set-last-result)))))) - (append last-result `((output . ,output))))) - -(define (eval-in form spec lang) - (call-with-result - (lambda () - (update-signature-cache spec form) - (eval form (module-spec->namespace spec lang))))) - -(define compile-in eval-in) - -(define (load-file file) - (call-with-result - (lambda () - (load-module file (current-output-port) (last-namespace)) - (update-signature-cache file)))) - -(define compile-file load-file) - -(define (macroexpand form . all) - (let ((all (and (not (null? all)) (car all)))) - (with-output-to-string - (lambda () - (pretty-print (syntax->datum ((if all expand expand-once) form))))))) - -(define (make-repl-reader builtin-reader) - (lambda (ns) - (last-namespace ns) - (printf "racket@~a" (namespace->module-name ns)) - (builtin-reader))) - -;;; eval.rkt ends here diff --git a/scheme/plt/geiser/locations.rkt b/scheme/plt/geiser/locations.rkt deleted file mode 100644 index bae7122..0000000 --- a/scheme/plt/geiser/locations.rkt +++ /dev/null @@ -1,54 +0,0 @@ -;;; locations.rkt -- locating symbols - -;; Copyright (C) 2009, 2010 Jose Antonio Ortega Ruiz - -;; This program is free software; you can redistribute it and/or -;; modify it under the terms of the Modified BSD License. You should -;; have received a copy of the license along with this program. If -;; not, see . - -;; Start date: Sun Apr 26, 2009 19:43 - -#lang scheme - -(provide symbol-location - symbol-location* - module-location - symbol-module-name - symbol-module-path-name) - -(require geiser/utils geiser/modules) - -(define (symbol-location* sym) - (let* ((id (namespace-symbol->identifier sym)) - (binding (and id (identifier-binding id)))) - (if (list? binding) - (cons - (cadr binding) - (resolved-module-path-name - (module-path-index-resolve (car binding)))) - (cons sym #f)))) - -(define (make-location name path line) - (list (cons 'name name) - (cons 'file (if (path? path) (path->string path) '())) - (cons 'line (or line '())))) - -(define (symbol-location sym) - (let* ((loc (symbol-location* sym)) - (name (car loc)) - (path (cdr loc))) - (if path - (make-location name path #f) - (module-location sym)))) - -(define symbol-module-path-name (compose cdr symbol-location*)) - -(define symbol-module-name - (compose module-path-name->name symbol-module-path-name)) - -(define (module-location sym) - (make-location sym (module-spec->path-name sym) 1)) - - -;;; locations.rkt ends here diff --git a/scheme/plt/geiser/main.rkt b/scheme/plt/geiser/main.rkt deleted file mode 100644 index d6ff332..0000000 --- a/scheme/plt/geiser/main.rkt +++ /dev/null @@ -1,47 +0,0 @@ -;;; main.rkt -- exported interface for emacs - -;; Copyright (C) 2010 Jose Antonio Ortega Ruiz - -;; This program is free software; you can redistribute it and/or -;; modify it under the terms of the Modified BSD License. You should -;; have received a copy of the license along with this program. If -;; not, see . - -;; Start date: Wed Mar 31, 2010 21:14 - -#lang scheme/base - -(provide geiser:eval - geiser:compile - geiser:load-file - geiser:compile-file - geiser:macroexpand - geiser:completions - geiser:module-completions - geiser:symbol-location - geiser:module-location - geiser:module-exports - geiser:autodoc - geiser:help) - -(require geiser/eval - geiser/modules - geiser/completions - geiser/locations - geiser/autodoc) - -(define (geiser:eval lang) - (lambda (form spec) (eval-in form spec lang))) -(define geiser:compile compile-in) -(define geiser:load-file load-file) -(define geiser:compile-file compile-file) -(define geiser:autodoc autodoc) -(define geiser:help get-help) -(define geiser:completions symbol-completions) -(define geiser:module-completions module-completions) -(define geiser:symbol-location symbol-location) -(define geiser:module-location module-location) -(define geiser:module-exports module-exports) -(define geiser:macroexpand macroexpand) - -;;; main.rkt ends here diff --git a/scheme/plt/geiser/modules.rkt b/scheme/plt/geiser/modules.rkt deleted file mode 100644 index 2de8e35..0000000 --- a/scheme/plt/geiser/modules.rkt +++ /dev/null @@ -1,150 +0,0 @@ -;;; modules.rkt -- module metadata - -;; Copyright (C) 2009, 2010 Jose Antonio Ortega Ruiz - -;; This program is free software; you can redistribute it and/or -;; modify it under the terms of the Modified BSD License. You should -;; have received a copy of the license along with this program. If -;; not, see . - -;; Start date: Wed May 06, 2009 02:35 - -#lang scheme - -(provide load-module - ensure-module-spec - module-spec->namespace - namespace->module-path-name - module-path-name->name - module-spec->path-name - module-list - module-exports) - -(require srfi/13 syntax/modresolve syntax/modcode geiser/enter) - -(define (ensure-module-spec spec) - (cond ((symbol? spec) spec) - ((not (string? spec)) #f) - (else `(file ,spec)))) - -(define (module-spec->namespace spec (lang #f)) - (let ((spec (ensure-module-spec spec)) - (try-lang (lambda (_) - (with-handlers ((exn? (const (current-namespace)))) - (and lang - (begin - (load-module lang #f (current-namespace)) - (module->namespace lang))))))) - (or (and spec - (with-handlers ((exn? try-lang)) (get-namespace spec))) - (current-namespace)))) - -(define nowhere (open-output-nowhere)) - -(define (load-module spec (port #f) (ns #f)) - (parameterize ((current-error-port (or port nowhere))) - (enter-module (ensure-module-spec spec)) - (when (namespace? ns) - (current-namespace ns)))) - -(define (namespace->module-path-name ns) - (let ((rmp (variable-reference->resolved-module-path - (eval '(#%variable-reference) ns)))) - (and (resolved-module-path? rmp) - (resolved-module-path-name rmp)))) - -(define (module-spec->path-name spec) - (with-handlers ((exn? (lambda (_) #f))) - (let ((ns (module-spec->namespace (ensure-module-spec spec)))) - (namespace->module-path-name ns)))) - -(define (module-path-name->name path) - (cond ((path? path) - (let* ((path (path->string path)) - (cpaths (map (compose path->string path->directory-path) - (current-library-collection-paths))) - (prefix-len (lambda (p) - (let ((pl (string-length p))) - (if (= pl (string-prefix-length p path)) - pl - 0)))) - (lens (map prefix-len cpaths)) - (real-path (substring path (apply max lens)))) - (if (absolute-path? real-path) - (call-with-values (lambda () (split-path path)) - (lambda (_ basename __) (path->string basename))) - (regexp-replace "\\.[^./]*$" real-path "")))) - ((eq? path '#%kernel) "(kernel)") - ((string? path) path) - ((symbol? path) (symbol->string path)) - (else ""))) - -(define (skippable-dir? path) - (call-with-values (lambda () (split-path path)) - (lambda (_ basename __) - (member (path->string basename) '(".svn" "compiled"))))) - -(define path->symbol (compose string->symbol path->string)) - -(define (path->entry path) - (let ((ext (filename-extension path))) - (and ext - (or (bytes=? ext #"rkt") (bytes=? ext #"ss")) - (let ((path (path->string path))) - (substring path 0 (- (string-length path) 3)))))) - -(define (visit-module-path path kind acc) - (case kind - ((file) (let ((entry (path->entry path))) - (if entry (cons entry acc) acc))) - ((dir) (cond ((skippable-dir? path) (values acc #f)) - ((or (file-exists? (build-path path "main.rkt")) - (file-exists? (build-path path "main.ss"))) - (cons (path->string path) acc)) - (else acc))) - (else acc))) - -(define (find-modules path acc) - (if (directory-exists? path) - (parameterize ((current-directory path)) - (fold-files visit-module-path acc)) - acc)) - -(define (known-modules) - (sort (foldl find-modules '() (current-library-collection-paths)) stringnamespace mod)))))) - -(define (startup) - (thread update-module-cache) - (void)) - -(startup) - -;;; modules.rkt ends here diff --git a/scheme/plt/geiser/user.rkt b/scheme/plt/geiser/user.rkt deleted file mode 100644 index 19b1e1b..0000000 --- a/scheme/plt/geiser/user.rkt +++ /dev/null @@ -1,57 +0,0 @@ -;;; user.rkt -- global bindings visible to geiser users - -;; Copyright (C) 2010 Jose Antonio Ortega Ruiz - -;; This program is free software; you can redistribute it and/or -;; modify it under the terms of the Modified BSD License. You should -;; have received a copy of the license along with this program. If -;; not, see . - -;; Start date: Wed Mar 31, 2010 22:24 - -#lang scheme/base - -(provide enter!) - -(require geiser/enter geiser/eval (for-syntax scheme/base)) - -(define-syntax (enter! stx) - (syntax-case stx () - [(enter! mod) - (if (or (not (syntax-e #'mod)) - (module-path? (syntax->datum #'mod))) - #'(do-enter! 'mod) - (raise-syntax-error - #f - "not a valid module path, and not #f" - stx - #'mod))] - [_ (raise-syntax-error - #f - "bad syntax; should be `(enter! )'" - stx)])) - -(define orig-namespace (current-namespace)) - -(define (do-enter! mod) - (if mod - (begin - (enter-module mod) - (let ([ns (module->namespace mod)]) - (current-namespace ns) - (namespace-require 'geiser/user))) - (current-namespace orig-namespace))) - - -(define orig-loader (current-load/use-compiled)) - -(define (init) - (compile-enforce-module-constants #f) - (current-load/use-compiled (module-loader orig-loader)) - (current-prompt-read (compose (make-repl-reader (current-prompt-read)) - current-namespace))) - -(init) - -;;; user.rkt ends here - diff --git a/scheme/plt/geiser/utils.rkt b/scheme/plt/geiser/utils.rkt deleted file mode 100644 index f6c739c..0000000 --- a/scheme/plt/geiser/utils.rkt +++ /dev/null @@ -1,27 +0,0 @@ -;;; utils.rkt -- generic utilities - -;; Copyright (C) 2009, 2010 Jose Antonio Ortega Ruiz - -;; This program is free software; you can redistribute it and/or -;; modify it under the terms of the Modified BSD License. You should -;; have received a copy of the license along with this program. If -;; not, see . - -;; Start date: Sun May 03, 2009 03:09 - -#lang scheme - -(provide pair->list - keyword->symbol - symbol->keyword) - -(define (pair->list pair) - (let loop ((d pair) (s '())) - (cond ((null? d) (reverse s)) - ((symbol? d) (reverse (cons d s))) - (else (loop (cdr d) (cons (car d) s)))))) - -(define keyword->symbol (compose string->symbol keyword->string)) -(define (symbol->keyword sym) (string->keyword (format "~a" sym))) - -;;; utils.rkt ends here diff --git a/scheme/racket/geiser.rkt b/scheme/racket/geiser.rkt new file mode 100644 index 0000000..45d1289 --- /dev/null +++ b/scheme/racket/geiser.rkt @@ -0,0 +1,22 @@ +;;; geiser.rkt -- entry point + +;; Copyright (C) 2009, 2010 Jose Antonio Ortega Ruiz + +;; This program is free software; you can redistribute it and/or +;; modify it under the terms of the Modified BSD License. You should +;; have received a copy of the license along with this program. If +;; not, see . + +;; Start date: Sat Apr 25, 2009 22:36 + +;;; Code: + +(require version/utils) +(unless (version<=? "5.0" (version)) + (error 'geiser + "Racket version 5.0 or better required (found ~a)" + (version))) + +(require geiser/user) + +;;; geiser.rkt ends here diff --git a/scheme/racket/geiser/autodoc.rkt b/scheme/racket/geiser/autodoc.rkt new file mode 100644 index 0000000..0bb850d --- /dev/null +++ b/scheme/racket/geiser/autodoc.rkt @@ -0,0 +1,189 @@ +;;; autodoc.rkt -- suport for autodoc echo + +;; Copyright (C) 2009, 2010 Jose Antonio Ortega Ruiz + +;; This program is free software; you can redistribute it and/or +;; modify it under the terms of the Modified BSD License. You should +;; have received a copy of the license along with this program. If +;; not, see . + +;; Start date: Sun May 03, 2009 14:45 + +#lang racket + +(provide autodoc update-signature-cache get-help) + +(require geiser/utils geiser/modules geiser/locations scheme/help) + +(define (get-help symbol mod) + (with-handlers ((exn? (lambda (_) + (eval `(help ,symbol))))) + (eval `(help ,symbol #:from ,(ensure-module-spec mod))))) + +(define (autodoc ids) + (if (not (list? ids)) + '() + (map (lambda (id) (or (autodoc* id) (list id))) ids))) + +(define (autodoc* id) + (and + (symbol? id) + (let* ((loc (symbol-location* id)) + (name (car loc)) + (path (cdr loc)) + (sgns (and path (find-signatures path name id))) + (sgns (and sgns (if (list? sgns) sgns '())))) + (and sgns + `(,id + (name . ,name) + (args ,@(map format-signature sgns)) + (module . ,(module-path-name->name path))))))) + +(define (format-signature sign) + (if (signature? sign) + `((required ,@(signature-required sign)) + (optional ,@(signature-optional sign) + ,@(let ((rest (signature-rest sign))) + (if rest (list "...") '()))) + (key ,@(signature-keys sign))) + '())) + +(define signatures (make-hash)) + +(define-struct signature (required optional keys rest)) + +(define (find-signatures path name local-name) + (let ((path (if (path? path) (path->string path) path))) + (hash-ref! (hash-ref! signatures + path + (lambda () (parse-signatures path))) + name + (lambda () (infer-signatures local-name))))) + +(define (parse-signatures path) + (let ((result (make-hasheq))) + (with-handlers ((exn? (lambda (e) result))) + (with-input-from-file path + (lambda () + (parameterize ((read-accept-reader #t)) + (let loop ((stx (read-syntax path))) + (cond ((eof-object? stx) void) + ((syntax->datum stx) => + (lambda (datum) + (parse-datum! datum result) + (loop (read-syntax path)))) + (else void))))))) + result)) + +(define (parse-datum! datum store) + (with-handlers ((exn? (lambda (_) void))) + (match datum + (`(module ,name ,lang (#%module-begin . ,forms)) + (for-each (lambda (f) (parse-datum! f store)) forms)) + (`(module ,name ,lang . ,forms) + (for-each (lambda (f) (parse-datum! f store)) forms)) + (`(define ((,name . ,formals) . ,_) . ,_) + (add-signature! name formals store)) + (`(define (,name . ,formals) . ,_) + (add-signature! name formals store)) + (`(define ,name (lambda ,formals . ,_)) + (add-signature! name formals store)) + (`(define ,name (case-lambda ,clauses ...)) + (for-each (lambda (c) (add-signature! name (car c) store)) + (reverse clauses))) + (`(define-for-syntax (,name . ,formals) . ,_) + (add-signature! name formals store)) + (`(define-for-syntax ,name (lambda ,formals . ,_)) + (add-signature! name formals store)) + (`(define-syntax-rule (,name . ,formals) . ,_) + (add-signature! name formals store)) + (`(define-syntax ,name (syntax-rules ,specials . ,clauses)) + (for-each (lambda (c) (add-signature! name (cdar c) store)) + (reverse clauses))) + (`(define-syntax ,name (lambda ,_ (syntax-case ,_ . ,clauses))) + (for-each (lambda (c) (add-signature! name (cdar c) store)) + (reverse clauses))) + (_ void)))) + +(define (add-signature! name formals store) + (when (symbol? name) + (hash-set! store + name + (cons (parse-formals formals) + (hash-ref store name '()))))) + +(define (parse-formals formals) + (let loop ((formals formals) (req '()) (opt '()) (keys '())) + (cond ((null? formals) + (make-signature (reverse req) (reverse opt) (reverse keys) #f)) + ((symbol? formals) + (make-signature (reverse req) (reverse opt) + (reverse keys) formals)) + ((pair? (car formals)) (loop (cdr formals) + req + (cons (car formals) opt) + keys)) + ((keyword? (car formals)) (let* ((kname + (keyword->symbol (car formals))) + (arg-id (cadr formals)) + (name (if (pair? arg-id) + (list kname + (cadr arg-id)) + kname))) + (loop (cddr formals) + req + opt + (cons name keys)))) + (else (loop (cdr formals) (cons (car formals) req) opt keys))))) + +(define (infer-signatures name) + (define syntax-tag (cons 1 0)) + (define error-tag (cons 1 1)) + (define generic-signature (make-signature '(...) '() '() #f)) + (let ((value (with-handlers ((exn:fail:syntax? (lambda (_) syntax-tag)) + (exn:fail:contract:variable? (lambda (_) + error-tag))) + (namespace-variable-value name)))) + (cond ((procedure? value) (arity->signatures (procedure-arity value))) + ((eq? value syntax-tag) (list generic-signature)) + ((eq? value error-tag) #f) + (else 'variable)))) + +(define (arity->signatures arity) + (define (args fst count) + (let* ((letts (list->vector '(#\x #\y #\z #\u #\v #\w #\r #\s))) + (len (vector-length letts)) + (lett (lambda (n) (vector-ref letts (modulo n len))))) + (map (lambda (n) (string->symbol (format "~a" (lett n)))) + (build-list count (lambda (n) (+ n fst)))))) + (define (arity->signature arity) + (cond ((number? arity) + (make-signature (args 0 arity) '() '() #f)) + ((arity-at-least? arity) + (make-signature (args 0 (arity-at-least-value arity)) + '() '() 'rest)))) + (define (conseq? lst) + (cond ((< (length lst) 2) (number? (car lst))) + ((and (number? (car lst)) + (number? (cadr lst)) + (eqv? (+ 1 (car lst)) (cadr lst))) + (conseq? (cdr lst))) + (else #f))) + (cond ((and (list? arity) (conseq? arity)) + (let ((mi (apply min arity)) + (ma (apply max arity))) + (list (make-signature (args 0 mi) (args mi (- ma mi)) '() #f)))) + ((list? arity) (map arity->signature arity)) + (else (list (arity->signature arity))))) + +(define (update-signature-cache path . form) + (when (and (string? path) + (or (null? form) + (and (list? (car form)) + (not (null? (car form))) + (memq (caar form) + '(define-syntax-rule + define-syntax define set! define-struct))))) + (hash-remove! signatures path))) + +;;; autodoc.rkt ends here diff --git a/scheme/racket/geiser/completions.rkt b/scheme/racket/geiser/completions.rkt new file mode 100644 index 0000000..4cbc09f --- /dev/null +++ b/scheme/racket/geiser/completions.rkt @@ -0,0 +1,31 @@ +;;; completions.rkt -- completion support + +;; Copyright (C) 2009, 2010 Jose Antonio Ortega Ruiz + +;; This program is free software; you can redistribute it and/or +;; modify it under the terms of the Modified BSD License. You should +;; have received a copy of the license along with this program. If +;; not, see . + +;; Start date: Sun Apr 26, 2009 19:02 + +#lang racket + +(provide symbol-completions + module-completions) + +(require srfi/13 geiser/utils geiser/modules) + +(define (filter-prefix prefix lst sort?) + (filter (lambda (s) (string-prefix? prefix s)) + (if sort? (sort lst stringstring (namespace-mapped-symbols)) + #t)) + +(define (module-completions prefix) + (filter-prefix prefix (module-list) #f)) + +;;; completions.rkt ends here diff --git a/scheme/racket/geiser/enter.rkt b/scheme/racket/geiser/enter.rkt new file mode 100644 index 0000000..eff37f6 --- /dev/null +++ b/scheme/racket/geiser/enter.rkt @@ -0,0 +1,103 @@ +;;; enter.rkt -- custom module loaders + +;; Copyright (C) 2010 Jose Antonio Ortega Ruiz + +;; This program is free software; you can redistribute it and/or +;; modify it under the terms of the Modified BSD License. You should +;; have received a copy of the license along with this program. If +;; not, see . + +;; Start date: Wed Mar 31, 2010 21:53 + +#lang racket/base + +(require syntax/modcode + (for-syntax scheme/base)) + +(provide get-namespace enter-module module-loader module-loaded?) + +(define-struct mod (name timestamp depends)) + +(define loaded (make-hash)) + +(define (module-loaded? path) + (with-handlers ((exn? (lambda (_) #f))) + (let ((rp (module-path-index-resolve (module-path-index-join path #f)))) + (hash-has-key? loaded (resolved-module-path-name rp))))) + +(define (enter-module mod) + (dynamic-require mod #f) + (check-latest mod)) + +(define (module-loader orig) + (enter-load/use-compiled orig #f)) + +(define (notify re? path) + (when re? + (fprintf (current-error-port) " [re-loading ~a]\n" path))) + +(define inhibit-eval (make-parameter #f)) + +(define (get-namespace mod) + (parameterize ([inhibit-eval #t]) + (module->namespace mod))) + +(define ((enter-load/use-compiled orig re?) path name) + (when (inhibit-eval) + (raise (make-exn:fail "namespace not found" + (current-continuation-marks)))) + (if name + ;; Module load: + (let ([code (get-module-code path "compiled" compile + (lambda (ext loader?) + (load-extension ext) + #f) + #:notify (lambda (chosen) + (notify re? chosen)))] + [path (normal-case-path + (simplify-path + (path->complete-path path + (or (current-load-relative-directory) + (current-directory)))))]) + ;; Record module timestamp and dependencies: + (let ([mod (make-mod name + (get-timestamp path) + (if code + (apply append + (map cdr (module-compiled-imports code))) + null))]) + (hash-set! loaded path mod)) + ;; Evaluate the module: + (eval code)) + ;; Not a module: + (begin + (notify re? path) + (orig path name)))) + +(define (get-timestamp path) + (file-or-directory-modify-seconds path #f (lambda () -inf.0))) + +(define (check-latest mod) + (let ([mpi (module-path-index-join mod #f)] + [done (make-hash)]) + (let loop ([mpi mpi]) + (let* ([rpath (module-path-index-resolve mpi)] + [path (resolved-module-path-name rpath)]) + (when (path? path) + (let ([path (normal-case-path path)]) + (unless (hash-ref done path #f) + (hash-set! done path #t) + (let ([mod (hash-ref loaded path #f)]) + (when mod + (for-each loop (mod-depends mod)) + (let ([ts (get-timestamp path)]) + (when (ts . > . (mod-timestamp mod)) + (let ([orig (current-load/use-compiled)]) + (parameterize ([current-load/use-compiled + (enter-load/use-compiled orig #f)] + [current-module-declare-name rpath]) + ((enter-load/use-compiled orig #t) + path + (mod-name mod))))))))))))))) + +;;; enter.rkt ends here diff --git a/scheme/racket/geiser/eval.rkt b/scheme/racket/geiser/eval.rkt new file mode 100644 index 0000000..e0bcffa --- /dev/null +++ b/scheme/racket/geiser/eval.rkt @@ -0,0 +1,81 @@ +;;; eval.rkt -- evaluation + +;; Copyright (C) 2009, 2010 Jose Antonio Ortega Ruiz + +;; This program is free software; you can redistribute it and/or +;; modify it under the terms of the Modified BSD License. You should +;; have received a copy of the license along with this program. If +;; not, see . + +;; Start date: Sun Apr 26, 2009 00:44 + +#lang racket + +(provide eval-in + compile-in + load-file + compile-file + macroexpand + make-repl-reader) + +(require scheme/enter geiser/modules geiser/autodoc) + +(define last-result (void)) + +(define namespace->module-name + (compose module-path-name->name namespace->module-path-name)) + +(define last-namespace (make-parameter (current-namespace))) + +(define (exn-key e) + (vector-ref (struct->vector e) 0)) + +(define (set-last-error e) + (set! last-result `((error (key . ,(exn-key e))))) + (display (exn-message e))) + +(define (write-value v) + (with-output-to-string + (lambda () (write v)))) + +(define (set-last-result . vs) + (set! last-result `((result ,@(map write-value vs))))) + +(define (call-with-result thunk) + (set-last-result (void)) + (let ((output + (with-output-to-string + (lambda () + (with-handlers ((exn? set-last-error)) + (call-with-values thunk set-last-result)))))) + (append last-result `((output . ,output))))) + +(define (eval-in form spec lang) + (call-with-result + (lambda () + (update-signature-cache spec form) + (eval form (module-spec->namespace spec lang))))) + +(define compile-in eval-in) + +(define (load-file file) + (call-with-result + (lambda () + (load-module file (current-output-port) (last-namespace)) + (update-signature-cache file)))) + +(define compile-file load-file) + +(define (macroexpand form . all) + (let ((all (and (not (null? all)) (car all)))) + (with-output-to-string + (lambda () + (pretty-print (syntax->datum ((if all expand expand-once) form))))))) + +(define (make-repl-reader builtin-reader) + (lambda (ns) + (last-namespace ns) + (printf "racket@~a" (namespace->module-name ns)) + (builtin-reader))) + +;;; eval.rkt ends here diff --git a/scheme/racket/geiser/locations.rkt b/scheme/racket/geiser/locations.rkt new file mode 100644 index 0000000..b4c0f37 --- /dev/null +++ b/scheme/racket/geiser/locations.rkt @@ -0,0 +1,54 @@ +;;; locations.rkt -- locating symbols + +;; Copyright (C) 2009, 2010 Jose Antonio Ortega Ruiz + +;; This program is free software; you can redistribute it and/or +;; modify it under the terms of the Modified BSD License. You should +;; have received a copy of the license along with this program. If +;; not, see . + +;; Start date: Sun Apr 26, 2009 19:43 + +#lang racket + +(provide symbol-location + symbol-location* + module-location + symbol-module-name + symbol-module-path-name) + +(require geiser/utils geiser/modules) + +(define (symbol-location* sym) + (let* ((id (namespace-symbol->identifier sym)) + (binding (and id (identifier-binding id)))) + (if (list? binding) + (cons + (cadr binding) + (resolved-module-path-name + (module-path-index-resolve (car binding)))) + (cons sym #f)))) + +(define (make-location name path line) + (list (cons 'name name) + (cons 'file (if (path? path) (path->string path) '())) + (cons 'line (or line '())))) + +(define (symbol-location sym) + (let* ((loc (symbol-location* sym)) + (name (car loc)) + (path (cdr loc))) + (if path + (make-location name path #f) + (module-location sym)))) + +(define symbol-module-path-name (compose cdr symbol-location*)) + +(define symbol-module-name + (compose module-path-name->name symbol-module-path-name)) + +(define (module-location sym) + (make-location sym (module-spec->path-name sym) 1)) + + +;;; locations.rkt ends here diff --git a/scheme/racket/geiser/main.rkt b/scheme/racket/geiser/main.rkt new file mode 100644 index 0000000..de1c21c --- /dev/null +++ b/scheme/racket/geiser/main.rkt @@ -0,0 +1,47 @@ +;;; main.rkt -- exported interface for emacs + +;; Copyright (C) 2010 Jose Antonio Ortega Ruiz + +;; This program is free software; you can redistribute it and/or +;; modify it under the terms of the Modified BSD License. You should +;; have received a copy of the license along with this program. If +;; not, see . + +;; Start date: Wed Mar 31, 2010 21:14 + +#lang racket/base + +(provide geiser:eval + geiser:compile + geiser:load-file + geiser:compile-file + geiser:macroexpand + geiser:completions + geiser:module-completions + geiser:symbol-location + geiser:module-location + geiser:module-exports + geiser:autodoc + geiser:help) + +(require geiser/eval + geiser/modules + geiser/completions + geiser/locations + geiser/autodoc) + +(define (geiser:eval lang) + (lambda (form spec) (eval-in form spec lang))) +(define geiser:compile compile-in) +(define geiser:load-file load-file) +(define geiser:compile-file compile-file) +(define geiser:autodoc autodoc) +(define geiser:help get-help) +(define geiser:completions symbol-completions) +(define geiser:module-completions module-completions) +(define geiser:symbol-location symbol-location) +(define geiser:module-location module-location) +(define geiser:module-exports module-exports) +(define geiser:macroexpand macroexpand) + +;;; main.rkt ends here diff --git a/scheme/racket/geiser/modules.rkt b/scheme/racket/geiser/modules.rkt new file mode 100644 index 0000000..0de316c --- /dev/null +++ b/scheme/racket/geiser/modules.rkt @@ -0,0 +1,150 @@ +;;; modules.rkt -- module metadata + +;; Copyright (C) 2009, 2010 Jose Antonio Ortega Ruiz + +;; This program is free software; you can redistribute it and/or +;; modify it under the terms of the Modified BSD License. You should +;; have received a copy of the license along with this program. If +;; not, see . + +;; Start date: Wed May 06, 2009 02:35 + +#lang racket + +(provide load-module + ensure-module-spec + module-spec->namespace + namespace->module-path-name + module-path-name->name + module-spec->path-name + module-list + module-exports) + +(require srfi/13 syntax/modresolve syntax/modcode geiser/enter) + +(define (ensure-module-spec spec) + (cond ((symbol? spec) spec) + ((not (string? spec)) #f) + (else `(file ,spec)))) + +(define (module-spec->namespace spec (lang #f)) + (let ((spec (ensure-module-spec spec)) + (try-lang (lambda (_) + (with-handlers ((exn? (const (current-namespace)))) + (and lang + (begin + (load-module lang #f (current-namespace)) + (module->namespace lang))))))) + (or (and spec + (with-handlers ((exn? try-lang)) (get-namespace spec))) + (current-namespace)))) + +(define nowhere (open-output-nowhere)) + +(define (load-module spec (port #f) (ns #f)) + (parameterize ((current-error-port (or port nowhere))) + (enter-module (ensure-module-spec spec)) + (when (namespace? ns) + (current-namespace ns)))) + +(define (namespace->module-path-name ns) + (let ((rmp (variable-reference->resolved-module-path + (eval '(#%variable-reference) ns)))) + (and (resolved-module-path? rmp) + (resolved-module-path-name rmp)))) + +(define (module-spec->path-name spec) + (with-handlers ((exn? (lambda (_) #f))) + (let ((ns (module-spec->namespace (ensure-module-spec spec)))) + (namespace->module-path-name ns)))) + +(define (module-path-name->name path) + (cond ((path? path) + (let* ((path (path->string path)) + (cpaths (map (compose path->string path->directory-path) + (current-library-collection-paths))) + (prefix-len (lambda (p) + (let ((pl (string-length p))) + (if (= pl (string-prefix-length p path)) + pl + 0)))) + (lens (map prefix-len cpaths)) + (real-path (substring path (apply max lens)))) + (if (absolute-path? real-path) + (call-with-values (lambda () (split-path path)) + (lambda (_ basename __) (path->string basename))) + (regexp-replace "\\.[^./]*$" real-path "")))) + ((eq? path '#%kernel) "(kernel)") + ((string? path) path) + ((symbol? path) (symbol->string path)) + (else ""))) + +(define (skippable-dir? path) + (call-with-values (lambda () (split-path path)) + (lambda (_ basename __) + (member (path->string basename) '(".svn" "compiled"))))) + +(define path->symbol (compose string->symbol path->string)) + +(define (path->entry path) + (let ((ext (filename-extension path))) + (and ext + (or (bytes=? ext #"rkt") (bytes=? ext #"ss")) + (let ((path (path->string path))) + (substring path 0 (- (string-length path) 3)))))) + +(define (visit-module-path path kind acc) + (case kind + ((file) (let ((entry (path->entry path))) + (if entry (cons entry acc) acc))) + ((dir) (cond ((skippable-dir? path) (values acc #f)) + ((or (file-exists? (build-path path "main.rkt")) + (file-exists? (build-path path "main.ss"))) + (cons (path->string path) acc)) + (else acc))) + (else acc))) + +(define (find-modules path acc) + (if (directory-exists? path) + (parameterize ((current-directory path)) + (fold-files visit-module-path acc)) + acc)) + +(define (known-modules) + (sort (foldl find-modules '() (current-library-collection-paths)) stringnamespace mod)))))) + +(define (startup) + (thread update-module-cache) + (void)) + +(startup) + +;;; modules.rkt ends here diff --git a/scheme/racket/geiser/user.rkt b/scheme/racket/geiser/user.rkt new file mode 100644 index 0000000..3c1d93e --- /dev/null +++ b/scheme/racket/geiser/user.rkt @@ -0,0 +1,56 @@ +;;; user.rkt -- global bindings visible to geiser users + +;; Copyright (C) 2010 Jose Antonio Ortega Ruiz + +;; This program is free software; you can redistribute it and/or +;; modify it under the terms of the Modified BSD License. You should +;; have received a copy of the license along with this program. If +;; not, see . + +;; Start date: Wed Mar 31, 2010 22:24 + +#lang racket/base + +(provide enter!) + +(require geiser/enter geiser/eval (for-syntax scheme/base)) + +(define-syntax (enter! stx) + (syntax-case stx () + [(enter! mod) + (if (or (not (syntax-e #'mod)) + (module-path? (syntax->datum #'mod))) + #'(do-enter! 'mod) + (raise-syntax-error + #f + "not a valid module path, and not #f" + stx + #'mod))] + [_ (raise-syntax-error + #f + "bad syntax; should be `(enter! )'" + stx)])) + +(define orig-namespace (current-namespace)) + +(define (do-enter! mod) + (if mod + (begin + (enter-module mod) + (let ([ns (module->namespace mod)]) + (current-namespace ns) + (namespace-require 'geiser/user))) + (current-namespace orig-namespace))) + + +(define orig-loader (current-load/use-compiled)) + +(define (init) + (compile-enforce-module-constants #f) + (current-load/use-compiled (module-loader orig-loader)) + (current-prompt-read (compose (make-repl-reader (current-prompt-read)) + current-namespace))) + +(init) + +;;; user.rkt ends here diff --git a/scheme/racket/geiser/utils.rkt b/scheme/racket/geiser/utils.rkt new file mode 100644 index 0000000..730a396 --- /dev/null +++ b/scheme/racket/geiser/utils.rkt @@ -0,0 +1,27 @@ +;;; utils.rkt -- generic utilities + +;; Copyright (C) 2009, 2010 Jose Antonio Ortega Ruiz + +;; This program is free software; you can redistribute it and/or +;; modify it under the terms of the Modified BSD License. You should +;; have received a copy of the license along with this program. If +;; not, see . + +;; Start date: Sun May 03, 2009 03:09 + +#lang racket + +(provide pair->list + keyword->symbol + symbol->keyword) + +(define (pair->list pair) + (let loop ((d pair) (s '())) + (cond ((null? d) (reverse s)) + ((symbol? d) (reverse (cons d s))) + (else (loop (cdr d) (cons (car d) s)))))) + +(define keyword->symbol (compose string->symbol keyword->string)) +(define (symbol->keyword sym) (string->keyword (format "~a" sym))) + +;;; utils.rkt ends here -- cgit v1.2.3