diff options
-rw-r--r-- | README.org | 7 | ||||
-rw-r--r-- | doc/cheat.texi | 6 | ||||
-rw-r--r-- | elisp/geiser-edit.el | 41 | ||||
-rw-r--r-- | elisp/geiser-mode.el | 40 | ||||
-rw-r--r-- | elisp/geiser-repl.el | 6 | ||||
-rw-r--r-- | scheme/chez/geiser/geiser.ss | 18 | ||||
-rw-r--r-- | scheme/chez/geiser/test.ss | 33 |
7 files changed, 100 insertions, 51 deletions
@@ -79,7 +79,7 @@ ** Gambit Addendum These steps are necessary to fully support Gambit Scheme. - + 1 - clone the last version of gambit 2 - configure gambit using --enable-rtlib-debug-source to activate autodoc #+BEGIN_EXAMPLE @@ -145,6 +145,7 @@ | C-c C-e m | Ask for a module and open its file | | C-c C-e C-l | Add a given directory to Scheme's load path | | C-c C-e [ | Toggle between () and [] for current form | + | c-c C-e \ | Insert λ | | | | |-------------+--------------------------------------------------| | C-M-x | Eval definition around point | @@ -200,6 +201,10 @@ | M-p, M-n | Prompt history, matching current prefix | | | | |-------------+----------------------------------------------------| + | C-c \ | Insert λ | + | C-c [ | Toggle between () and [] for current form | + | | | + |-------------+----------------------------------------------------| | C-c C-m | Set current module | | C-c C-i | Import module into current namespace | | C-c C-r | Add a given directory to scheme's load path | diff --git a/doc/cheat.texi b/doc/cheat.texi index cbfe08d..f1ef04f 100644 --- a/doc/cheat.texi +++ b/doc/cheat.texi @@ -163,6 +163,12 @@ third key not modified by @key{Control}; e.g., @item M-`, C-. @tab @code{geiser-completion--complete-module} @tab Complete module name at point +@item C-c [, C-c C-[ +@tab @code{geiser-squarify} +@tab Toggle between () and [] for current form +@item C-c \, C-c C-\ +@tab @code{geiser-insert-lambda} +@tab Insert greek lambda or, with prefix, a lambda form @item C-c C-r @tab @code{geiser-add-to-load-path} @tab Ask for a directory and add to Scheme load path diff --git a/elisp/geiser-edit.el b/elisp/geiser-edit.el index c374c92..bca57a3 100644 --- a/elisp/geiser-edit.el +++ b/elisp/geiser-edit.el @@ -1,6 +1,6 @@ ;;; geiser-edit.el -- scheme edit locations -;; Copyright (C) 2009, 2010, 2012, 2013, 2019 Jose Antonio Ortega Ruiz +;; Copyright (C) 2009, 2010, 2012, 2013, 2019, 2020 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 @@ -259,7 +259,6 @@ With prefix, asks for the symbol to edit." (let ((cmd `(:eval (:ge module-location '(:module ,module))))) (geiser-edit--try-edit module (geiser-eval--send/wait cmd) method))) - (defun geiser-edit-module-at-point () "Opens a new window visiting the module at point." (interactive) @@ -268,6 +267,44 @@ With prefix, asks for the symbol to edit." (geiser-completion--read-module))) (when marker (xref-push-marker-stack)))) +(defun geiser-insert-lambda (&optional full) + "Insert λ at point. With prefix, inserts (λ ())." + (interactive "P") + (if (not full) + (insert (make-char 'greek-iso8859-7 107)) + (insert "(" (make-char 'greek-iso8859-7 107) " ())") + (backward-char 2))) + +(defun geiser-squarify (n) + "Toggle between () and [] for current form. + +With numeric prefix, perform that many toggles, forward for +positive values and backward for negative." + (interactive "p") + (let ((pared (and (boundp 'paredit-mode) paredit-mode)) + (fwd (> n 0)) + (steps (abs n))) + (when (and pared (fboundp 'paredit-mode)) (paredit-mode -1)) + (unwind-protect + (save-excursion + (unless (looking-at-p "\\s(") (backward-up-list)) + (while (> steps 0) + (let ((p (point)) + (round (looking-at-p "("))) + (forward-sexp) + (backward-delete-char 1) + (insert (if round "]" ")")) + (goto-char p) + (delete-char 1) + (insert (if round "[" "(")) + (setq steps (1- steps)) + (backward-char) + (condition-case nil + (progn (when fwd (forward-sexp 2)) + (backward-sexp)) + (error (setq steps 0)))))) + (when (and pared (fboundp 'paredit-mode)) (paredit-mode 1))))) + (provide 'geiser-edit) diff --git a/elisp/geiser-mode.el b/elisp/geiser-mode.el index 9a28b02..c8d28ad 100644 --- a/elisp/geiser-mode.el +++ b/elisp/geiser-mode.el @@ -1,6 +1,6 @@ ;; geiser-mode.el -- minor mode for scheme buffers -;; Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Jose Antonio Ortega Ruiz +;; Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2020 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 @@ -272,44 +272,6 @@ With prefix, try to enter the current buffer's module." (goto-char (point-max)) (pop-to-buffer b))) -(defun geiser-squarify (n) - "Toggle between () and [] for current form. - -With numeric prefix, perform that many toggles, forward for -positive values and backward for negative." - (interactive "p") - (let ((pared (and (boundp 'paredit-mode) paredit-mode)) - (fwd (> n 0)) - (steps (abs n))) - (when (and pared (fboundp 'paredit-mode)) (paredit-mode -1)) - (unwind-protect - (save-excursion - (unless (looking-at-p "\\s(") (backward-up-list)) - (while (> steps 0) - (let ((p (point)) - (round (looking-at-p "("))) - (forward-sexp) - (backward-delete-char 1) - (insert (if round "]" ")")) - (goto-char p) - (delete-char 1) - (insert (if round "[" "(")) - (setq steps (1- steps)) - (backward-char) - (condition-case nil - (progn (when fwd (forward-sexp 2)) - (backward-sexp)) - (error (setq steps 0)))))) - (when (and pared (fboundp 'paredit-mode)) (paredit-mode 1))))) - -(defun geiser-insert-lambda (&optional full) - "Insert λ at point. With prefix, inserts (λ ())." - (interactive "P") - (if (not full) - (insert (make-char 'greek-iso8859-7 107)) - (insert "(" (make-char 'greek-iso8859-7 107) " ())") - (backward-char 2))) - ;;; Geiser mode: diff --git a/elisp/geiser-repl.el b/elisp/geiser-repl.el index 9f400a3..18da072 100644 --- a/elisp/geiser-repl.el +++ b/elisp/geiser-repl.el @@ -1,6 +1,6 @@ ;;; geiser-repl.el --- Geiser's REPL -;; Copyright (C) 2009, 2010, 2011, 2012, 2013, 2015, 2016, 2018, 2019 Jose Antonio Ortega Ruiz +;; Copyright (C) 2009, 2010, 2011, 2012, 2013, 2015, 2016, 2018, 2019, 2020 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 @@ -824,6 +824,7 @@ buffer." (define-key geiser-repl-mode-map "\C-a" 'geiser-repl--bol) (define-key geiser-repl-mode-map (kbd "<home>") 'geiser-repl--bol) +(define-key geiser-repl-mode-map "\C-c" 'geiser-repl--bol) (geiser-menu--defmenu repl geiser-repl-mode-map ("Complete symbol" ((kbd "M-TAB")) @@ -862,6 +863,9 @@ buffer." -- ("Clear buffer" "\C-c\M-o" geiser-repl-clear-buffer "Clean up REPL buffer, leaving just a lonely prompt") + ("Toggle ()/[]" ("\C-c\C-e\C-[" "\C-c\C-e[") geiser-squarify) + ("Insert λ" ("\C-c\\" "\C-c\C-\\") geiser-insert-lambda) + -- ("Kill Scheme interpreter" "\C-c\C-q" geiser-repl-exit :enable (geiser-repl--live-p)) ("Restart" "\C-c\C-z" switch-to-geiser :enable (not (geiser-repl--live-p))) diff --git a/scheme/chez/geiser/geiser.ss b/scheme/chez/geiser/geiser.ss index 70b6b67..5c92a5b 100644 --- a/scheme/chez/geiser/geiser.ss +++ b/scheme/chez/geiser/geiser.ss @@ -5,7 +5,8 @@ geiser:autodoc geiser:no-values geiser:load-file - geiser:newline) + geiser:newline + geiser:macroexpand) (import (chezscheme)) (define (last-index-of str-list char idx last-idx) @@ -56,8 +57,8 @@ (k `((result "") (output . ,(get-output-string output-string)) (error (key . ,(with-output-to-string - (lambda () - (display-condition e)))))))) + (lambda () + (display-condition e)))))))) (lambda () (call-with-values ;; evaluate form, allow for multiple return values, @@ -69,9 +70,9 @@ (eval form)))) (lambda result `((result ,(with-output-to-string - (lambda () - (pretty-print - (if (null? (cdr result)) (car result) result))))) + (lambda () + (pretty-print + (if (null? (cdr result)) (car result) result))))) (output . ,(get-output-string output-string)))))))))) (newline) (close-output-port output-string))) @@ -145,4 +146,7 @@ #f) (define (geiser:newline) - #f)) + #f) + + (define (geiser:macroexpand form . rest) + (syntax->datum (expand form)))) diff --git a/scheme/chez/geiser/test.ss b/scheme/chez/geiser/test.ss index ac5503b..21f3396 100644 --- a/scheme/chez/geiser/test.ss +++ b/scheme/chez/geiser/test.ss @@ -1,13 +1,21 @@ (import (geiser) (chezscheme)) +(define-syntax assert-equal + (syntax-rules () + ((_ a b) + (if (equal? a b) + #t + (begin + (display (format "failed assertion `~a' == `~a'" a b)) + (assert (equal? a b))))))) (define-syntax get-result (syntax-rules () ((_ form) (with-output-to-string (lambda () - (geiser:eval #f form)))))) + (geiser:eval #f form)))))) (define-syntax do-test (syntax-rules () @@ -17,6 +25,29 @@ (get-result form) result))))) +(define-syntax do-test-macroexpand + (syntax-rules () + ((_ form result) + (assert + (equal? (geiser:macroexpand form) + result))))) + +(define-syntax test-or + (syntax-rules () + ((_ x) x) + ((_ x xs ...) + (if x + x + (test-or xs ...))))) + +(do-test-macroexpand + '(test-or 1) + '1) + +(do-test-macroexpand + '(test-or 1 2) + '(if 1 1 2)) + ;; (something-doesnot-exist) ;;=> Error: Exception: variable something-doesnot-exist is not bound (do-test |